Skip to content

Commit

Permalink
refactor: adapted "global" options example
Browse files Browse the repository at this point in the history
  • Loading branch information
mfranzke committed Jan 4, 2023
1 parent 0018768 commit 500f467
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/cli/bin/cli-actions/build.js
Expand Up @@ -6,7 +6,7 @@ const { error, info, wrapAsync } = require('../utils');
const build = (options) =>
wrapAsync(function* () {
try {
const config = yield resolveConfig(options.parent.config);
const config = yield resolveConfig(options.config);
yield buildPatterns(config, options);
info(`build: Yay, your Pattern Lab project was successfully built ☺`);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/cli-actions/disable.js
Expand Up @@ -35,7 +35,7 @@ const enable = (options) =>
}
});
}
yield writeJsonAsync(options.parent.config, config);
yield writeJsonAsync(options.config, config);
spinner.succeed(`⊙ patternlab → Updated config`);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/cli-actions/enable.js
Expand Up @@ -33,7 +33,7 @@ const enable = (options) =>
}
});
}
yield writeJsonAsync(options.parent.config, config);
yield writeJsonAsync(options.config, config);
spinner.succeed(`⊙ patternlab → Updated config`);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/cli-actions/export.js
Expand Up @@ -5,7 +5,7 @@ const wrapAsync = require('../utils').wrapAsync;

const _export = (options) =>
wrapAsync(function* () {
const config = yield resolveConfig(options.parent.config);
const config = yield resolveConfig(options.config);
archive(config);
});

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/bin/cli-actions/install.js
Expand Up @@ -13,7 +13,7 @@ const writeJsonAsync = require('../utils').writeJsonAsync;
*/
const install = (options) =>
wrapAsync(function* () {
const config = yield resolveConfig(options.parent.config);
const config = yield resolveConfig(options.config);

const spinner = ora(
`⊙ patternlab → Installing additional resources …`
Expand Down Expand Up @@ -58,7 +58,7 @@ const install = (options) =>
`⊙ patternlab → Installed following plugins: ${plugins.join(', ')}`
);
}
yield writeJsonAsync(options.parent.config, config);
yield writeJsonAsync(options.config, config);
spinner.succeed(`⊙ patternlab → Updated config`);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/cli-actions/serve.js
Expand Up @@ -5,7 +5,7 @@ const wrapAsync = require('../utils').wrapAsync;

const serve = (options) =>
wrapAsync(function* () {
const config = yield resolveConfig(options.parent.config);
const config = yield resolveConfig(options.config);
servePatterns(config, options);
});

Expand Down
27 changes: 17 additions & 10 deletions packages/cli/bin/patternlab.js
@@ -1,7 +1,8 @@
#!/usr/bin/env node
/* eslint-disable no-unused-vars */
'use strict';
const cli = require('commander');
const { Command } = require('commander');
const cli = new Command();
const path = require('path');
const build = require('./cli-actions/build');
const disable = require('./cli-actions/disable');
Expand Down Expand Up @@ -38,15 +39,7 @@ const list = (val) => val.split(',');
cli
.version(version(pkg), '-V, --version')
.usage('<cmd> [options]')
.arguments('<cmd> [options]')
.option(
'-c, --config <path>',
'Specify config file. Default looks up the project dir',
(val) => val.trim(),
path.resolve(process.cwd(), 'patternlab-config.json')
)
.option('-v, --verbose', 'Show verbose console logs', verboseLogs)
.option('--silent', 'Turn off console logs', silenceLogs);
.arguments('<cmd> [options]');

/**
* build
Expand Down Expand Up @@ -134,6 +127,20 @@ cli
.option('--no-watch', 'Start watching for changes')
.action(serve);

// Common options can be added manually after setting up program and subcommands.
// If the options are unsorted in the help, these will appear last.
cli.commands.forEach((command) => {
command
.option(
'-c, --config <path>',
'Specify config file. Default looks up the project dir',
(val) => val.trim(),
path.resolve(process.cwd(), 'patternlab-config.json')
)
.option('-v, --verbose', 'Show verbose console logs', verboseLogs)
.option('--silent', 'Turn off console logs', silenceLogs);
});

// Show additional help
cli.on('--help', help);

Expand Down

0 comments on commit 500f467

Please sign in to comment.