@lingual/i18n-check 0.8.1 → 0.8.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/bin/index.js +16 -43
- package/dist/bin/index.test.js +557 -469
- package/dist/errorReporters.d.ts +5 -7
- package/dist/errorReporters.js +59 -73
- package/dist/errorReporters.test.d.ts +1 -0
- package/dist/errorReporters.test.js +165 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +21 -14
- package/dist/types.d.ts +5 -0
- package/dist/utils/findInvalidTranslations.d.ts +3 -6
- package/dist/utils/findInvalidTranslations.js +3 -3
- package/dist/utils/findInvalidi18nTranslations.d.ts +3 -3
- package/dist/utils/findInvalidi18nTranslations.js +1 -1
- package/dist/utils/findMissingKeys.d.ts +1 -1
- package/dist/utils/findMissingKeys.js +1 -1
- package/dist/utils/flattenTranslations.js +1 -1
- package/dist/utils/nextIntlSrcParser.test.js +50 -50
- package/package.json +1 -1
package/dist/bin/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
|
13
13
|
const __1 = require("..");
|
|
14
14
|
const errorReporters_1 = require("../errorReporters");
|
|
15
15
|
const flattenTranslations_1 = require("../utils/flattenTranslations");
|
|
16
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
16
17
|
const version = require("../../package.json").version;
|
|
17
18
|
commander_1.program
|
|
18
19
|
.version(version)
|
|
@@ -66,6 +67,7 @@ const main = async () => {
|
|
|
66
67
|
: `${localePath.join(",").trim()}/**/*.{json,yaml,yml}`;
|
|
67
68
|
const files = await (0, glob_1.glob)(pattern, {
|
|
68
69
|
ignore: ["node_modules/**"].concat(excludedPaths),
|
|
70
|
+
windowsPathsNoEscape: true,
|
|
69
71
|
});
|
|
70
72
|
console.log("i18n translations checker");
|
|
71
73
|
console.log(chalk_1.default.gray(`Source: ${srcPath}`));
|
|
@@ -78,14 +80,14 @@ const main = async () => {
|
|
|
78
80
|
};
|
|
79
81
|
const fileInfos = [];
|
|
80
82
|
files.sort().forEach((file) => {
|
|
81
|
-
const
|
|
82
|
-
const name =
|
|
83
|
+
const filePath = file.split(node_path_1.default.sep);
|
|
84
|
+
const name = filePath.pop() ?? "";
|
|
83
85
|
const extension = name.split(".").pop() ?? "json";
|
|
84
86
|
fileInfos.push({
|
|
85
87
|
extension,
|
|
86
88
|
file,
|
|
87
89
|
name,
|
|
88
|
-
path,
|
|
90
|
+
path: filePath,
|
|
89
91
|
});
|
|
90
92
|
});
|
|
91
93
|
fileInfos.forEach(({ extension, file, name, path }) => {
|
|
@@ -163,6 +165,7 @@ const main = async () => {
|
|
|
163
165
|
: `${unusedSrcPath.join(",").trim()}/**/*.{ts,tsx}`;
|
|
164
166
|
const filesToParse = (0, glob_1.globSync)(pattern, {
|
|
165
167
|
ignore: ["node_modules/**"],
|
|
168
|
+
windowsPathsNoEscape: true,
|
|
166
169
|
});
|
|
167
170
|
const unusedKeys = await (0, __1.checkUnusedKeys)(srcFiles, filesToParse, options, componentFunctions);
|
|
168
171
|
printUnusedKeysResult({ unusedKeys });
|
|
@@ -192,10 +195,11 @@ const printTranslationResult = ({ missingKeys, invalidKeys, }) => {
|
|
|
192
195
|
if (missingKeys && Object.keys(missingKeys).length > 0) {
|
|
193
196
|
console.log(chalk_1.default.red("\nFound missing keys!"));
|
|
194
197
|
if (isSummary) {
|
|
195
|
-
console.log(chalk_1.default.red((0, errorReporters_1.
|
|
198
|
+
console.log(chalk_1.default.red((0, errorReporters_1.formatSummaryTable)(missingKeys)));
|
|
196
199
|
}
|
|
197
200
|
else {
|
|
198
|
-
|
|
201
|
+
const table = (0, errorReporters_1.formatCheckResultTable)(missingKeys);
|
|
202
|
+
console.log(chalk_1.default.red(table));
|
|
199
203
|
}
|
|
200
204
|
}
|
|
201
205
|
else if (missingKeys) {
|
|
@@ -204,10 +208,11 @@ const printTranslationResult = ({ missingKeys, invalidKeys, }) => {
|
|
|
204
208
|
if (invalidKeys && Object.keys(invalidKeys).length > 0) {
|
|
205
209
|
console.log(chalk_1.default.red("\nFound invalid keys!"));
|
|
206
210
|
if (isSummary) {
|
|
207
|
-
console.log(chalk_1.default.red((0, errorReporters_1.
|
|
211
|
+
console.log(chalk_1.default.red((0, errorReporters_1.formatSummaryTable)(invalidKeys)));
|
|
208
212
|
}
|
|
209
213
|
else {
|
|
210
|
-
|
|
214
|
+
const table = (0, errorReporters_1.formatInvalidTranslationsResultTable)(invalidKeys);
|
|
215
|
+
console.log(chalk_1.default.red(table));
|
|
211
216
|
}
|
|
212
217
|
}
|
|
213
218
|
else if (invalidKeys) {
|
|
@@ -220,10 +225,10 @@ const printUnusedKeysResult = ({ unusedKeys, }) => {
|
|
|
220
225
|
if (unusedKeys && hasKeys(unusedKeys)) {
|
|
221
226
|
console.log(chalk_1.default.red("\nFound unused keys!"));
|
|
222
227
|
if (isSummary) {
|
|
223
|
-
console.log(chalk_1.default.red((0, errorReporters_1.
|
|
228
|
+
console.log(chalk_1.default.red((0, errorReporters_1.formatSummaryTable)(unusedKeys)));
|
|
224
229
|
}
|
|
225
230
|
else {
|
|
226
|
-
console.log(chalk_1.default.red((0, errorReporters_1.
|
|
231
|
+
console.log(chalk_1.default.red((0, errorReporters_1.formatCheckResultTable)(unusedKeys)));
|
|
227
232
|
}
|
|
228
233
|
}
|
|
229
234
|
else if (unusedKeys) {
|
|
@@ -236,48 +241,16 @@ const printUndefinedKeysResult = ({ undefinedKeys, }) => {
|
|
|
236
241
|
if (undefinedKeys && hasKeys(undefinedKeys)) {
|
|
237
242
|
console.log(chalk_1.default.red("\nFound undefined keys!"));
|
|
238
243
|
if (isSummary) {
|
|
239
|
-
console.log(chalk_1.default.red((0, errorReporters_1.
|
|
244
|
+
console.log(chalk_1.default.red((0, errorReporters_1.formatSummaryTable)(undefinedKeys)));
|
|
240
245
|
}
|
|
241
246
|
else {
|
|
242
|
-
console.log(chalk_1.default.red((0, errorReporters_1.
|
|
247
|
+
console.log(chalk_1.default.red((0, errorReporters_1.formatCheckResultTable)(undefinedKeys)));
|
|
243
248
|
}
|
|
244
249
|
}
|
|
245
250
|
else if (undefinedKeys) {
|
|
246
251
|
console.log(chalk_1.default.green("\nNo undefined keys found!"));
|
|
247
252
|
}
|
|
248
253
|
};
|
|
249
|
-
const truncate = (chars, len = 80) => chars.length > 80 ? `${chars.substring(0, len)}...` : chars;
|
|
250
|
-
const getSummaryRows = (checkResult) => {
|
|
251
|
-
const formattedRows = [];
|
|
252
|
-
for (const [file, keys] of Object.entries(checkResult)) {
|
|
253
|
-
formattedRows.push({
|
|
254
|
-
file: truncate(file),
|
|
255
|
-
total: keys.length,
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
return formattedRows;
|
|
259
|
-
};
|
|
260
|
-
const getStandardRows = (checkResult) => {
|
|
261
|
-
const formattedRows = [];
|
|
262
|
-
for (const [file, keys] of Object.entries(checkResult)) {
|
|
263
|
-
for (const entry of keys) {
|
|
264
|
-
if (typeof entry === "object") {
|
|
265
|
-
formattedRows.push({
|
|
266
|
-
file: truncate(file),
|
|
267
|
-
key: truncate(entry.key),
|
|
268
|
-
msg: truncate(entry.msg, 120),
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
formattedRows.push({
|
|
273
|
-
file: truncate(file),
|
|
274
|
-
key: truncate(entry),
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return formattedRows;
|
|
280
|
-
};
|
|
281
254
|
const hasKeys = (checkResult) => {
|
|
282
255
|
for (const [_, keys] of Object.entries(checkResult)) {
|
|
283
256
|
if (keys.length > 0) {
|