diff --git a/package.json b/package.json index 5d2aab085..a7e6355e4 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,6 @@ "@babel/plugin-syntax-dynamic-import": "^7.0.0", "@babel/plugin-transform-modules-commonjs": "^7.1.0", "@babel/register": "^7.0.0", - "commander": "^2.19.0", "dedent": "^0.7.0", "glob": "^7.1.3", "loader-utils": "^1.1.0", @@ -94,7 +93,8 @@ "react-is": "^16.5.1", "rollup-pluginutils": "^2.3.3", "source-map": "^0.7.3", - "stylis": "^3.5.4" + "stylis": "^3.5.4", + "yargs": "^12.0.5" }, "resolutions": { "**/babel-core": "7.0.0-bridge.0" diff --git a/src/cli.js b/src/cli.js index 8b5fab7ab..549ad8377 100644 --- a/src/cli.js +++ b/src/cli.js @@ -6,51 +6,48 @@ const path = require('path'); const fs = require('fs'); const mkdirp = require('mkdirp'); const glob = require('glob'); -const commander = require('commander'); +const yargs = require('yargs'); const transform = require('./transform'); -commander - .version(require('../package.json').version) - .usage('[options] ') - .option('-o, --out-dir ', 'output directory for the extracted CSS files') - .option('-s, --source-maps', 'generate source maps for the CSS files') - .option('-r, --source-root ', 'directory contaning the source JS files') - .option( - '-i, --insert-css-requires ', - 'directory containing JS files to insert require statements for the CSS files' - ) - .action((file, ...rest) => { - if (typeof file !== 'string') { - console.error('No files were specified to extract CSS from.\n'); - commander.help(); - process.exit(1); - } - - const command = rest[rest.length - 1]; - const files = [file, ...rest.slice(0, -1)]; - - if (!command.outDir) { - console.error('--out-dir must be specified.\n'); - commander.help(); - process.exit(1); - } - - if (command.insertCssRequires && !command.sourceRoot) { - console.error( - '--source-root must be specified when --insert-css-requires is specified.\n' - ); - commander.help(); - process.exit(1); - } - - processFiles(files, { - outDir: command.outDir, - sourceMaps: command.sourceMaps, - sourceRoot: command.sourceRoot, - insertCssRequires: command.insertCssRequires, - }); +const { argv } = yargs + .usage('Usage: $0 [options] ') + .option('out-dir', { + alias: 'o', + type: 'string', + description: 'Output directory for the extracted CSS files', + demandOption: true, + requiresArg: true, + }) + .option('source-maps', { + alias: 's', + type: 'boolean', + description: 'Generate source maps for the CSS files', + default: false, + }) + .option('source-root', { + alias: 'r', + // type: 'string', + description: 'Directory contaning the source JS files', + requiresArg: true, + }) + .option('insert-css-requires', { + alias: 'i', + type: 'string', + description: + 'Directory containing JS files to insert require statements for the CSS files', + requiresArg: true, }) - .parse(process.argv); + .implies('insert-css-requires', 'source-root') + .alias('help', 'h') + .alias('version', 'v') + .strict(); + +processFiles(argv._, { + outDir: argv['out-dir'], + sourceMaps: argv['source-maps'], + sourceRoot: argv['source-root'], + insertCssRequires: argv['insert-css-requires'], +}); type Options = { outDir: string, diff --git a/yarn.lock b/yarn.lock index 9b5d99481..8ccc0feb6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2318,7 +2318,7 @@ commander@^2.11.0, commander@^2.8.1: resolved "https://registry.yarnpkg.com/commander/-/commander-2.18.0.tgz#2bf063ddee7c7891176981a2cc798e5754bc6970" integrity sha512-6CYPa+JP2ftfRU2qkDK+UTVeQYosOg/2GbcjIcKPHfinyOLPVGXu/ovN86RP49Re5ndJK1N0kuiidFFuepc4ZQ== -commander@^2.12.1, commander@^2.19.0: +commander@^2.12.1: version "2.19.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a" integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg== @@ -8356,6 +8356,14 @@ yargs-parser@^10.1.0: dependencies: camelcase "^4.1.0" +yargs-parser@^11.1.1: + version "11.1.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-11.1.1.tgz#879a0865973bca9f6bab5cbdf3b1c67ec7d3bcf4" + integrity sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + yargs-parser@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-8.1.0.tgz#f1376a33b6629a5d063782944da732631e966950" @@ -8424,6 +8432,24 @@ yargs@^12.0.1: y18n "^3.2.1 || ^4.0.0" yargs-parser "^10.1.0" +yargs@^12.0.5: + version "12.0.5" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-12.0.5.tgz#05f5997b609647b64f66b81e3b4b10a368e7ad13" + integrity sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw== + dependencies: + cliui "^4.0.0" + decamelize "^1.2.0" + find-up "^3.0.0" + get-caller-file "^1.0.1" + os-locale "^3.0.0" + require-directory "^2.1.1" + require-main-filename "^1.0.1" + set-blocking "^2.0.0" + string-width "^2.0.0" + which-module "^2.0.0" + y18n "^3.2.1 || ^4.0.0" + yargs-parser "^11.1.1" + yargs@~3.10.0: version "3.10.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"