|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 |
| -module.exports = { |
| 3 | +const Shell = module.exports = { |
4 | 4 | command: 'shell',
|
5 | 5 | aliases: ['sh'],
|
6 | 6 | describe: 'Launch a tink shell or execute a script',
|
7 | 7 | builder (yargs) {
|
8 |
| - return yargs.help().alias('help', 'h').options({ |
9 |
| - 'ignore-scripts': {}, |
10 |
| - 'node-arg': { |
11 |
| - alias: ['n', 'nodeArg'], |
12 |
| - describe: 'Arguments to pass down directly to node', |
13 |
| - type: 'array' |
14 |
| - }, |
15 |
| - prefix: { |
16 |
| - describe: 'Directory to execute package management operations in.', |
17 |
| - type: 'string' |
18 |
| - }, |
19 |
| - 'restore-missing': { |
20 |
| - default: true, |
21 |
| - type: 'boolean' |
22 |
| - } |
23 |
| - }) |
| 8 | + return yargs.help().alias('help', 'h').options(Shell.options) |
24 | 9 | },
|
| 10 | + options: Object.assign(require('../common-opts'), { |
| 11 | + _: { default: [] }, |
| 12 | + 'ignore-scripts': {}, |
| 13 | + nodeArg: { |
| 14 | + alias: ['n', 'node-arg'], |
| 15 | + describe: 'Arguments to pass down directly to node', |
| 16 | + type: 'array' |
| 17 | + }, |
| 18 | + prefix: { |
| 19 | + alias: 'C', |
| 20 | + describe: 'Directory to execute package management operations in.', |
| 21 | + type: 'string' |
| 22 | + }, |
| 23 | + restore: { |
| 24 | + alias: 'restore-missing', |
| 25 | + default: true, |
| 26 | + type: 'boolean' |
| 27 | + }, |
| 28 | + also: { |
| 29 | + hidden: true |
| 30 | + }, |
| 31 | + dev: { |
| 32 | + hidden: true |
| 33 | + }, |
| 34 | + development: { |
| 35 | + hidden: true |
| 36 | + }, |
| 37 | + only: { |
| 38 | + hidden: true |
| 39 | + }, |
| 40 | + production: { |
| 41 | + type: 'boolean', |
| 42 | + describe: 'Limit downloads to production dependencies, skipping devDependencies.' |
| 43 | + } |
| 44 | + }), |
25 | 45 | // lazy-load subcommands
|
26 |
| - handler: shell |
| 46 | + handler: async argv => shell(argv) |
27 | 47 | }
|
28 | 48 |
|
29 |
| -function shell (argv) { |
| 49 | +async function shell (argv) { |
30 | 50 | const cp = require('child_process')
|
| 51 | + const figgyPudding = require('figgy-pudding') |
| 52 | + const path = require('path') |
31 | 53 | const prepare = require('./prepare.js')
|
32 | 54 |
|
33 |
| - prepare.handler(argv) |
34 |
| - if (argv.nodeArg && argv.nodeArg.length) { |
| 55 | + const opts = figgyPudding(Shell.options)(argv) |
| 56 | + |
| 57 | + await prepare.handler(argv) |
| 58 | + if (opts.nodeArg && opts.nodeArg.length) { |
35 | 59 | cp.spawnSync(
|
36 | 60 | process.argv[0],
|
37 |
| - ['-r', require.resolve('../node'), ...(argv.nodeArg || []), ...(argv.script ? [argv.script, ...(argv.arguments || [])] : [])], |
| 61 | + ['-r', require.resolve('../node/index.js'), ...(opts.nodeArg || []), ...(argv.script ? [argv.script, ...(argv.arguments || [])] : [])], |
38 | 62 | { stdio: 'inherit' }
|
39 | 63 | )
|
40 | 64 | } else if (argv._.length > 1) {
|
41 | 65 | const Module = require('module')
|
42 |
| - require('clear-module').all() |
| 66 | + require('clear-module').match(/yargs/) |
43 | 67 | process.argv = [
|
44 | 68 | process.argv[0],
|
45 |
| - ...argv._.slice(1) |
| 69 | + path.resolve(argv._[1]), |
| 70 | + ...argv._.slice(2) |
46 | 71 | ]
|
47 | 72 | Module.runMain()
|
48 | 73 | } else {
|
|
0 commit comments