1
0
mirror of synced 2026-04-03 06:28:35 +08:00

feat(cli): 新增tamgic-cli,用于runtime 依赖生成

This commit is contained in:
roymondchen
2022-08-03 14:56:54 +08:00
committed by jia000
parent f1a8097e06
commit f18e7b275d
15 changed files with 1343 additions and 339 deletions

44
packages/cli/src/cli.ts Normal file
View File

@@ -0,0 +1,44 @@
import { allowTs, info } from '@vuepress/cli';
import { cac } from 'cac';
import chalk from 'chalk';
import { scripts } from './commands';
import { UserConfig } from './types';
/**
* Wrap raw command to catch errors and exit process
*/
const wrapCommand = (cmd: (...args: any[]) => Promise<void>): typeof cmd => {
const wrappedCommand: typeof cmd = (...args) =>
cmd(...args).catch((err) => {
console.error(chalk.red(err.stack));
process.exit(1);
});
return wrappedCommand;
};
/**
* Vuepress cli
*/
export const cli = (defaultAppConfig: UserConfig): void => {
// allow ts files globally
allowTs();
// create cac instance
const program = cac('tmagic');
// display core version and cli version
const versionCli = require('../package.json').version;
program.version(`tmagic/cli@${versionCli}`);
// display help message
program.help();
// register `dev` command
program.command('entry', 'Start development server').action(wrapCommand(scripts(defaultAppConfig)));
// register `info` command
program.command('info', 'Display environment information').action(wrapCommand(info));
program.parse(process.argv);
};