This repository has been archived by the owner on Aug 30, 2019. It is now read-only.
[WIP] Implementation of issue #6's proposal #7
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ node_modules/ | |
styleguide/ | ||
themes/theme.scss | ||
.DS_Store | ||
wallaby.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const getStylesAndSaveTheme = require('./getStylesAndSaveTheme'); | ||
const runWebpackAndCopyFilesToFinalDestination = require('./runWebpackAndCopyFilesToFinalDestination'); | ||
const webpackConfig = require('./webpack.config'); | ||
|
||
const webpackNodeEnv = { | ||
'process.env.NODE_ENV': process.env.NODE_ENV || 'development', | ||
}; | ||
|
||
/** | ||
* Triggers the build process. | ||
* | ||
* @module builder | ||
* @param {String} cssDir Destination folder for the ui-bundle.css | ||
* @param {String} jsDir Destination folder for the ui-bundle.js | ||
* @param {String} themeFile Path where a custom YAML w/ styles' definitions | ||
* @param {Boolean} watch Flag to determine if it should run in 'watch' mode | ||
* @return {Promise} | ||
*/ | ||
module.exports = ({ cssDir, jsDir, themeFile, watch }) => { | ||
return getStylesAndSaveTheme(themeFile, watch) | ||
.then(runWebpackAndCopyFilesToFinalDestination({ | ||
webpackConfig, | ||
webpackNodeEnv, | ||
cssDir, | ||
jsDir, | ||
watch, | ||
})); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
/** | ||
* Copies a given file from one path to another. | ||
* | ||
* @module copyToFinalDestination | ||
* @param {String} originalPath Source path to be copied | ||
* @param {String} finalPath Destination folder to copy the originalPath to. | ||
* @return {Promise} | ||
*/ | ||
module.exports = ({ originalPath, finalPath }) => new Promise((resolve, reject) => { | ||
if (!finalPath) { | ||
resolve(); | ||
return; | ||
} | ||
|
||
const copyTo = path.join(finalPath, path.basename(originalPath)); | ||
fs.readFile(originalPath, (readErr, content) => { | ||
if (readErr) { | ||
reject(readErr); | ||
return; | ||
} | ||
|
||
fs.writeFile(copyTo, content, (writeErr) => { | ||
if (writeErr) { | ||
reject(writeErr); | ||
return; | ||
} | ||
|
||
resolve(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const fs = require('fs'); | ||
const saveThemeScssFile = require('./saveThemeScssFile'); | ||
const themeBuilder = require('theme-builder'); | ||
|
||
/** | ||
* Generates the themes/theme.scss file, based on a given YAML file. | ||
* | ||
* @module generateThemeFile | ||
* @param {String} yamlFile File path to a YAML file with the styles' definitions. | ||
* @return {Promise} | ||
*/ | ||
module.exports = (yamlFile) => { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(yamlFile, { encoding: 'utf-8' }, (err, content) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
|
||
const themeChunks = themeBuilder(content, 'scss', { prefix: 'tx' }); | ||
resolve(themeChunks.join('\n')); | ||
}); | ||
}).then(saveThemeScssFile); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const generateThemeFile = require('./generateThemeFile'); | ||
|
||
/** | ||
* Triggers the generation of the theme file (theme.scss) | ||
* and handles the watch mode. | ||
* | ||
* @module getStylesAndSaveTheme | ||
* @param {String} [themeFile] Path to a custom YAML file with styles' definitions. | ||
* @param {Boolean} [isWatchEnabled] Flag that enables the 'watch mode' when true. Default: false. | ||
* @return {Promise} | ||
*/ | ||
module.exports = (themeFile, isWatchEnabled) => new Promise((resolve, reject) => { | ||
const yamlFile = themeFile || path.join(__dirname, '..', 'themes', '_default.yaml'); | ||
|
||
if (isWatchEnabled) { | ||
fs.watch(yamlFile, { persistent: true }, () => { | ||
/** TODO: Do proper error handling on watch mode */ | ||
generateThemeFile(yamlFile).catch(reject); | ||
}); | ||
} | ||
|
||
generateThemeFile(yamlFile).then(resolve).catch(reject); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env node | ||
|
||
const program = require('commander'); | ||
const pkg = require('../package.json'); | ||
const builder = require('./builder'); | ||
|
||
program | ||
.version(pkg.version) | ||
.option('-c, --css-dir <directory>', 'Destination directory of the ui-kit.css') | ||
.option('-j, --js-dir <directory>', 'Destination directory of the ui-kit.js') | ||
.option('-t, --theme-file <path>', 'Path to a theme file to override default UI Kit styles') | ||
.option('-w, --watch', 'Enables file-watcher functionality', false); | ||
|
||
program.parse(process.argv); | ||
|
||
builder(program) | ||
.then(() => console.log('Done!')) | ||
.catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const copyToFinalDestination = require('./copyToFinalDestination'); | ||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
|
||
/** | ||
* @module runWebpackAndCopyFilesToFinaDestination | ||
* @param {Object} options Object containing the configuration props. | ||
* @param {String} options.cssDir Folder where to place the ui-bundle.css | ||
* @param {String} options.jsDir Folder where to place the ui-bundle.js | ||
* @param {String} options.watch Flag that enables the 'watch mode' on Webpack. Default: false | ||
* @param {Object} options.webpackConfig Webpack configuration object | ||
* @param {Object} options.webpackNodeEnv Webpack NODE_ENV configuration | ||
* @return {Promise} | ||
*/ | ||
module.exports = ({ cssDir, jsDir, watch, webpackConfig, webpackNodeEnv }) => new Promise((resolve, reject) => { | ||
webpackConfig.plugins.push(new webpack.DefinePlugin(webpackNodeEnv)); | ||
webpackConfig.context = __dirname; | ||
|
||
const runner = webpack(webpackConfig); | ||
const runnerFn = watch ? runner.watch.bind(runner, {}) : runner.run.bind(runner); | ||
|
||
runnerFn((err, stats) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
|
||
copyToFinalDestination({ | ||
finalPath: jsDir, | ||
originalPath: path.join(webpackConfig.output.path, 'ui-bundle.js'), | ||
}).then(() => copyToFinalDestination({ | ||
finalPath: cssDir, | ||
originalPath: path.join(webpackConfig.output.path, 'ui-bundle.css'), | ||
})).then(() => { | ||
resolve(stats); | ||
}).catch(reject); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
/** | ||
* @module saveThemeScssFile | ||
* @param {String} themeScss SCSS content to be stored as themes/theme.scss | ||
* @return {Promise} | ||
*/ | ||
module.exports = themeScss => new Promise((resolve, reject) => { | ||
fs.writeFile(path.join(__dirname, '..', 'themes', 'theme.scss'), themeScss, (err) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
|
||
resolve(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is
V
capital?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 comes from
commander
: tj/commander.js#560Nevertheless it is also more common to do
-v
to add verbosity on node CLI tools. Still, it is possible to provide an override of the help I think.