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 | const initNodeEnv = require('../utils/init-node-env')
|
11 |
|
12 | const kootBuild = require('../core/webpack/enter')
|
13 |
|
14 | program
|
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 |
|
25 | const run = async () => {
|
26 |
|
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 |
|
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 |
|
63 | run()
|