-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add css generating script and package.json hook (2/7) #162
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nits! But this is looking great.
scripts/renderAllComponents.jsx
Outdated
function App() { | ||
return ( | ||
<LabeledSlider /> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just simplify this return <LabeledSlider />;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively, ReactDOM.render(<LabeledSlider />
- no need for App at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think simplifying to Jordan's comment seems reasonable.
scripts/buildCSS.js
Outdated
|
||
const path = './scripts/renderAllComponents.jsx'; | ||
|
||
const CSS = compileCSS(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid this dereference:
const CSS = compileCSS('./scripts/renderAllComponents.jsx');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also define the format function before this.
const format = new CleanCSS({...});
const CSS = compileCSS('./scripts/renderAllComponents.jsx');
const { styles: formattedCSS } = format.minify(CSS);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not passionate about this order.
const args = process.argv.slice(2); | ||
const optimizeForProduction = args.includes('-o') || args.includes('--optimize'); | ||
|
||
registerMaxSpecificity(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it important to run this before registerCSSInterfaceWithDefaultTheme
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the order matters, as long as it's before the compile script is run. Looks like it just sets a global flag.
scripts/buildCSS.js
Outdated
const compileCSS = require('react-with-styles-interface-css-compiler'); | ||
|
||
const registerMaxSpecificity = require('react-with-styles-interface-css/dist/utils/registerMaxSpecificity').default; | ||
const registerCSSInterfaceWithDefaultTheme = require('../src/utils/registerCSSInterfaceWithDefaultTheme').default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would bunch up all of these imports without whitespace between them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm - the .default
is unfortunate. can this pull from lib
instead of src
- so it must run after the build process - and then it can require from the babel output, which would have add-module-exports
applied?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is add-module-exports
part of the airbnb babel config? We tried to pull from lib and it still needs the .default
(also notably, registerMaxSpecificity
needs the .default
even though it is a built file.
@philipfweiss Can you post a sample result of this script? |
package.json
Outdated
@@ -5,7 +5,10 @@ | |||
"main": "lib/Slider", | |||
"jsnext:main": "src/Slider.jsx", | |||
"scripts": { | |||
"build": "npm run clean && babel src -d lib", | |||
"prebuild": "npm run clean", | |||
"build": "npm run clean && babel src -d lib && npm run build:css -- --optimize ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the clean script can be removed here, since it's in prebuild.
also, let's add a "postbuild" that does npm run build:css
, instead of doing it inside the build step?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the css building part of the build step (just like, semantically).
Maybe let's move the babel src -d lib
to a npm run build:js
and then change npm run build
to be npm run build:js && npm run build:css -- --optimize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sure that's fine too
scripts/buildCSS.js
Outdated
const compileCSS = require('react-with-styles-interface-css-compiler'); | ||
|
||
const registerMaxSpecificity = require('react-with-styles-interface-css/dist/utils/registerMaxSpecificity').default; | ||
const registerCSSInterfaceWithDefaultTheme = require('../src/utils/registerCSSInterfaceWithDefaultTheme').default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm - the .default
is unfortunate. can this pull from lib
instead of src
- so it must run after the build process - and then it can require from the babel output, which would have add-module-exports
applied?
scripts/renderAllComponents.jsx
Outdated
function App() { | ||
return ( | ||
<LabeledSlider /> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively, ReactDOM.render(<LabeledSlider />
- no need for App at all.
src/utils/.eslintrc
Outdated
{ | ||
"rules": { | ||
"import/no-extraneous-dependencies": [2, { | ||
"devDependencies": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should these utils maybe live inside scripts/
, since they're not for public consumption?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well actually they might be? as part of the eventual initialize script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if that's the case then they definitely shouldn't be allowed to have dev deps :-)
package.json
Outdated
@@ -5,7 +5,10 @@ | |||
"main": "lib/Slider", | |||
"jsnext:main": "src/Slider.jsx", | |||
"scripts": { | |||
"build": "npm run clean && babel src -d lib", | |||
"prebuild": "npm run clean", | |||
"build": "npm run clean && babel src -d lib && npm run build:css -- --optimize ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the css building part of the build step (just like, semantically).
Maybe let's move the babel src -d lib
to a npm run build:js
and then change npm run build
to be npm run build:js && npm run build:css -- --optimize
package.json
Outdated
@@ -54,6 +58,8 @@ | |||
"react-addons-pure-render-mixin": "^15.6.2", | |||
"react-dom": "^15.6.2", | |||
"react-with-styles-interface-aphrodite": "^5.0.0", | |||
"react-with-styles-interface-css": "^4.0.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is going to be used by the consumer as part of the initialize script, it will need to be part of the regular dependencies
scripts/buildCSS.js
Outdated
const compileCSS = require('react-with-styles-interface-css-compiler'); | ||
|
||
const registerMaxSpecificity = require('react-with-styles-interface-css/dist/utils/registerMaxSpecificity').default; | ||
const registerCSSInterfaceWithDefaultTheme = require('../src/utils/registerCSSInterfaceWithDefaultTheme').default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is add-module-exports
part of the airbnb babel config? We tried to pull from lib and it still needs the .default
(also notably, registerMaxSpecificity
needs the .default
even though it is a built file.
scripts/renderAllComponents.jsx
Outdated
function App() { | ||
return ( | ||
<LabeledSlider /> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think simplifying to Jordan's comment seems reasonable.
src/utils/.eslintrc
Outdated
{ | ||
"rules": { | ||
"import/no-extraneous-dependencies": [2, { | ||
"devDependencies": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well actually they might be? as part of the eventual initialize script.
import ThemedStyleSheet from 'react-with-styles/lib/ThemedStyleSheet'; | ||
import DefaultTheme from '../themes/DefaultTheme'; | ||
|
||
export default function registerInterfaceWithDefaultTheme(reactWithStylesInterface) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'd be good to change the test setup and storybook config to use this instead maybe
e10ddba
to
3fd8ae1
Compare
3fd8ae1
to
5ecf6e1
Compare
ca50ace
to
7f4a8eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me! I have a few small comments and then I think it's ready to merge.
package.json
Outdated
"build": "npm run clean && babel src -d lib", | ||
"postbuild": "npm run build:css", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still prefer to have:
"build:js": "babel src -d lib",
as a separate script and then have "build"
be "npm run build:js && npm run build:css"
. The CSS step is not a postbuild, it's part of the build itself.
package.json
Outdated
@@ -5,7 +5,11 @@ | |||
"main": "lib/Slider", | |||
"jsnext:main": "src/Slider.jsx", | |||
"scripts": { | |||
"prebuild": "npm run clean", | |||
"build": "npm run clean && babel src -d lib", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this npm run clean
since it's in the prebuild now.
package.json
Outdated
@@ -63,9 +68,11 @@ | |||
}, | |||
"dependencies": { | |||
"airbnb-prop-types": "^2.10.0", | |||
"clean-css": "^4.1.11", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean-css
should be a dev dep
const registerCSSInterfaceWithDefaultTheme = require('./utils/registerCSSInterfaceWithDefaultTheme').default; | ||
|
||
const args = process.argv.slice(2); | ||
const optimizeForProduction = args.includes('-o') || args.includes('--optimize'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not critical, but it might be cleaner to update this to use yargs
or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we’re going to do that, maybe this should be a command line util in the css interface repo?
scripts/buildCSS.js
Outdated
fs.mkdirSync(dir); | ||
} | ||
|
||
const outputFilePath = optimizeForProduction ? `${dir}/_styles.css` : `${dir}/styles.css`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the underscore is probably not necessary (it was there for some backwards compatibility w/ react-dates). It might be nice to name this file rheostat.css
so that it is easy to understand in the context of a bigger app.
.storybook/config.js
Outdated
import '../css/slider-horizontal.css'; | ||
import '../css/slider-vertical.css'; | ||
/* Register react with styles interface */ | ||
ThemedStyleSheet.registerTheme(DefaultTheme); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use utils/registerInterfaceWithDefaultTheme.js
here with the aphroditeInterface. :)
7f4a8eb
to
e5cb7f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for the one comment
"build": "npm run build:js && npm run build:css", | ||
"build:js": "babel src -d lib", | ||
"prebuild:css": "rimraf lib/css && mkdir -p lib/css", | ||
"build:css": "node scripts/buildCSS.js", | ||
"clean": "rimraf lib", | ||
"prepublish": "in-publish && safe-publish-latest && npm run build || not-in-publish", | ||
"lint": "eslint --ext .js,.jsx src test stories", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to add a script for running the css storybook? e.g.
"storybook:css": "npm run build:css && start-storybook -p 9001 -c .storybook-css",
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have this in a later commit! #166
Adds a script which will generate a CSS stylesheet from an example component. Based off a similar implementation in https://github.com/airbnb/react-dates.
Sample result of script (inside
css/styles.css
). Another PR with improvements to/refactoring of the CSS/theming coming soon.