lingo-linter-tool 1.0.1 → 1.0.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.
@@ -27,78 +27,40 @@ 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
- const translator_1 = require("./translator");
33
33
  const chalk_1 = __importDefault(require("chalk"));
34
- function getSourceText(localesDir, key) {
35
- try {
36
- const enPath = path.join(localesDir, "en.json");
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;
49
- }
50
- catch (e) {
51
- return null;
52
- }
53
- }
54
34
  async function healIssues(issues, localesDir) {
55
- console.log(chalk_1.default.blue("\n🩹 Initializing Lingo.dev Auto-Healer..."));
56
- const missingKeyIssues = issues.filter((i) => i.ruleId === "missing-keys" && i.key);
57
- if (missingKeyIssues.length === 0) {
58
- console.log("✨ No missing keys to heal.");
35
+ console.log(chalk_1.default.blue("\n🩹 Initializing Lingo.dev Official Sync..."));
36
+ const missingKeys = issues.filter((i) => i.ruleId === "missing-keys");
37
+ if (missingKeys.length === 0)
59
38
  return;
60
- }
61
- const updates = {};
62
- for (const issue of missingKeyIssues) {
63
- const targetFile = path.basename(issue.file);
64
- const targetLang = targetFile.replace(".json", "");
65
- const key = issue.key;
66
- const sourceText = getSourceText(localesDir, key);
67
- if (!sourceText) {
68
- console.warn(chalk_1.default.yellow(`āš ļø Skipping "${key}": Key also missing in en.json (Source)`));
69
- continue;
39
+ const enPath = path.join(localesDir, "en.json");
40
+ const enContent = JSON.parse(fs.readFileSync(enPath, "utf-8"));
41
+ let hasChanges = false;
42
+ missingKeys.forEach((issue) => {
43
+ if (issue.key && !enContent[issue.key]) {
44
+ const humanText = issue.key.split(".").pop() || issue.key;
45
+ enContent[issue.key] = humanText;
46
+ hasChanges = true;
47
+ console.log(chalk_1.default.gray(` āž• Added source key: "${issue.key}"`));
70
48
  }
71
- if (!updates[targetFile])
72
- updates[targetFile] = {};
73
- process.stdout.write(` ✨ Translating "${key}" to ${targetLang}... `);
74
- const translation = await translator_1.Translator.translate(sourceText, targetLang);
75
- console.log(chalk_1.default.green("Done"));
76
- updates[targetFile][key] = translation;
49
+ });
50
+ if (hasChanges) {
51
+ fs.writeFileSync(enPath, JSON.stringify(enContent, null, 2));
77
52
  }
78
- Object.keys(updates).forEach((file) => {
79
- if (Object.keys(updates[file]).length === 0)
80
- return;
81
- const filePath = path.join(localesDir, file);
82
- let currentContent = {};
83
- try {
84
- currentContent = JSON.parse(fs.readFileSync(filePath, "utf-8"));
85
- }
86
- catch (e) {
87
- }
88
- const newContent = { ...currentContent };
89
- Object.entries(updates[file]).forEach(([key, val]) => {
90
- const parts = key.split(".");
91
- let current = newContent;
92
- for (let i = 0; i < parts.length - 1; i++) {
93
- const part = parts[i];
94
- if (!current[part])
95
- current[part] = {};
96
- current = current[part];
97
- }
98
- current[parts[parts.length - 1]] = val;
53
+ try {
54
+ console.log(chalk_1.default.magenta("šŸš€ Triggering 'npx lingo.dev run' to generate translations..."));
55
+ (0, child_process_1.execSync)("npx lingo.dev run --force", {
56
+ stdio: "inherit",
57
+ cwd: path.dirname(localesDir),
99
58
  });
100
- fs.writeFileSync(filePath, JSON.stringify(newContent, null, 2));
101
- console.log(chalk_1.default.magenta(`šŸ’¾ Written ${Object.keys(updates[file]).length} new keys to ${file}`));
102
- });
59
+ console.log(chalk_1.default.green("\nāœ… Lingo.dev successfully healed your files!"));
60
+ }
61
+ catch (error) {
62
+ console.error(chalk_1.default.red("āŒ Failed to run Lingo.dev CLI. Is it installed in the target app?"));
63
+ console.error(chalk_1.default.yellow("šŸ‘‰ Try running: npm install -D lingo.dev"));
64
+ }
103
65
  }
104
66
  exports.healIssues = healIssues;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "lingo-linter-tool",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Localization linter and self-healing tool",
5
5
  "bin": {
6
- "lingo": "./dist/cli.js"
6
+ "lingo-lint": "./dist/cli.js"
7
7
  },
8
8
  "files": [
9
9
  "dist",