@taole/deploy-helper 1.2.6 → 1.2.8
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 +38 -10
- package/lib/project.mjs +11 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -154,7 +154,7 @@ function doRegisterCommands() {
|
|
|
154
154
|
registerCommand("create", cmdProjectCreate, "创建项目");
|
|
155
155
|
registerCommand("publish", cmdProjectPublish, "更新项目到H5平台");
|
|
156
156
|
registerCommand("pull", cmdProjectPull, "拉取已有项目到本地");
|
|
157
|
-
registerCommand("mr", cmdProjectMr, "创建合并请求到 master
|
|
157
|
+
registerCommand("mr", cmdProjectMr, "创建合并请求到 master(可选 [title] [--verbose])");
|
|
158
158
|
registerCommand("commit", cmdCommit, "按任务号提交(参数为说明,如 feat: xxx)");
|
|
159
159
|
registerCommand("whoami", cmdWhoami, "查看当前登录用户信息");
|
|
160
160
|
registerCommand("logout", cmdLogout, "退出登录");
|
|
@@ -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/project.mjs
CHANGED
|
@@ -450,8 +450,16 @@ const MR_FORBIDDEN_BRANCHES = new Set(["master", "test"]);
|
|
|
450
450
|
/**
|
|
451
451
|
* 创建合并请求:当前分支 → master
|
|
452
452
|
* 前置:工作区干净、非 master/test、无未推送 commit
|
|
453
|
+
* 用法: dh mr [title] [--verbose]
|
|
453
454
|
*/
|
|
454
455
|
export const cmdProjectMr = async () => {
|
|
456
|
+
const rawArgs = process.argv.slice(3);
|
|
457
|
+
const verbose = rawArgs.some((arg) => arg === "--verbose" || arg === "-V");
|
|
458
|
+
const titleArg = rawArgs
|
|
459
|
+
.filter((arg) => arg !== "--verbose" && arg !== "-V")
|
|
460
|
+
.join(" ")
|
|
461
|
+
.trim();
|
|
462
|
+
|
|
455
463
|
const git = simpleGit(process.cwd());
|
|
456
464
|
const gitStatus = await git.status();
|
|
457
465
|
|
|
@@ -491,7 +499,6 @@ export const cmdProjectMr = async () => {
|
|
|
491
499
|
}
|
|
492
500
|
await checkPackageNameWithGitRemote(git, packageJson.name);
|
|
493
501
|
|
|
494
|
-
const titleArg = process.argv.slice(3).join(" ").trim();
|
|
495
502
|
log(`开始创建 MR: ${sourceBranch} → master(项目 ${packageJson.name})`);
|
|
496
503
|
const result = await apiCreateMergeRequest(packageJson.name, sourceBranch, userCache, {
|
|
497
504
|
title: titleArg || undefined,
|
|
@@ -501,5 +508,8 @@ export const cmdProjectMr = async () => {
|
|
|
501
508
|
if (mrUrl) {
|
|
502
509
|
log(`MR 地址: ${mrUrl}`);
|
|
503
510
|
}
|
|
511
|
+
if (verbose) {
|
|
512
|
+
log(`MR 接口返回:\n${JSON.stringify(result, null, 2)}`);
|
|
513
|
+
}
|
|
504
514
|
process.exit(0);
|
|
505
515
|
};
|