@taole/deploy-helper 1.2.8 → 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/lib/pipelineApi.mjs +15 -1
- package/lib/project.mjs +43 -12
- package/package.json +1 -1
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
|
|