@formatjs/cli-lib 5.0.6 → 5.1.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 (54) hide show
  1. package/LICENSE.md +0 -0
  2. package/README.md +0 -0
  3. package/index.d.ts +0 -0
  4. package/index.d.ts.map +1 -1
  5. package/index.js +0 -0
  6. package/main.d.ts +0 -0
  7. package/main.d.ts.map +1 -1
  8. package/main.js +0 -0
  9. package/package.json +61 -61
  10. package/src/cli.d.ts +0 -0
  11. package/src/cli.d.ts.map +1 -1
  12. package/src/cli.js +159 -136
  13. package/src/compile.d.ts +0 -0
  14. package/src/compile.d.ts.map +1 -1
  15. package/src/compile.js +72 -97
  16. package/src/compile_folder.d.ts +0 -0
  17. package/src/compile_folder.d.ts.map +1 -1
  18. package/src/compile_folder.js +7 -18
  19. package/src/console_utils.d.ts +1 -0
  20. package/src/console_utils.d.ts.map +1 -1
  21. package/src/console_utils.js +42 -107
  22. package/src/extract.d.ts +0 -0
  23. package/src/extract.d.ts.map +1 -1
  24. package/src/extract.js +145 -188
  25. package/src/formatters/crowdin.d.ts +0 -0
  26. package/src/formatters/crowdin.d.ts.map +1 -1
  27. package/src/formatters/crowdin.js +6 -8
  28. package/src/formatters/default.d.ts +0 -0
  29. package/src/formatters/default.d.ts.map +1 -1
  30. package/src/formatters/default.js +4 -4
  31. package/src/formatters/index.d.ts +0 -0
  32. package/src/formatters/index.d.ts.map +1 -1
  33. package/src/formatters/index.js +36 -41
  34. package/src/formatters/lokalise.d.ts +0 -0
  35. package/src/formatters/lokalise.d.ts.map +1 -1
  36. package/src/formatters/lokalise.js +6 -8
  37. package/src/formatters/simple.d.ts +0 -0
  38. package/src/formatters/simple.d.ts.map +1 -1
  39. package/src/formatters/simple.js +3 -3
  40. package/src/formatters/smartling.d.ts +0 -0
  41. package/src/formatters/smartling.d.ts.map +1 -1
  42. package/src/formatters/smartling.js +7 -9
  43. package/src/formatters/transifex.d.ts +0 -0
  44. package/src/formatters/transifex.d.ts.map +1 -1
  45. package/src/formatters/transifex.js +6 -8
  46. package/src/parse_script.d.ts +0 -0
  47. package/src/parse_script.d.ts.map +1 -1
  48. package/src/parse_script.js +12 -11
  49. package/src/pseudo_locale.d.ts +0 -0
  50. package/src/pseudo_locale.d.ts.map +1 -1
  51. package/src/pseudo_locale.js +27 -31
  52. package/src/vue_extractor.d.ts +0 -0
  53. package/src/vue_extractor.d.ts.map +1 -1
  54. 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":["../../../../../packages/cli-lib/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"}
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":["../../../../../packages/cli-lib/main.ts"],"names":[],"mappings":""}
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
- "name": "@formatjs/cli-lib",
3
- "version": "5.0.6",
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"
2
+ "name": "@formatjs/cli-lib",
3
+ "version": "5.1.0",
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.7",
35
+ "@formatjs/ts-transformer": "3.10.0",
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.7"
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
- "bugs": {
31
- "url": "https://github.com/formatjs/formatjs/issues"
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":["../../../../../../packages/cli-lib/src/cli.ts"],"names":[],"mappings":"AAWA,iBAAe,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,iBAmOjC;AACD,eAAe,IAAI,CAAA"}
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
- var tslib_1 = require("tslib");
4
- var commander_1 = require("commander");
5
- var loud_rejection_1 = (0, tslib_1.__importDefault)(require("loud-rejection"));
6
- var extract_1 = (0, tslib_1.__importDefault)(require("./extract"));
7
- var compile_1 = (0, tslib_1.__importDefault)(require("./compile"));
8
- var compile_folder_1 = (0, tslib_1.__importDefault)(require("./compile_folder"));
9
- var fast_glob_1 = require("fast-glob");
10
- var console_utils_1 = require("./console_utils");
11
- var package_json_1 = require("../package.json");
12
- var KNOWN_COMMANDS = ['extract'];
13
- function main(argv) {
14
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
15
- var _this = this;
16
- return (0, tslib_1.__generator)(this, function (_a) {
17
- (0, loud_rejection_1.default)();
18
- commander_1.program
19
- .version(package_json_1.version, '-v, --version')
20
- .usage('<command> [flags]')
21
- .action(function (command) {
22
- if (!KNOWN_COMMANDS.includes(command)) {
23
- commander_1.program.help();
24
- }
25
- });
26
- commander_1.program
27
- .command('help', { isDefault: true })
28
- .description('Show this help message.')
29
- .action(function () { return commander_1.program.help(); });
30
- // Long text wrapping to available terminal columns: https://github.com/tj/commander.js/pull/956
31
- // NOTE: please keep the help text in sync with babel-plugin-formatjs documentation.
32
- commander_1.program
33
- .command('extract [files...]')
34
- .description("Extract string messages from React components that use react-intl.\nThe input language is expected to be TypeScript or ES2017 with JSX.")
35
- .option('--format <path>', "Path to a formatter file that controls the shape of JSON file from `--out-file`.\nThe formatter file must export a function called `format` with the signature\n```\ntype FormatFn = <T = Record<string, MessageDescriptor>>(\n msgs: Record<string, MessageDescriptor>\n) => T\n``` \nThis is especially useful to convert from our extracted format to a TMS-specific format.\n")
36
- .option('--out-file <path>', "The target file path where the plugin will output an aggregated \n`.json` file of all the translations from the `files` supplied.")
37
- .option('--id-interpolation-pattern <pattern>', "If certain message descriptors don't have id, this `pattern` will be used to automatically\ngenerate IDs for them. Default to `[sha512:contenthash:base64:6]` where `contenthash` is the hash of\n`defaultMessage` and `description`.\nSee https://github.com/webpack/loader-utils#interpolatename for sample patterns", '[sha512:contenthash:base64:6]')
38
- .option('--extract-source-location', "Whether the metadata about the location of the message in the source file should be \nextracted. If `true`, then `file`, `start`, and `end` fields will exist for each \nextracted message descriptors.", false)
39
- .option('--remove-default-message', 'Remove `defaultMessage` field in generated js after extraction', false)
40
- .option('--additional-component-names <comma-separated-names>', "Additional component names to extract messages from, e.g: `'FormattedFooBarMessage'`. \n**NOTE**: By default we check for the fact that `FormattedMessage` \nis imported from `moduleSourceName` to make sure variable alias \nworks. This option does not do that so it's less safe.", function (val) { return val.split(','); })
41
- .option('--additional-function-names <comma-separated-names>', "Additional function names to extract messages from, e.g: `'$t'`.", function (val) { return val.split(','); })
42
- .option('--ignore <files...>', 'List of glob paths to **not** extract translations from.')
43
- .option('--throws', 'Whether to throw an exception when we fail to process any file in the batch.')
44
- .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:\n\n ```\n // @intl-meta project:my-custom-project\n import {FormattedMessage} from 'react-intl';\n\n <FormattedMessage defaultMessage=\"foo\" id=\"bar\" />;\n ```\n\n 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.")
45
- .option('--preserve-whitespace', 'Whether to preserve whitespace and newlines.')
46
- .option('--flatten', "Whether to hoist selectors & flatten sentences as much as possible. E.g:\n\"I have {count, plural, one{a dog} other{many dogs}}\"\nbecomes \"{count, plural, one{I have a dog} other{I have many dogs}}\".\nThe goal is to provide as many full sentences as possible since fragmented\nsentences are not translator-friendly.")
47
- .action(function (filePatterns, cmdObj) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
48
- var files;
49
- return (0, tslib_1.__generator)(this, function (_a) {
50
- switch (_a.label) {
51
- case 0:
52
- (0, console_utils_1.debug)('File pattern:', filePatterns);
53
- (0, console_utils_1.debug)('Options:', cmdObj);
54
- files = (0, fast_glob_1.sync)(filePatterns, {
55
- ignore: cmdObj.ignore,
56
- });
57
- (0, console_utils_1.debug)('Files to extract:', files);
58
- return [4 /*yield*/, (0, extract_1.default)(files, {
59
- outFile: cmdObj.outFile,
60
- idInterpolationPattern: cmdObj.idInterpolationPattern || '[sha1:contenthash:base64:6]',
61
- extractSourceLocation: cmdObj.extractSourceLocation,
62
- removeDefaultMessage: cmdObj.removeDefaultMessage,
63
- additionalComponentNames: cmdObj.additionalComponentNames,
64
- additionalFunctionNames: cmdObj.additionalFunctionNames,
65
- throws: cmdObj.throws,
66
- pragma: cmdObj.pragma,
67
- format: cmdObj.format,
68
- // It is possible that the glob pattern does NOT match anything.
69
- // But so long as the glob pattern is provided, don't read from stdin.
70
- readFromStdin: filePatterns.length === 0,
71
- preserveWhitespace: cmdObj.preserveWhitespace,
72
- flatten: cmdObj.flatten,
73
- })];
74
- case 1:
75
- _a.sent();
76
- process.exit(0);
77
- return [2 /*return*/];
78
- }
79
- });
80
- }); });
81
- commander_1.program
82
- .command('compile [translation_files...]')
83
- .description("Compile extracted translation file into react-intl consumable JSON\nWe also verify that the messages are valid ICU and not malformed. \n<translation_files> can be a glob like \"foo/**/en.json\"")
84
- .option('--format <path>', "Path to a formatter file that converts `<translation_file>` 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")
85
- .option('--out-file <path>', "Compiled translation output file.\nIf this is not provided, result will be printed to stdout")
86
- .option('--ast', "Whether to compile to AST. See https://formatjs.io/docs/guides/advanced-usage#pre-parsing-messages\nfor more information")
87
- .option('--skip-errors', "Whether to continue compiling messages after encountering an error. Any keys with errors will not be included in the output file.")
88
- .option('--pseudo-locale <pseudoLocale>', "Whether to generate pseudo-locale files. See https://formatjs.io/docs/tooling/cli#--pseudo-locale-pseudolocale for possible values. \n\"--ast\" is required for this to work.")
89
- .action(function (filePatterns, opts) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
90
- var files;
91
- return (0, tslib_1.__generator)(this, function (_a) {
92
- switch (_a.label) {
93
- case 0:
94
- (0, console_utils_1.debug)('File pattern:', filePatterns);
95
- (0, console_utils_1.debug)('Options:', opts);
96
- files = (0, fast_glob_1.sync)(filePatterns);
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
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli-lib/src/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"}
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"}