@taole/deploy-helper 1.2.7 → 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.
Files changed (2) hide show
  1. package/index.mjs +37 -9
  2. 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 = join(workDir, file);
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
- // 获取srcFilePath的目录
272
- const fileDir = dirname(srcFilePath);
273
- const fileName = basename(srcFilePath);
274
- const dest = process.argv[4] || fileName;
275
- if (dest.includes("/") || dest.includes("\\")) {
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
- if (workDir !== fileDir) {
281
- log(`仅支持scp当前目录下的文件(不带子目录)`);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/deploy-helper",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
5
5
  "main": "index.mjs",
6
6
  "type": "module",