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