This repository has been archived by the owner on Feb 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,61 @@ | ||
#!/usr/bin/env node | ||
const cac = require('cac').default | ||
const SAOError = require('../lib/SAOError') | ||
const cac = require('cac') | ||
const pkg = require('../package') | ||
|
||
const cli = cac() | ||
|
||
cli | ||
.command( | ||
'*', | ||
{ | ||
desc: 'Run a generator', | ||
alias: 'run' | ||
}, | ||
(input, flags) => { | ||
const options = Object.assign( | ||
{ | ||
generator: input[0], | ||
outDir: input[1] || '.', | ||
updateCheck: true | ||
}, | ||
flags | ||
) | ||
|
||
if (!options.generator) { | ||
return cli.showHelp() | ||
} | ||
|
||
return require('../')(options).run() | ||
.command('<generator> [outDir]', 'Run a generator') | ||
.action((generator, outDir, flags) => { | ||
const options = Object.assign( | ||
{ | ||
generator, | ||
outDir: outDir || '.', | ||
updateCheck: true | ||
}, | ||
flags | ||
) | ||
|
||
if (!options.generator) { | ||
return cli.showHelp() | ||
} | ||
) | ||
.option('npm-client', { | ||
desc: `Use a specific npm client ('yarn' or 'npm')`, | ||
type: 'string' | ||
}) | ||
.option('update', { | ||
desc: 'Update cached generator', | ||
type: 'boolean', | ||
alias: 'u' | ||
}) | ||
.option('clone', { | ||
desc: 'Clone repository instead of archive download', | ||
type: 'boolean', | ||
alias: 'c' | ||
}) | ||
.option('yes', { | ||
desc: 'Use the default options', | ||
alias: 'y' | ||
}) | ||
.option('registry', { | ||
desc: 'Use a custom registry for npm and yarn', | ||
type: 'string' | ||
}) | ||
|
||
cli.command('set-alias', 'Set an alias for a generator path', input => { | ||
const store = require('../lib/store') | ||
const { escapeDots } = require('../lib/utils/common') | ||
const logger = require('../lib/logger') | ||
|
||
const name = input[0] | ||
const value = input[1] | ||
if (!name || !value) { | ||
throw new SAOError(`Invalid arguments: sao set-alias <alias> <generator>`) | ||
} | ||
return require('../')(options) | ||
.run() | ||
.catch(err => { | ||
require('..').handleError(err) | ||
}) | ||
}) | ||
.option( | ||
'--npm-client <client>', | ||
`Use a specific npm client ('yarn' or 'npm')` | ||
) | ||
.option('-u, --update', 'Update cached generator') | ||
.option('-c, --clone', 'Clone repository instead of archive download') | ||
.option('-y, --yes', 'Use the default options') | ||
.option('--registry <registry>', 'Use a custom registry for npm and yarn') | ||
|
||
store.set(`alias.${escapeDots(name)}`, value) | ||
logger.success(`Added alias '${name}'`) | ||
}) | ||
cli | ||
.command('set-alias <name> <value>', 'Set an alias for a generator path') | ||
.action((name, value) => { | ||
const store = require('../lib/store') | ||
const { escapeDots } = require('../lib/utils/common') | ||
const logger = require('../lib/logger') | ||
|
||
store.set(`alias.${escapeDots(name)}`, value) | ||
logger.success(`Added alias '${name}'`) | ||
}) | ||
|
||
cli.command('get-alias', 'Get the generator for an alias', input => { | ||
const store = require('../lib/store') | ||
const { escapeDots } = require('../lib/utils/common') | ||
cli | ||
.command('get-alias <name>', 'Get the generator for an alias') | ||
.action(name => { | ||
const store = require('../lib/store') | ||
const { escapeDots } = require('../lib/utils/common') | ||
|
||
console.log(store.get(`alias.${escapeDots(input[0])}`)) | ||
}) | ||
console.log(store.get(`alias.${escapeDots(name)}`)) | ||
}) | ||
|
||
cli.on('error', error => { | ||
return require('..').handleError(error) | ||
}) | ||
cli.version(pkg.version) | ||
cli.help() | ||
|
||
cli.parse() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
"author": "egoist <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"cac": "^5.0.15", | ||
"cac": "^6.0.1", | ||
"chalk": "^2.4.1", | ||
"conf": "^2.0.0", | ||
"cross-spawn": "^6.0.5", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters