Skip to content

Commit

Permalink
feat(config): use config.js if config.json is not found (#249)
Browse files Browse the repository at this point in the history
Added functionality to search / use 'config.js' in root if 'config.json' is not found in root.
Modified documentation to ensure clarity around using JS based config with the CLI.

fix: #238
docs: #238
replaces #247 to be from master branch instead of develop
  • Loading branch information
chazzmoney authored and dbanksdesign committed Feb 19, 2019
1 parent 234f209 commit 09fc43f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 14 additions & 1 deletion bin/style-dictionary
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,20 @@ program.on('command:*', function () {

function styleDictionaryBuild(options) {
options = options || {};
var configPath = options.config ? options.config : './config.json';
var configPath = options.config;

if(!configPath) {
if(fs.existsSync('./config.json')) {
configPath = './config.json';
}
else if(fs.existsSync('./config.js')) {
configPath = './config.js';
}
else {
console.error('Build failed; unable to find config file.');
process.exit(1);
}
}

// Create a style dictionary object with the config
var styleDictionary = StyleDictionary.extend( configPath );
Expand Down
5 changes: 4 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

Style dictionaries are configuration driven. Your config file defines what executes and what to output when the style dictionary builds.

By default, Style Dictionary looks for a `config.json` file in the root of your package. You can also specify a custom location when you use the [CLI](using_the_cli.md). If you want a custom build system using the [npm module](using_the_npm_module.md), you can specify a custom location for a configuration file or use a plain Javascript object.
By default, Style Dictionary looks for a `config.json` file in the root of your package. If not found, it looks for a `config.js` file in the root of your package. You can also specify a custom location when you use the [CLI](using_the_cli.md). If you want a custom build system using the [npm module](using_the_npm_module.md), you can specify a custom location for a configuration file or use a plain Javascript object.

## config.js
You can find out more about creating configurations in JS in our documentation about using the [npm module](using_the_npm_module.md).

## config.json
Here is a quick example:
Expand Down

0 comments on commit 09fc43f

Please sign in to comment.