i18-fe-automator-beta 2.1.2 → 2.1.3

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.
@@ -403,8 +403,8 @@ const sleep = (time) =>
403
403
  setTimeout(resolve, time);
404
404
  });
405
405
  // 上传翻译包(支持 --env/--files/--username/--password/--cache 一键, 参数齐全时跳过确认/选择)
406
- async function upload$1(cliOpts = {}) {
407
- // 空字符串视为未传(与askOrUse语义一致); 兼容交互菜单的to-前缀值(如 to-mit,sit,uat)
406
+ async function upload$1(cliOpts = {}) {
407
+ // 空字符串视为未传(与askOrUse语义一致); 兼容交互菜单的to-前缀值(如 to-mit,sit,uat)
408
408
  const cliEnv = (cliOpts.env || undefined)?.replace(/^to-/, "");
409
409
  const cliFiles = cliOpts.files || undefined;
410
410
  const cliUsername = cliOpts.username || undefined;
@@ -3431,6 +3431,52 @@ function translateUtil(appid, key, projectName, isLintFix, isMergeDecision) {
3431
3431
  // isMergeDecision: true/false为预决定值(一键执行), null表示仍需交互询问
3432
3432
  let isMerge = isMergeDecision;
3433
3433
  if (isMerge === null || isMerge === undefined) {
3434
+ // 询问前预览当前export.xlsx(最近更新时间+内容), 便于判断覆盖还是合并
3435
+ if (fs.existsSync("./export.xlsx")) {
3436
+ const stat = fs.statSync("./export.xlsx");
3437
+ const pad = (n) => String(n).padStart(2, "0");
3438
+ const mtimeStr = `${stat.mtime.getFullYear()}-${pad(stat.mtime.getMonth() + 1)}-${pad(stat.mtime.getDate())} ${pad(stat.mtime.getHours())}:${pad(stat.mtime.getMinutes())}:${pad(stat.mtime.getSeconds())}`;
3439
+ console.log(chalk.green(`export.xlsx 最近更新: ${mtimeStr}`));
3440
+ try {
3441
+ const rows = xlsx.parse(fs.readFileSync("./export.xlsx"))[0].data;
3442
+ const headerRow = rows[0] || [];
3443
+ const dataRows = rows.slice(1);
3444
+ const PREVIEW_LIMIT = 20;
3445
+ // 数据不超过2倍上限时全量展示, 避免头尾重叠导致重复打印
3446
+ const previewRows =
3447
+ dataRows.length <= PREVIEW_LIMIT * 2
3448
+ ? dataRows
3449
+ : [...dataRows.slice(0, PREVIEW_LIMIT), ...dataRows.slice(-PREVIEW_LIMIT)];
3450
+ console.log(
3451
+ chalk.green(
3452
+ dataRows.length <= PREVIEW_LIMIT * 2
3453
+ ? `当前内容预览(共${dataRows.length}条数据):`
3454
+ : `当前内容预览(共${dataRows.length}条数据, 展示前${PREVIEW_LIMIT}条与倒数${PREVIEW_LIMIT}条):`
3455
+ )
3456
+ );
3457
+ if (dataRows.length) {
3458
+ // 仅展示编码与中文值两列, 避免全列表格(11列)在终端超宽; 列序以标题行为准, 找不到时退回默认列位(编码=3, 中文值=6)
3459
+ const colIdx = (title, fallback) => {
3460
+ const i = headerRow.indexOf(title);
3461
+ return i < 0 ? fallback : i;
3462
+ };
3463
+ const codeIdx = colIdx("编码", 3);
3464
+ const zhIdx = colIdx("中文值", 6);
3465
+ console.table(
3466
+ previewRows.map((row) => ({
3467
+ 编码: row[codeIdx],
3468
+ 中文值: row[zhIdx],
3469
+ }))
3470
+ );
3471
+ } else {
3472
+ console.log(chalk.yellow("当前文件无数据(仅标题或空文件)"));
3473
+ }
3474
+ } catch (error) {
3475
+ console.log(chalk.yellow("export.xlsx 解析失败, 选择合并将按覆盖处理"));
3476
+ }
3477
+ } else {
3478
+ console.log(chalk.yellow("export.xlsx 不存在, 本次将直接新建"));
3479
+ }
3434
3480
  const res = await inquirer.prompt([
3435
3481
  {
3436
3482
  message: `是否合并至export.xlsx,默认${chalk.red("否,直接覆盖")}`,
@@ -381,8 +381,8 @@ const sleep = (time) =>
381
381
  setTimeout(resolve, time);
382
382
  });
383
383
  // 上传翻译包(支持 --env/--files/--username/--password/--cache 一键, 参数齐全时跳过确认/选择)
384
- async function upload$1(cliOpts = {}) {
385
- // 空字符串视为未传(与askOrUse语义一致); 兼容交互菜单的to-前缀值(如 to-mit,sit,uat)
384
+ async function upload$1(cliOpts = {}) {
385
+ // 空字符串视为未传(与askOrUse语义一致); 兼容交互菜单的to-前缀值(如 to-mit,sit,uat)
386
386
  const cliEnv = (cliOpts.env || undefined)?.replace(/^to-/, "");
387
387
  const cliFiles = cliOpts.files || undefined;
388
388
  const cliUsername = cliOpts.username || undefined;
@@ -3409,6 +3409,52 @@ function translateUtil(appid, key, projectName, isLintFix, isMergeDecision) {
3409
3409
  // isMergeDecision: true/false为预决定值(一键执行), null表示仍需交互询问
3410
3410
  let isMerge = isMergeDecision;
3411
3411
  if (isMerge === null || isMerge === undefined) {
3412
+ // 询问前预览当前export.xlsx(最近更新时间+内容), 便于判断覆盖还是合并
3413
+ if (fs.existsSync("./export.xlsx")) {
3414
+ const stat = fs.statSync("./export.xlsx");
3415
+ const pad = (n) => String(n).padStart(2, "0");
3416
+ const mtimeStr = `${stat.mtime.getFullYear()}-${pad(stat.mtime.getMonth() + 1)}-${pad(stat.mtime.getDate())} ${pad(stat.mtime.getHours())}:${pad(stat.mtime.getMinutes())}:${pad(stat.mtime.getSeconds())}`;
3417
+ console.log(chalk.green(`export.xlsx 最近更新: ${mtimeStr}`));
3418
+ try {
3419
+ const rows = xlsx.parse(fs.readFileSync("./export.xlsx"))[0].data;
3420
+ const headerRow = rows[0] || [];
3421
+ const dataRows = rows.slice(1);
3422
+ const PREVIEW_LIMIT = 20;
3423
+ // 数据不超过2倍上限时全量展示, 避免头尾重叠导致重复打印
3424
+ const previewRows =
3425
+ dataRows.length <= PREVIEW_LIMIT * 2
3426
+ ? dataRows
3427
+ : [...dataRows.slice(0, PREVIEW_LIMIT), ...dataRows.slice(-PREVIEW_LIMIT)];
3428
+ console.log(
3429
+ chalk.green(
3430
+ dataRows.length <= PREVIEW_LIMIT * 2
3431
+ ? `当前内容预览(共${dataRows.length}条数据):`
3432
+ : `当前内容预览(共${dataRows.length}条数据, 展示前${PREVIEW_LIMIT}条与倒数${PREVIEW_LIMIT}条):`
3433
+ )
3434
+ );
3435
+ if (dataRows.length) {
3436
+ // 仅展示编码与中文值两列, 避免全列表格(11列)在终端超宽; 列序以标题行为准, 找不到时退回默认列位(编码=3, 中文值=6)
3437
+ const colIdx = (title, fallback) => {
3438
+ const i = headerRow.indexOf(title);
3439
+ return i < 0 ? fallback : i;
3440
+ };
3441
+ const codeIdx = colIdx("编码", 3);
3442
+ const zhIdx = colIdx("中文值", 6);
3443
+ console.table(
3444
+ previewRows.map((row) => ({
3445
+ 编码: row[codeIdx],
3446
+ 中文值: row[zhIdx],
3447
+ }))
3448
+ );
3449
+ } else {
3450
+ console.log(chalk.yellow("当前文件无数据(仅标题或空文件)"));
3451
+ }
3452
+ } catch (error) {
3453
+ console.log(chalk.yellow("export.xlsx 解析失败, 选择合并将按覆盖处理"));
3454
+ }
3455
+ } else {
3456
+ console.log(chalk.yellow("export.xlsx 不存在, 本次将直接新建"));
3457
+ }
3412
3458
  const res = await inquirer.prompt([
3413
3459
  {
3414
3460
  message: `是否合并至export.xlsx,默认${chalk.red("否,直接覆盖")}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18-fe-automator-beta",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "i18-fe-automator-beta内测版本,只用于key: ''替换、检测中文规则等",
5
5
  "type": "module",
6
6
  "bin": {