@ttoss/i18n-cli 0.4.2 → 0.4.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.
Files changed (2) hide show
  1. package/dist/index.js +57 -47
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
  "use strict";
3
+
3
4
  var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
5
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -8,20 +9,22 @@ var __getProtoOf = Object.getPrototypeOf;
8
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
10
  var __copyProps = (to, from, except, desc) => {
10
11
  if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
14
16
  }
15
17
  return to;
16
18
  };
17
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
- // If the importer is in node compatibility mode or this is not an ESM
19
- // file that has been converted to a CommonJS file using a Babel-
20
- // compatible transform (i.e. "__esModule" has not been set), then set
21
- // "default" to the CommonJS "module.exports" for node compatibility.
22
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
- mod
24
- ));
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
25
28
 
26
29
  // src/index.ts
27
30
  var fs = __toESM(require("fs"));
@@ -31,21 +34,18 @@ var import_cli_lib = require("@formatjs/cli-lib");
31
34
  var DEFAULT_DIR = "i18n";
32
35
  var EXTRACT_DIR = path.join(DEFAULT_DIR, "lang");
33
36
  var EXTRACT_FILE = path.join(EXTRACT_DIR, "en.json");
34
- var COMPILE_DIR = path.join(DEFAULT_DIR, "compiled-lang");
37
+ var COMPILE_DIR = path.join(DEFAULT_DIR, "compiled");
38
+ var MISSING_DIR = path.join(DEFAULT_DIR, "missing");
35
39
  var args = process.argv.slice(2);
36
40
  var getTtossExtractedTranslations = async () => {
37
- const packageJsonAsString = await fs.promises.readFile(
38
- path.join(process.cwd(), "package.json")
39
- );
41
+ const packageJsonAsString = await fs.promises.readFile(path.join(process.cwd(), "package.json"));
40
42
  const packageJson = JSON.parse(packageJsonAsString.toString());
41
- const ttossDependencies = Object.keys(
42
- {
43
- ...packageJson.dependencies,
44
- ...packageJson.peerDependencies
45
- }
46
- ).filter((dependency) => {
43
+ const ttossDependencies = Object.keys({
44
+ ...packageJson.dependencies,
45
+ ...packageJson.peerDependencies
46
+ }).filter(dependency => {
47
47
  return dependency.startsWith("@ttoss");
48
- }).filter((dependency) => {
48
+ }).filter(dependency => {
49
49
  return dependency !== "@ttoss/react-i18n";
50
50
  }).filter((dependency, index, array) => {
51
51
  return array.indexOf(dependency) === index;
@@ -53,13 +53,8 @@ var getTtossExtractedTranslations = async () => {
53
53
  const ttossExtractedTranslations = {};
54
54
  for (const dependency of ttossDependencies) {
55
55
  try {
56
- const extractedTranslations = require(path.join(
57
- dependency,
58
- EXTRACT_FILE
59
- ));
60
- const extractedTranslationsWithModule = Object.keys(
61
- extractedTranslations
62
- ).reduce((acc, key) => {
56
+ const extractedTranslations = require(path.join(dependency, EXTRACT_FILE));
57
+ const extractedTranslationsWithModule = Object.keys(extractedTranslations).reduce((acc, key) => {
63
58
  return {
64
59
  ...acc,
65
60
  [key]: {
@@ -68,10 +63,7 @@ var getTtossExtractedTranslations = async () => {
68
63
  }
69
64
  };
70
65
  }, {});
71
- Object.assign(
72
- ttossExtractedTranslations,
73
- extractedTranslationsWithModule
74
- );
66
+ Object.assign(ttossExtractedTranslations, extractedTranslationsWithModule);
75
67
  } catch (error) {
76
68
  continue;
77
69
  }
@@ -79,14 +71,11 @@ var getTtossExtractedTranslations = async () => {
79
71
  return ttossExtractedTranslations;
80
72
  };
81
73
  (async () => {
82
- const extractedDataAsString = await (0, import_cli_lib.extract)(
83
- glob.sync("src/**/*.{ts,tsx}", {
84
- ignore: ["src/**/*.test.{ts,tsx}", "src/**/*.d.ts"]
85
- }),
86
- {
87
- idInterpolationPattern: "[sha512:contenthash:base64:6]"
88
- }
89
- );
74
+ const extractedDataAsString = await (0, import_cli_lib.extract)(glob.sync("src/**/*.{ts,tsx}", {
75
+ ignore: ["src/**/*.test.{ts,tsx}", "src/**/*.d.ts"]
76
+ }), {
77
+ idInterpolationPattern: "[sha512:contenthash:base64:6]"
78
+ });
90
79
  const ignoreTtossPackages = args.includes("--ignore-ttoss-packages");
91
80
  const ttossExtractedTranslations = await getTtossExtractedTranslations();
92
81
  const finalExtractedData = (() => {
@@ -100,25 +89,46 @@ var getTtossExtractedTranslations = async () => {
100
89
  };
101
90
  return JSON.stringify(finalExtractedData2, null, 2);
102
91
  })();
103
- await fs.promises.mkdir(EXTRACT_DIR, { recursive: true });
92
+ await fs.promises.mkdir(EXTRACT_DIR, {
93
+ recursive: true
94
+ });
104
95
  await fs.promises.writeFile(EXTRACT_FILE, finalExtractedData);
105
96
  if (args.includes("--no-compile")) {
106
97
  return;
107
98
  }
99
+ const translations = glob.sync(EXTRACT_DIR + "/*.json");
108
100
  await fs.promises.mkdir(COMPILE_DIR, {
109
101
  recursive: true
110
102
  });
111
- const translations = glob.sync(EXTRACT_DIR + "/*.json");
112
103
  for (const translation of translations) {
113
104
  const filename = translation.split("/").pop();
114
105
  const compiledDataAsString = await (0, import_cli_lib.compile)([translation], {
115
106
  ast: true
116
107
  });
117
108
  if (filename) {
118
- await fs.promises.writeFile(
119
- path.join(COMPILE_DIR, filename),
120
- compiledDataAsString
121
- );
109
+ await fs.promises.writeFile(path.join(COMPILE_DIR, filename), compiledDataAsString);
110
+ }
111
+ }
112
+ await fs.promises.mkdir(MISSING_DIR, {
113
+ recursive: true
114
+ });
115
+ for (const translation of translations) {
116
+ const filename = translation.split("/").pop();
117
+ if (filename === "en.json") {
118
+ continue;
119
+ }
120
+ const extractedTranslations = JSON.parse(finalExtractedData);
121
+ const obj = JSON.parse(fs.readFileSync(translation, {
122
+ encoding: "utf-8"
123
+ }));
124
+ const missingTranslations = Object.keys(extractedTranslations).reduce((acc, key) => {
125
+ if (!obj[key]) {
126
+ acc[key] = extractedTranslations[key];
127
+ }
128
+ return acc;
129
+ }, {});
130
+ if (filename) {
131
+ await fs.promises.writeFile(path.join(MISSING_DIR, filename), JSON.stringify(missingTranslations, null, 2));
122
132
  }
123
133
  }
124
- })();
134
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/i18n-cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "license": "UNLICENSED",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -21,10 +21,10 @@
21
21
  "glob": "^9.3.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@ttoss/config": "^1.29.1"
24
+ "@ttoss/config": "^1.29.2"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
- "gitHead": "ee0c2e51d38f37f997c020d4303cf90be720ecb0"
29
+ "gitHead": "0609bb0f6e6a1c0999c29e7a5c8f8ebb1c6d3d7a"
30
30
  }