@ttoss/i18n-cli 0.7.25 → 0.7.27

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.
Files changed (2) hide show
  1. package/dist/index.js +38 -4
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -27,16 +27,17 @@ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
27
27
  }) : target, mod));
28
28
 
29
29
  // src/index.ts
30
- var fs = __toESM(require("fs"));
31
- var import_fast_glob = __toESM(require("fast-glob"));
32
- var path = __toESM(require("path"));
33
30
  var import_cli_lib = require("@formatjs/cli-lib");
31
+ var import_fast_glob = __toESM(require("fast-glob"));
32
+ var fs = __toESM(require("fs"));
34
33
  var import_minimist = __toESM(require("minimist"));
34
+ var path = __toESM(require("path"));
35
35
  var DEFAULT_DIR = "i18n";
36
36
  var EXTRACT_DIR = path.join(DEFAULT_DIR, "lang");
37
37
  var EXTRACT_FILE = path.join(EXTRACT_DIR, "en.json");
38
38
  var COMPILE_DIR = path.join(DEFAULT_DIR, "compiled");
39
39
  var MISSING_DIR = path.join(DEFAULT_DIR, "missing");
40
+ var UNUSED_DIR = path.join(DEFAULT_DIR, "unused");
40
41
  var argv = (0, import_minimist.default)(process.argv.slice(2));
41
42
  var getTtossExtractedTranslations = async () => {
42
43
  const packageJsonAsString = await fs.promises.readFile(path.join(process.cwd(), "package.json"));
@@ -67,7 +68,7 @@ var getTtossExtractedTranslations = async () => {
67
68
  };
68
69
  }, {});
69
70
  Object.assign(ttossExtractedTranslations, extractedTranslationsWithModule);
70
- } catch (error) {
71
+ } catch {
71
72
  continue;
72
73
  }
73
74
  }
@@ -120,6 +121,9 @@ var getTtossExtractedTranslations = async () => {
120
121
  await fs.promises.mkdir(MISSING_DIR, {
121
122
  recursive: true
122
123
  });
124
+ await fs.promises.mkdir(UNUSED_DIR, {
125
+ recursive: true
126
+ });
123
127
  for (const translation of translations) {
124
128
  const filename = translation.split("/").pop();
125
129
  if (filename === "en.json") {
@@ -137,8 +141,38 @@ var getTtossExtractedTranslations = async () => {
137
141
  },
138
142
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
143
  {});
144
+ const unusedTranslations = Object.keys(obj).reduce((acc, key) => {
145
+ if (!extractedTranslations[key]) {
146
+ acc[key] = obj[key];
147
+ }
148
+ return acc;
149
+ },
150
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
151
+ {});
152
+ const withoutUnecessaryTranslations = Object.keys(obj).reduce((acc, key) => {
153
+ if (obj[key] !== unusedTranslations[key]) {
154
+ acc[key] = obj[key];
155
+ }
156
+ return acc;
157
+ },
158
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
+ {});
140
160
  if (filename) {
141
161
  await fs.promises.writeFile(path.join(MISSING_DIR, filename), JSON.stringify(missingTranslations, null, 2));
162
+ try {
163
+ const existentUnusedJsonAsString = await fs.promises.readFile(path.join(UNUSED_DIR, filename));
164
+ if (existentUnusedJsonAsString) {
165
+ const existentUnusedJson = JSON.parse(existentUnusedJsonAsString.toString());
166
+ const updatedUnusedTranslations = {
167
+ ...existentUnusedJson,
168
+ ...unusedTranslations
169
+ };
170
+ await fs.promises.writeFile(path.join(UNUSED_DIR, filename), JSON.stringify(updatedUnusedTranslations, null, 2));
171
+ }
172
+ } catch {
173
+ await fs.promises.writeFile(path.join(UNUSED_DIR, filename), JSON.stringify(unusedTranslations, null, 2));
174
+ }
175
+ await fs.promises.writeFile(path.join(EXTRACT_DIR, filename), JSON.stringify(withoutUnecessaryTranslations, null, 2));
142
176
  }
143
177
  }
144
178
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/i18n-cli",
3
- "version": "0.7.25",
3
+ "version": "0.7.27",
4
4
  "license": "MIT",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -27,7 +27,7 @@
27
27
  "@types/minimist": "^1.2.5",
28
28
  "ts-node": "^10.9.2",
29
29
  "tsup": "^8.3.5",
30
- "@ttoss/config": "^1.35.1"
30
+ "@ttoss/config": "^1.35.2"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public",