@taole/deploy-helper 1.2.7 → 1.2.9
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/index.mjs +37 -9
- package/lib/pipelineApi.mjs +15 -1
- package/lib/project.mjs +43 -12
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -227,6 +227,7 @@ async function main() {
|
|
|
227
227
|
console.log(`command: test [-c {configFileName}] 测试环境部署`);
|
|
228
228
|
console.log(`command: scp {file} 复制文件{file}到OfficialSite测试服务器{file}`);
|
|
229
229
|
console.log(`command: scp {file} {dest} 复制文件{file}到OfficialSite测试服务器{dest}`);
|
|
230
|
+
console.log(`command: scp {subdir/file} OfficialSite目录下仅放开admin子目录, 如scp admin/xxx.htm`);
|
|
230
231
|
console.log(`command: scpevt {file} 复制文件{file}到events测试服务器{file}`);
|
|
231
232
|
console.log(`command: scpevt {file} {dest} 复制文件{file}到events测试服务器{dest}`);
|
|
232
233
|
console.log(`command: pipeline {pipelineName|pipelineId} [branch] 触发流水线{pipelineName|pipelineId}, 指定分支(可省略)`);
|
|
@@ -258,8 +259,9 @@ async function main() {
|
|
|
258
259
|
process.exit(1);
|
|
259
260
|
}
|
|
260
261
|
const workDir = process.cwd(); // 当前项目根目录
|
|
262
|
+
const isOfficialSite = workDir.replace(/\\/g, '/').split('/').includes('OfficialSite');
|
|
261
263
|
|
|
262
|
-
const srcFilePath =
|
|
264
|
+
const srcFilePath = path.resolve(workDir, file);
|
|
263
265
|
if (!fs.existsSync(srcFilePath)) {
|
|
264
266
|
log(`${srcFilePath}不存在`);
|
|
265
267
|
process.exit(1);
|
|
@@ -268,20 +270,46 @@ async function main() {
|
|
|
268
270
|
log(`${srcFilePath}是目录, 不支持scp目录`);
|
|
269
271
|
process.exit(1);
|
|
270
272
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
log(`dest不能包含/或\\`);
|
|
273
|
+
|
|
274
|
+
// 相对 workDir 的路径,用于判断是否在 admin/ 下
|
|
275
|
+
const relPath = path.relative(workDir, srcFilePath).replace(/\\/g, '/');
|
|
276
|
+
if (!relPath || relPath.startsWith('..') || path.isAbsolute(relPath)) {
|
|
277
|
+
log(`仅支持scp当前目录下的文件`);
|
|
277
278
|
process.exit(1);
|
|
278
279
|
}
|
|
280
|
+
// OfficialSite 仅放开 admin/ 这一级子目录
|
|
281
|
+
const isAdminSubFile = isOfficialSite && /^admin\/[^/]+$/.test(relPath);
|
|
282
|
+
const fileName = basename(srcFilePath);
|
|
283
|
+
const hasSubPath = relPath.includes('/');
|
|
279
284
|
|
|
280
|
-
|
|
281
|
-
|
|
285
|
+
// OfficialSite 下 admin/xxx 时,默认保留相对路径到远端 play/admin/
|
|
286
|
+
let dest = process.argv[4] || (isAdminSubFile ? relPath : fileName);
|
|
287
|
+
dest = dest.replace(/\\/g, '/');
|
|
288
|
+
if (dest.includes('..')) {
|
|
289
|
+
log(`dest不能包含..`);
|
|
282
290
|
process.exit(1);
|
|
283
291
|
}
|
|
284
292
|
|
|
293
|
+
if (isAdminSubFile) {
|
|
294
|
+
// dest 只能是文件名,或 admin/文件名
|
|
295
|
+
if (dest.includes('/') && !/^admin\/[^/]+$/.test(dest)) {
|
|
296
|
+
log(`OfficialSite下仅支持admin子目录, dest须为文件名或admin/文件名`);
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
299
|
+
if (!dest.includes('/')) {
|
|
300
|
+
dest = `admin/${dest}`;
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
if (dest.includes("/")) {
|
|
304
|
+
log(`dest不能包含/或\\`);
|
|
305
|
+
process.exit(1);
|
|
306
|
+
}
|
|
307
|
+
if (hasSubPath) {
|
|
308
|
+
log(`仅支持scp当前目录下的文件(不带子目录); OfficialSite下可使用admin/文件名`);
|
|
309
|
+
process.exit(1);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
285
313
|
const destPath = "/home/web/website/tuwan_www/templets/static/play/" + (command === 'scp' ? '' : 'events/') + dest;
|
|
286
314
|
|
|
287
315
|
const scpClient = await getScpClient();
|
package/lib/pipelineApi.mjs
CHANGED
|
@@ -136,9 +136,23 @@ export function setDevToken(token) {
|
|
|
136
136
|
async function getPipelineInfoByName(name) {
|
|
137
137
|
let pipeline = null;
|
|
138
138
|
try {
|
|
139
|
+
// 云效 ListPipelines 不支持按创建时间排序,需本地按 createTime 升序取最早创建的同名流水线
|
|
139
140
|
const pipelines = await listPipelines(organizationId, { pipelineName: name, perPage: 50, page: 1 });
|
|
140
141
|
if (pipelines && Array.isArray(pipelines.items) && pipelines.items.length > 0) {
|
|
141
|
-
|
|
142
|
+
const matched = pipelines.items
|
|
143
|
+
.filter((item) => item.name === name)
|
|
144
|
+
.sort((a, b) => {
|
|
145
|
+
const ta = Number(a.createTime) || 0;
|
|
146
|
+
const tb = Number(b.createTime) || 0;
|
|
147
|
+
if (ta !== tb) {
|
|
148
|
+
return ta - tb;
|
|
149
|
+
}
|
|
150
|
+
return Number(a.id) - Number(b.id);
|
|
151
|
+
});
|
|
152
|
+
if (matched.length > 1) {
|
|
153
|
+
log(`发现${matched.length}条同名流水线【${name}】,将使用最早创建的: id=${matched[0].id}, createTime=${matched[0].createTime}`);
|
|
154
|
+
}
|
|
155
|
+
pipeline = matched[0] || null;
|
|
142
156
|
}
|
|
143
157
|
} catch (error) {
|
|
144
158
|
throw new Error(`获取流水线信息失败, 请确认流水线名称:【${name}】是否正确或检查云效token的权限是否足够: ${error}`);
|
package/lib/project.mjs
CHANGED
|
@@ -102,6 +102,20 @@ async function apiGetTemplateProjects(userCache) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
async function apiGetProject(nameOrId, userCache) {
|
|
106
|
+
const res = await fetch(`${apiHost}/h5projects/${encodeURIComponent(nameOrId)}`, {
|
|
107
|
+
headers: {
|
|
108
|
+
Cookie: `Tuwan_Passport=${userCache.Tuwan_Passport}`,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
const resJson = await res.json();
|
|
112
|
+
if (!res.ok) {
|
|
113
|
+
const error = (resJson && resJson.message) || "获取项目信息失败";
|
|
114
|
+
throw new Error(error);
|
|
115
|
+
}
|
|
116
|
+
return resJson;
|
|
117
|
+
}
|
|
118
|
+
|
|
105
119
|
async function apiCreateProject(name, userCache, templateId) {
|
|
106
120
|
try {
|
|
107
121
|
const body = { name };
|
|
@@ -388,7 +402,6 @@ export const cmdProjectPublish = async () => {
|
|
|
388
402
|
|
|
389
403
|
export const cmdProjectPull = async () => {
|
|
390
404
|
const name = process.argv[3];
|
|
391
|
-
const projectDir = path.join(process.cwd(), name);
|
|
392
405
|
if (!name) {
|
|
393
406
|
log("请输入项目名称");
|
|
394
407
|
process.exit(1);
|
|
@@ -402,13 +415,30 @@ export const cmdProjectPull = async () => {
|
|
|
402
415
|
log("项目名称不能是纯数字");
|
|
403
416
|
process.exit(1);
|
|
404
417
|
}
|
|
418
|
+
const projectDir = path.join(process.cwd(), name);
|
|
405
419
|
if (fs.existsSync(projectDir)) {
|
|
406
420
|
log(`项目目录${projectDir}已存在`);
|
|
407
421
|
process.exit(1);
|
|
408
422
|
}
|
|
409
|
-
|
|
423
|
+
|
|
424
|
+
const userCache = await getLoginCache();
|
|
425
|
+
if (!userCache || !userCache.userInfo || !userCache.userInfo.uid) {
|
|
426
|
+
log("请先登录");
|
|
427
|
+
process.exit(1);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const project = await apiGetProject(name, userCache);
|
|
431
|
+
if (project.projectType !== "normal") {
|
|
432
|
+
log(`仅支持拉取 projectType=normal 的项目,当前类型为 ${project.projectType || "未知"}`);
|
|
433
|
+
process.exit(1);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const projectName = project.name || name;
|
|
437
|
+
const repoUrl =
|
|
438
|
+
project.repoUrl ||
|
|
439
|
+
`https://codeup.aliyun.com/69b3821af7b43e00d420cb32/Web-Act/${projectName}`;
|
|
410
440
|
log(`项目仓库地址: ${repoUrl}`);
|
|
411
|
-
const httpRepoUrl = repoUrl + ".git";
|
|
441
|
+
const httpRepoUrl = repoUrl.endsWith(".git") ? repoUrl : repoUrl + ".git";
|
|
412
442
|
const sshRepoUrl = httpRepoUrl.replace(
|
|
413
443
|
"https://codeup.aliyun.com/",
|
|
414
444
|
"git@codeup.aliyun.com:"
|
|
@@ -416,32 +446,33 @@ export const cmdProjectPull = async () => {
|
|
|
416
446
|
let git = simpleGit(process.cwd());
|
|
417
447
|
let sshFail = false;
|
|
418
448
|
try {
|
|
419
|
-
await git.clone(sshRepoUrl,
|
|
449
|
+
await git.clone(sshRepoUrl, projectName);
|
|
420
450
|
} catch (error) {
|
|
421
451
|
log(`使用SSH协议克隆失败, 尝试使用HTTP协议克隆`);
|
|
422
452
|
sshFail = true;
|
|
423
453
|
}
|
|
424
454
|
if (sshFail) {
|
|
425
455
|
try {
|
|
426
|
-
await git.clone(httpRepoUrl,
|
|
456
|
+
await git.clone(httpRepoUrl, projectName);
|
|
427
457
|
} catch (error) {
|
|
428
458
|
throw new Error(`克隆仓库失败`);
|
|
429
459
|
}
|
|
430
460
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
461
|
+
const clonedDir = path.join(process.cwd(), projectName);
|
|
462
|
+
log(`项目拉取成功, 项目目录: ${projectName}`);
|
|
463
|
+
git = simpleGit(clonedDir);
|
|
464
|
+
const targetPackageJson = getJsonConfig(clonedDir, "package.json");
|
|
465
|
+
if (targetPackageJson.name !== projectName) {
|
|
466
|
+
targetPackageJson.name = projectName;
|
|
436
467
|
fs.writeFileSync(
|
|
437
|
-
path.join(
|
|
468
|
+
path.join(clonedDir, "package.json"),
|
|
438
469
|
JSON.stringify(targetPackageJson, null, 2)
|
|
439
470
|
);
|
|
440
471
|
log(`项目package.json覆盖成功`);
|
|
441
472
|
await git.add(".");
|
|
442
473
|
await git.commit(`-#DH-07 feat: 项目初始化`);
|
|
443
474
|
}
|
|
444
|
-
log(`请cd至项目目录: ${
|
|
475
|
+
log(`请cd至项目目录: ${clonedDir} 进行后续开发`);
|
|
445
476
|
process.exit(0);
|
|
446
477
|
};
|
|
447
478
|
|