UNPKG

@daiyu-5577/quickbuild

Version:

front-end build service

45 lines (44 loc) 1.59 kB
import { Command } from "commander"; import Build from './commandBuild/index.js'; import CommandServer from './commandServer/index.js'; import fs from 'fs-extra'; import path from 'path'; import '../utils/axios.js'; const __dirname = new URL('.', import.meta.url).pathname; let packageJsonPath = path.join(__dirname, '../../package.json'); if (process.env.NODE_ENV === 'development') { packageJsonPath = path.join(__dirname, '../package.json'); } let packageJson = fs.readJSONSync(packageJsonPath); const program = new Command(); program .name('quickbuild') .description(packageJson.description) .version(packageJson.version); program.command('build') .description('build website') .requiredOption('-b, --branch <string>', '选择构建分支') .option('-p, --packagePaths <string...>', '指定构建目录') .option('-c, --commit <string>', '选择构建commit...commit区间,用于monorepo项目', '') .option('-n, --notify <string>', '构建消息通知地址', '') .action((options) => { const { packagePaths = ['.'], branch, commit, notify } = options; const builder = new Build({}); packagePaths.forEach((v) => { builder.addTask({ packagePath: v, branch, commit, notify, }); }); }); program.command('server') .description('start build service') .option('-p, --port [number]', 'select port', '3000') .action((options) => { const { port } = options; const commandServer = new CommandServer({ port }); commandServer.start(); }); program.parse();