@formatjs/cli-lib 8.1.0 → 8.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.
Files changed (40) hide show
  1. package/index.d.ts +7 -7
  2. package/index.js +2 -2
  3. package/main.d.ts +0 -1
  4. package/main.js +1 -1
  5. package/package.json +12 -12
  6. package/src/cli.js +99 -153
  7. package/src/compile.d.ts +45 -45
  8. package/src/compile.js +79 -80
  9. package/src/compile_folder.d.ts +1 -1
  10. package/src/compile_folder.js +6 -6
  11. package/src/console_utils.d.ts +1 -1
  12. package/src/console_utils.js +44 -46
  13. package/src/extract.d.ts +68 -68
  14. package/src/extract.js +165 -178
  15. package/src/formatters/crowdin.d.ts +3 -3
  16. package/src/formatters/crowdin.js +19 -20
  17. package/src/formatters/default.d.ts +1 -1
  18. package/src/formatters/default.js +8 -7
  19. package/src/formatters/index.d.ts +6 -6
  20. package/src/formatters/index.js +29 -34
  21. package/src/formatters/lokalise.d.ts +5 -5
  22. package/src/formatters/lokalise.js +16 -17
  23. package/src/formatters/simple.d.ts +1 -1
  24. package/src/formatters/simple.js +7 -6
  25. package/src/formatters/smartling.d.ts +13 -15
  26. package/src/formatters/smartling.js +35 -40
  27. package/src/formatters/transifex.d.ts +5 -5
  28. package/src/formatters/transifex.js +16 -17
  29. package/src/gts_extractor.js +11 -11
  30. package/src/hbs_extractor.js +34 -41
  31. package/src/parse_script.d.ts +5 -5
  32. package/src/parse_script.js +40 -43
  33. package/src/pseudo_locale.d.ts +15 -15
  34. package/src/pseudo_locale.js +210 -94
  35. package/src/verify/checkExtraKeys.js +28 -32
  36. package/src/verify/checkMissingKeys.js +29 -33
  37. package/src/verify/checkStructuralEquality.js +67 -71
  38. package/src/verify/index.d.ts +5 -5
  39. package/src/verify/index.js +24 -27
  40. package/src/vue_extractor.js +52 -62
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
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';
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 './src/extract.js';
2
- export { default as compileAndWrite, compile } from './src/compile.js';
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
@@ -1,2 +1 @@
1
- #!/usr/bin/env node
2
1
  export {};
package/main.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import cli from './src/cli.js';
2
+ import cli from "./src/cli.js";
3
3
  cli(process.argv);
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.1.0",
4
+ "version": "8.2.0",
5
5
  "license": "MIT",
6
6
  "author": "Linjie Ding <linjie@airtable.com>",
7
7
  "type": "module",
@@ -9,27 +9,27 @@
9
9
  "node": ">= 16"
10
10
  },
11
11
  "dependencies": {
12
- "@types/estree": "^1.0.6",
12
+ "@types/estree": "^1.0.8",
13
13
  "@types/fs-extra": "^11.0.4",
14
- "@types/node": "^22.0.0",
14
+ "@types/node": "^22.19.5",
15
15
  "chalk": "^4.1.2",
16
16
  "commander": "^14.0.0",
17
- "fast-glob": "^3.3.2",
18
- "fs-extra": "^11.2.0",
17
+ "fast-glob": "^3.3.3",
18
+ "fs-extra": "^11.3.3",
19
19
  "json-stable-stringify": "^1.3.0",
20
20
  "loud-rejection": "^2",
21
- "tslib": "^2.8.0",
21
+ "tslib": "^2.8.1",
22
22
  "typescript": "^5.6.0",
23
- "@formatjs/icu-messageformat-parser": "3.2.1",
24
- "@formatjs/ts-transformer": "4.1.0",
25
- "@formatjs/icu-skeleton-parser": "2.0.7"
23
+ "@formatjs/icu-messageformat-parser": "3.4.0",
24
+ "@formatjs/icu-skeleton-parser": "2.1.0",
25
+ "@formatjs/ts-transformer": "4.3.0"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@glimmer/syntax": "^0.95.0",
29
- "@vue/compiler-core": "^3.5.12",
30
- "content-tag": "4",
29
+ "@vue/compiler-core": "3.5.26",
30
+ "content-tag": "^4.1.0",
31
31
  "ember-template-recast": "^6.1.5",
32
- "vue": "^3.5.12"
32
+ "vue": "3.5.26"
33
33
  },
34
34
  "bugs": "https://github.com/formatjs/formatjs/issues",
35
35
  "homepage": "https://github.com/formatjs/formatjs",
package/src/cli.js CHANGED
@@ -1,36 +1,26 @@
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'];
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
- loudRejection();
14
- 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
- program.help();
21
- }
22
- });
23
- program
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
- .option('--in-file <path>', `The file containing list of files to extract from, separated by newlines. This is mainly
43
- to deal with the case where you have a large number of files to extract from and bash chokes.`)
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`, '[sha512:contenthash:base64:6]')
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
- .action(async (filePatterns, cmdObj) => {
77
- debug('File pattern:', filePatterns);
78
- debug('Options:', cmdObj);
79
- const files = [];
80
- if (filePatterns.length) {
81
- files.push(...globSync(filePatterns, {
82
- ignore: cmdObj.ignore,
83
- }));
84
- }
85
- if (cmdObj.inFile) {
86
- debug('Reading inFile:', cmdObj.inFile);
87
- const inFile = readFileSync(cmdObj.inFile, 'utf8');
88
- files.push(...inFile
89
- .split(/\n|\s+/)
90
- .filter(Boolean)
91
- .map(f => resolve(f)));
92
- }
93
- debug('Files to extract:', files);
94
- await extract(files, {
95
- outFile: cmdObj.outFile,
96
- idInterpolationPattern: cmdObj.idInterpolationPattern || '[sha1:contenthash:base64:6]',
97
- extractSourceLocation: cmdObj.extractSourceLocation,
98
- removeDefaultMessage: cmdObj.removeDefaultMessage,
99
- additionalComponentNames: cmdObj.additionalComponentNames,
100
- additionalFunctionNames: cmdObj.additionalFunctionNames,
101
- throws: cmdObj.throws,
102
- pragma: cmdObj.pragma,
103
- format: cmdObj.format,
104
- // It is possible that the glob pattern does NOT match anything.
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
- .option('--out-file <path>', `Compiled translation output file. If this is not provided, result will be printed to stdout`)
124
- .option('--ast', `Whether to compile to AST. See https://formatjs.github.io/docs/guides/advanced-usage#pre-parsing-messages for more information`)
125
- .option('--skip-errors', `Whether to continue compiling messages after encountering an error. Any keys with errors will not be included in the output file.`)
126
- .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.`)
127
- .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.`)
128
- .action(async (filePatterns, opts) => {
129
- debug('File pattern:', filePatterns);
130
- debug('Options:', opts);
131
- const files = globSync(filePatterns);
132
- if (!files.length) {
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
- .option('--ast', `Whether to compile to AST. See https://formatjs.github.io/docs/guides/advanced-usage#pre-parsing-messages for more information`)
150
- .action(async (folder, outFolder, opts) => {
151
- debug('Folder:', folder);
152
- debug('Options:', opts);
153
- // fast-glob expect `/` in Windows as well
154
- const files = globSync(`${folder}/*.json`);
155
- if (!files.length) {
156
- throw new Error(`No JSON file found in ${folder}`);
157
- }
158
- debug('Files to compile:', files);
159
- await compileFolder(files, outFolder, opts);
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
- .option('--ignore <files...>', 'List of glob paths to ignore')
168
- .option('--missing-keys', `Whether to check for missing keys in target locale compared to source locale.
169
- This basically guarantees that no messages are untranslated.`)
170
- .option('--extra-keys', `Whether to check that target locales don't have extra keys not present in the source locale.`)
171
- .option('--structural-equality', `Whether to check for structural equality of messages between source and target locale.
172
- This makes sure translations are formattable and are not missing any tokens.`)
173
- .action(async (filePatterns, opts) => {
174
- debug('File pattern:', filePatterns);
175
- debug('Options:', opts);
176
- const files = globSync(filePatterns, {
177
- ignore: opts.ignore,
178
- });
179
- if (!files.length) {
180
- throw new Error(`No input file found with pattern ${filePatterns}`);
181
- }
182
- debug('Files to verify:', files);
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 './formatters/index.js';
1
+ import { type Formatter } from "./formatters/index.js";
2
2
  export type CompileFn = (msgs: any) => Record<string, string>;
3
- export type PseudoLocale = 'xx-LS' | 'xx-AC' | 'xx-HA' | 'en-XA' | 'en-XB';
3
+ export type PseudoLocale = "xx-LS" | "xx-AC" | "xx-HA" | "en-XA" | "en-XB";
4
4
  export interface CompileCLIOpts extends Opts {
5
- /**
6
- * The target file that contains compiled messages.
7
- */
8
- outFile?: string;
5
+ /**
6
+ * The target file that contains compiled messages.
7
+ */
8
+ outFile?: string;
9
9
  }
10
10
  export interface Opts {
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;
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
- * 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
- */
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
- * 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
- */
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>;