lingo-linter-tool 1.0.2 ā 1.0.4
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/healer/index.js +40 -25
- package/package.json +2 -2
package/dist/healer/index.js
CHANGED
|
@@ -27,42 +27,57 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.healIssues = void 0;
|
|
30
|
+
const child_process_1 = require("child_process");
|
|
30
31
|
const fs = __importStar(require("fs"));
|
|
31
32
|
const path = __importStar(require("path"));
|
|
32
33
|
const chalk_1 = __importDefault(require("chalk"));
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
async function healIssues(issues, localesDir) {
|
|
35
|
+
console.log(chalk_1.default.blue("\n𩹠Initializing Lingo.dev Integration..."));
|
|
36
|
+
const missingKeys = issues.filter((i) => i.ruleId === "missing-keys");
|
|
37
|
+
if (missingKeys.length === 0)
|
|
38
|
+
return;
|
|
39
|
+
const projectRoot = path.dirname(localesDir);
|
|
40
|
+
const configPath = path.join(projectRoot, "i18n.json");
|
|
41
|
+
if (!fs.existsSync(configPath)) {
|
|
42
|
+
console.log(chalk_1.default.yellow("ā ļø i18n.json not found. Auto-generating default config..."));
|
|
43
|
+
const defaultConfig = {
|
|
44
|
+
source: "en",
|
|
45
|
+
targets: ["fr", "de", "es"],
|
|
46
|
+
localesDir: "./" + path.basename(localesDir),
|
|
47
|
+
provider: "openai",
|
|
48
|
+
};
|
|
49
|
+
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
|
|
50
|
+
console.log(chalk_1.default.green("ā
Created i18n.json"));
|
|
51
|
+
}
|
|
52
|
+
const enPath = path.join(localesDir, "en.json");
|
|
53
|
+
let enContent = {};
|
|
35
54
|
try {
|
|
36
|
-
|
|
37
|
-
if (!fs.existsSync(enPath))
|
|
38
|
-
return null;
|
|
39
|
-
const raw = fs.readFileSync(enPath, "utf-8");
|
|
40
|
-
const json = JSON.parse(raw);
|
|
41
|
-
const keys = key.split(".");
|
|
42
|
-
let current = json;
|
|
43
|
-
for (const k of keys) {
|
|
44
|
-
if (current[k] === undefined)
|
|
45
|
-
return null;
|
|
46
|
-
current = current[k];
|
|
47
|
-
}
|
|
48
|
-
return typeof current === "string" ? current : null;
|
|
55
|
+
enContent = JSON.parse(fs.readFileSync(enPath, "utf-8"));
|
|
49
56
|
}
|
|
50
57
|
catch (e) {
|
|
51
|
-
return null;
|
|
52
58
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
let hasChanges = false;
|
|
60
|
+
missingKeys.forEach((issue) => {
|
|
61
|
+
if (issue.key && !enContent[issue.key]) {
|
|
62
|
+
const humanText = issue.key.split(".").pop() || issue.key;
|
|
63
|
+
enContent[issue.key] = humanText;
|
|
64
|
+
hasChanges = true;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
if (hasChanges) {
|
|
68
|
+
fs.writeFileSync(enPath, JSON.stringify(enContent, null, 2));
|
|
69
|
+
console.log(chalk_1.default.gray(" ā Injected missing keys into source (en.json)"));
|
|
70
|
+
}
|
|
56
71
|
try {
|
|
57
|
-
console.log("š Triggering Lingo.dev
|
|
58
|
-
(0, child_process_1.execSync)(
|
|
72
|
+
console.log(chalk_1.default.magenta("š Triggering Lingo.dev AI Translation..."));
|
|
73
|
+
(0, child_process_1.execSync)("npx lingo.dev run --force", {
|
|
59
74
|
stdio: "inherit",
|
|
75
|
+
cwd: projectRoot,
|
|
60
76
|
});
|
|
61
|
-
console.log("ā
|
|
62
|
-
return;
|
|
77
|
+
console.log(chalk_1.default.green("\nā
Auto-Healing Complete!"));
|
|
63
78
|
}
|
|
64
|
-
catch (
|
|
65
|
-
console.error("ā
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error(chalk_1.default.red("ā Failed to run lingo.dev CLI."));
|
|
66
81
|
}
|
|
67
82
|
}
|
|
68
83
|
exports.healIssues = healIssues;
|
package/package.json
CHANGED