(args: string[])
| 75 | } |
| 76 | |
| 77 | export async function cli(args: string[]) { |
| 78 | // parse CLI flags |
| 79 | const cliFlags = yargs(args, { |
| 80 | array: ['install', 'env', 'exclude', 'external'], |
| 81 | }) as CLIFlags; |
| 82 | |
| 83 | if (cliFlags.verbose) { |
| 84 | logger.level = 'debug'; |
| 85 | } |
| 86 | if (cliFlags.quiet) { |
| 87 | logger.level = 'silent'; |
| 88 | } |
| 89 | if (cliFlags.help) { |
| 90 | printHelp(); |
| 91 | process.exit(0); |
| 92 | } |
| 93 | if (cliFlags.version) { |
| 94 | logger.info(require('../../package.json').version); |
| 95 | process.exit(0); |
| 96 | } |
| 97 | if (cliFlags.reload) { |
| 98 | logger.info(colors.yellow('! clearing cache...')); |
| 99 | await clearCache(); |
| 100 | } |
| 101 | |
| 102 | const cmd = cliFlags['_'][2]; |
| 103 | logger.debug(`run command: ${cmd}`); |
| 104 | if (!cmd) { |
| 105 | printHelp(); |
| 106 | process.exit(1); |
| 107 | } |
| 108 | |
| 109 | // Set this early -- before config loading -- so that plugins see it. |
| 110 | if (cmd === 'build') { |
| 111 | process.env.NODE_ENV = process.env.NODE_ENV || 'production'; |
| 112 | } |
| 113 | if (cmd === 'dev') { |
| 114 | process.env.NODE_ENV = process.env.NODE_ENV || 'development'; |
| 115 | } |
| 116 | |
| 117 | const cliConfig = expandCliFlags(cliFlags); |
| 118 | const config = await loadConfiguration(cliConfig, cliFlags.config); |
| 119 | logger.debug(`config loaded: ${util.format(config)}`); |
| 120 | const lockfile = await readLockfile(config.root); |
| 121 | logger.debug(`lockfile ${lockfile ? 'loaded.' : 'not loaded'}`); |
| 122 | const commandOptions: CommandOptions = { |
| 123 | config, |
| 124 | lockfile, |
| 125 | }; |
| 126 | |
| 127 | if (cmd === 'add') { |
| 128 | await addCommand(cliFlags['_'][3], commandOptions); |
| 129 | return process.exit(0); |
| 130 | } |
| 131 | if (cmd === 'rm') { |
| 132 | await rmCommand(cliFlags['_'][3], commandOptions); |
| 133 | return process.exit(0); |
| 134 | } |
nothing calls this directly
no test coverage detected