@formatjs/cli-lib 5.0.5 → 5.0.8
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/LICENSE.md +0 -0
- package/README.md +0 -0
- package/index.d.ts +0 -0
- package/index.d.ts.map +1 -1
- package/index.js +0 -0
- package/main.d.ts +0 -0
- package/main.d.ts.map +1 -1
- package/main.js +0 -0
- package/package.json +61 -61
- package/src/cli.d.ts +0 -0
- package/src/cli.d.ts.map +1 -1
- package/src/cli.js +159 -136
- package/src/compile.d.ts +0 -0
- package/src/compile.d.ts.map +1 -1
- package/src/compile.js +72 -97
- package/src/compile_folder.d.ts +0 -0
- package/src/compile_folder.d.ts.map +1 -1
- package/src/compile_folder.js +7 -18
- package/src/console_utils.d.ts +1 -0
- package/src/console_utils.d.ts.map +1 -1
- package/src/console_utils.js +42 -107
- package/src/extract.d.ts +0 -0
- package/src/extract.d.ts.map +1 -1
- package/src/extract.js +145 -188
- package/src/formatters/crowdin.d.ts +0 -0
- package/src/formatters/crowdin.d.ts.map +1 -1
- package/src/formatters/crowdin.js +6 -8
- package/src/formatters/default.d.ts +0 -0
- package/src/formatters/default.d.ts.map +1 -1
- package/src/formatters/default.js +4 -4
- package/src/formatters/index.d.ts +0 -0
- package/src/formatters/index.d.ts.map +1 -1
- package/src/formatters/index.js +36 -40
- package/src/formatters/lokalise.d.ts +0 -0
- package/src/formatters/lokalise.d.ts.map +1 -1
- package/src/formatters/lokalise.js +6 -8
- package/src/formatters/simple.d.ts +0 -0
- package/src/formatters/simple.d.ts.map +1 -1
- package/src/formatters/simple.js +3 -3
- package/src/formatters/smartling.d.ts +0 -0
- package/src/formatters/smartling.d.ts.map +1 -1
- package/src/formatters/smartling.js +7 -9
- package/src/formatters/transifex.d.ts +0 -0
- package/src/formatters/transifex.d.ts.map +1 -1
- package/src/formatters/transifex.js +6 -8
- package/src/parse_script.d.ts +0 -0
- package/src/parse_script.d.ts.map +1 -1
- package/src/parse_script.js +12 -11
- package/src/pseudo_locale.d.ts +0 -0
- package/src/pseudo_locale.d.ts.map +1 -1
- package/src/pseudo_locale.js +27 -31
- package/src/vue_extractor.d.ts +0 -0
- package/src/vue_extractor.d.ts.map +1 -1
- package/src/vue_extractor.js +19 -19
package/LICENSE.md
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/index.d.ts
CHANGED
|
File without changes
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,eAAe,EAAE,OAAO,EAAC,MAAM,eAAe,CAAA;AACjE,YAAY,EAAC,iBAAiB,EAAE,WAAW,EAAC,MAAM,eAAe,CAAA;AACjE,YAAY,EAAC,iBAAiB,EAAC,MAAM,0BAA0B,CAAA;AAC/D,YAAY,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,0BAA0B,CAAA;AACjE,YAAY,EAAC,OAAO,EAAE,UAAU,EAAC,MAAM,uBAAuB,CAAA;AAC9D,OAAO,EAAC,OAAO,IAAI,eAAe,EAAE,OAAO,EAAC,MAAM,eAAe,CAAA;AACjE,YAAY,EAAC,cAAc,EAAE,IAAI,IAAI,WAAW,EAAC,MAAM,eAAe,CAAA"}
|
package/index.js
CHANGED
|
File without changes
|
package/main.d.ts
CHANGED
|
File without changes
|
package/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":""}
|
package/main.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
2
|
+
"name": "@formatjs/cli-lib",
|
|
3
|
+
"version": "5.0.8",
|
|
4
|
+
"description": "Lib for CLI for formatjs.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"intl",
|
|
7
|
+
"i18n",
|
|
8
|
+
"internationalization",
|
|
9
|
+
"locale",
|
|
10
|
+
"localization",
|
|
11
|
+
"globalization",
|
|
12
|
+
"react",
|
|
13
|
+
"react-intl",
|
|
14
|
+
"reactjs",
|
|
15
|
+
"format",
|
|
16
|
+
"formatjs",
|
|
17
|
+
"formatting",
|
|
18
|
+
"translate",
|
|
19
|
+
"translation",
|
|
20
|
+
"cli"
|
|
21
|
+
],
|
|
22
|
+
"author": "Linjie Ding <linjie@airtable.com>",
|
|
23
|
+
"homepage": "https://github.com/formatjs/formatjs",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"main": "index.js",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+ssh://git@github.com/formatjs/formatjs.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/formatjs/formatjs/issues"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@formatjs/icu-messageformat-parser": "2.1.6",
|
|
35
|
+
"@formatjs/ts-transformer": "3.9.11",
|
|
36
|
+
"@types/estree": "^0.0.50",
|
|
37
|
+
"@types/fs-extra": "^9.0.1",
|
|
38
|
+
"@types/json-stable-stringify": "^1.0.32",
|
|
39
|
+
"@types/node": "14 || 16 || 17",
|
|
40
|
+
"chalk": "^4.0.0",
|
|
41
|
+
"commander": "8",
|
|
42
|
+
"fast-glob": "^3.2.7",
|
|
43
|
+
"fs-extra": "10",
|
|
44
|
+
"json-stable-stringify": "^1.0.1",
|
|
45
|
+
"loud-rejection": "^2.2.0",
|
|
46
|
+
"tslib": "2.4.0",
|
|
47
|
+
"typescript": "^4.5"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@vue/compiler-core": "^3.2.23",
|
|
51
|
+
"@vue/compiler-sfc": "^3.2.34"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"@vue/compiler-sfc": {
|
|
55
|
+
"optional": true
|
|
29
56
|
},
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"@formatjs/icu-messageformat-parser": "2.1.4",
|
|
35
|
-
"@formatjs/ts-transformer": "3.9.9",
|
|
36
|
-
"@types/estree": "^0.0.50",
|
|
37
|
-
"@types/fs-extra": "^9.0.1",
|
|
38
|
-
"@types/json-stable-stringify": "^1.0.32",
|
|
39
|
-
"@types/node": "14 || 16 || 17",
|
|
40
|
-
"chalk": "^4.0.0",
|
|
41
|
-
"commander": "8",
|
|
42
|
-
"fast-glob": "^3.2.7",
|
|
43
|
-
"fs-extra": "10",
|
|
44
|
-
"json-stable-stringify": "^1.0.1",
|
|
45
|
-
"loud-rejection": "^2.2.0",
|
|
46
|
-
"tslib": "2.4.0",
|
|
47
|
-
"typescript": "^4.5"
|
|
48
|
-
},
|
|
49
|
-
"peerDependencies": {
|
|
50
|
-
"@vue/compiler-core": "^3.2.23",
|
|
51
|
-
"@vue/compiler-sfc": "^3.2.34"
|
|
52
|
-
},
|
|
53
|
-
"peerDependenciesMeta": {
|
|
54
|
-
"@vue/compiler-sfc": {
|
|
55
|
-
"optional": true
|
|
56
|
-
},
|
|
57
|
-
"@vue/compiler-core": {
|
|
58
|
-
"optional": true
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
"engines": {
|
|
62
|
-
"node": ">= 16.5.0"
|
|
57
|
+
"@vue/compiler-core": {
|
|
58
|
+
"optional": true
|
|
63
59
|
}
|
|
64
|
-
}
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">= 16.5.0"
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/cli.d.ts
CHANGED
|
File without changes
|
package/src/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["cli.ts"],"names":[],"mappings":"AAUA,iBAAe,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,iBAoOjC;AACD,eAAe,IAAI,CAAA"}
|
package/src/cli.js
CHANGED
|
@@ -1,142 +1,165 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (!files.length) {
|
|
98
|
-
throw new Error("No input file found with pattern ".concat(filePatterns));
|
|
99
|
-
}
|
|
100
|
-
(0, console_utils_1.debug)('Files to compile:', files);
|
|
101
|
-
return [4 /*yield*/, (0, compile_1.default)(files, opts)];
|
|
102
|
-
case 1:
|
|
103
|
-
_a.sent();
|
|
104
|
-
return [2 /*return*/];
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}); });
|
|
108
|
-
commander_1.program
|
|
109
|
-
.command('compile-folder <folder> <outFolder>')
|
|
110
|
-
.description("Batch compile all extracted translation JSON files in <folder> to <outFolder> containing\nreact-intl consumable JSON. We also verify that the messages are \nvalid ICU and not malformed.")
|
|
111
|
-
.option('--format <path>', "Path to a formatter file that converts JSON files in `<folder>` to `Record<string, string>`\nso we can compile. The file must export a function named `compile` with the signature:\n```\ntype CompileFn = <T = Record<string, MessageDescriptor>>(\n msgs: T\n) => Record<string, string>;\n```\nThis is especially useful to convert from a TMS-specific format back to react-intl format\n")
|
|
112
|
-
.option('--ast', "Whether to compile to AST. See https://formatjs.io/docs/guides/advanced-usage#pre-parsing-messages\nfor more information")
|
|
113
|
-
.action(function (folder, outFolder, opts) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
114
|
-
var files;
|
|
115
|
-
return (0, tslib_1.__generator)(this, function (_a) {
|
|
116
|
-
switch (_a.label) {
|
|
117
|
-
case 0:
|
|
118
|
-
(0, console_utils_1.debug)('Folder:', folder);
|
|
119
|
-
(0, console_utils_1.debug)('Options:', opts);
|
|
120
|
-
files = (0, fast_glob_1.sync)("".concat(folder, "/*.json"));
|
|
121
|
-
if (!files.length) {
|
|
122
|
-
throw new Error("No JSON file found in ".concat(folder));
|
|
123
|
-
}
|
|
124
|
-
(0, console_utils_1.debug)('Files to compile:', files);
|
|
125
|
-
return [4 /*yield*/, (0, compile_folder_1.default)(files, outFolder, opts)];
|
|
126
|
-
case 1:
|
|
127
|
-
_a.sent();
|
|
128
|
-
return [2 /*return*/];
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}); });
|
|
132
|
-
if (argv.length < 3) {
|
|
133
|
-
commander_1.program.help();
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
commander_1.program.parse(argv);
|
|
137
|
-
}
|
|
138
|
-
return [2 /*return*/];
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const loud_rejection_1 = tslib_1.__importDefault(require("loud-rejection"));
|
|
6
|
+
const extract_1 = tslib_1.__importDefault(require("./extract"));
|
|
7
|
+
const compile_1 = tslib_1.__importDefault(require("./compile"));
|
|
8
|
+
const compile_folder_1 = tslib_1.__importDefault(require("./compile_folder"));
|
|
9
|
+
const fast_glob_1 = require("fast-glob");
|
|
10
|
+
const console_utils_1 = require("./console_utils");
|
|
11
|
+
const KNOWN_COMMANDS = ['extract'];
|
|
12
|
+
async function main(argv) {
|
|
13
|
+
(0, loud_rejection_1.default)();
|
|
14
|
+
commander_1.program
|
|
15
|
+
// TODO: fix this
|
|
16
|
+
.version('5.0.6', '-v, --version')
|
|
17
|
+
.usage('<command> [flags]')
|
|
18
|
+
.action(command => {
|
|
19
|
+
if (!KNOWN_COMMANDS.includes(command)) {
|
|
20
|
+
commander_1.program.help();
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
commander_1.program
|
|
24
|
+
.command('help', { isDefault: true })
|
|
25
|
+
.description('Show this help message.')
|
|
26
|
+
.action(() => commander_1.program.help());
|
|
27
|
+
// Long text wrapping to available terminal columns: https://github.com/tj/commander.js/pull/956
|
|
28
|
+
// NOTE: please keep the help text in sync with babel-plugin-formatjs documentation.
|
|
29
|
+
commander_1.program
|
|
30
|
+
.command('extract [files...]')
|
|
31
|
+
.description(`Extract string messages from React components that use react-intl.
|
|
32
|
+
The input language is expected to be TypeScript or ES2017 with JSX.`)
|
|
33
|
+
.option('--format <path>', `Path to a formatter file that controls the shape of JSON file from \`--out-file\`.
|
|
34
|
+
The formatter file must export a function called \`format\` with the signature
|
|
35
|
+
\`\`\`
|
|
36
|
+
type FormatFn = <T = Record<string, MessageDescriptor>>(
|
|
37
|
+
msgs: Record<string, MessageDescriptor>
|
|
38
|
+
) => T
|
|
39
|
+
\`\`\`
|
|
40
|
+
This is especially useful to convert from our extracted format to a TMS-specific format.
|
|
41
|
+
`)
|
|
42
|
+
.option('--out-file <path>', `The target file path where the plugin will output an aggregated
|
|
43
|
+
\`.json\` file of all the translations from the \`files\` supplied.`)
|
|
44
|
+
.option('--id-interpolation-pattern <pattern>', `If certain message descriptors don't have id, this \`pattern\` will be used to automatically
|
|
45
|
+
generate IDs for them. Default to \`[sha512:contenthash:base64:6]\` where \`contenthash\` is the hash of
|
|
46
|
+
\`defaultMessage\` and \`description\`.
|
|
47
|
+
See https://github.com/webpack/loader-utils#interpolatename for sample patterns`, '[sha512:contenthash:base64:6]')
|
|
48
|
+
.option('--extract-source-location', `Whether the metadata about the location of the message in the source file should be
|
|
49
|
+
extracted. If \`true\`, then \`file\`, \`start\`, and \`end\` fields will exist for each
|
|
50
|
+
extracted message descriptors.`, false)
|
|
51
|
+
.option('--remove-default-message', 'Remove `defaultMessage` field in generated js after extraction', false)
|
|
52
|
+
.option('--additional-component-names <comma-separated-names>', `Additional component names to extract messages from, e.g: \`'FormattedFooBarMessage'\`.
|
|
53
|
+
**NOTE**: By default we check for the fact that \`FormattedMessage\`
|
|
54
|
+
is imported from \`moduleSourceName\` to make sure variable alias
|
|
55
|
+
works. This option does not do that so it's less safe.`, (val) => val.split(','))
|
|
56
|
+
.option('--additional-function-names <comma-separated-names>', `Additional function names to extract messages from, e.g: \`'$t'\`.`, (val) => val.split(','))
|
|
57
|
+
.option('--ignore <files...>', 'List of glob paths to **not** extract translations from.')
|
|
58
|
+
.option('--throws', 'Whether to throw an exception when we fail to process any file in the batch.')
|
|
59
|
+
.option('--pragma <pragma>', `parse specific additional custom pragma. This allows you to tag certain file with metadata such as \`project\`. For example with this file:
|
|
60
|
+
|
|
61
|
+
\`\`\`
|
|
62
|
+
// @intl-meta project:my-custom-project
|
|
63
|
+
import {FormattedMessage} from 'react-intl';
|
|
64
|
+
|
|
65
|
+
<FormattedMessage defaultMessage="foo" id="bar" />;
|
|
66
|
+
\`\`\`
|
|
67
|
+
|
|
68
|
+
and with option \`{pragma: "intl-meta"}\`, we'll parse out \`// @intl-meta project:my-custom-project\` into \`{project: 'my-custom-project'}\` in the result file.`)
|
|
69
|
+
.option('--preserve-whitespace', 'Whether to preserve whitespace and newlines.')
|
|
70
|
+
.option('--flatten', `Whether to hoist selectors & flatten sentences as much as possible. E.g:
|
|
71
|
+
"I have {count, plural, one{a dog} other{many dogs}}"
|
|
72
|
+
becomes "{count, plural, one{I have a dog} other{I have many dogs}}".
|
|
73
|
+
The goal is to provide as many full sentences as possible since fragmented
|
|
74
|
+
sentences are not translator-friendly.`)
|
|
75
|
+
.action(async (filePatterns, cmdObj) => {
|
|
76
|
+
(0, console_utils_1.debug)('File pattern:', filePatterns);
|
|
77
|
+
(0, console_utils_1.debug)('Options:', cmdObj);
|
|
78
|
+
const files = (0, fast_glob_1.sync)(filePatterns, {
|
|
79
|
+
ignore: cmdObj.ignore,
|
|
80
|
+
});
|
|
81
|
+
(0, console_utils_1.debug)('Files to extract:', files);
|
|
82
|
+
await (0, extract_1.default)(files, {
|
|
83
|
+
outFile: cmdObj.outFile,
|
|
84
|
+
idInterpolationPattern: cmdObj.idInterpolationPattern || '[sha1:contenthash:base64:6]',
|
|
85
|
+
extractSourceLocation: cmdObj.extractSourceLocation,
|
|
86
|
+
removeDefaultMessage: cmdObj.removeDefaultMessage,
|
|
87
|
+
additionalComponentNames: cmdObj.additionalComponentNames,
|
|
88
|
+
additionalFunctionNames: cmdObj.additionalFunctionNames,
|
|
89
|
+
throws: cmdObj.throws,
|
|
90
|
+
pragma: cmdObj.pragma,
|
|
91
|
+
format: cmdObj.format,
|
|
92
|
+
// It is possible that the glob pattern does NOT match anything.
|
|
93
|
+
// But so long as the glob pattern is provided, don't read from stdin.
|
|
94
|
+
readFromStdin: filePatterns.length === 0,
|
|
95
|
+
preserveWhitespace: cmdObj.preserveWhitespace,
|
|
96
|
+
flatten: cmdObj.flatten,
|
|
139
97
|
});
|
|
98
|
+
process.exit(0);
|
|
99
|
+
});
|
|
100
|
+
commander_1.program
|
|
101
|
+
.command('compile [translation_files...]')
|
|
102
|
+
.description(`Compile extracted translation file into react-intl consumable JSON
|
|
103
|
+
We also verify that the messages are valid ICU and not malformed.
|
|
104
|
+
<translation_files> can be a glob like "foo/**/en.json"`)
|
|
105
|
+
.option('--format <path>', `Path to a formatter file that converts \`<translation_file>\` to \`Record<string, string>\`
|
|
106
|
+
so we can compile. The file must export a function named \`compile\` with the signature:
|
|
107
|
+
\`\`\`
|
|
108
|
+
type CompileFn = <T = Record<string, MessageDescriptor>>(
|
|
109
|
+
msgs: T
|
|
110
|
+
) => Record<string, string>;
|
|
111
|
+
\`\`\`
|
|
112
|
+
This is especially useful to convert from a TMS-specific format back to react-intl format
|
|
113
|
+
`)
|
|
114
|
+
.option('--out-file <path>', `Compiled translation output file.
|
|
115
|
+
If this is not provided, result will be printed to stdout`)
|
|
116
|
+
.option('--ast', `Whether to compile to AST. See https://formatjs.io/docs/guides/advanced-usage#pre-parsing-messages
|
|
117
|
+
for more information`)
|
|
118
|
+
.option('--skip-errors', `Whether to continue compiling messages after encountering an error. Any keys with errors will not be included in the output file.`)
|
|
119
|
+
.option('--pseudo-locale <pseudoLocale>', `Whether to generate pseudo-locale files. See https://formatjs.io/docs/tooling/cli#--pseudo-locale-pseudolocale for possible values.
|
|
120
|
+
"--ast" is required for this to work.`)
|
|
121
|
+
.action(async (filePatterns, opts) => {
|
|
122
|
+
(0, console_utils_1.debug)('File pattern:', filePatterns);
|
|
123
|
+
(0, console_utils_1.debug)('Options:', opts);
|
|
124
|
+
const files = (0, fast_glob_1.sync)(filePatterns);
|
|
125
|
+
if (!files.length) {
|
|
126
|
+
throw new Error(`No input file found with pattern ${filePatterns}`);
|
|
127
|
+
}
|
|
128
|
+
(0, console_utils_1.debug)('Files to compile:', files);
|
|
129
|
+
await (0, compile_1.default)(files, opts);
|
|
130
|
+
});
|
|
131
|
+
commander_1.program
|
|
132
|
+
.command('compile-folder <folder> <outFolder>')
|
|
133
|
+
.description(`Batch compile all extracted translation JSON files in <folder> to <outFolder> containing
|
|
134
|
+
react-intl consumable JSON. We also verify that the messages are
|
|
135
|
+
valid ICU and not malformed.`)
|
|
136
|
+
.option('--format <path>', `Path to a formatter file that converts JSON files in \`<folder>\` to \`Record<string, string>\`
|
|
137
|
+
so we can compile. The file must export a function named \`compile\` with the signature:
|
|
138
|
+
\`\`\`
|
|
139
|
+
type CompileFn = <T = Record<string, MessageDescriptor>>(
|
|
140
|
+
msgs: T
|
|
141
|
+
) => Record<string, string>;
|
|
142
|
+
\`\`\`
|
|
143
|
+
This is especially useful to convert from a TMS-specific format back to react-intl format
|
|
144
|
+
`)
|
|
145
|
+
.option('--ast', `Whether to compile to AST. See https://formatjs.io/docs/guides/advanced-usage#pre-parsing-messages
|
|
146
|
+
for more information`)
|
|
147
|
+
.action(async (folder, outFolder, opts) => {
|
|
148
|
+
(0, console_utils_1.debug)('Folder:', folder);
|
|
149
|
+
(0, console_utils_1.debug)('Options:', opts);
|
|
150
|
+
// fast-glob expect `/` in Windows as well
|
|
151
|
+
const files = (0, fast_glob_1.sync)(`${folder}/*.json`);
|
|
152
|
+
if (!files.length) {
|
|
153
|
+
throw new Error(`No JSON file found in ${folder}`);
|
|
154
|
+
}
|
|
155
|
+
(0, console_utils_1.debug)('Files to compile:', files);
|
|
156
|
+
await (0, compile_folder_1.default)(files, outFolder, opts);
|
|
140
157
|
});
|
|
158
|
+
if (argv.length < 3) {
|
|
159
|
+
commander_1.program.help();
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
commander_1.program.parse(argv);
|
|
163
|
+
}
|
|
141
164
|
}
|
|
142
165
|
exports.default = main;
|
package/src/compile.d.ts
CHANGED
|
File without changes
|
package/src/compile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["compile.ts"],"names":[],"mappings":"AAIA,OAAO,EAA0B,SAAS,EAAC,MAAM,cAAc,CAAA;AAS/D,oBAAY,SAAS,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE7D,oBAAY,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAA;AAE1E,MAAM,WAAW,cAAe,SAAQ,IAAI;IAC1C;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AACD,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAsB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,IAAI,GAAE,IAAS,mBAkElE;AAED;;;;;;GAMG;AACH,wBAA8B,eAAe,CAC3C,UAAU,EAAE,MAAM,EAAE,EACpB,WAAW,GAAE,cAAmB,iBAUjC"}
|