|
| 1 | +import prompts from 'prompts'; |
| 2 | +import {getConfig} from '../getConfig.js'; |
| 3 | +import child_process from 'node:child_process'; |
| 4 | +import {parseConfigTasks} from '../parseConfigTasks.js'; |
| 5 | +import chalk from 'chalk'; |
| 6 | + |
| 7 | +export async function defaultCommand(argv) { |
| 8 | + const {config: specifiedConfigPath} = argv; |
| 9 | + |
| 10 | + /** @type {import('../types.js').BeginConfig} */ |
| 11 | + const config = getConfig(specifiedConfigPath); |
| 12 | + |
| 13 | + /** @type {{task: import('../types.js').TaskObjectForm}} */ |
| 14 | + const {task} = await prompts({ |
| 15 | + type: 'autocomplete', |
| 16 | + name: 'task', |
| 17 | + message: 'Select a task to run', |
| 18 | + suggest: (input, choices) => |
| 19 | + Promise.resolve( |
| 20 | + choices.filter(choice => |
| 21 | + choice.title.toLowerCase().includes(input.toLowerCase()) |
| 22 | + ) |
| 23 | + ), |
| 24 | + clearFirst: true, |
| 25 | + choices: parseConfigTasks(config).map(({name, script, description}) => ({ |
| 26 | + title: name ?? script, |
| 27 | + value: {name, script, description}, |
| 28 | + description |
| 29 | + })) |
| 30 | + }); |
| 31 | + |
| 32 | + if (task) { |
| 33 | + console.log(); |
| 34 | + console.log( |
| 35 | + `${chalk.bgMagenta.bold(' Task ➤_ ')} ${chalk.magenta.bold(task.description)} |
| 36 | + ` |
| 37 | + ); |
| 38 | + console.log(chalk.grey(task.script)); |
| 39 | + child_process.spawnSync( |
| 40 | + task.script.split(' ')[0], |
| 41 | + task.script.split(' ').slice(1), |
| 42 | + {stdio: 'inherit', shell: true} |
| 43 | + ); |
| 44 | + console.log(); |
| 45 | + } |
| 46 | +} |
0 commit comments