@ttoss/i18n-cli 0.2.0

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/bin/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('../dist/index.js');
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
18
+ mod
19
+ ));
20
+
21
+ // src/index.ts
22
+ var fs = __toESM(require("fs"));
23
+ var glob = __toESM(require("glob"));
24
+ var path = __toESM(require("path"));
25
+ var import_cli_lib = require("@formatjs/cli-lib");
26
+ var DEFAULT_DIR = "i18n";
27
+ var EXTRACT_DIR = path.join(DEFAULT_DIR, "lang");
28
+ var COMPILE_DIR = path.join(DEFAULT_DIR, "compiled-lang");
29
+ var args = process.argv.slice(2);
30
+ (async () => {
31
+ const extractedDataAsString = await (0, import_cli_lib.extract)(glob.sync("src/**/*.{ts,tsx}"), {
32
+ idInterpolationPattern: "[sha512:contenthash:base64:6]"
33
+ });
34
+ await fs.promises.mkdir(EXTRACT_DIR, { recursive: true });
35
+ await fs.promises.writeFile(
36
+ path.join(EXTRACT_DIR, "en.json"),
37
+ extractedDataAsString
38
+ );
39
+ if (args.includes("--no-compile")) {
40
+ return;
41
+ }
42
+ await fs.promises.mkdir(COMPILE_DIR, {
43
+ recursive: true
44
+ });
45
+ const translations = glob.sync(EXTRACT_DIR + "/*.json");
46
+ for (const translation of translations) {
47
+ const filename = translation.split("/").pop();
48
+ const compiledDataAsString = await (0, import_cli_lib.compile)([translation], {
49
+ ast: true
50
+ });
51
+ if (filename) {
52
+ await fs.promises.writeFile(
53
+ path.join(COMPILE_DIR, filename),
54
+ compiledDataAsString
55
+ );
56
+ }
57
+ }
58
+ })();
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@ttoss/i18n-cli",
3
+ "version": "0.2.0",
4
+ "license": "UNLICENSED",
5
+ "author": "ttoss",
6
+ "contributors": [
7
+ "Pedro Arantes <arantespp@gmail.com> (https://arantespp.com)"
8
+ ],
9
+ "bin": {
10
+ "ttoss-i18n": "./bin/cli.js"
11
+ },
12
+ "files": [
13
+ "bin",
14
+ "dist"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsup-node"
18
+ },
19
+ "dependencies": {
20
+ "@formatjs/cli-lib": "^5.1.10",
21
+ "glob": "^8.0.3"
22
+ },
23
+ "devDependencies": {
24
+ "@ttoss/config": "^1.25.0"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "gitHead": "9159bd57009f4fee620218bc1a0e7bbac28acccd"
30
+ }