fes.js/packages/fes/bin/index.js
2020-11-02 09:51:40 +08:00

55 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
const commander = require('commander');
const pkg = require('../package.json');
const generateConfig = require('../build/helpers/config');
const log = require('../build/helpers/log');
commander.usage('<command> [options]')
.version(pkg.version, '-v, --vers')
.option('-e, --env <env>', '配置环境 local(本地) | sit(测试) | prod(生产)')
.description(pkg.description);
commander.command('init [name]')
.description('创建项目')
.action(async (name) => {
const projectInit = require('../build/tasks/init');
const config = generateConfig('init');
await projectInit(config, name);
});
commander.command('update')
.description('将 fes2 项目升级到 fes3')
.action(() => {
const update = require('../build/tasks/update');
const config = generateConfig('update');
update(config);
});
commander.command('dev')
.description('开发调试, 默认 local')
.action(() => {
const dev = require('../build/tasks/dev');
const config = generateConfig('dev', commander.env || 'local');
dev(config);
});
commander.command('build')
.description('打包压缩,默认 prod')
.action(() => {
const build = require('../build/tasks/build');
const config = generateConfig('build', commander.env || 'prod');
build(config);
});
commander.parse(process.argv);
if (!process.argv.slice(2).length) {
commander.outputHelp((text) => {
log.message(text);
return '';
});
}