UNPKG

1.66 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3const program = require('commander')
4// const chalk = require('chalk')
5
6// const __ = require('../utils/translate')
7const validateConfig = require('../libs/validate-config')
8// const readBuildConfigFile = require('../utils/read-build-config-file')
9const setEnvFromCommand = require('../utils/set-env-from-command')
10const initNodeEnv = require('../utils/init-node-env')
11
12const kootBuild = require('../core/webpack/enter')
13
14program
15 .version(require('../package').version, '-v, --version')
16 .usage('[options]')
17 .option('-c, --client', 'Set STAGE to CLIENT')
18 .option('-s, --server', 'Set STAGE to SERVER')
19 .option('--stage <stage>', 'Set STAGE')
20 .option('--config <config-file-path>', 'Set config file pathname')
21 .option('--type <project-type>', 'Set project type')
22 .option('--koot-test', 'Koot test mode')
23 .parse(process.argv)
24
25const run = async () => {
26 // 清空 log
27 process.stdout.write('\x1B[2J\x1B[0f')
28
29 const {
30 client, server,
31 stage: _stage,
32 config,
33 type,
34 } = program
35
36 initNodeEnv()
37 // console.log(program)
38
39 setEnvFromCommand({
40 config,
41 type,
42 })
43
44 const stage = _stage ||
45 (client ? 'client' : undefined) ||
46 (server ? 'server' : undefined) ||
47 'client'
48
49 process.env.WEBPACK_BUILD_STAGE = stage || 'client'
50 process.env.WEBPACK_BUILD_ENV = 'prod'
51
52 // 读取构建配置
53 const buildConfig = await validateConfig()
54
55 await kootBuild({
56 analyze: true,
57 ...buildConfig
58 })
59
60 console.log(' ')
61}
62
63run()