hm-react-cli
Version:
Create a Huimei React project by module
67 lines (60 loc) • 2.95 kB
JavaScript
const { program } = require('commander');
const path = require('path');
const pkg = require('./package.json');
const create = require('./command/create');
const serve = require('./command/serve');
const build = require('./command/build');
// 配置command
program
.command(`create`)
.argument('<appName>', '项目名称')
.description('使用 hm-cli-service 创建一个新项目 react 项目')
.action((appName) => {
// yarn create ./app.js -p ./hm.config.js
create(appName);
});
program
.command(`serve`)
.argument('[entry...]', '入口文件')
.option('-c, --config <path>', '配置文件路径')
.description('使用 hm-cli-service 启动一个或多个页面服务服务')
.action((entry, options) => {
// yarn serve ./app.js -c ./hm.config.js
serve(entry, options);
});
program
.command(`build`)
.argument('[entry...]', '入口文件')
.option('-c, --config <path>', '配置文件路径')
.description('使用 hm-cli-service 创建一个新项目 react 项目')
.action((entry,options) => {
// yarn build ./app.js -c ./hm.config.js
build(entry, options);
});
function blue(str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m';
}
// 配置 cli 信息,版本、cli说明等
program.version(pkg.version);
// 接管命令行输入,参数处理
program.parse(process.argv);
function initFn() {
console.log(`
使用方式:hm-react <command> [options]
Commands:
create [options] <app-name> create a new project powered by react-cli-service
add [options] <plugin> [pluginOptions] install a plugin and invoke its generator in an already created project
invoke [options] <plugin> [pluginOptions] invoke the generator of a plugin in an already created project
inspect [options] [paths...] inspect the webpack config in a project with vue-cli-service
serve [options] [entry] serve a .js or .vue file in development mode with zero config
build [options] [entry] build a .js or .vue file in production mode with zero config
ui [options] start and open the vue-cli ui
init [options] <template> <app-name> generate a project from a remote template (legacy API, requires @vue/cli-init)
config [options] [value] inspect and modify the config
outdated [options] (experimental) check for outdated vue cli service / plugins
upgrade [options] [plugin-name] (experimental) upgrade vue cli service / plugins
migrate [options] [plugin-name] (experimental) run migrator for an already-installed cli plugin
info print debugging information about your environment
运行 ${blue(' hm-react --help ')} 获取给定命令的详细用法。`);
}