@lingual/i18n-check 0.8.0 → 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 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)
@@ -23,7 +24,7 @@ commander_1.program
23
24
  .option("-o, --only <only...>", "define the specific checks you want to run: invalidKeys, missingKeys, unused, undefined. By default the check will validate against missing and invalid keys, i.e. --only invalidKeys,missingKeys")
24
25
  .option("-r, --reporter <style>", "define the reporting style: standard or summary")
25
26
  .option("-e, --exclude <exclude...>", "define the file(s) and/or folders(s) that should be excluded from the check")
26
- .option("-u, --unused <path>", "define the source path to find all unused and undefined keys")
27
+ .option("-u, --unused <paths...>", "define the source path(s) to find all unused and undefined keys")
27
28
  .option("--parser-component-functions <components...>", "a list of component names to parse when using the --unused option")
28
29
  .parse();
29
30
  const getCheckOptions = () => {
@@ -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 path = file.split("/");
82
- const name = path.pop() ?? "";
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 }) => {
@@ -157,8 +159,13 @@ const main = async () => {
157
159
  const result = (0, __1.checkTranslations)(srcFiles, targetFiles, options);
158
160
  printTranslationResult(result);
159
161
  if (unusedSrcPath) {
160
- const filesToParse = (0, glob_1.globSync)(`${unusedSrcPath}/**/*.{ts,tsx}`, {
162
+ const isMultiUnusedFolders = unusedSrcPath.length > 1;
163
+ const pattern = isMultiUnusedFolders
164
+ ? `{${unusedSrcPath.join(",").trim()}}/**/*.{ts,tsx}`
165
+ : `${unusedSrcPath.join(",").trim()}/**/*.{ts,tsx}`;
166
+ const filesToParse = (0, glob_1.globSync)(pattern, {
161
167
  ignore: ["node_modules/**"],
168
+ windowsPathsNoEscape: true,
162
169
  });
163
170
  const unusedKeys = await (0, __1.checkUnusedKeys)(srcFiles, filesToParse, options, componentFunctions);
164
171
  printUnusedKeysResult({ unusedKeys });
@@ -188,10 +195,11 @@ const printTranslationResult = ({ missingKeys, invalidKeys, }) => {
188
195
  if (missingKeys && Object.keys(missingKeys).length > 0) {
189
196
  console.log(chalk_1.default.red("\nFound missing keys!"));
190
197
  if (isSummary) {
191
- console.log(chalk_1.default.red((0, errorReporters_1.summaryReporter)(getSummaryRows(missingKeys))));
198
+ console.log(chalk_1.default.red((0, errorReporters_1.formatSummaryTable)(missingKeys)));
192
199
  }
193
200
  else {
194
- console.log(chalk_1.default.red((0, errorReporters_1.standardReporter)(getStandardRows(missingKeys))));
201
+ const table = (0, errorReporters_1.formatCheckResultTable)(missingKeys);
202
+ console.log(chalk_1.default.red(table));
195
203
  }
196
204
  }
197
205
  else if (missingKeys) {
@@ -200,10 +208,11 @@ const printTranslationResult = ({ missingKeys, invalidKeys, }) => {
200
208
  if (invalidKeys && Object.keys(invalidKeys).length > 0) {
201
209
  console.log(chalk_1.default.red("\nFound invalid keys!"));
202
210
  if (isSummary) {
203
- console.log(chalk_1.default.red((0, errorReporters_1.summaryReporter)(getSummaryRows(invalidKeys))));
211
+ console.log(chalk_1.default.red((0, errorReporters_1.formatSummaryTable)(invalidKeys)));
204
212
  }
205
213
  else {
206
- console.log(chalk_1.default.red((0, errorReporters_1.standardReporter)(getStandardRows(invalidKeys), true)));
214
+ const table = (0, errorReporters_1.formatInvalidTranslationsResultTable)(invalidKeys);
215
+ console.log(chalk_1.default.red(table));
207
216
  }
208
217
  }
209
218
  else if (invalidKeys) {
@@ -216,10 +225,10 @@ const printUnusedKeysResult = ({ unusedKeys, }) => {
216
225
  if (unusedKeys && hasKeys(unusedKeys)) {
217
226
  console.log(chalk_1.default.red("\nFound unused keys!"));
218
227
  if (isSummary) {
219
- console.log(chalk_1.default.red((0, errorReporters_1.summaryReporter)(getSummaryRows(unusedKeys))));
228
+ console.log(chalk_1.default.red((0, errorReporters_1.formatSummaryTable)(unusedKeys)));
220
229
  }
221
230
  else {
222
- console.log(chalk_1.default.red((0, errorReporters_1.standardReporter)(getStandardRows(unusedKeys))));
231
+ console.log(chalk_1.default.red((0, errorReporters_1.formatCheckResultTable)(unusedKeys)));
223
232
  }
224
233
  }
225
234
  else if (unusedKeys) {
@@ -232,48 +241,16 @@ const printUndefinedKeysResult = ({ undefinedKeys, }) => {
232
241
  if (undefinedKeys && hasKeys(undefinedKeys)) {
233
242
  console.log(chalk_1.default.red("\nFound undefined keys!"));
234
243
  if (isSummary) {
235
- console.log(chalk_1.default.red((0, errorReporters_1.summaryReporter)(getSummaryRows(undefinedKeys))));
244
+ console.log(chalk_1.default.red((0, errorReporters_1.formatSummaryTable)(undefinedKeys)));
236
245
  }
237
246
  else {
238
- console.log(chalk_1.default.red((0, errorReporters_1.standardReporter)(getStandardRows(undefinedKeys))));
247
+ console.log(chalk_1.default.red((0, errorReporters_1.formatCheckResultTable)(undefinedKeys)));
239
248
  }
240
249
  }
241
250
  else if (undefinedKeys) {
242
251
  console.log(chalk_1.default.green("\nNo undefined keys found!"));
243
252
  }
244
253
  };
245
- const truncate = (chars, len = 80) => chars.length > 80 ? `${chars.substring(0, len)}...` : chars;
246
- const getSummaryRows = (checkResult) => {
247
- const formattedRows = [];
248
- for (const [file, keys] of Object.entries(checkResult)) {
249
- formattedRows.push({
250
- file: truncate(file),
251
- total: keys.length,
252
- });
253
- }
254
- return formattedRows;
255
- };
256
- const getStandardRows = (checkResult) => {
257
- const formattedRows = [];
258
- for (const [file, keys] of Object.entries(checkResult)) {
259
- for (const entry of keys) {
260
- if (typeof entry === "object") {
261
- formattedRows.push({
262
- file: truncate(file),
263
- key: truncate(entry.key),
264
- msg: truncate(entry.msg, 120),
265
- });
266
- }
267
- else {
268
- formattedRows.push({
269
- file: truncate(file),
270
- key: truncate(entry),
271
- });
272
- }
273
- }
274
- }
275
- return formattedRows;
276
- };
277
254
  const hasKeys = (checkResult) => {
278
255
  for (const [_, keys] of Object.entries(checkResult)) {
279
256
  if (keys.length > 0) {