Skip to content

Commit

Permalink
chore(cli): migrate from yargs to commander (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra authored Aug 26, 2024
1 parent e1edc05 commit 7ca5a28
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 186 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ nwbuild({
### Features

- feat(get): support canary releases
- feat(bld): rename MacOS Helper apps
- feat(pkg): add `AppImage` installer
- feat(pkg): add `NSIS` installer
- feat(pkg): add `DMG` installer
Expand All @@ -389,7 +388,6 @@ nwbuild({
- chore: annotate file paths as `fs.PathLike` instead of `string`.
- chore(bld): factor out core build step
- chore(bld): factor out linux config
- chore(bld): factor out macos config
- chore(bld): factor out windows config
- chore(bld): factor out native addon
- chore(bld): factor out compressing
Expand Down
97 changes: 1 addition & 96 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"test": "vitest run --coverage",
"test:cov": "vitest --coverage.enabled true",
"demo:bld": "node ./tests/fixtures/demo.js",
"demo:exe": "./tests/fixtures/out/nwapp.app/Contents/MacOS/nwapp"
"demo:exe": "./tests/fixtures/out/nwapp.app/Contents/MacOS/nwapp",
"demo:cli": "nwbuild --mode run ./src ./app/**"
},
"devDependencies": {
"@eslint/js": "^9.9.1",
Expand All @@ -63,13 +64,13 @@
"dependencies": {
"archiver": "^7.0.1",
"axios": "^1.7.5",
"commander": "^12.1.0",
"glob": "^11.0.0",
"node-gyp": "^10.2.0",
"plist": "^3.1.0",
"resedit": "^2.0.2",
"semver": "^7.6.3",
"tar": "^7.4.3",
"yargs": "^17.7.2",
"yauzl-promise": "^4.0.0"
},
"volta": {
Expand Down
109 changes: 23 additions & 86 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,32 @@
#!/usr/bin/env node

import process from 'node:process';

import yargs from 'yargs/yargs';
import * as yargs_helpers from 'yargs/helpers';
import { program } from 'commander';

import nwbuild from './index.js';

const cli = yargs(yargs_helpers.hideBin(process.argv))
.version(false)
.command('[srcDir] [options]')
.option('mode', {
type: 'string',
description: '`get`, `run` or `build` application',
choices: ['get', 'run', 'build']
})
.option('version', {
type: 'string',
description: 'NW.js version',
})
.option('flavor', {
type: 'string',
description: 'NW.js build flavor',
choices: ['normal', 'sdk']
})
.option('platform', {
type: 'string',
description: 'NW.js supported platform',
choices: ['linux', 'osx', 'win']
})
.option('arch', {
type: 'string',
description: 'NW.js supported architecture',
choices: ['ia32', 'x64', 'arm64']
})
.option('downloadUrl', {
type: 'string',
description: 'NW.js download server',
})
.option('manifestUrl', {
type: 'string',
description: 'NW.js version info',
})
.option('cacheDir', {
type: 'string',
description: 'Cache NW.js binaries',
})
.option('outDir', {
type: 'string',
description: 'NW.js build artifacts',
})
.option('app', {
type: 'object',
description: 'Platform specific app metadata. Refer to docs for more info',
})
.option('cache', {
type: 'boolean',
description: 'Flag to enable/disable caching',
})
.option('ffmpeg', {
type: 'boolean',
description: 'Flag to enable/disable downloading community ffmpeg',
})
.option('glob', {
type: 'boolean',
description: 'Flag to enable/disable globbing',
})
.option('logLevel', {
type: 'string',
description: 'Specify log level',
choices: ['error', 'warn', 'info', 'debug']
})
.option('zip', {
type: 'string',
description: 'Flag to enable/disable compression',
choices: ['zip', 'tar', 'tgz']
})
.option('managedManifest', {
type: 'string',
description: 'Managed manifest mode',
})
.option('nodeAddon', {
type: 'string',
description: 'Download NW.js Node headers',
choices: [false, 'gyp']
})
.strictOptions()
.parse();
program
.option('--mode', 'get, run or build mode')
.option('--version', 'NW.js version')
.option('--flavor', 'NW.js build flavor')
.option('--platform', 'NW.js supported platform')
.option('--arch', 'NW.js supported architecture')
.option('--downloadUrl', 'NW.js download server')
.option('--manifestUrl', 'NW.js version info')
.option('--cacheDir', 'Cache NW.js binaries')
.option('--outDir', 'NW.js build artifacts')
.option('--app', 'Platform specific app metadata. Refer to docs for more info')
.option('--cache', 'Flag to enable/disable caching')
.option('--ffmpeg', 'Flag to enable/disable downloading community ffmpeg')
.option('--glob', 'Flag to enable/disable globbing')
.option('--logLevel', 'Specify log level')
.option('--zip', 'Flag to enable/disable compression')
.option('--managedManifest', 'Managed manifest mode')
.option('--nodeAddon', 'Download NW.js Node headers');

program.parse();

nwbuild({
...cli,
srcDir: cli._.join(' '),
...program.opts(),
srcDir: program.args.join(' '),
cli: true,
});

0 comments on commit 7ca5a28

Please sign in to comment.