i18-fe-automator-beta 2.0.4 → 2.0.6
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 +106 -12
- package/dist/esm/index.mjs +107 -13
- package/package.json +1 -1
package/dist/commonjs/index.js
CHANGED
|
@@ -2134,7 +2134,7 @@ async function lint$1(patterns, fix, rule, hook = {}) {
|
|
|
2134
2134
|
.then(({ isTransKey }) => {
|
|
2135
2135
|
if (isTransKey) {
|
|
2136
2136
|
console.log(chalk.green(`开始准备翻译...`));
|
|
2137
|
-
process$1.execSync(`fe-it-beta --fix -i ${patterns} `, {
|
|
2137
|
+
process$1.execSync(`fe-it-beta --fix -i "${patterns}" `, {
|
|
2138
2138
|
stdio: "inherit", // 打印子进程的输出到父进程
|
|
2139
2139
|
});
|
|
2140
2140
|
}
|
|
@@ -2333,6 +2333,73 @@ async function getColumn(moduleArr = [], dynamicsArr = [], parentRule) {
|
|
|
2333
2333
|
|
|
2334
2334
|
// import packageJson from "../package.json" assert { type: "json" };
|
|
2335
2335
|
const { version } = getPackageJson();
|
|
2336
|
+
|
|
2337
|
+
// 获取git修改的文件以及暂存区的文件(包含未跟踪的新文件)
|
|
2338
|
+
function getGitChangedFiles() {
|
|
2339
|
+
const cwd = process.cwd();
|
|
2340
|
+
try {
|
|
2341
|
+
const repoRoot = process$1.execSync("git rev-parse --show-toplevel", {
|
|
2342
|
+
cwd,
|
|
2343
|
+
encoding: "utf-8",
|
|
2344
|
+
}).trim();
|
|
2345
|
+
// 1. git status --porcelain 获取已跟踪文件的变更(已暂存staged + 未暂存unstaged)
|
|
2346
|
+
// 注意: 不能用 git diff --name-only HEAD, 它不会包含未跟踪(untracked)的新文件
|
|
2347
|
+
const statusOutput = process$1.execSync("git status --porcelain", {
|
|
2348
|
+
cwd: repoRoot,
|
|
2349
|
+
encoding: "utf-8",
|
|
2350
|
+
});
|
|
2351
|
+
const trackedFiles = statusOutput
|
|
2352
|
+
.split("\n")
|
|
2353
|
+
.map((line) => line.replace(/\r$/, ""))
|
|
2354
|
+
.filter(Boolean)
|
|
2355
|
+
.map((line) => {
|
|
2356
|
+
// 输出格式: XY filename, X=暂存区状态, Y=工作区状态
|
|
2357
|
+
const status = line.slice(0, 2);
|
|
2358
|
+
let filePath = line.slice(3);
|
|
2359
|
+
// 重命名(R)/复制(C): "old -> new", 取新文件名
|
|
2360
|
+
if (status[0] === "R" || status[0] === "C") {
|
|
2361
|
+
const idx = filePath.indexOf(" -> ");
|
|
2362
|
+
if (idx > -1) filePath = filePath.slice(idx + 4);
|
|
2363
|
+
}
|
|
2364
|
+
// 含特殊字符的文件名git会加引号, 去除引号
|
|
2365
|
+
if (filePath.startsWith('"') && filePath.endsWith('"')) {
|
|
2366
|
+
filePath = filePath.slice(1, -1);
|
|
2367
|
+
}
|
|
2368
|
+
return { status, filePath };
|
|
2369
|
+
})
|
|
2370
|
+
// 排除删除的文件 (D 在暂存区或工作区)
|
|
2371
|
+
.filter(({ status }) => !status.includes("D"))
|
|
2372
|
+
// 未跟踪文件(??)用 git ls-files 单独处理(因为可能只显示目录,不展开)
|
|
2373
|
+
.filter(({ status }) => status !== "??")
|
|
2374
|
+
.map(({ filePath }) => filePath);
|
|
2375
|
+
|
|
2376
|
+
// 2. git ls-files --others --exclude-standard 获取未跟踪的新文件
|
|
2377
|
+
// 相比 git status --porcelain, 它会自动展开目录, 列出具体文件
|
|
2378
|
+
const untrackedOutput = process$1.execSync(
|
|
2379
|
+
"git ls-files --others --exclude-standard",
|
|
2380
|
+
{ cwd: repoRoot, encoding: "utf-8" }
|
|
2381
|
+
);
|
|
2382
|
+
const untrackedFiles = untrackedOutput
|
|
2383
|
+
.split("\n")
|
|
2384
|
+
.map((f) => f.trim())
|
|
2385
|
+
.filter(Boolean);
|
|
2386
|
+
|
|
2387
|
+
// 合并去重
|
|
2388
|
+
const allFiles = Array.from(
|
|
2389
|
+
new Set([...trackedFiles, ...untrackedFiles])
|
|
2390
|
+
)
|
|
2391
|
+
// 只保留lint支持的文件类型
|
|
2392
|
+
.filter((f) => /\.(js|jsx|vue|ts|tsx)$/.test(f))
|
|
2393
|
+
// git输出的路径相对于仓库根目录, 转为绝对路径
|
|
2394
|
+
.map((f) => path.join(repoRoot, f))
|
|
2395
|
+
// 过滤掉不存在的文件
|
|
2396
|
+
.filter((f) => fs.existsSync(f));
|
|
2397
|
+
return allFiles;
|
|
2398
|
+
} catch (error) {
|
|
2399
|
+
console.log(chalk.red("获取git修改文件失败,请确保在git仓库中运行"));
|
|
2400
|
+
return [];
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2336
2403
|
// const spinner = ora();
|
|
2337
2404
|
commander.program.version(version);
|
|
2338
2405
|
commander.program.option("-i, --input <type>", "翻译空key");
|
|
@@ -2391,8 +2458,26 @@ if (sass) {
|
|
|
2391
2458
|
syncSassConfig();
|
|
2392
2459
|
} else if (upload) {
|
|
2393
2460
|
upload$1();
|
|
2394
|
-
} else if (lint) {
|
|
2395
|
-
|
|
2461
|
+
} else if (lint !== undefined) {
|
|
2462
|
+
// 必须传入路径
|
|
2463
|
+
if (!lint || !lint.trim()) {
|
|
2464
|
+
console.log(
|
|
2465
|
+
chalk.red("请传入要检测的路径, 或使用 -lint git 检测git修改的文件")
|
|
2466
|
+
);
|
|
2467
|
+
process.exit(1);
|
|
2468
|
+
}
|
|
2469
|
+
let lintPatterns = lint.trim();
|
|
2470
|
+
// 如果路径写死为 git, 则用git检测修改的文件以及暂存区的文件作为路径
|
|
2471
|
+
if (lintPatterns === "git") {
|
|
2472
|
+
lintPatterns = getGitChangedFiles();
|
|
2473
|
+
if (!lintPatterns.length) {
|
|
2474
|
+
console.log(chalk.green("没有检测到git修改的文件"));
|
|
2475
|
+
process.exit(0);
|
|
2476
|
+
}
|
|
2477
|
+
console.log(chalk.green(`检测到${lintPatterns.length}个git修改文件:`));
|
|
2478
|
+
lintPatterns.forEach((f) => console.log(chalk.gray(` ${f}`)));
|
|
2479
|
+
}
|
|
2480
|
+
lint$1(lintPatterns, fix);
|
|
2396
2481
|
} else if (lintc) {
|
|
2397
2482
|
inquirer.prompt(rules).then(async ({ rule }) => {
|
|
2398
2483
|
const parentRule = rule;
|
|
@@ -2505,15 +2590,24 @@ if (sass) {
|
|
|
2505
2590
|
|
|
2506
2591
|
function translateUtil(appid, key, projectName, isLintFix) {
|
|
2507
2592
|
const { input } = commander.program.opts();
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2593
|
+
// 支持逗号分隔的多个路径(来自 -lint git 的多文件场景)
|
|
2594
|
+
const inputPaths = String(input)
|
|
2595
|
+
.split(",")
|
|
2596
|
+
.map((s) => s.trim())
|
|
2597
|
+
.filter(Boolean);
|
|
2598
|
+
let src = [];
|
|
2599
|
+
inputPaths.forEach((inputPath) => {
|
|
2600
|
+
const normalizedInput = inputPath.replace(/\\/g, "/");
|
|
2601
|
+
if (fs.statSync(inputPath).isDirectory()) {
|
|
2602
|
+
const directory = normalizedInput + "/**/*.{js,vue,jsx,ts,tsx}";
|
|
2603
|
+
const files = glob.glob.sync(directory, {
|
|
2604
|
+
ignore: directory + `/**/node_modules/**`,
|
|
2605
|
+
});
|
|
2606
|
+
src = src.concat(files);
|
|
2607
|
+
} else {
|
|
2608
|
+
src.push(normalizedInput);
|
|
2609
|
+
}
|
|
2610
|
+
});
|
|
2517
2611
|
let allArr = []; // 所有文本组成的数组
|
|
2518
2612
|
let groupArr = []; // 分组后的数组
|
|
2519
2613
|
let newAllArr = []; // 分组后的数组还原成所有数组
|
package/dist/esm/index.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import { createRequire } from 'node:module';
|
|
|
20
20
|
import tsParser from '@typescript-eslint/parser';
|
|
21
21
|
import stripAnsi from 'strip-ansi';
|
|
22
22
|
import 'shelljs';
|
|
23
|
-
import process$1 from 'child_process';
|
|
23
|
+
import process$1, { execSync } from 'child_process';
|
|
24
24
|
import _ from 'lodash';
|
|
25
25
|
import 'nanoid';
|
|
26
26
|
import request$1 from 'request-promise';
|
|
@@ -2112,7 +2112,7 @@ async function lint$1(patterns, fix, rule, hook = {}) {
|
|
|
2112
2112
|
.then(({ isTransKey }) => {
|
|
2113
2113
|
if (isTransKey) {
|
|
2114
2114
|
console.log(chalk.green(`开始准备翻译...`));
|
|
2115
|
-
process$1.execSync(`fe-it-beta --fix -i ${patterns} `, {
|
|
2115
|
+
process$1.execSync(`fe-it-beta --fix -i "${patterns}" `, {
|
|
2116
2116
|
stdio: "inherit", // 打印子进程的输出到父进程
|
|
2117
2117
|
});
|
|
2118
2118
|
}
|
|
@@ -2311,6 +2311,73 @@ async function getColumn(moduleArr = [], dynamicsArr = [], parentRule) {
|
|
|
2311
2311
|
|
|
2312
2312
|
// import packageJson from "../package.json" assert { type: "json" };
|
|
2313
2313
|
const { version } = getPackageJson();
|
|
2314
|
+
|
|
2315
|
+
// 获取git修改的文件以及暂存区的文件(包含未跟踪的新文件)
|
|
2316
|
+
function getGitChangedFiles() {
|
|
2317
|
+
const cwd = process.cwd();
|
|
2318
|
+
try {
|
|
2319
|
+
const repoRoot = execSync("git rev-parse --show-toplevel", {
|
|
2320
|
+
cwd,
|
|
2321
|
+
encoding: "utf-8",
|
|
2322
|
+
}).trim();
|
|
2323
|
+
// 1. git status --porcelain 获取已跟踪文件的变更(已暂存staged + 未暂存unstaged)
|
|
2324
|
+
// 注意: 不能用 git diff --name-only HEAD, 它不会包含未跟踪(untracked)的新文件
|
|
2325
|
+
const statusOutput = execSync("git status --porcelain", {
|
|
2326
|
+
cwd: repoRoot,
|
|
2327
|
+
encoding: "utf-8",
|
|
2328
|
+
});
|
|
2329
|
+
const trackedFiles = statusOutput
|
|
2330
|
+
.split("\n")
|
|
2331
|
+
.map((line) => line.replace(/\r$/, ""))
|
|
2332
|
+
.filter(Boolean)
|
|
2333
|
+
.map((line) => {
|
|
2334
|
+
// 输出格式: XY filename, X=暂存区状态, Y=工作区状态
|
|
2335
|
+
const status = line.slice(0, 2);
|
|
2336
|
+
let filePath = line.slice(3);
|
|
2337
|
+
// 重命名(R)/复制(C): "old -> new", 取新文件名
|
|
2338
|
+
if (status[0] === "R" || status[0] === "C") {
|
|
2339
|
+
const idx = filePath.indexOf(" -> ");
|
|
2340
|
+
if (idx > -1) filePath = filePath.slice(idx + 4);
|
|
2341
|
+
}
|
|
2342
|
+
// 含特殊字符的文件名git会加引号, 去除引号
|
|
2343
|
+
if (filePath.startsWith('"') && filePath.endsWith('"')) {
|
|
2344
|
+
filePath = filePath.slice(1, -1);
|
|
2345
|
+
}
|
|
2346
|
+
return { status, filePath };
|
|
2347
|
+
})
|
|
2348
|
+
// 排除删除的文件 (D 在暂存区或工作区)
|
|
2349
|
+
.filter(({ status }) => !status.includes("D"))
|
|
2350
|
+
// 未跟踪文件(??)用 git ls-files 单独处理(因为可能只显示目录,不展开)
|
|
2351
|
+
.filter(({ status }) => status !== "??")
|
|
2352
|
+
.map(({ filePath }) => filePath);
|
|
2353
|
+
|
|
2354
|
+
// 2. git ls-files --others --exclude-standard 获取未跟踪的新文件
|
|
2355
|
+
// 相比 git status --porcelain, 它会自动展开目录, 列出具体文件
|
|
2356
|
+
const untrackedOutput = execSync(
|
|
2357
|
+
"git ls-files --others --exclude-standard",
|
|
2358
|
+
{ cwd: repoRoot, encoding: "utf-8" }
|
|
2359
|
+
);
|
|
2360
|
+
const untrackedFiles = untrackedOutput
|
|
2361
|
+
.split("\n")
|
|
2362
|
+
.map((f) => f.trim())
|
|
2363
|
+
.filter(Boolean);
|
|
2364
|
+
|
|
2365
|
+
// 合并去重
|
|
2366
|
+
const allFiles = Array.from(
|
|
2367
|
+
new Set([...trackedFiles, ...untrackedFiles])
|
|
2368
|
+
)
|
|
2369
|
+
// 只保留lint支持的文件类型
|
|
2370
|
+
.filter((f) => /\.(js|jsx|vue|ts|tsx)$/.test(f))
|
|
2371
|
+
// git输出的路径相对于仓库根目录, 转为绝对路径
|
|
2372
|
+
.map((f) => path.join(repoRoot, f))
|
|
2373
|
+
// 过滤掉不存在的文件
|
|
2374
|
+
.filter((f) => fs.existsSync(f));
|
|
2375
|
+
return allFiles;
|
|
2376
|
+
} catch (error) {
|
|
2377
|
+
console.log(chalk.red("获取git修改文件失败,请确保在git仓库中运行"));
|
|
2378
|
+
return [];
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2314
2381
|
// const spinner = ora();
|
|
2315
2382
|
program.version(version);
|
|
2316
2383
|
program.option("-i, --input <type>", "翻译空key");
|
|
@@ -2369,8 +2436,26 @@ if (sass) {
|
|
|
2369
2436
|
syncSassConfig();
|
|
2370
2437
|
} else if (upload) {
|
|
2371
2438
|
upload$1();
|
|
2372
|
-
} else if (lint) {
|
|
2373
|
-
|
|
2439
|
+
} else if (lint !== undefined) {
|
|
2440
|
+
// 必须传入路径
|
|
2441
|
+
if (!lint || !lint.trim()) {
|
|
2442
|
+
console.log(
|
|
2443
|
+
chalk.red("请传入要检测的路径, 或使用 -lint git 检测git修改的文件")
|
|
2444
|
+
);
|
|
2445
|
+
process.exit(1);
|
|
2446
|
+
}
|
|
2447
|
+
let lintPatterns = lint.trim();
|
|
2448
|
+
// 如果路径写死为 git, 则用git检测修改的文件以及暂存区的文件作为路径
|
|
2449
|
+
if (lintPatterns === "git") {
|
|
2450
|
+
lintPatterns = getGitChangedFiles();
|
|
2451
|
+
if (!lintPatterns.length) {
|
|
2452
|
+
console.log(chalk.green("没有检测到git修改的文件"));
|
|
2453
|
+
process.exit(0);
|
|
2454
|
+
}
|
|
2455
|
+
console.log(chalk.green(`检测到${lintPatterns.length}个git修改文件:`));
|
|
2456
|
+
lintPatterns.forEach((f) => console.log(chalk.gray(` ${f}`)));
|
|
2457
|
+
}
|
|
2458
|
+
lint$1(lintPatterns, fix);
|
|
2374
2459
|
} else if (lintc) {
|
|
2375
2460
|
inquirer.prompt(rules).then(async ({ rule }) => {
|
|
2376
2461
|
const parentRule = rule;
|
|
@@ -2483,15 +2568,24 @@ if (sass) {
|
|
|
2483
2568
|
|
|
2484
2569
|
function translateUtil(appid, key, projectName, isLintFix) {
|
|
2485
2570
|
const { input } = program.opts();
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2571
|
+
// 支持逗号分隔的多个路径(来自 -lint git 的多文件场景)
|
|
2572
|
+
const inputPaths = String(input)
|
|
2573
|
+
.split(",")
|
|
2574
|
+
.map((s) => s.trim())
|
|
2575
|
+
.filter(Boolean);
|
|
2576
|
+
let src = [];
|
|
2577
|
+
inputPaths.forEach((inputPath) => {
|
|
2578
|
+
const normalizedInput = inputPath.replace(/\\/g, "/");
|
|
2579
|
+
if (fs.statSync(inputPath).isDirectory()) {
|
|
2580
|
+
const directory = normalizedInput + "/**/*.{js,vue,jsx,ts,tsx}";
|
|
2581
|
+
const files = glob.sync(directory, {
|
|
2582
|
+
ignore: directory + `/**/node_modules/**`,
|
|
2583
|
+
});
|
|
2584
|
+
src = src.concat(files);
|
|
2585
|
+
} else {
|
|
2586
|
+
src.push(normalizedInput);
|
|
2587
|
+
}
|
|
2588
|
+
});
|
|
2495
2589
|
let allArr = []; // 所有文本组成的数组
|
|
2496
2590
|
let groupArr = []; // 分组后的数组
|
|
2497
2591
|
let newAllArr = []; // 分组后的数组还原成所有数组
|