UNPKG

1.54 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')
10
11const kootBuild = require('../core/webpack/enter')
12
13program
14 .version(require('../package').version, '-v, --version')
15 .usage('[options]')
16 .option('-c, --client', 'Set STAGE to CLIENT')
17 .option('-s, --server', 'Set STAGE to SERVER')
18 .option('--stage <stage>', 'Set STAGE')
19 .option('--config <config-file-path>', 'Set config file pathname')
20 .option('--type <project-type>', 'Set project type')
21 .parse(process.argv)
22
23const run = async () => {
24 // 清空 log
25 process.stdout.write('\x1B[2J\x1B[0f')
26
27 const {
28 client, server,
29 stage: _stage,
30 config,
31 type,
32 } = program
33 // console.log(program)
34
35 setEnvFromCommand({
36 config,
37 type,
38 })
39
40 const stage = _stage ||
41 (client ? 'client' : undefined) ||
42 (server ? 'server' : undefined) ||
43 'client'
44
45 process.env.WEBPACK_BUILD_STAGE = stage || 'client'
46 process.env.WEBPACK_BUILD_ENV = 'prod'
47
48 // 读取构建配置
49 const buildConfig = await validateConfig()
50
51 await kootBuild({
52 analyze: true,
53 ...buildConfig
54 })
55
56 console.log(' ')
57}
58
59run()