@opentapd/tplugin-cli 0.21.0-beta.2 → 0.21.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/deploy.js +90 -18
- package/package.json +1 -1
package/lib/deploy.js
CHANGED
|
@@ -19,7 +19,7 @@ const archiver = require('archiver');
|
|
|
19
19
|
const crypto = require('crypto');
|
|
20
20
|
const path = require('path');
|
|
21
21
|
const { get } = require('lodash');
|
|
22
|
-
|
|
22
|
+
const getFolderHash = require('../util/getFolderHash');
|
|
23
23
|
// CLI部署
|
|
24
24
|
module.exports = async () => {
|
|
25
25
|
// 先lint检查插件格式是否正常
|
|
@@ -39,7 +39,30 @@ module.exports = async () => {
|
|
|
39
39
|
if (tpluginConf.tapd.pluginEnv === 'oa') {
|
|
40
40
|
await oaEnvDeploy(docObj);
|
|
41
41
|
} else {
|
|
42
|
-
|
|
42
|
+
// 生成插件的文件hash;
|
|
43
|
+
const projectHash = (await getFolderHash(process.cwd(), new SimpleGit())).slice(0, 8);
|
|
44
|
+
|
|
45
|
+
// 检测版本是否被占用
|
|
46
|
+
await checkDeployVersion({
|
|
47
|
+
version: `v-${projectHash}`,
|
|
48
|
+
code: docObj.app.code,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// 版本别名
|
|
52
|
+
const { versionAlias } = await inquirer.prompt([{
|
|
53
|
+
type: 'input',
|
|
54
|
+
name: 'versionAlias',
|
|
55
|
+
message: `请填写发布的版本号(default:v-${projectHash})`,
|
|
56
|
+
default: `v-${projectHash}`,
|
|
57
|
+
}]);
|
|
58
|
+
|
|
59
|
+
const zipper = promisify(zipCurrentWorkspace);
|
|
60
|
+
const zipFilePath = await zipper(docObj.app.code);
|
|
61
|
+
await uploadZipFile(docObj.app.code, zipFilePath);
|
|
62
|
+
removeZipFile(zipFilePath);
|
|
63
|
+
await deploy('', projectHash, docObj.app.code, {
|
|
64
|
+
nick: versionAlias,
|
|
65
|
+
});
|
|
43
66
|
}
|
|
44
67
|
};
|
|
45
68
|
|
|
@@ -113,17 +136,12 @@ async function oaEnvDeploy(docObj) {
|
|
|
113
136
|
}
|
|
114
137
|
}
|
|
115
138
|
|
|
116
|
-
|
|
117
|
-
function
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// 删除文件
|
|
123
|
-
removeZipFile(zipFilePath);
|
|
124
|
-
// 开始触发部署流水线
|
|
125
|
-
deploy('', '', docObj.app.code);
|
|
126
|
-
});
|
|
139
|
+
function promisify(fun) {
|
|
140
|
+
return function (...args) {
|
|
141
|
+
return new Promise(resolove => fun.apply(fun, [...args, (result) => {
|
|
142
|
+
resolove(result);
|
|
143
|
+
}]));
|
|
144
|
+
};
|
|
127
145
|
}
|
|
128
146
|
|
|
129
147
|
function removeZipFile(filePath) {
|
|
@@ -210,8 +228,9 @@ function uploadToCos(...args) {
|
|
|
210
228
|
* @param commit 部署的commit点
|
|
211
229
|
* @param code 插件code
|
|
212
230
|
*/
|
|
213
|
-
async function deploy(branch, commit, code) {
|
|
231
|
+
async function deploy(branch, commit, code, { nick } = {}) {
|
|
214
232
|
let buildId = '';
|
|
233
|
+
const { pluginEnv } = tpluginConf.tapd;
|
|
215
234
|
try {
|
|
216
235
|
spinner.start('启动部署任务');
|
|
217
236
|
|
|
@@ -220,7 +239,8 @@ async function deploy(branch, commit, code) {
|
|
|
220
239
|
branch,
|
|
221
240
|
commit_id: commit,
|
|
222
241
|
client_id: code,
|
|
223
|
-
plugin_env:
|
|
242
|
+
plugin_env: pluginEnv,
|
|
243
|
+
nick,
|
|
224
244
|
}, method: 'POST' });
|
|
225
245
|
|
|
226
246
|
// 流水线启动失败
|
|
@@ -257,14 +277,21 @@ async function deploy(branch, commit, code) {
|
|
|
257
277
|
|
|
258
278
|
// 部署后,提示安装测试项目
|
|
259
279
|
if (buildStatus === 'SUCCEED') {
|
|
260
|
-
if (
|
|
280
|
+
if (pluginEnv === 'oa') {
|
|
261
281
|
spinner.succeed(`部署成功 => 分支[${branch}], 部署节点[${commit}]`);
|
|
262
282
|
} else {
|
|
263
283
|
spinner.succeed(`部署成功, 部署版本[${commit}]`);
|
|
264
284
|
}
|
|
265
285
|
|
|
266
|
-
|
|
267
|
-
|
|
286
|
+
if (pluginEnv === 'cloud') {
|
|
287
|
+
await switchTestVersionTips({
|
|
288
|
+
code,
|
|
289
|
+
version: `v-${commit}`,
|
|
290
|
+
});
|
|
291
|
+
} else {
|
|
292
|
+
const tips = `前往TAPD开放平台,添加项目进行测试。${tpluginConf.tapd.openHost}/admin/${code}/testdeploy`;
|
|
293
|
+
console.log(chalk.green(tips));
|
|
294
|
+
}
|
|
268
295
|
|
|
269
296
|
return undefined;
|
|
270
297
|
} if (buildStatus === 'FAILED') {
|
|
@@ -277,3 +304,48 @@ async function deploy(branch, commit, code) {
|
|
|
277
304
|
const deployTips = `前往TAPD开放平台,查看部署进度。${tpluginConf.tapd.openHost}/admin/${code}/codedeploy`;
|
|
278
305
|
spinner.fail(deployTips);
|
|
279
306
|
}
|
|
307
|
+
|
|
308
|
+
async function switchTestVersionTips({ code, version }) {
|
|
309
|
+
const currentVersion = await getAppTestVersion({ code });
|
|
310
|
+
if (currentVersion) {
|
|
311
|
+
const { switchVersion } = await inquirer.prompt({
|
|
312
|
+
type: 'confirm',
|
|
313
|
+
message: '是否将当前版本替换为测试版本',
|
|
314
|
+
name: 'switchVersion',
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
if (switchVersion) {
|
|
318
|
+
await switchTestVersion({ code, version });
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
spinner.succeed(`前往TAPD开放平台,测试应用。${tpluginConf.tapd.openHost}/admin/${code}/codedeploy`);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// 获取当前公司的测试版本
|
|
325
|
+
async function getAppTestVersion({ code }) {
|
|
326
|
+
const { data } = await tapdsdk.request({ url: 'open_user_app/get_app_current_test_version', params: {
|
|
327
|
+
code,
|
|
328
|
+
} });
|
|
329
|
+
return get(data, 'data.test_deploy_info');
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// 切换当前公司的测试版本
|
|
333
|
+
async function switchTestVersion({ code, version }) {
|
|
334
|
+
const { data } = await tapdsdk.request({ url: 'open_user_app/switch_test_app_version', params: {
|
|
335
|
+
code,
|
|
336
|
+
version,
|
|
337
|
+
} });
|
|
338
|
+
return data;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
async function checkDeployVersion({ version, code }) {
|
|
342
|
+
const { data } = await tapdsdk.request({ url: 'open_user_app/check_app_version', params: {
|
|
343
|
+
code,
|
|
344
|
+
version,
|
|
345
|
+
} });
|
|
346
|
+
|
|
347
|
+
if (data.data.exist !== false) {
|
|
348
|
+
throw new Error('该代码已经部署过了');
|
|
349
|
+
}
|
|
350
|
+
return true;
|
|
351
|
+
}
|