1 | #!/usr/bin/env node
|
2 |
|
3 | const program = require('commander')
|
4 |
|
5 |
|
6 |
|
7 | const validateConfig = require('../libs/validate-config')
|
8 |
|
9 | const setEnvFromCommand = require('../utils/set-env-from-command')
|
10 |
|
11 | const kootBuild = require('../core/webpack/enter')
|
12 |
|
13 | program
|
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 |
|
23 | const run = async () => {
|
24 |
|
25 | process.stdout.write('\x1B[2J\x1B[0f')
|
26 |
|
27 | const {
|
28 | client, server,
|
29 | stage: _stage,
|
30 | config,
|
31 | type,
|
32 | } = program
|
33 |
|
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 |
|
59 | run()
|