@formatjs/cli-lib 8.0.8 → 8.1.1
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/index.d.ts +7 -7
- package/index.js +2 -2
- package/main.d.ts +0 -1
- package/main.js +1 -1
- package/package.json +5 -5
- package/src/cli.js +99 -153
- package/src/compile.d.ts +45 -45
- package/src/compile.js +79 -80
- package/src/compile_folder.d.ts +1 -1
- package/src/compile_folder.js +6 -6
- package/src/console_utils.d.ts +3 -1
- package/src/console_utils.js +44 -46
- package/src/extract.d.ts +68 -68
- package/src/extract.js +165 -182
- package/src/formatters/crowdin.d.ts +3 -3
- package/src/formatters/crowdin.js +19 -20
- package/src/formatters/default.d.ts +1 -1
- package/src/formatters/default.js +8 -7
- package/src/formatters/index.d.ts +6 -6
- package/src/formatters/index.js +29 -34
- package/src/formatters/lokalise.d.ts +5 -5
- package/src/formatters/lokalise.js +16 -17
- package/src/formatters/simple.d.ts +1 -1
- package/src/formatters/simple.js +7 -6
- package/src/formatters/smartling.d.ts +13 -15
- package/src/formatters/smartling.js +35 -40
- package/src/formatters/transifex.d.ts +5 -5
- package/src/formatters/transifex.js +16 -17
- package/src/gts_extractor.js +11 -11
- package/src/hbs_extractor.js +34 -41
- package/src/parse_script.d.ts +5 -5
- package/src/parse_script.js +40 -43
- package/src/pseudo_locale.d.ts +15 -15
- package/src/pseudo_locale.js +210 -94
- package/src/verify/checkExtraKeys.js +28 -32
- package/src/verify/checkMissingKeys.js +29 -33
- package/src/verify/checkStructuralEquality.js +67 -71
- package/src/verify/index.d.ts +5 -5
- package/src/verify/index.js +24 -27
- package/src/vue_extractor.js +52 -62
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { default as extractAndWrite, extract } from
|
|
2
|
-
export type { ExtractCLIOptions, ExtractOpts } from
|
|
3
|
-
export type { MessageDescriptor } from
|
|
4
|
-
export type { FormatFn, CompileFn } from
|
|
5
|
-
export type { Comparator } from
|
|
6
|
-
export { default as compileAndWrite, compile } from
|
|
7
|
-
export type { CompileCLIOpts, Opts as CompileOpts } from
|
|
1
|
+
export { default as extractAndWrite, extract } from "./src/extract.js";
|
|
2
|
+
export type { ExtractCLIOptions, ExtractOpts } from "./src/extract.js";
|
|
3
|
+
export type { MessageDescriptor } from "@formatjs/ts-transformer";
|
|
4
|
+
export type { FormatFn, CompileFn } from "./src/formatters/default.js";
|
|
5
|
+
export type { Comparator } from "json-stable-stringify";
|
|
6
|
+
export { default as compileAndWrite, compile } from "./src/compile.js";
|
|
7
|
+
export type { CompileCLIOpts, Opts as CompileOpts } from "./src/compile.js";
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as extractAndWrite, extract } from
|
|
2
|
-
export { default as compileAndWrite, compile } from
|
|
1
|
+
export { default as extractAndWrite, extract } from "./src/extract.js";
|
|
2
|
+
export { default as compileAndWrite, compile } from "./src/compile.js";
|
package/main.d.ts
CHANGED
package/main.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/cli-lib",
|
|
3
3
|
"description": "Lib for CLI for formatjs.",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.1.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Linjie Ding <linjie@airtable.com>",
|
|
7
7
|
"type": "module",
|
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
"@types/fs-extra": "^11.0.4",
|
|
14
14
|
"@types/node": "^22.0.0",
|
|
15
15
|
"chalk": "^4.1.2",
|
|
16
|
-
"commander": "^
|
|
16
|
+
"commander": "^14.0.0",
|
|
17
17
|
"fast-glob": "^3.3.2",
|
|
18
18
|
"fs-extra": "^11.2.0",
|
|
19
19
|
"json-stable-stringify": "^1.3.0",
|
|
20
20
|
"loud-rejection": "^2",
|
|
21
21
|
"tslib": "^2.8.0",
|
|
22
22
|
"typescript": "^5.6.0",
|
|
23
|
-
"@formatjs/icu-
|
|
24
|
-
"@formatjs/icu-
|
|
25
|
-
"@formatjs/ts-transformer": "4.0
|
|
23
|
+
"@formatjs/icu-messageformat-parser": "3.3.0",
|
|
24
|
+
"@formatjs/icu-skeleton-parser": "2.0.8",
|
|
25
|
+
"@formatjs/ts-transformer": "4.2.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@glimmer/syntax": "^0.95.0",
|
package/src/cli.js
CHANGED
|
@@ -1,36 +1,26 @@
|
|
|
1
|
-
import { program } from
|
|
2
|
-
import { sync as globSync } from
|
|
3
|
-
import loudRejection from
|
|
4
|
-
import compile from
|
|
5
|
-
import compileFolder from
|
|
6
|
-
import { debug } from
|
|
7
|
-
import extract from
|
|
8
|
-
import { verify } from
|
|
9
|
-
import { resolve } from
|
|
10
|
-
import { readFileSync } from
|
|
11
|
-
const KNOWN_COMMANDS = [
|
|
1
|
+
import { program } from "commander";
|
|
2
|
+
import { sync as globSync } from "fast-glob";
|
|
3
|
+
import loudRejection from "loud-rejection";
|
|
4
|
+
import compile from "./compile.js";
|
|
5
|
+
import compileFolder from "./compile_folder.js";
|
|
6
|
+
import { debug } from "./console_utils.js";
|
|
7
|
+
import extract from "./extract.js";
|
|
8
|
+
import { verify } from "./verify/index.js";
|
|
9
|
+
import { resolve } from "path";
|
|
10
|
+
import { readFileSync } from "fs";
|
|
11
|
+
const KNOWN_COMMANDS = ["extract"];
|
|
12
12
|
async function main(argv) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.command('help', { isDefault: true })
|
|
25
|
-
.description('Show this help message.')
|
|
26
|
-
.action(() => 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
|
-
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\`.
|
|
13
|
+
loudRejection();
|
|
14
|
+
program.version("5.0.6", "-v, --version").usage("<command> [flags]").action((command) => {
|
|
15
|
+
if (!KNOWN_COMMANDS.includes(command)) {
|
|
16
|
+
program.help();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
program.command("help", { isDefault: true }).description("Show this help message.").action(() => program.help());
|
|
20
|
+
// Long text wrapping to available terminal columns: https://github.com/tj/commander.js/pull/956
|
|
21
|
+
// NOTE: please keep the help text in sync with babel-plugin-formatjs documentation.
|
|
22
|
+
program.command("extract [files...]").description(`Extract string messages from React components that use react-intl.
|
|
23
|
+
The input language is expected to be TypeScript or ES2017 with JSX.`).option("--format <path>", `Path to a formatter file that controls the shape of JSON file from \`--out-file\`.
|
|
34
24
|
The formatter file must export a function called \`format\` with the signature
|
|
35
25
|
\`\`\`
|
|
36
26
|
type FormatFn = <T = Record<string, MessageDescriptor>>(
|
|
@@ -38,26 +28,17 @@ type FormatFn = <T = Record<string, MessageDescriptor>>(
|
|
|
38
28
|
) => T
|
|
39
29
|
\`\`\`
|
|
40
30
|
This is especially useful to convert from our extracted format to a TMS-specific format.
|
|
41
|
-
`)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.option('--out-file <path>', `The target file path where the plugin will output an aggregated
|
|
45
|
-
\`.json\` file of all the translations from the \`files\` supplied.`)
|
|
46
|
-
.option('--id-interpolation-pattern <pattern>', `If certain message descriptors don't have id, this \`pattern\` will be used to automatically
|
|
31
|
+
`).option("--in-file <path>", `The file containing list of files to extract from, separated by newlines. This is mainly
|
|
32
|
+
to deal with the case where you have a large number of files to extract from and bash chokes.`).option("--out-file <path>", `The target file path where the plugin will output an aggregated
|
|
33
|
+
\`.json\` file of all the translations from the \`files\` supplied.`).option("--id-interpolation-pattern <pattern>", `If certain message descriptors don't have id, this \`pattern\` will be used to automatically
|
|
47
34
|
generate IDs for them. Default to \`[sha512:contenthash:base64:6]\` where \`contenthash\` is the hash of
|
|
48
35
|
\`defaultMessage\` and \`description\`.
|
|
49
|
-
See https://github.com/webpack/loader-utils#interpolatename for sample patterns`,
|
|
50
|
-
.option('--extract-source-location', `Whether the metadata about the location of the message in the source file should be
|
|
36
|
+
See https://github.com/webpack/loader-utils#interpolatename for sample patterns`, "[sha512:contenthash:base64:6]").option("--extract-source-location", `Whether the metadata about the location of the message in the source file should be
|
|
51
37
|
extracted. If \`true\`, then \`file\`, \`start\`, and \`end\` fields will exist for each
|
|
52
|
-
extracted message descriptors.`, false)
|
|
53
|
-
.option('--additional-component-names <comma-separated-names>', `Additional component names to extract messages from, e.g: \`'FormattedFooBarMessage'\`.
|
|
38
|
+
extracted message descriptors.`, false).option("--additional-component-names <comma-separated-names>", `Additional component names to extract messages from, e.g: \`'FormattedFooBarMessage'\`.
|
|
54
39
|
**NOTE**: By default we check for the fact that \`FormattedMessage\`
|
|
55
40
|
is imported from \`moduleSourceName\` to make sure variable alias
|
|
56
|
-
works. This option does not do that so it's less safe.`, (val) => val.split(
|
|
57
|
-
.option('--additional-function-names <comma-separated-names>', `Additional function names to extract messages from, e.g: \`'$t'\`.`, (val) => val.split(','))
|
|
58
|
-
.option('--ignore <files...>', 'List of glob paths to **not** extract translations from.')
|
|
59
|
-
.option('--throws', 'Whether to throw an exception when we fail to process any file in the batch.')
|
|
60
|
-
.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:
|
|
41
|
+
works. This option does not do that so it's less safe.`, (val) => val.split(",")).option("--additional-function-names <comma-separated-names>", `Additional function names to extract messages from, e.g: \`'$t'\`.`, (val) => val.split(",")).option("--ignore <files...>", "List of glob paths to **not** extract translations from.").option("--throws", "Whether to throw an exception when we fail to process any file in the batch.").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:
|
|
61
42
|
|
|
62
43
|
\`\`\`
|
|
63
44
|
// @intl-meta project:my-custom-project
|
|
@@ -66,127 +47,92 @@ works. This option does not do that so it's less safe.`, (val) => val.split(',')
|
|
|
66
47
|
<FormattedMessage defaultMessage="foo" id="bar" />;
|
|
67
48
|
\`\`\`
|
|
68
49
|
|
|
69
|
-
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.`)
|
|
70
|
-
.option('--preserve-whitespace', 'Whether to preserve whitespace and newlines.')
|
|
71
|
-
.option('--flatten', `Whether to hoist selectors & flatten sentences as much as possible. E.g:
|
|
50
|
+
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.`).option("--preserve-whitespace", "Whether to preserve whitespace and newlines.").option("--flatten", `Whether to hoist selectors & flatten sentences as much as possible. E.g:
|
|
72
51
|
"I have {count, plural, one{a dog} other{many dogs}}"
|
|
73
52
|
becomes "{count, plural, one{I have a dog} other{I have many dogs}}".
|
|
74
53
|
The goal is to provide as many full sentences as possible since fragmented
|
|
75
|
-
sentences are not translator-friendly.`)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// But so long as the glob pattern is provided, don't read from stdin.
|
|
106
|
-
readFromStdin: files.length === 0,
|
|
107
|
-
preserveWhitespace: cmdObj.preserveWhitespace,
|
|
108
|
-
flatten: cmdObj.flatten,
|
|
109
|
-
});
|
|
110
|
-
process.exit(0);
|
|
111
|
-
});
|
|
112
|
-
program
|
|
113
|
-
.command('compile [translation_files...]')
|
|
114
|
-
.description(`Compile extracted translation file into react-intl consumable JSON We also verify that the messages are valid ICU and not malformed. <translation_files> can be a glob like "foo/**/en.json"`)
|
|
115
|
-
.option('--format <path>', `Path to a formatter file that converts \`<translation_file>\` to \`Record<string, string>\` so we can compile. The file must export a function named \`compile\` with the signature:
|
|
54
|
+
sentences are not translator-friendly.`).action(async (filePatterns, cmdObj) => {
|
|
55
|
+
debug("File pattern:", filePatterns);
|
|
56
|
+
debug("Options:", cmdObj);
|
|
57
|
+
const files = [];
|
|
58
|
+
if (filePatterns.length) {
|
|
59
|
+
files.push(...globSync(filePatterns, { ignore: cmdObj.ignore }));
|
|
60
|
+
}
|
|
61
|
+
if (cmdObj.inFile) {
|
|
62
|
+
debug("Reading inFile:", cmdObj.inFile);
|
|
63
|
+
const inFile = readFileSync(cmdObj.inFile, "utf8");
|
|
64
|
+
files.push(...inFile.split(/\n|\s+/).filter(Boolean).map((f) => resolve(f)));
|
|
65
|
+
}
|
|
66
|
+
debug("Files to extract:", files);
|
|
67
|
+
await extract(files, {
|
|
68
|
+
outFile: cmdObj.outFile,
|
|
69
|
+
idInterpolationPattern: cmdObj.idInterpolationPattern || "[sha1:contenthash:base64:6]",
|
|
70
|
+
extractSourceLocation: cmdObj.extractSourceLocation,
|
|
71
|
+
removeDefaultMessage: cmdObj.removeDefaultMessage,
|
|
72
|
+
additionalComponentNames: cmdObj.additionalComponentNames,
|
|
73
|
+
additionalFunctionNames: cmdObj.additionalFunctionNames,
|
|
74
|
+
throws: cmdObj.throws,
|
|
75
|
+
pragma: cmdObj.pragma,
|
|
76
|
+
format: cmdObj.format,
|
|
77
|
+
readFromStdin: files.length === 0,
|
|
78
|
+
preserveWhitespace: cmdObj.preserveWhitespace,
|
|
79
|
+
flatten: cmdObj.flatten
|
|
80
|
+
});
|
|
81
|
+
process.exit(0);
|
|
82
|
+
});
|
|
83
|
+
program.command("compile [translation_files...]").description(`Compile extracted translation file into react-intl consumable JSON We also verify that the messages are valid ICU and not malformed. <translation_files> can be a glob like "foo/**/en.json"`).option("--format <path>", `Path to a formatter file that converts \`<translation_file>\` to \`Record<string, string>\` so we can compile. The file must export a function named \`compile\` with the signature:
|
|
116
84
|
\`\`\`
|
|
117
85
|
type CompileFn = <T = Record<string, MessageDescriptor>>(
|
|
118
86
|
msgs: T
|
|
119
87
|
) => Record<string, string>;
|
|
120
88
|
\`\`\`
|
|
121
89
|
This is especially useful to convert from a TMS-specific format back to react-intl format
|
|
122
|
-
`)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
throw new Error(`No input file found with pattern ${filePatterns}`);
|
|
134
|
-
}
|
|
135
|
-
debug('Files to compile:', files);
|
|
136
|
-
await compile(files, opts);
|
|
137
|
-
});
|
|
138
|
-
program
|
|
139
|
-
.command('compile-folder <folder> <outFolder>')
|
|
140
|
-
.description(`Batch compile all extracted translation JSON files in <folder> to <outFolder> containing react-intl consumable JSON. We also verify that the messages are valid ICU and not malformed.`)
|
|
141
|
-
.option('--format <path>', `Path to a formatter file that converts JSON files in \`<folder>\` to \`Record<string, string>\` so we can compile. The file must export a function named \`compile\` with the signature:
|
|
90
|
+
`).option("--out-file <path>", `Compiled translation output file. If this is not provided, result will be printed to stdout`).option("--ast", `Whether to compile to AST. See https://formatjs.github.io/docs/guides/advanced-usage#pre-parsing-messages for more information`).option("--skip-errors", `Whether to continue compiling messages after encountering an error. Any keys with errors will not be included in the output file.`).option("--pseudo-locale <pseudoLocale>", `Whether to generate pseudo-locale files. See https://formatjs.github.io/docs/tooling/cli#--pseudo-locale-pseudolocale for possible values. "--ast" is required for this to work.`).option("--ignore-tag", `Whether the parser to treat HTML/XML tags as string literal instead of parsing them as tag token. When this is false we only allow simple tags without any attributes.`).action(async (filePatterns, opts) => {
|
|
91
|
+
debug("File pattern:", filePatterns);
|
|
92
|
+
debug("Options:", opts);
|
|
93
|
+
const files = globSync(filePatterns);
|
|
94
|
+
if (!files.length) {
|
|
95
|
+
throw new Error(`No input file found with pattern ${filePatterns}`);
|
|
96
|
+
}
|
|
97
|
+
debug("Files to compile:", files);
|
|
98
|
+
await compile(files, opts);
|
|
99
|
+
});
|
|
100
|
+
program.command("compile-folder <folder> <outFolder>").description(`Batch compile all extracted translation JSON files in <folder> to <outFolder> containing react-intl consumable JSON. We also verify that the messages are valid ICU and not malformed.`).option("--format <path>", `Path to a formatter file that converts JSON files in \`<folder>\` to \`Record<string, string>\` so we can compile. The file must export a function named \`compile\` with the signature:
|
|
142
101
|
\`\`\`
|
|
143
102
|
type CompileFn = <T = Record<string, MessageDescriptor>>(
|
|
144
103
|
msgs: T
|
|
145
104
|
) => Record<string, string>;
|
|
146
105
|
\`\`\`
|
|
147
106
|
This is especially useful to convert from a TMS-specific format back to react-intl format
|
|
148
|
-
`)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
});
|
|
161
|
-
program
|
|
162
|
-
.command('verify [translation_files...]')
|
|
163
|
-
.description(`Run a series of checks on a list of translation files. <translation_files> can be a glob like "foo/**/en.json"`)
|
|
164
|
-
.option('--source-locale <sourceLocale>', `The source locale of the translation files.
|
|
107
|
+
`).option("--ast", `Whether to compile to AST. See https://formatjs.github.io/docs/guides/advanced-usage#pre-parsing-messages for more information`).action(async (folder, outFolder, opts) => {
|
|
108
|
+
debug("Folder:", folder);
|
|
109
|
+
debug("Options:", opts);
|
|
110
|
+
// fast-glob expect `/` in Windows as well
|
|
111
|
+
const files = globSync(`${folder}/*.json`);
|
|
112
|
+
if (!files.length) {
|
|
113
|
+
throw new Error(`No JSON file found in ${folder}`);
|
|
114
|
+
}
|
|
115
|
+
debug("Files to compile:", files);
|
|
116
|
+
await compileFolder(files, outFolder, opts);
|
|
117
|
+
});
|
|
118
|
+
program.command("verify [translation_files...]").description(`Run a series of checks on a list of translation files. <translation_files> can be a glob like "foo/**/en.json"`).option("--source-locale <sourceLocale>", `The source locale of the translation files.
|
|
165
119
|
There must be a file named <sourceLocale>.json in the list of translation files.
|
|
166
|
-
This is used as source to verify other translations against.`)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
await verify(files, opts);
|
|
184
|
-
});
|
|
185
|
-
if (argv.length < 3) {
|
|
186
|
-
program.help();
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
program.parse(argv);
|
|
190
|
-
}
|
|
120
|
+
This is used as source to verify other translations against.`).option("--ignore <files...>", "List of glob paths to ignore").option("--missing-keys", `Whether to check for missing keys in target locale compared to source locale.
|
|
121
|
+
This basically guarantees that no messages are untranslated.`).option("--extra-keys", `Whether to check that target locales don't have extra keys not present in the source locale.`).option("--structural-equality", `Whether to check for structural equality of messages between source and target locale.
|
|
122
|
+
This makes sure translations are formattable and are not missing any tokens.`).action(async (filePatterns, opts) => {
|
|
123
|
+
debug("File pattern:", filePatterns);
|
|
124
|
+
debug("Options:", opts);
|
|
125
|
+
const files = globSync(filePatterns, { ignore: opts.ignore });
|
|
126
|
+
if (!files.length) {
|
|
127
|
+
throw new Error(`No input file found with pattern ${filePatterns}`);
|
|
128
|
+
}
|
|
129
|
+
debug("Files to verify:", files);
|
|
130
|
+
await verify(files, opts);
|
|
131
|
+
});
|
|
132
|
+
if (argv.length < 3) {
|
|
133
|
+
program.help();
|
|
134
|
+
} else {
|
|
135
|
+
program.parse(argv);
|
|
136
|
+
}
|
|
191
137
|
}
|
|
192
138
|
export default main;
|
package/src/compile.d.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { Formatter } from
|
|
1
|
+
import { type Formatter } from "./formatters/index.js";
|
|
2
2
|
export type CompileFn = (msgs: any) => Record<string, string>;
|
|
3
|
-
export type PseudoLocale =
|
|
3
|
+
export type PseudoLocale = "xx-LS" | "xx-AC" | "xx-HA" | "en-XA" | "en-XB";
|
|
4
4
|
export interface CompileCLIOpts extends Opts {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The target file that contains compiled messages.
|
|
7
|
+
*/
|
|
8
|
+
outFile?: string;
|
|
9
9
|
}
|
|
10
10
|
export interface Opts {
|
|
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
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Whether to compile message into AST instead of just string
|
|
13
|
+
*/
|
|
14
|
+
ast?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to continue compiling messages after encountering an error.
|
|
17
|
+
* Any keys with errors will not be included in the output file.
|
|
18
|
+
*/
|
|
19
|
+
skipErrors?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Path to a formatter file that converts <translation_files> to
|
|
22
|
+
* `Record<string, string>` so we can compile.
|
|
23
|
+
*/
|
|
24
|
+
format?: string | Formatter<unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to compile to pseudo locale
|
|
27
|
+
*/
|
|
28
|
+
pseudoLocale?: PseudoLocale;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the parser to treat HTML/XML tags as string literal
|
|
31
|
+
* instead of parsing them as tag token.
|
|
32
|
+
* When this is false we only allow simple tags without
|
|
33
|
+
* any attributes
|
|
34
|
+
*/
|
|
35
|
+
ignoreTag?: boolean;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
* Aggregate `inputFiles` into a single JSON blob and compile.
|
|
39
|
+
* Also checks for conflicting IDs.
|
|
40
|
+
* Then returns the serialized result as a `string` since key order
|
|
41
|
+
* makes a difference in some vendor.
|
|
42
|
+
* @param inputFiles Input files
|
|
43
|
+
* @param opts Options
|
|
44
|
+
* @returns serialized result in string format
|
|
45
|
+
*/
|
|
46
46
|
export declare function compile(inputFiles: string[], opts?: Opts): Promise<string>;
|
|
47
47
|
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
* Aggregate `inputFiles` into a single JSON blob and compile.
|
|
49
|
+
* Also checks for conflicting IDs and write output to `outFile`.
|
|
50
|
+
* @param inputFiles Input files
|
|
51
|
+
* @param compileOpts options
|
|
52
|
+
* @returns A `Promise` that resolves if file was written successfully
|
|
53
|
+
*/
|
|
54
54
|
export default function compileAndWrite(inputFiles: string[], compileOpts?: CompileCLIOpts): Promise<void>;
|