ylyx-cli 1.0.7 → 1.0.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/lib/deploy.js +16 -12
- package/package.json +1 -1
package/lib/deploy.js
CHANGED
|
@@ -63,6 +63,17 @@ function sanitizeBuildDirName(name) {
|
|
|
63
63
|
.slice(0, 80);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
function getBuildDirBaseName({ buildDir, localDir }) {
|
|
67
|
+
// buildDir 可能是路径:只取最后一级目录名
|
|
68
|
+
if (buildDir != null && String(buildDir).trim()) {
|
|
69
|
+
const normalized = String(buildDir).trim().replace(/\\/g, '/').replace(/\/+$/, '');
|
|
70
|
+
const last = normalized.split('/').filter(Boolean).pop();
|
|
71
|
+
if (last) return sanitizeBuildDirName(last);
|
|
72
|
+
}
|
|
73
|
+
// 兜底:使用 localDir 的最后一段目录名
|
|
74
|
+
return sanitizeBuildDirName(path.basename(path.resolve(localDir || process.cwd())));
|
|
75
|
+
}
|
|
76
|
+
|
|
66
77
|
async function zipDirAsTopFolder({ srcDir, zipPath, topFolderName }) {
|
|
67
78
|
fs.ensureDirSync(path.dirname(zipPath));
|
|
68
79
|
await new Promise((resolve, reject) => {
|
|
@@ -234,14 +245,11 @@ async function deploy(overrides = {}) {
|
|
|
234
245
|
|
|
235
246
|
// 正式服:仅压缩
|
|
236
247
|
if (env === 'prod') {
|
|
237
|
-
const buildDirName =
|
|
238
|
-
cfg.buildDir != null && cfg.buildDir !== ''
|
|
239
|
-
? String(cfg.buildDir).replace(/\//g, '').replace(/\\/g, '')
|
|
240
|
-
: path.basename(path.resolve(localFolderPath)).replace(/[\\/]/g, '')
|
|
241
|
-
);
|
|
248
|
+
const buildDirName = getBuildDirBaseName({ buildDir: cfg.buildDir, localDir: localFolderPath });
|
|
242
249
|
const ts = formatTimestampCompact(new Date());
|
|
243
250
|
const hashLetters = computeDirHashLetters(localFolderPath); // 纯字母
|
|
244
|
-
|
|
251
|
+
// 优化命名:更可读、更易分割(buildDir-时间-哈希)
|
|
252
|
+
const zipBaseName = `${buildDirName}-${ts}-${hashLetters}`;
|
|
245
253
|
fs.ensureDirSync(cfg.zipOutDir);
|
|
246
254
|
const zipName = `${zipBaseName}.zip`;
|
|
247
255
|
const zipPath = path.join(cfg.zipOutDir, zipName);
|
|
@@ -317,14 +325,10 @@ async function deploy(overrides = {}) {
|
|
|
317
325
|
|
|
318
326
|
// 测试服可选:部署后压缩(延续之前的可选开关)
|
|
319
327
|
if (cfg.zipAfter) {
|
|
320
|
-
const buildDirName =
|
|
321
|
-
cfg.buildDir != null && cfg.buildDir !== ''
|
|
322
|
-
? String(cfg.buildDir).replace(/\//g, '').replace(/\\/g, '')
|
|
323
|
-
: path.basename(path.resolve(localFolderPath)).replace(/[\\/]/g, '')
|
|
324
|
-
);
|
|
328
|
+
const buildDirName = getBuildDirBaseName({ buildDir: cfg.buildDir, localDir: localFolderPath });
|
|
325
329
|
const ts = formatTimestampCompact(new Date());
|
|
326
330
|
const hashLetters = computeDirHashLetters(localFolderPath); // 纯字母
|
|
327
|
-
const zipBaseName = `${buildDirName}
|
|
331
|
+
const zipBaseName = `${buildDirName}-${ts}-${hashLetters}`;
|
|
328
332
|
fs.ensureDirSync(cfg.zipOutDir);
|
|
329
333
|
const zipName = `${zipBaseName}.zip`;
|
|
330
334
|
const zipPath = path.join(cfg.zipOutDir, zipName);
|