Skip to content

Commit

Permalink
fix(cli): update clean config path logic (#454)
Browse files Browse the repository at this point in the history
`style-dictionary build` and `style-dictionary clean` were not using the same config path defaults. This fixes that.
  • Loading branch information
kyh authored Oct 8, 2020
1 parent 4064e6a commit 3cc3d4e
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions bin/style-dictionary
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ function collect(val, arr) {
return arr;
}

function getConfigPath(options) {
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);
}
}

return configPath;
}

program
.version(pkg.version)
.description(pkg.description)
Expand Down Expand Up @@ -59,20 +78,7 @@ program.on('command:*', function () {

function styleDictionaryBuild(options) {
options = options || {};
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);
}
}
var configPath = getConfigPath(options);

// Create a style dictionary object with the config
var styleDictionary = StyleDictionary.extend( configPath );
Expand All @@ -88,7 +94,7 @@ function styleDictionaryBuild(options) {

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

// Create a style dictionary object with the config
var styleDictionary = StyleDictionary.extend( configPath );
Expand Down

0 comments on commit 3cc3d4e

Please sign in to comment.