i18-fe-automator-beta 2.1.0 → 2.1.2
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/dist/commonjs/index.js +358 -290
- package/dist/esm/index.mjs +358 -290
- package/package.json +1 -1
package/dist/commonjs/index.js
CHANGED
|
@@ -25,7 +25,6 @@ var stripAnsi = require('strip-ansi');
|
|
|
25
25
|
require('shelljs');
|
|
26
26
|
var process$1 = require('child_process');
|
|
27
27
|
var _ = require('lodash');
|
|
28
|
-
require('nanoid');
|
|
29
28
|
var request$1 = require('request-promise');
|
|
30
29
|
require('os');
|
|
31
30
|
require('console');
|
|
@@ -197,11 +196,23 @@ function importExcel({ uploadFilePath, token, env }) {
|
|
|
197
196
|
}
|
|
198
197
|
function readExcel({ uploadFilePath }) {
|
|
199
198
|
return new Promise((resolve, reject) => {
|
|
200
|
-
// 读取文件
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
199
|
+
// 读取文件(损坏/非excel文件解析会同步抛错, 转为友好提示)
|
|
200
|
+
let workSheetsFromFile;
|
|
201
|
+
try {
|
|
202
|
+
workSheetsFromFile = xlsx.parse(uploadFilePath);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
reject(
|
|
205
|
+
new Error(`${uploadFilePath} 解析失败, 请检查是否为有效的excel文件`)
|
|
206
|
+
);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
// 空 sheet 防护: 无sheet或首个sheet无数据时给出友好提示而非TypeError
|
|
210
|
+
const data = workSheetsFromFile[0]?.data;
|
|
211
|
+
const titleList = data?.[0];
|
|
212
|
+
if (!titleList || !titleList.length) {
|
|
213
|
+
reject(new Error(`${uploadFilePath} 文件无数据, 请检查首个sheet是否为空`));
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
205
216
|
// 获取项目所在的列
|
|
206
217
|
let projectIndex;
|
|
207
218
|
if (titleList.indexOf("项目") > -1) {
|
|
@@ -387,265 +398,295 @@ async function resolveSecretQuestions({
|
|
|
387
398
|
return resolved;
|
|
388
399
|
}
|
|
389
400
|
|
|
390
|
-
const sleep = (time) =>
|
|
391
|
-
new Promise((resolve
|
|
392
|
-
setTimeout(
|
|
393
|
-
});
|
|
394
|
-
// 上传翻译包(支持 --env/--files/--username/--password/--cache 一键, 参数齐全时跳过确认/选择)
|
|
401
|
+
const sleep = (time) =>
|
|
402
|
+
new Promise((resolve) => {
|
|
403
|
+
setTimeout(resolve, time);
|
|
404
|
+
});
|
|
405
|
+
// 上传翻译包(支持 --env/--files/--username/--password/--cache 一键, 参数齐全时跳过确认/选择)
|
|
395
406
|
async function upload$1(cliOpts = {}) {
|
|
396
|
-
// 空字符串视为未传(与askOrUse语义一致)
|
|
397
|
-
const cliEnv = cliOpts.env || undefined;
|
|
398
|
-
const cliFiles = cliOpts.files || undefined;
|
|
399
|
-
const cliUsername = cliOpts.username || undefined;
|
|
400
|
-
const cliPassword = cliOpts.password || undefined;
|
|
401
|
-
const cache = Boolean(cliOpts.cache);
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
);
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
)
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
.
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
407
|
+
// 空字符串视为未传(与askOrUse语义一致); 兼容交互菜单的to-前缀值(如 to-mit,sit,uat)
|
|
408
|
+
const cliEnv = (cliOpts.env || undefined)?.replace(/^to-/, "");
|
|
409
|
+
const cliFiles = cliOpts.files || undefined;
|
|
410
|
+
const cliUsername = cliOpts.username || undefined;
|
|
411
|
+
const cliPassword = cliOpts.password || undefined;
|
|
412
|
+
const cache = Boolean(cliOpts.cache);
|
|
413
|
+
// 传了任一CLI参数即视为一键意图, 跳过"是否上传"确认(传参即意图)
|
|
414
|
+
const oneClick =
|
|
415
|
+
cliEnv !== undefined ||
|
|
416
|
+
cliFiles !== undefined ||
|
|
417
|
+
cliUsername !== undefined ||
|
|
418
|
+
cliPassword !== undefined ||
|
|
419
|
+
cache;
|
|
420
|
+
// CLI参数校验前置(快速失败, 不进交互)
|
|
421
|
+
if (cliEnv !== undefined) {
|
|
422
|
+
const envArr = cliEnv
|
|
423
|
+
.split(",")
|
|
424
|
+
.map((item) => item.trim())
|
|
425
|
+
.filter(Boolean);
|
|
426
|
+
// 纯分隔符/空白值(如 ",")解析后为空数组, 须快速失败避免静默零上传
|
|
427
|
+
if (envArr.length === 0) {
|
|
428
|
+
console.log(
|
|
429
|
+
chalk.red(
|
|
430
|
+
`参数 --env 的值 "${cliEnv}" 不合法, 可选值: mit | sit | uat | pro, 多环境逗号分隔(仅mit/sit/uat, pro须单独传)`
|
|
431
|
+
)
|
|
432
|
+
);
|
|
433
|
+
process.exit(1);
|
|
434
|
+
}
|
|
435
|
+
if (envArr.length === 1) {
|
|
436
|
+
if (!["mit", "sit", "uat", "pro"].includes(envArr[0])) {
|
|
437
|
+
console.log(
|
|
438
|
+
chalk.red(
|
|
439
|
+
`参数 --env 的值 "${cliEnv}" 不合法, 可选值: mit | sit | uat | pro, 多环境逗号分隔(仅mit/sit/uat, pro须单独传)`
|
|
440
|
+
)
|
|
441
|
+
);
|
|
442
|
+
process.exit(1);
|
|
443
|
+
}
|
|
444
|
+
} else {
|
|
445
|
+
const invalid = envArr.filter(
|
|
446
|
+
(item) => !["mit", "sit", "uat"].includes(item)
|
|
447
|
+
);
|
|
448
|
+
if (invalid.length) {
|
|
449
|
+
console.log(
|
|
450
|
+
chalk.red(
|
|
451
|
+
`多环境仅支持 mit | sit | uat 逗号分隔, 不支持: ${invalid.join(
|
|
452
|
+
" | "
|
|
453
|
+
)} (pro须单独传)`
|
|
454
|
+
)
|
|
455
|
+
);
|
|
456
|
+
process.exit(1);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
const excelChoices = fs
|
|
461
|
+
.readdirSync("./")
|
|
462
|
+
.filter(
|
|
463
|
+
(item) =>
|
|
464
|
+
// 后缀精确匹配(.xls/.xlsx), 排除Excel锁文件(~$开头)与目录
|
|
465
|
+
/\.xlsx?$/i.test(item) &&
|
|
466
|
+
!item.startsWith("~$") &&
|
|
467
|
+
fs.statSync(item).isFile()
|
|
468
|
+
);
|
|
469
|
+
if (excelChoices.length === 0) {
|
|
470
|
+
console.log(chalk.red("当前目录下没有excel文件(.xlsx/.xls)"));
|
|
471
|
+
process.exit(1);
|
|
472
|
+
}
|
|
473
|
+
let cliFileArr;
|
|
474
|
+
if (cliFiles !== undefined) {
|
|
475
|
+
if (cliFiles === "all") {
|
|
476
|
+
cliFileArr = excelChoices;
|
|
477
|
+
} else {
|
|
478
|
+
cliFileArr = cliFiles
|
|
479
|
+
.split(",")
|
|
480
|
+
.map((item) => item.trim())
|
|
481
|
+
.filter(Boolean);
|
|
482
|
+
// 纯分隔符/空白值(如 ",")解析后为空数组, 须快速失败避免静默零上传
|
|
483
|
+
if (!cliFileArr.length) {
|
|
484
|
+
console.log(
|
|
485
|
+
chalk.red(
|
|
486
|
+
`参数 --files 的值 "${cliFiles}" 不合法, 可选值: 逗号分隔的excel文件名或all(全部)`
|
|
487
|
+
)
|
|
488
|
+
);
|
|
489
|
+
process.exit(1);
|
|
490
|
+
}
|
|
491
|
+
const invalid = cliFileArr.filter((item) => !excelChoices.includes(item));
|
|
492
|
+
if (invalid.length) {
|
|
493
|
+
console.log(
|
|
494
|
+
chalk.red(`当前目录不存在excel文件: ${invalid.join(", ")}`)
|
|
495
|
+
);
|
|
496
|
+
process.exit(1);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
// 1.是否上传(一键模式跳过, 选否属用户主动取消, exit 0)
|
|
501
|
+
if (!oneClick) {
|
|
502
|
+
const { isUpload } = await inquirer.prompt([
|
|
503
|
+
{
|
|
504
|
+
message: "是否上传到sass平台",
|
|
505
|
+
name: "isUpload",
|
|
506
|
+
type: "confirm",
|
|
507
|
+
default: true,
|
|
508
|
+
},
|
|
509
|
+
]);
|
|
510
|
+
if (!isUpload) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
// 2.选择环境(CLI参数 > 交互)
|
|
515
|
+
let envValue;
|
|
516
|
+
if (cliEnv !== undefined) {
|
|
517
|
+
envValue = cliEnv
|
|
518
|
+
.split(",")
|
|
519
|
+
.map((item) => item.trim())
|
|
520
|
+
.filter(Boolean)
|
|
521
|
+
.join(",");
|
|
522
|
+
} else {
|
|
523
|
+
const res = await inquirer.prompt([
|
|
524
|
+
{
|
|
525
|
+
message: "请选择环境",
|
|
526
|
+
name: "env",
|
|
527
|
+
type: "rawlist",
|
|
528
|
+
choices: [
|
|
529
|
+
{
|
|
530
|
+
name: "mit",
|
|
531
|
+
value: "mit",
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
name: "sit",
|
|
535
|
+
value: "sit",
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
name: "uat",
|
|
539
|
+
value: "uat",
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
name: "pro",
|
|
543
|
+
value: "pro",
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
name: "一键发布uat(mit->sit->uat)",
|
|
547
|
+
value: "to-mit,sit,uat",
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
name: "一键发布sit(mit->sit)",
|
|
551
|
+
value: "to-mit,sit",
|
|
552
|
+
},
|
|
553
|
+
],
|
|
554
|
+
validate: function (val) {
|
|
555
|
+
if (val.length > 0) {
|
|
556
|
+
return true;
|
|
557
|
+
}
|
|
558
|
+
return "请选择环境";
|
|
559
|
+
},
|
|
560
|
+
},
|
|
561
|
+
]);
|
|
562
|
+
envValue = res.env;
|
|
563
|
+
}
|
|
564
|
+
// 统一解析: 去掉to-前缀(兼容交互选择值) → 按逗号拆分
|
|
565
|
+
const envList = envValue
|
|
566
|
+
.replace(/^to-/, "")
|
|
567
|
+
.split(",")
|
|
568
|
+
.map((item) => item.trim())
|
|
569
|
+
.filter(Boolean);
|
|
570
|
+
const isPro = envList.length === 1 && envList[0] === "pro";
|
|
571
|
+
// 3.凭据: CLI参数 > --cache缓存 > 交互(展示缓存默认值), 解析后回写缓存
|
|
572
|
+
const secret = await resolveSecretQuestions({
|
|
573
|
+
questions: [
|
|
574
|
+
{
|
|
575
|
+
message: isPro ? "请输入生产域账号" : "请输入域账号",
|
|
576
|
+
name: "username",
|
|
577
|
+
// 必填
|
|
578
|
+
validate: function (val) {
|
|
579
|
+
if (val) {
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
582
|
+
return isPro ? "请输入生产域账号" : "请输入域账号";
|
|
583
|
+
},
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
message: isPro ? "请输入生产域密码" : "请输入域密码",
|
|
587
|
+
name: "password",
|
|
588
|
+
// 必填
|
|
589
|
+
validate: function (val) {
|
|
590
|
+
if (val) {
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
return isPro ? "请输入生产域密码" : "请输入域密码";
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
],
|
|
597
|
+
cliValues: { username: cliUsername, password: cliPassword },
|
|
598
|
+
useCache: cache,
|
|
599
|
+
cacheKey: isPro ? "sass_pro" : "sass",
|
|
600
|
+
});
|
|
601
|
+
const { username, password } = secret;
|
|
602
|
+
// 4.选择上传文件(CLI参数 > 交互, 交互带全选联动)
|
|
603
|
+
let excelFileNames;
|
|
604
|
+
if (cliFileArr !== undefined) {
|
|
605
|
+
excelFileNames = cliFileArr;
|
|
606
|
+
} else {
|
|
607
|
+
inquirer.registerPrompt("checkbox-all", CheckboxAllPrompt);
|
|
608
|
+
// 选项拼接序号,与数字键选择对应(按1选全选,按2选第一个文件...)
|
|
609
|
+
const promptChoices = [
|
|
610
|
+
{ name: "全选", value: SELECT_ALL, short: "全选" },
|
|
611
|
+
...excelChoices.map((file) => ({ name: file, value: file, short: file })),
|
|
612
|
+
].map((choice, index) => ({
|
|
613
|
+
...choice,
|
|
614
|
+
name: `${index + 1}. ${choice.name}`,
|
|
615
|
+
}));
|
|
616
|
+
const res = await inquirer.prompt([
|
|
617
|
+
{
|
|
618
|
+
type: "checkbox-all",
|
|
619
|
+
name: "excelFileNames",
|
|
620
|
+
message: "请选择要上传的excel文件(可多选)",
|
|
621
|
+
choices: promptChoices,
|
|
622
|
+
validate: function (val) {
|
|
623
|
+
if (val.length > 0) {
|
|
624
|
+
return true;
|
|
625
|
+
}
|
|
626
|
+
return "请选择要上传的excel文件";
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
]);
|
|
630
|
+
excelFileNames = res.excelFileNames;
|
|
631
|
+
// 勾选了全选则上传所有文件
|
|
632
|
+
if (excelFileNames.includes(SELECT_ALL)) {
|
|
633
|
+
excelFileNames = excelChoices;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
// 环境外层循环(每个环境只登录一次),文件内层循环批量上传
|
|
637
|
+
const failList = [];
|
|
638
|
+
for (const env of envList) {
|
|
639
|
+
// 1.登录
|
|
640
|
+
let token;
|
|
641
|
+
try {
|
|
642
|
+
token = await login({
|
|
643
|
+
env,
|
|
644
|
+
username,
|
|
645
|
+
password,
|
|
646
|
+
});
|
|
647
|
+
} catch (e) {
|
|
648
|
+
console.log(chalk.red(`${env} 登录失败: ${e.message || e}`));
|
|
649
|
+
failList.push(`${env} 登录`);
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
for (const excelFileName of excelFileNames) {
|
|
653
|
+
const uploadFilePath = "./" + excelFileName;
|
|
654
|
+
try {
|
|
655
|
+
// 2.读取excel
|
|
656
|
+
const projectList = await readExcel({ uploadFilePath });
|
|
657
|
+
// 3.导入excel
|
|
658
|
+
await importExcel({
|
|
659
|
+
uploadFilePath,
|
|
660
|
+
token,
|
|
661
|
+
env,
|
|
662
|
+
});
|
|
663
|
+
await sleep(2000);
|
|
664
|
+
// 4.上传
|
|
665
|
+
await uploadExcel({
|
|
666
|
+
data: {
|
|
667
|
+
projectList,
|
|
668
|
+
},
|
|
669
|
+
token,
|
|
670
|
+
env,
|
|
671
|
+
});
|
|
672
|
+
console.log(
|
|
673
|
+
`🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀${env} ${excelFileName} 成功`
|
|
674
|
+
);
|
|
675
|
+
} catch (e) {
|
|
676
|
+
console.log(
|
|
677
|
+
chalk.red(`${env} ${excelFileName} 失败: ${e.message || e}`)
|
|
678
|
+
);
|
|
679
|
+
failList.push(`${env} ${excelFileName}`);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
// 汇总失败项(登录失败也计入, 统一失败退出码1)
|
|
684
|
+
if (failList.length > 0) {
|
|
685
|
+
console.log(
|
|
686
|
+
chalk.red(`\n以下 ${failList.length} 项上传失败,请检查:\n- ${failList.join("\n- ")}`)
|
|
687
|
+
);
|
|
688
|
+
process.exit(1);
|
|
689
|
+
}
|
|
649
690
|
}
|
|
650
691
|
|
|
651
692
|
// 百度翻译接口
|
|
@@ -862,7 +903,13 @@ async function excelFn(cliOpts = {}) {
|
|
|
862
903
|
// 1.获取excel文件列表, CLI传入file先校验存在性(快速失败, 不进交互)
|
|
863
904
|
const choices = fs
|
|
864
905
|
.readdirSync("./")
|
|
865
|
-
.filter(
|
|
906
|
+
.filter(
|
|
907
|
+
(item) =>
|
|
908
|
+
// 后缀精确匹配(.xls/.xlsx), 排除Excel锁文件(~$开头)与目录
|
|
909
|
+
/\.xlsx?$/i.test(item) &&
|
|
910
|
+
!item.startsWith("~$") &&
|
|
911
|
+
fs.statSync(item).isFile()
|
|
912
|
+
);
|
|
866
913
|
if (choices.length === 0) {
|
|
867
914
|
console.log(chalk.red("当前目录下没有excel文件(.xlsx/.xls)"));
|
|
868
915
|
process.exit(1);
|
|
@@ -942,6 +989,11 @@ async function excelFn(cliOpts = {}) {
|
|
|
942
989
|
},
|
|
943
990
|
]);
|
|
944
991
|
language = res.language;
|
|
992
|
+
// 用户选择不翻译则直接退出(一键模式传 --lang 视为翻译, 不进入该询问)
|
|
993
|
+
if (!res.isTranslate) {
|
|
994
|
+
console.log(chalk.green(`已跳过${language}列翻译`));
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
945
997
|
}
|
|
946
998
|
const content = data.slice(1);
|
|
947
999
|
const zhArr = content.map((row) => {
|
|
@@ -1036,7 +1088,6 @@ function getApplicationList({ appName, env, token }) {
|
|
|
1036
1088
|
);
|
|
1037
1089
|
} else {
|
|
1038
1090
|
const errorData = error || JSON.stringify(res.data);
|
|
1039
|
-
console.log(chalk.red(errorData));
|
|
1040
1091
|
reject(errorData);
|
|
1041
1092
|
}
|
|
1042
1093
|
}
|
|
@@ -1068,7 +1119,6 @@ function getApplicationConfig({ appId, env, token }) {
|
|
|
1068
1119
|
} else {
|
|
1069
1120
|
Loading$1.fail(`获取应用配置失败`);
|
|
1070
1121
|
const errorData = error || JSON.stringify(res.data);
|
|
1071
|
-
console.log(chalk.red(errorData));
|
|
1072
1122
|
reject(errorData);
|
|
1073
1123
|
}
|
|
1074
1124
|
}
|
|
@@ -1100,7 +1150,6 @@ function getApplicationButtonConfig({ appId, env, token }) {
|
|
|
1100
1150
|
} else {
|
|
1101
1151
|
Loading$1.fail(`获取${env}环境按钮权限配置失败`);
|
|
1102
1152
|
const errorData = error || JSON.stringify(res.data);
|
|
1103
|
-
console.log(chalk.red(errorData));
|
|
1104
1153
|
reject(errorData);
|
|
1105
1154
|
}
|
|
1106
1155
|
}
|
|
@@ -1129,7 +1178,6 @@ function deleteApplicationButtonConfig({ data, env, token }) {
|
|
|
1129
1178
|
resolve(res.data);
|
|
1130
1179
|
} else {
|
|
1131
1180
|
const errorData = error || JSON.stringify(res.data);
|
|
1132
|
-
console.log(chalk.red(errorData));
|
|
1133
1181
|
reject(errorData);
|
|
1134
1182
|
}
|
|
1135
1183
|
}
|
|
@@ -1161,7 +1209,6 @@ function addApplicationButtonConfig({ data, env, token }) {
|
|
|
1161
1209
|
} else {
|
|
1162
1210
|
Loading$1.fail(`${data.code}`);
|
|
1163
1211
|
const errorData = error || JSON.stringify(res.data);
|
|
1164
|
-
console.log(chalk.red(errorData));
|
|
1165
1212
|
reject(errorData);
|
|
1166
1213
|
}
|
|
1167
1214
|
}
|
|
@@ -1214,8 +1261,9 @@ async function sassMain(rawCliOpts = {}) {
|
|
|
1214
1261
|
async function syncSassFlow(cliOpts) {
|
|
1215
1262
|
const { from: cliFrom, to: cliTo, app: cliApp } = cliOpts;
|
|
1216
1263
|
const envList = ["mit", "sit", "uat"];
|
|
1264
|
+
// 传了任一同步参数即视为一键意图, 自动同意使用须知(传参即意图)
|
|
1217
1265
|
const oneClick =
|
|
1218
|
-
cliFrom !== undefined
|
|
1266
|
+
cliFrom !== undefined || cliTo !== undefined || cliApp !== undefined;
|
|
1219
1267
|
if (!oneClick) {
|
|
1220
1268
|
const { notice } = await inquirer.prompt([
|
|
1221
1269
|
{
|
|
@@ -1290,14 +1338,36 @@ async function syncSassFlow(cliOpts) {
|
|
|
1290
1338
|
console.log(chalk.red(`查询${from}环境应用列表失败: ${e.message || e}`));
|
|
1291
1339
|
process.exit(1);
|
|
1292
1340
|
}
|
|
1293
|
-
|
|
1294
|
-
{
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1341
|
+
if (!applicationList.length) {
|
|
1342
|
+
console.log(chalk.red(`${from}环境未找到该应用`));
|
|
1343
|
+
process.exit(1);
|
|
1344
|
+
}
|
|
1345
|
+
// 一键模式: 唯一匹配或精确匹配CLI传入的应用名时自动选中(与新增按钮权限流程一致)
|
|
1346
|
+
let appName;
|
|
1347
|
+
if (applicationList.length === 1) {
|
|
1348
|
+
appName = applicationList[0].name;
|
|
1349
|
+
console.log(chalk.gray(`唯一匹配,已自动选中: ${appName}`));
|
|
1350
|
+
} else if (oneClick) {
|
|
1351
|
+
const exactMatch = applicationList.find((item) => item.name === cliApp);
|
|
1352
|
+
if (!exactMatch) {
|
|
1353
|
+
console.log(
|
|
1354
|
+
chalk.red(`${from}环境未精确匹配到应用: ${cliApp}, 请更换关键字`)
|
|
1355
|
+
);
|
|
1356
|
+
process.exit(1);
|
|
1357
|
+
}
|
|
1358
|
+
appName = exactMatch.name;
|
|
1359
|
+
console.log(chalk.gray(`精确匹配,已自动选中: ${appName}`));
|
|
1360
|
+
} else {
|
|
1361
|
+
const res = await inquirer.prompt([
|
|
1362
|
+
{
|
|
1363
|
+
message: "请选择应用名称",
|
|
1364
|
+
name: "appName",
|
|
1365
|
+
type: "rawlist",
|
|
1366
|
+
choices: applicationList,
|
|
1367
|
+
},
|
|
1368
|
+
]);
|
|
1369
|
+
appName = res.appName;
|
|
1370
|
+
}
|
|
1301
1371
|
const appId = applicationList.find((item) => item.name === appName).id;
|
|
1302
1372
|
let fromButtonList;
|
|
1303
1373
|
try {
|
|
@@ -1372,7 +1442,9 @@ async function syncSassFlow(cliOpts) {
|
|
|
1372
1442
|
Loading$1.succeed(`删除${to}环境按钮权限配置成功`);
|
|
1373
1443
|
}
|
|
1374
1444
|
} catch (error) {
|
|
1375
|
-
console.log(
|
|
1445
|
+
console.log(
|
|
1446
|
+
chalk.red(`删除${to}环境按钮权限配置失败: ${error.message || error}`)
|
|
1447
|
+
);
|
|
1376
1448
|
} finally {
|
|
1377
1449
|
try {
|
|
1378
1450
|
for (const item of fromButtonList) {
|
|
@@ -2952,7 +3024,8 @@ function getGitChangedFiles() {
|
|
|
2952
3024
|
return allFiles;
|
|
2953
3025
|
} catch (error) {
|
|
2954
3026
|
// git命令失败(如不在git仓库中运行)属于使用错误, 以退出码1结束
|
|
2955
|
-
|
|
3027
|
+
console.log(chalk.red("获取git修改文件失败,请确保在git仓库中运行"));
|
|
3028
|
+
process.exit(1);
|
|
2956
3029
|
}
|
|
2957
3030
|
}
|
|
2958
3031
|
// const spinner = ora();
|
|
@@ -3066,9 +3139,9 @@ const rules = [
|
|
|
3066
3139
|
},
|
|
3067
3140
|
];
|
|
3068
3141
|
if (sass) {
|
|
3069
|
-
sassMain(cliOpts);
|
|
3142
|
+
sassMain(cliOpts).catch((error) => console.error(error));
|
|
3070
3143
|
} else if (upload) {
|
|
3071
|
-
upload$1(cliOpts);
|
|
3144
|
+
upload$1(cliOpts).catch((error) => console.error(error));
|
|
3072
3145
|
} else if (lint !== undefined) {
|
|
3073
3146
|
// 必须传入路径
|
|
3074
3147
|
if (!lint || !lint.trim()) {
|
|
@@ -3092,7 +3165,7 @@ if (sass) {
|
|
|
3092
3165
|
} else if (lintc) {
|
|
3093
3166
|
runLintc().catch((error) => console.error(error));
|
|
3094
3167
|
} else if (excel) {
|
|
3095
|
-
excelFn(cliOpts);
|
|
3168
|
+
excelFn(cliOpts).catch((error) => console.error(error));
|
|
3096
3169
|
} else {
|
|
3097
3170
|
runTranslate().catch((error) => console.error(error));
|
|
3098
3171
|
}
|
|
@@ -3452,12 +3525,7 @@ function translateUtil(appid, key, projectName, isLintFix, isMergeDecision) {
|
|
|
3452
3525
|
let EN = result[index1].dst;
|
|
3453
3526
|
EN = EN[0].toUpperCase() + EN.slice(1);
|
|
3454
3527
|
item1.EN = EN;
|
|
3455
|
-
|
|
3456
|
-
// item1.key = nanoid().replace("_", "a");
|
|
3457
|
-
item1.key = id + "-" + key;
|
|
3458
|
-
} else {
|
|
3459
|
-
item1.key = id + "-" + key;
|
|
3460
|
-
}
|
|
3528
|
+
item1.key = id + "-" + key;
|
|
3461
3529
|
}
|
|
3462
3530
|
});
|
|
3463
3531
|
resolve(true);
|