feat(support-various-styling): add support for 3 styling types (closes #4)#9
feat(support-various-styling): add support for 3 styling types (closes #4)#9
Conversation
|
BTW, Sorry I was deep inside the code and forgot to commit features one at a time |
joshwcomeau
left a comment
There was a problem hiding this comment.
Omg this is awesome!!! Thanks so so much for your work on it, quality is fantastic. Both your PRs went above and beyond the requirements, so I really appreciate it :)
Don't worry about it all being 1 commit; I like to squash PRs before merging anyway, so it makes no difference to me.
I'm requesting changes for 1 main reason, and that's to add none as a valid styling type (where the templates would just do nothing, but support it as an option), where we still log it out.
I have a bunch of tiny nitpicks as well, but they should be really quick to implement.
I know you're busy so feel free to hand off this work to me, I can do the changes I requested. I'm in no rush, though, so if you want to wait and tackle it later, that's 100% cool with me as well.
Thanks Mohammad!
| CSS_MODULES: 'css-modules', | ||
| APHRODITE: 'aphrodite', | ||
| }; | ||
| module.exports.stylingTypes = stylingTypes; |
There was a problem hiding this comment.
Nit: I think we can just do module.exports.componentTypes = { ... }. Same for stylingTypes.
My reasoning is that I'm so used to ES6 exports... the fact that it's const stylingTypes and not export const stylingTypes made me think it wasn't exported... so having it connected directly to module.exports = would make it easier to tell at a glance.
There was a problem hiding this comment.
My reasoning is that I'm so used to ES6 exports
Me too.
They were like what you said, but later I discovered we'll need these variables here for example. Can we reference these by modules.exports.componentTypes?
There was a problem hiding this comment.
Ohh, I see. Didn't realize that. Yeah, I'd leave this as-is then :)
EDIT: For what it's worth, you can reference them that way. but it feels a little funny to me.
| @@ -66,17 +95,21 @@ const logComponentType = (selected) => ( | |||
| )).join(' ') | |||
| ); | |||
There was a problem hiding this comment.
I think there's enough duplication that an abstraction could come in handy here :)
const logSelected = (values, selected) => (
Object.values(values)
.sort((a, b) => a === selected ? -1 : 1)
.map(option => (
option === selected
? `${chalk.bold.rgb(...colors.blue)(option)}`
: `${chalk.rgb(...colors.darkGray)(option)}`
)).join(' ')
);Then you could just use it:
const componentTypeString = logSelected(componentTypes, type);
const stylingTypeString = logSelected(stylingTypes, styling);There was a problem hiding this comment.
Good refactoring tip. I'll do better with refactoring later on.
| ${belowComponentTemplates(style)} | ||
|
|
||
| ${exportsTemplates(style, componentName)} | ||
| `; |
There was a problem hiding this comment.
Nit: So with the templates (even the ones I wrote), we don't indent the template string contents:
const template = `
stuff
`;Initially this was because I didn't want the exported file having a bunch of leading whitespace... but now that I think about it, I think prettier would trim all that, so it wouldn't be a problem.
In this case though, because it's already indented by the module.exports function, I think it's fine to indent:
module.exports = (componentName, componentType, style) => {
const template = `
stuff
`;
}No change necessary for the other template strings though (unless you think it'd be better; I'm happy either way with the stuff in templates/component-definition.js)
| STYLED: 'styled-components', | ||
| CSS_MODULES: 'css-modules', | ||
| APHRODITE: 'aphrodite', | ||
| }; |
There was a problem hiding this comment.
I think we should consider none a valid styling type.
My reasoning is that the default styling is no styling. Someone may install this project, skim the README too quickly, and not even realize that it's capable of doing styling!
By showing that "None" is the styling option they've selected, we also show the options they haven't selected. They might say "oh cool this does styled-components! I need that".
There was a problem hiding this comment.
OK! When you said you want to keep the project as simple as possible, I thought showing the styling: none styled css-modules aphrodite in console every time would confuse beginner users.
There was a problem hiding this comment.
Yeah, my fault for not specifying! I can see the argument of wanting to reduce the noise as much as possible, but I think that ultimately it's worth the added line of info :)
| console.info(`Directory: ${pathString}`); | ||
| console.info(`Type: ${typeString}`); | ||
| console.info(`Type: ${componentTypeString}`); | ||
| if (styling && styling !== 'none') { |
There was a problem hiding this comment.
I talked more about this above, but yeah I think we should log the styling even when "none" is selected :)
| logItemCompletion('Index file built and saved to disk.'); | ||
| return template; | ||
| }) | ||
| .then(template => { |
There was a problem hiding this comment.
Good catch! Didn't realize I was pointlessly passing the template down :)
There was a problem hiding this comment.
I was confused for a few moments why we're doing this :))
| const aphrodite = `\ | ||
| const styles = StyleSheet.create({ | ||
| wrapper: { | ||
| }, |
There was a problem hiding this comment.
Nit: Same note as above; if possible with Prettier, can we add a blank line between open and close curlies?
There was a problem hiding this comment.
I think as Prettier introduces itself as an opinionated code formatter, it shouldn't be possible :) (Also I couldn't find an option to avoid it here)
But maybe we can write a placeholder style for wrapper as create-react-app does that when you first init a project. I mean something like this:
{
wrapper: {
height: 'auto',
width: 'auto',
}
}What do you think? Happy to discuss!
There was a problem hiding this comment.
Its ok :) no change necessary, I'd rather not apply any styles, and it's super easy for a developer to just add that new line themselves when they want to add styles.
|
|
||
| const styled = `\ | ||
| const Wrapper = styled.div\` | ||
| \`; |
There was a problem hiding this comment.
Nit: can you add a blank line inside the template string?
Will Prettier strip it out, if you do? I like the idea of having a space for someone to add their styles, but it's not a big deal :)
There was a problem hiding this comment.
Will Prettier strip it out, if you do?
Yeah, Prettier will make it like so:
const Wrapper = styled.div``
| case componentTypes.PURE_CLASS: | ||
| return pureClass(...args); | ||
| } | ||
| } |
There was a problem hiding this comment.
Great method! Good use of rest/spread :)
| @@ -0,0 +1,4 @@ | |||
| module.exports = ` | |||
| .wrapper { | |||
| } | |||
There was a problem hiding this comment.
Nit: same note as above, add a blank line if possible
Hey, another one today!
This one was a bit more complicated, it needed some serious (🤔) structural changes to the codebase. I'm in the middle of a project but I really like this tool and started to do it! so I hope you like it. Most of it is based on your awesome idea (Thanks, @joshwcomeau ❤️) + some tweaks to optimize and future proof it.
I added 3 styling solutions for now (we can add more easily later!):
Styled-Components
Sample code:
Aphrodite
Sample code:
CSS Modules
Sample code:
And
.
.
Now I'm gonna use it everyday ✌️😋