-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroadhog.js
230 lines (205 loc) · 7.37 KB
/
roadhog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/usr/bin/env node
const argv = require('yargs').argv;
const _ = require('lodash');
// eslint-disable-next-line no-unused-vars
const shell = require('shelljs');
const fs = require('fs');
let fileProjEnv = false;
try {
fileProjEnv = `${fs.readFileSync('./.proj_env').toString()}`.trim();
}
catch (e) {
// do nothing
}
// eslint-disable-next-line no-console
console.log('\n\n');
// eslint-disable-next-line no-console
console.log('argv', argv);
// eslint-disable-next-line no-console
console.log('argv.force', `'${argv.force || ''}'`);
// eslint-disable-next-line no-console
console.log('process.env.SMART_PC_PROJ', `'${process.env.SMART_PC_PROJ || ''}'`);
// eslint-disable-next-line no-console
console.log('fileProjEnv:', `'${fileProjEnv || ''}'`);
// eslint-disable-next-line no-console
console.log('\n\n');
if (process.env.SMART_PC_PROJ && fileProjEnv && fileProjEnv !== process.env.SMART_PC_PROJ) {
if (!argv.force) {
// eslint-disable-next-line no-console
console.log('process.env.SMART_PC_PROJ 和 fileProjEnv 同时存在而且不相等,不能发布');
// eslint-disable-next-line no-console
console.log('如果一定要发布这个环境的项目,需要使用 --force 指令');
// eslint-disable-next-line no-console
console.log(`process.env.SMART_PC_PROJ:'${process.env.SMART_PC_PROJ}' ,fileProjEnv: '${fileProjEnv}'`);
process.exit();
}
}
// 优先判断这个环境变量
if (!argv.mergeBranch && fileProjEnv) {
if (!argv.force && argv.proj !== fileProjEnv) {
if (!argv.force) {
// eslint-disable-next-line no-console
console.log('当前发布的环境与服务器预计的发布环境不一致,不能发布。');
// eslint-disable-next-line no-console
console.log('如果一定要发布这个环境的项目,需要使用 --force 指令');
// eslint-disable-next-line no-console
console.log(`(fileProjEnv)当前环境应该为: ${fileProjEnv} ,实际传输为: ${argv.proj}`);
process.exit();
}
}
}
//
if (!argv.mergeBranch && process.env.SMART_PC_PROJ) {
if (!argv.force && argv.proj !== process.env.SMART_PC_PROJ) {
if (!argv.force) {
// eslint-disable-next-line no-console
console.log('当前发布的环境与服务器预计的发布环境不一致,不能发布。');
// eslint-disable-next-line no-console
console.log('如果一定要发布这个环境的项目,需要使用 --force 指令');
// eslint-disable-next-line no-console
console.log(`(process.env.SMART_PC_PROJ)当前环境应该为: ${process.env.SMART_PC_PROJ} ,实际传输为: ${argv.proj}`);
process.exit();
}
}
}
const {
buildModules,
getProjectConfig,
} = require('./get_config');
// eslint-disable-next-line no-unused-vars
const shells = [];
const parallelShells = [];
const normalEnv = 'TSLINT=none ESLINT=none BROWSER=none';
let isValid = false;
if (argv.mergeBranch) {
const baseBr = argv.base;
const releaseBr = argv.release;
// 这里是进行测试分支的处理操作,需要合并当前优化的分支
const shellsTemp = [];
shellsTemp.push('git reset --hard HEAD');
shellsTemp.push('git checkout master');
// 先运行基础指令
shell.exec(shellsTemp.join(' && '));
try {
// 进行删除分支,如果有的话。
shell.exec(`git branch -D ${baseBr}`);
}
catch (e) {
// do nothing
}
try {
// 进行删除分支,如果有的话。
shell.exec(`git branch -D ${releaseBr}`);
}
catch (e) {
// do nothing
}
// 运行接下来的分支
shells.push('git remote update');
shells.push(`git checkout ${baseBr}`);
shells.push(`git checkout -b pre-test-${releaseBr}-${new Date() * 1}`);
// // 这个是不进行 commit 的
// shells.push(`git merge --no-commit --no-edit origin/${baseBr} -X theirs`);
// 这个是进行 commit 的
shells.push(`git merge --no-edit origin/${releaseBr} -X theirs`);
isValid = true;
}
else if (argv.watch) {
isValid = true;
let modules = buildModules;
if (argv.modules && _.split(argv.modules, ',').length) {
modules = _.split(argv.modules, ',');
}
_.each(modules, (buildModule) => {
if (buildModules.includes(buildModule)) {
const projConfig = getProjectConfig({
module: buildModule,
proj: argv.proj,
});
// const SOCKET_SERVER = `SOCKET_SERVER=${projConfig.DEV_SOCKET_PREFIX}:${projConfig.CURRENT_DEV_PORT}`;
const SOCKET_SERVER = `SOCKET_SERVER=/${(projConfig.CURRENT_WEB_PREFIX.replace(/^\//, '')).replace(/\/$/, '')}/${((projConfig.DEV_SOCKET_PREFIX || '').replace(/^\//, '')).replace(/\/$/, '')}/sockjs-node`;
// SOCKET_SERVER = SOCKET_SERVER.replace(/\/$/, '/');
// SOCKET_SERVER = `${projConfig.CURRENT_WEB_PREFIX.replace(/^\//, '')}/${SOCKET_SERVER}/sockjs-node`;
const shellStr = [
'cross-env',
`${SOCKET_SERVER}`,
`PORT=${projConfig.CURRENT_DEV_PORT}`,
`proj=${argv.proj}`,
`RELEASE_MODULE=${buildModule}`,
`${normalEnv}`,
'RELEASE_ENV=DEV',
`ASSET_PATH=/${buildModule}/`,
'NODE_ENV=development',
'mode=development',
];
console.log(shellStr)
shellStr.push('yarn w4start');
parallelShells.push(shellStr.join(' '));
}
else {
isValid = false;
}
});
}
else if (argv.build) {
isValid = true;
let modules = buildModules;
if (argv.modules && _.split(argv.modules, ',').length) {
modules = _.split(argv.modules, ',');
}
_.each(modules, (buildModule) => {
// shells.push(`rimraf prod/${buildModule}`);
const shellStr = [
'cross-env',
`RELEASE_MODULE=${buildModule}`,
`${normalEnv}`,
`proj=${argv.proj}`,
`ASSET_PATH=/${buildModule}/`,
'RELEASE_ENV=RELEASE',
'NODE_ENV=production',
'mode=production',
];
shellStr.push('yarn w4build');
shells.push(shellStr.join(' '));
// 创建打包存放的目标文件夹。如果存在,那也不会报错。
shells.push(`mkdir -p ./prod/${buildModule}`);
// 将打包完毕的文件存储到
shells.push(`cp -rf ./.prod_v2/${buildModule}/* ./prod/${buildModule}/`);
});
}
if (!isValid) {
// eslint-disable-next-line no-console
console.warn('目前已有的模块', buildModules.join(','));
// eslint-disable-next-line no-console
console.warn('请传入参数');
// eslint-disable-next-line no-console
console.warn('开发模式 单个例子: yarn start -- --module app');
// eslint-disable-next-line no-console
console.warn('开发模式 多个个例子: yarn start -- --modules app,hse,cas');
// eslint-disable-next-line no-console
console.warn('开发模式 全部例子: yarn start');
// eslint-disable-next-line no-console
console.warn('打包模式 单个例子: yarn release -- --module app');
// eslint-disable-next-line no-console
console.warn('打包模式 全部例子:yarn release');
}
else {
// // eslint-disable-next-line no-console
// console.log(argv);
// eslint-disable-next-line no-console
console.log('\n\n');
// eslint-disable-next-line no-console
console.log(shells.join(' && '));
// eslint-disable-next-line no-console
console.log('\n\n');
// eslint-disable-next-line no-console
console.log(parallelShells.join(' | '));
// eslint-disable-next-line no-console
console.log('\n\n');
if (shells && shells.length) {
shell.exec(shells.join(' && '));
}
if (parallelShells && parallelShells.length) {
shell.exec(parallelShells.join(' | '));
}
}