(originalCommand: commander.Command)
| 129 | }; |
| 130 | |
| 131 | const addScriptCommand = (originalCommand: commander.Command) => { |
| 132 | // inso script |
| 133 | originalCommand |
| 134 | .command('script <name>', { |
| 135 | isDefault: true, |
| 136 | }) |
| 137 | .description('Run scripts defined in .insorc') |
| 138 | .allowUnknownOption() |
| 139 | // @ts-expect-error this appears to actually be valid, and I don't want to risk changing any behavior |
| 140 | .action((scriptName, cmd) => { |
| 141 | // Load scripts |
| 142 | let options = getOptions(cmd); |
| 143 | options = prepareCommand(options); |
| 144 | |
| 145 | // Ignore the first arg because that will be scriptName, get the rest |
| 146 | const passThroughArgs = cmd.args.slice(1); |
| 147 | |
| 148 | // Find script |
| 149 | const scriptTask = options.__configFile?.scripts?.[scriptName]; |
| 150 | |
| 151 | if (!scriptTask) { |
| 152 | logger.fatal(`Could not find inso script "${scriptName}" in the config file.`); |
| 153 | return exit(new Promise(resolve => resolve(false))); |
| 154 | } |
| 155 | |
| 156 | if (!scriptTask.startsWith('inso')) { |
| 157 | logger.fatal('Tasks in a script should start with `inso`.'); |
| 158 | return exit(new Promise(resolve => resolve(false))); |
| 159 | } |
| 160 | |
| 161 | // Collect args |
| 162 | const scriptArgs: string[] = parseArgsStringToArgv( |
| 163 | `self ${scriptTask} ${passThroughArgs.join(' ')}`, |
| 164 | ); |
| 165 | |
| 166 | // Print command |
| 167 | logger.debug(`>> ${scriptArgs.slice(1).join(' ')}`); // Run |
| 168 | |
| 169 | runWithArgs(originalCommand, scriptArgs); |
| 170 | }); |
| 171 | }; |
| 172 | |
| 173 | export const go = (args?: string[], exitOverride?: boolean) => { |
| 174 | const commandCreator = (cmd?: string) => { |
no test coverage detected