1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 | const program = require('commander')
|
5 | const chalk = require('chalk')
|
6 |
|
7 | const __ = require('../utils/translate')
|
8 | const readBuildConfigFile = require('../utils/read-build-config-file')
|
9 | const sleep = require('../utils/sleep')
|
10 | const setEnvFromCommand = require('../utils/set-env-from-command')
|
11 |
|
12 | const superBuild = 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('--env <env>', 'Set ENV')
|
21 | .option('--config <config-file-path>', 'Set config file')
|
22 | .option('--type <project-type>', 'Set project type')
|
23 | .parse(process.argv)
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | const run = async () => {
|
29 |
|
30 | process.stdout.write('\x1B[2J\x1B[0f')
|
31 |
|
32 | const {
|
33 | client, server,
|
34 | stage: _stage,
|
35 | env = 'prod',
|
36 | config,
|
37 | type,
|
38 | } = program
|
39 |
|
40 | setEnvFromCommand({
|
41 | config,
|
42 | type,
|
43 | })
|
44 |
|
45 | const stage = _stage ? _stage : (client ? 'client' : (server ? 'server' : false))
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | process.env.WEBPACK_BUILD_STAGE = stage || 'client'
|
75 | process.env.WEBPACK_BUILD_ENV = env
|
76 |
|
77 |
|
78 | const buildConfig = await readBuildConfigFile()
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | if (stage) {
|
85 |
|
86 |
|
87 |
|
88 | return await superBuild(buildConfig)
|
89 | }
|
90 |
|
91 |
|
92 | await superBuild({ ...buildConfig })
|
93 | await sleep(100)
|
94 |
|
95 |
|
96 |
|
97 | console.log('\n' + ''.padEnd(60, '=') + '\n')
|
98 | process.env.WEBPACK_BUILD_STAGE = 'server'
|
99 | await superBuild({ ...buildConfig })
|
100 | await sleep(100)
|
101 |
|
102 | console.log('\n' + ''.padEnd(60, '=') + '\n')
|
103 | console.log(
|
104 | chalk.green('√ ')
|
105 | + chalk.yellowBright('[super/build] ')
|
106 | + __('build.complete', {
|
107 | time: (new Date()).toLocaleString()
|
108 | })
|
109 | )
|
110 | }
|
111 |
|
112 | run()
|