react-i18next-scanner 0.1.8 → 0.1.10

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.
@@ -1,13 +1,14 @@
1
1
  import fs from "fs/promises";
2
2
  import path from "path";
3
3
  import { sortObject } from "../utils/sortObject.js";
4
- const DEFAULT_DYNAMIC_REPORT_DIR = path.resolve(process.cwd(), "reports/dynamic-translations");
5
- export async function writeDynamicTranslationReport(report, outputDir = DEFAULT_DYNAMIC_REPORT_DIR) {
4
+ export async function writeDynamicTranslationReport(report, outputDir) {
6
5
  if (Object.keys(report).length === 0) {
7
6
  return;
8
7
  }
9
- await fs.mkdir(outputDir, { recursive: true });
10
- const reportPath = path.join(outputDir, "dynamic-translation-usages.json");
8
+ const rootReportDir = outputDir ?? "reports";
9
+ const reportDir = path.join(rootReportDir, "dynamic-translations");
10
+ await fs.mkdir(reportDir, { recursive: true });
11
+ const reportPath = path.join(reportDir, "dynamic-translation-usages.json");
11
12
  const sortedReport = sortObject(report);
12
13
  await fs.writeFile(reportPath, `${JSON.stringify(sortedReport, null, 2)}\n`, "utf-8");
13
14
  console.log(`📝 Dynamic translation report created: ${reportPath}`);
@@ -3,8 +3,7 @@ import fs from "fs/promises";
3
3
  import path from "path";
4
4
  import { addKey } from "../utils/addKey.js";
5
5
  import { sortObject } from "../utils/sortObject.js";
6
- const DEFAULT_OUTPUT_DIR = path.resolve(process.cwd(), "dynamic-translations");
7
- export async function writePossiblyDynamicallyUsedReport(keysByFile, jsonFiles, outputDir = DEFAULT_OUTPUT_DIR) {
6
+ export async function writePossiblyDynamicallyUsedReport(keysByFile, jsonFiles, outputDir) {
8
7
  const reportDataByFile = {};
9
8
  for (const file of jsonFiles) {
10
9
  const possibleKeys = keysByFile[file.filePath] ?? [];
@@ -26,7 +25,9 @@ export async function writePossiblyDynamicallyUsedReport(keysByFile, jsonFiles,
26
25
  if (Object.keys(reportDataByFile).length === 0) {
27
26
  return;
28
27
  }
29
- await fs.mkdir(outputDir, { recursive: true });
28
+ const rootReportDir = outputDir ?? "reports";
29
+ const reportDir = path.join(rootReportDir, "possibly-dynamically-used");
30
+ await fs.mkdir(reportDir, { recursive: true });
30
31
  const reportPath = path.join(outputDir, "possibly-dynamically-used.json");
31
32
  await fs.writeFile(reportPath, `${JSON.stringify(sortObject(reportDataByFile), null, 2)}\n`, "utf-8");
32
33
  console.log(`📝 Possibly dynamically used report created: ${reportPath}`);
@@ -18,7 +18,8 @@ function getConfigTemplate(format) {
18
18
  ],
19
19
  outputDir: "./unused",
20
20
  syncMissing: false,
21
- removeUnused: false
21
+ removeUnused: false,
22
+ sortJson: false
22
23
  }`;
23
24
  if (format === "cjs") {
24
25
  return `module.exports = ${configObject};\n`;
@@ -12,7 +12,7 @@ import { deepVerifyUnusedKeys } from "./analysis/deepVerifyUnusedKeys.js";
12
12
  export async function runScanner(config) {
13
13
  const files = await getFiles(config.srcPaths);
14
14
  const dynamicUsages = await detectDynamicTranslationUsages(files);
15
- await writeDynamicTranslationReport(dynamicUsages);
15
+ await writeDynamicTranslationReport(dynamicUsages, config.outputDir);
16
16
  const usedKeys = await extractKeysFromFiles(files);
17
17
  const jsonData = await loadJsonKeys(config.jsonDir);
18
18
  const result = analyzeKeys(usedKeys, jsonData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-i18next-scanner",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "CLI tool to scan React projects for missing and unused react-i18next translation keys",
5
5
  "bin": "./dist/cli/cli.js",
6
6
  "scripts": {