@formatjs/cli 4.3.1 → 4.5.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/package.json +4 -4
- package/src/cli.js +32 -32
- package/src/compile.js +24 -24
- package/src/compile_folder.js +5 -5
- package/src/console_utils.js +22 -22
- package/src/extract.js +40 -40
- package/src/formatters/index.js +10 -10
- package/src/parse_script.d.ts.map +1 -1
- package/src/parse_script.js +6 -4
- package/src/pseudo_locale.js +21 -21
- package/src/vue_extractor.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/cli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"description": "A CLI for formatjs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intl",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"url": "git+ssh://git@github.com/formatjs/formatjs.git"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@formatjs/icu-messageformat-parser": "2.0.
|
|
35
|
-
"@formatjs/ts-transformer": "3.
|
|
34
|
+
"@formatjs/icu-messageformat-parser": "2.0.16",
|
|
35
|
+
"@formatjs/ts-transformer": "3.8.0",
|
|
36
36
|
"@types/estree": "^0.0.50",
|
|
37
37
|
"@types/fs-extra": "^9.0.1",
|
|
38
38
|
"@types/json-stable-stringify": "^1.0.32",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"json-stable-stringify": "^1.0.1",
|
|
47
47
|
"loud-rejection": "^2.2.0",
|
|
48
48
|
"tslib": "^2.1.0",
|
|
49
|
-
"typescript": "^4.
|
|
49
|
+
"typescript": "^4.5"
|
|
50
50
|
},
|
|
51
51
|
"bugs": {
|
|
52
52
|
"url": "https://github.com/formatjs/formatjs/issues"
|
package/src/cli.js
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var commander_1 = require("commander");
|
|
5
|
-
var loud_rejection_1 = tslib_1.__importDefault(require("loud-rejection"));
|
|
6
|
-
var extract_1 = tslib_1.__importDefault(require("./extract"));
|
|
7
|
-
var compile_1 = tslib_1.__importDefault(require("./compile"));
|
|
8
|
-
var compile_folder_1 = tslib_1.__importDefault(require("./compile_folder"));
|
|
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
9
|
var fast_glob_1 = require("fast-glob");
|
|
10
10
|
var console_utils_1 = require("./console_utils");
|
|
11
11
|
var KNOWN_COMMANDS = ['extract'];
|
|
12
12
|
function main(argv) {
|
|
13
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
13
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
14
14
|
var version;
|
|
15
15
|
var _this = this;
|
|
16
|
-
return tslib_1.__generator(this, function (_a) {
|
|
17
|
-
loud_rejection_1.default();
|
|
16
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
17
|
+
(0, loud_rejection_1.default)();
|
|
18
18
|
version = require('../package.json').version;
|
|
19
19
|
commander_1.program
|
|
20
20
|
.version(version, '-v, --version')
|
|
@@ -38,29 +38,29 @@ function main(argv) {
|
|
|
38
38
|
.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]')
|
|
39
39
|
.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)
|
|
40
40
|
.option('--remove-default-message', 'Remove `defaultMessage` field in generated js after extraction', false)
|
|
41
|
-
.option('--additional-component-names <comma-separated-names>', "Additional component names to extract messages from, e.g: `
|
|
42
|
-
.option('--additional-function-names <comma-separated-names>', "Additional function names to extract messages from, e.g: `
|
|
41
|
+
.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(','); })
|
|
42
|
+
.option('--additional-function-names <comma-separated-names>', "Additional function names to extract messages from, e.g: `'$t'`.", function (val) { return val.split(','); })
|
|
43
43
|
.option('--ignore <files...>', 'List of glob paths to **not** extract translations from.')
|
|
44
44
|
.option('--throws', 'Whether to throw an exception when we fail to process any file in the batch.')
|
|
45
45
|
.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.")
|
|
46
46
|
.option('--preserve-whitespace', 'Whether to preserve whitespace and newlines.')
|
|
47
47
|
.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.")
|
|
48
|
-
.action(function (files, cmdObj) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
48
|
+
.action(function (files, cmdObj) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
49
49
|
var processedFiles, _i, files_1, f;
|
|
50
|
-
return tslib_1.__generator(this, function (_a) {
|
|
50
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
51
51
|
switch (_a.label) {
|
|
52
52
|
case 0:
|
|
53
|
-
console_utils_1.debug('File pattern:', files);
|
|
54
|
-
console_utils_1.debug('Options:', cmdObj);
|
|
53
|
+
(0, console_utils_1.debug)('File pattern:', files);
|
|
54
|
+
(0, console_utils_1.debug)('Options:', cmdObj);
|
|
55
55
|
processedFiles = [];
|
|
56
56
|
for (_i = 0, files_1 = files; _i < files_1.length; _i++) {
|
|
57
57
|
f = files_1[_i];
|
|
58
|
-
processedFiles.push.apply(processedFiles, fast_glob_1.sync(f, {
|
|
58
|
+
processedFiles.push.apply(processedFiles, (0, fast_glob_1.sync)(f, {
|
|
59
59
|
ignore: cmdObj.ignore,
|
|
60
60
|
}));
|
|
61
61
|
}
|
|
62
|
-
console_utils_1.debug('Files to extract:', files);
|
|
63
|
-
return [4 /*yield*/, extract_1.default(processedFiles, {
|
|
62
|
+
(0, console_utils_1.debug)('Files to extract:', files);
|
|
63
|
+
return [4 /*yield*/, (0, extract_1.default)(processedFiles, {
|
|
64
64
|
outFile: cmdObj.outFile,
|
|
65
65
|
idInterpolationPattern: cmdObj.idInterpolationPattern || '[sha1:contenthash:base64:6]',
|
|
66
66
|
extractSourceLocation: cmdObj.extractSourceLocation,
|
|
@@ -91,19 +91,19 @@ function main(argv) {
|
|
|
91
91
|
.option('--ast', "Whether to compile to AST. See https://formatjs.io/docs/guides/advanced-usage#pre-parsing-messages\nfor more information")
|
|
92
92
|
.option('--skip-errors', "Whether to continue compiling messages after encountering an error. Any keys with errors will not be included in the output file.")
|
|
93
93
|
.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.")
|
|
94
|
-
.action(function (filePattern, opts) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
94
|
+
.action(function (filePattern, opts) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
95
95
|
var files;
|
|
96
|
-
return tslib_1.__generator(this, function (_a) {
|
|
96
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
97
97
|
switch (_a.label) {
|
|
98
98
|
case 0:
|
|
99
|
-
console_utils_1.debug('File pattern:', filePattern);
|
|
100
|
-
console_utils_1.debug('Options:', opts);
|
|
101
|
-
files = fast_glob_1.sync(filePattern);
|
|
99
|
+
(0, console_utils_1.debug)('File pattern:', filePattern);
|
|
100
|
+
(0, console_utils_1.debug)('Options:', opts);
|
|
101
|
+
files = (0, fast_glob_1.sync)(filePattern);
|
|
102
102
|
if (!files.length) {
|
|
103
|
-
throw new Error("No input file found with pattern "
|
|
103
|
+
throw new Error("No input file found with pattern ".concat(filePattern));
|
|
104
104
|
}
|
|
105
|
-
console_utils_1.debug('Files to compile:', files);
|
|
106
|
-
return [4 /*yield*/, compile_1.default(files, opts)];
|
|
105
|
+
(0, console_utils_1.debug)('Files to compile:', files);
|
|
106
|
+
return [4 /*yield*/, (0, compile_1.default)(files, opts)];
|
|
107
107
|
case 1:
|
|
108
108
|
_a.sent();
|
|
109
109
|
return [2 /*return*/];
|
|
@@ -115,19 +115,19 @@ function main(argv) {
|
|
|
115
115
|
.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.")
|
|
116
116
|
.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")
|
|
117
117
|
.option('--ast', "Whether to compile to AST. See https://formatjs.io/docs/guides/advanced-usage#pre-parsing-messages\nfor more information")
|
|
118
|
-
.action(function (folder, outFolder, opts) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
118
|
+
.action(function (folder, outFolder, opts) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
119
119
|
var files;
|
|
120
|
-
return tslib_1.__generator(this, function (_a) {
|
|
120
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
121
121
|
switch (_a.label) {
|
|
122
122
|
case 0:
|
|
123
|
-
console_utils_1.debug('Folder:', folder);
|
|
124
|
-
console_utils_1.debug('Options:', opts);
|
|
125
|
-
files = fast_glob_1.sync(folder
|
|
123
|
+
(0, console_utils_1.debug)('Folder:', folder);
|
|
124
|
+
(0, console_utils_1.debug)('Options:', opts);
|
|
125
|
+
files = (0, fast_glob_1.sync)("".concat(folder, "/*.json"));
|
|
126
126
|
if (!files.length) {
|
|
127
|
-
throw new Error("No JSON file found in "
|
|
127
|
+
throw new Error("No JSON file found in ".concat(folder));
|
|
128
128
|
}
|
|
129
|
-
console_utils_1.debug('Files to compile:', files);
|
|
130
|
-
return [4 /*yield*/, compile_folder_1.default(files, outFolder, opts)];
|
|
129
|
+
(0, console_utils_1.debug)('Files to compile:', files);
|
|
130
|
+
return [4 /*yield*/, (0, compile_folder_1.default)(files, outFolder, opts)];
|
|
131
131
|
case 1:
|
|
132
132
|
_a.sent();
|
|
133
133
|
return [2 /*return*/];
|
package/src/compile.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.compile = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
|
|
6
6
|
var fs_extra_1 = require("fs-extra");
|
|
7
|
-
var json_stable_stringify_1 = tslib_1.__importDefault(require("json-stable-stringify"));
|
|
7
|
+
var json_stable_stringify_1 = (0, tslib_1.__importDefault)(require("json-stable-stringify"));
|
|
8
8
|
var console_utils_1 = require("./console_utils");
|
|
9
9
|
var formatters_1 = require("./formatters");
|
|
10
10
|
var pseudo_locale_1 = require("./pseudo_locale");
|
|
@@ -19,49 +19,49 @@ var pseudo_locale_1 = require("./pseudo_locale");
|
|
|
19
19
|
*/
|
|
20
20
|
function compile(inputFiles, opts) {
|
|
21
21
|
if (opts === void 0) { opts = {}; }
|
|
22
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
22
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
23
23
|
var ast, format, pseudoLocale, skipErrors, formatter, messages, messageAsts, idsWithFileName, compiledFiles, i, inputFile, compiled, id, msgAst;
|
|
24
|
-
return tslib_1.__generator(this, function (_a) {
|
|
24
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
25
25
|
switch (_a.label) {
|
|
26
26
|
case 0:
|
|
27
|
-
console_utils_1.debug('Compiling files:', inputFiles);
|
|
27
|
+
(0, console_utils_1.debug)('Compiling files:', inputFiles);
|
|
28
28
|
ast = opts.ast, format = opts.format, pseudoLocale = opts.pseudoLocale, skipErrors = opts.skipErrors;
|
|
29
|
-
return [4 /*yield*/, formatters_1.resolveBuiltinFormatter(format)];
|
|
29
|
+
return [4 /*yield*/, (0, formatters_1.resolveBuiltinFormatter)(format)];
|
|
30
30
|
case 1:
|
|
31
31
|
formatter = _a.sent();
|
|
32
32
|
messages = {};
|
|
33
33
|
messageAsts = {};
|
|
34
34
|
idsWithFileName = {};
|
|
35
|
-
return [4 /*yield*/, Promise.all(inputFiles.map(function (f) { return fs_extra_1.readJSON(f).then(formatter.compile); }))];
|
|
35
|
+
return [4 /*yield*/, Promise.all(inputFiles.map(function (f) { return (0, fs_extra_1.readJSON)(f).then(formatter.compile); }))];
|
|
36
36
|
case 2:
|
|
37
37
|
compiledFiles = _a.sent();
|
|
38
|
-
console_utils_1.debug('Compiled files:', compiledFiles);
|
|
38
|
+
(0, console_utils_1.debug)('Compiled files:', compiledFiles);
|
|
39
39
|
for (i = 0; i < inputFiles.length; i++) {
|
|
40
40
|
inputFile = inputFiles[i];
|
|
41
|
-
console_utils_1.debug('Processing file:', inputFile);
|
|
41
|
+
(0, console_utils_1.debug)('Processing file:', inputFile);
|
|
42
42
|
compiled = compiledFiles[i];
|
|
43
43
|
for (id in compiled) {
|
|
44
44
|
if (messages[id] && messages[id] !== compiled[id]) {
|
|
45
|
-
throw new Error("Conflicting ID \""
|
|
45
|
+
throw new Error("Conflicting ID \"".concat(id, "\" with different translation found in these 2 files:\nID: ").concat(id, "\nMessage from ").concat(idsWithFileName[id], ": ").concat(messages[id], "\nMessage from ").concat(compiled[id], ": ").concat(inputFile, "\n"));
|
|
46
46
|
}
|
|
47
47
|
try {
|
|
48
|
-
msgAst = icu_messageformat_parser_1.parse(compiled[id]);
|
|
48
|
+
msgAst = (0, icu_messageformat_parser_1.parse)(compiled[id]);
|
|
49
49
|
messages[id] = compiled[id];
|
|
50
50
|
switch (pseudoLocale) {
|
|
51
51
|
case 'xx-LS':
|
|
52
|
-
messageAsts[id] = pseudo_locale_1.generateXXLS(msgAst);
|
|
52
|
+
messageAsts[id] = (0, pseudo_locale_1.generateXXLS)(msgAst);
|
|
53
53
|
break;
|
|
54
54
|
case 'xx-AC':
|
|
55
|
-
messageAsts[id] = pseudo_locale_1.generateXXAC(msgAst);
|
|
55
|
+
messageAsts[id] = (0, pseudo_locale_1.generateXXAC)(msgAst);
|
|
56
56
|
break;
|
|
57
57
|
case 'xx-HA':
|
|
58
|
-
messageAsts[id] = pseudo_locale_1.generateXXHA(msgAst);
|
|
58
|
+
messageAsts[id] = (0, pseudo_locale_1.generateXXHA)(msgAst);
|
|
59
59
|
break;
|
|
60
60
|
case 'en-XA':
|
|
61
|
-
messageAsts[id] = pseudo_locale_1.generateENXA(msgAst);
|
|
61
|
+
messageAsts[id] = (0, pseudo_locale_1.generateENXA)(msgAst);
|
|
62
62
|
break;
|
|
63
63
|
case 'en-XB':
|
|
64
|
-
messageAsts[id] = pseudo_locale_1.generateENXB(msgAst);
|
|
64
|
+
messageAsts[id] = (0, pseudo_locale_1.generateENXB)(msgAst);
|
|
65
65
|
break;
|
|
66
66
|
default:
|
|
67
67
|
messageAsts[id] = msgAst;
|
|
@@ -70,14 +70,14 @@ function compile(inputFiles, opts) {
|
|
|
70
70
|
idsWithFileName[id] = inputFile;
|
|
71
71
|
}
|
|
72
72
|
catch (e) {
|
|
73
|
-
console_utils_1.warn('Error validating message "%s" with ID "%s" in file "%s"', compiled[id], id, inputFile);
|
|
73
|
+
(0, console_utils_1.warn)('Error validating message "%s" with ID "%s" in file "%s"', compiled[id], id, inputFile);
|
|
74
74
|
if (!skipErrors) {
|
|
75
75
|
throw e;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
return [2 /*return*/, json_stable_stringify_1.default(ast ? messageAsts : messages, {
|
|
80
|
+
return [2 /*return*/, (0, json_stable_stringify_1.default)(ast ? messageAsts : messages, {
|
|
81
81
|
space: 2,
|
|
82
82
|
cmp: formatter.compareMessages || undefined,
|
|
83
83
|
})];
|
|
@@ -95,23 +95,23 @@ exports.compile = compile;
|
|
|
95
95
|
*/
|
|
96
96
|
function compileAndWrite(inputFiles, compileOpts) {
|
|
97
97
|
if (compileOpts === void 0) { compileOpts = {}; }
|
|
98
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
98
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
99
99
|
var outFile, opts, serializedResult;
|
|
100
|
-
return tslib_1.__generator(this, function (_a) {
|
|
100
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
101
101
|
switch (_a.label) {
|
|
102
102
|
case 0:
|
|
103
|
-
outFile = compileOpts.outFile, opts = tslib_1.__rest(compileOpts, ["outFile"]);
|
|
103
|
+
outFile = compileOpts.outFile, opts = (0, tslib_1.__rest)(compileOpts, ["outFile"]);
|
|
104
104
|
return [4 /*yield*/, compile(inputFiles, opts)];
|
|
105
105
|
case 1:
|
|
106
106
|
serializedResult = _a.sent();
|
|
107
107
|
if (outFile) {
|
|
108
|
-
console_utils_1.debug('Writing output file:', outFile);
|
|
109
|
-
return [2 /*return*/, fs_extra_1.outputFile(outFile, serializedResult)];
|
|
108
|
+
(0, console_utils_1.debug)('Writing output file:', outFile);
|
|
109
|
+
return [2 /*return*/, (0, fs_extra_1.outputFile)(outFile, serializedResult)];
|
|
110
110
|
}
|
|
111
|
-
return [4 /*yield*/, console_utils_1.writeStdout(serializedResult)];
|
|
111
|
+
return [4 /*yield*/, (0, console_utils_1.writeStdout)(serializedResult)];
|
|
112
112
|
case 2:
|
|
113
113
|
_a.sent();
|
|
114
|
-
return [4 /*yield*/, console_utils_1.writeStdout('\n')];
|
|
114
|
+
return [4 /*yield*/, (0, console_utils_1.writeStdout)('\n')];
|
|
115
115
|
case 3:
|
|
116
116
|
_a.sent();
|
|
117
117
|
return [2 /*return*/];
|
package/src/compile_folder.js
CHANGED
|
@@ -6,15 +6,15 @@ var path_1 = require("path");
|
|
|
6
6
|
var fs_extra_1 = require("fs-extra");
|
|
7
7
|
function compileFolder(files, outFolder, opts) {
|
|
8
8
|
if (opts === void 0) { opts = {}; }
|
|
9
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
9
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
10
10
|
var results, outFiles;
|
|
11
|
-
return tslib_1.__generator(this, function (_a) {
|
|
11
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
12
12
|
switch (_a.label) {
|
|
13
|
-
case 0: return [4 /*yield*/, Promise.all(files.map(function (f) { return compile_1.compile([f], opts); }))];
|
|
13
|
+
case 0: return [4 /*yield*/, Promise.all(files.map(function (f) { return (0, compile_1.compile)([f], opts); }))];
|
|
14
14
|
case 1:
|
|
15
15
|
results = _a.sent();
|
|
16
|
-
outFiles = files.map(function (f) { return path_1.join(outFolder, path_1.basename(f)); });
|
|
17
|
-
return [2 /*return*/, Promise.all(outFiles.map(function (outFile, i) { return fs_extra_1.outputFile(outFile, results[i]); }))];
|
|
16
|
+
outFiles = files.map(function (f) { return (0, path_1.join)(outFolder, (0, path_1.basename)(f)); });
|
|
17
|
+
return [2 /*return*/, Promise.all(outFiles.map(function (outFile, i) { return (0, fs_extra_1.outputFile)(outFile, results[i]); }))];
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
});
|
package/src/console_utils.js
CHANGED
|
@@ -3,28 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getStdinAsString = exports.error = exports.warn = exports.debug = exports.clearLine = exports.writeStdout = exports.writeStderr = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var chalk_1 = require("chalk");
|
|
6
|
-
var readline_1 = tslib_1.__importDefault(require("readline"));
|
|
6
|
+
var readline_1 = (0, tslib_1.__importDefault)(require("readline"));
|
|
7
7
|
var util_1 = require("util");
|
|
8
8
|
var CLEAR_WHOLE_LINE = 0;
|
|
9
|
-
exports.writeStderr = util_1.promisify(process.stderr.write).bind(process.stderr);
|
|
10
|
-
exports.writeStdout = util_1.promisify(process.stdout.write).bind(process.stdout);
|
|
11
|
-
var nativeClearLine = util_1.promisify(readline_1.default.clearLine).bind(readline_1.default);
|
|
12
|
-
var nativeCursorTo = util_1.promisify(readline_1.default.cursorTo).bind(readline_1.default);
|
|
9
|
+
exports.writeStderr = (0, util_1.promisify)(process.stderr.write).bind(process.stderr);
|
|
10
|
+
exports.writeStdout = (0, util_1.promisify)(process.stdout.write).bind(process.stdout);
|
|
11
|
+
var nativeClearLine = (0, util_1.promisify)(readline_1.default.clearLine).bind(readline_1.default);
|
|
12
|
+
var nativeCursorTo = (0, util_1.promisify)(readline_1.default.cursorTo).bind(readline_1.default);
|
|
13
13
|
// From:
|
|
14
14
|
// https://github.com/yarnpkg/yarn/blob/53d8004229f543f342833310d5af63a4b6e59c8a/src/reporters/console/util.js
|
|
15
15
|
function clearLine(terminal) {
|
|
16
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
17
|
-
return tslib_1.__generator(this, function (_a) {
|
|
16
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
17
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
18
18
|
switch (_a.label) {
|
|
19
19
|
case 0:
|
|
20
20
|
if (!!chalk_1.supportsColor) return [3 /*break*/, 5];
|
|
21
21
|
if (!terminal.isTTY) return [3 /*break*/, 4];
|
|
22
22
|
if (!(terminal.columns > 0)) return [3 /*break*/, 2];
|
|
23
|
-
return [4 /*yield*/, exports.writeStderr("\r"
|
|
23
|
+
return [4 /*yield*/, (0, exports.writeStderr)("\r".concat(' '.repeat(terminal.columns - 1)))];
|
|
24
24
|
case 1:
|
|
25
25
|
_a.sent();
|
|
26
26
|
_a.label = 2;
|
|
27
|
-
case 2: return [4 /*yield*/, exports.writeStderr("\r")];
|
|
27
|
+
case 2: return [4 /*yield*/, (0, exports.writeStderr)("\r")];
|
|
28
28
|
case 3:
|
|
29
29
|
_a.sent();
|
|
30
30
|
_a.label = 4;
|
|
@@ -48,15 +48,15 @@ var LEVEL_COLORS = {
|
|
|
48
48
|
error: chalk_1.red,
|
|
49
49
|
};
|
|
50
50
|
function label(level, message) {
|
|
51
|
-
return "[@formatjs/cli] ["
|
|
51
|
+
return "[@formatjs/cli] [".concat(LEVEL_COLORS[level](level.toUpperCase()), "] ").concat(message);
|
|
52
52
|
}
|
|
53
53
|
function debug(message) {
|
|
54
54
|
var args = [];
|
|
55
55
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
56
56
|
args[_i - 1] = arguments[_i];
|
|
57
57
|
}
|
|
58
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
59
|
-
return tslib_1.__generator(this, function (_a) {
|
|
58
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
59
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
60
60
|
switch (_a.label) {
|
|
61
61
|
case 0:
|
|
62
62
|
if (process.env.LOG_LEVEL !== 'debug') {
|
|
@@ -65,10 +65,10 @@ function debug(message) {
|
|
|
65
65
|
return [4 /*yield*/, clearLine(process.stderr)];
|
|
66
66
|
case 1:
|
|
67
67
|
_a.sent();
|
|
68
|
-
return [4 /*yield*/, exports.writeStderr(util_1.format.apply(void 0, tslib_1.__spreadArray([label('debug', message)], args)))];
|
|
68
|
+
return [4 /*yield*/, (0, exports.writeStderr)(util_1.format.apply(void 0, (0, tslib_1.__spreadArray)([label('debug', message)], args, false)))];
|
|
69
69
|
case 2:
|
|
70
70
|
_a.sent();
|
|
71
|
-
return [4 /*yield*/, exports.writeStderr('\n')];
|
|
71
|
+
return [4 /*yield*/, (0, exports.writeStderr)('\n')];
|
|
72
72
|
case 3:
|
|
73
73
|
_a.sent();
|
|
74
74
|
return [2 /*return*/];
|
|
@@ -82,16 +82,16 @@ function warn(message) {
|
|
|
82
82
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
83
83
|
args[_i - 1] = arguments[_i];
|
|
84
84
|
}
|
|
85
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
86
|
-
return tslib_1.__generator(this, function (_a) {
|
|
85
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
86
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
87
87
|
switch (_a.label) {
|
|
88
88
|
case 0: return [4 /*yield*/, clearLine(process.stderr)];
|
|
89
89
|
case 1:
|
|
90
90
|
_a.sent();
|
|
91
|
-
return [4 /*yield*/, exports.writeStderr(util_1.format.apply(void 0, tslib_1.__spreadArray([label('warn', message)], args)))];
|
|
91
|
+
return [4 /*yield*/, (0, exports.writeStderr)(util_1.format.apply(void 0, (0, tslib_1.__spreadArray)([label('warn', message)], args, false)))];
|
|
92
92
|
case 2:
|
|
93
93
|
_a.sent();
|
|
94
|
-
return [4 /*yield*/, exports.writeStderr('\n')];
|
|
94
|
+
return [4 /*yield*/, (0, exports.writeStderr)('\n')];
|
|
95
95
|
case 3:
|
|
96
96
|
_a.sent();
|
|
97
97
|
return [2 /*return*/];
|
|
@@ -105,16 +105,16 @@ function error(message) {
|
|
|
105
105
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
106
106
|
args[_i - 1] = arguments[_i];
|
|
107
107
|
}
|
|
108
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
109
|
-
return tslib_1.__generator(this, function (_a) {
|
|
108
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
109
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
110
110
|
switch (_a.label) {
|
|
111
111
|
case 0: return [4 /*yield*/, clearLine(process.stderr)];
|
|
112
112
|
case 1:
|
|
113
113
|
_a.sent();
|
|
114
|
-
return [4 /*yield*/, exports.writeStderr(util_1.format.apply(void 0, tslib_1.__spreadArray([label('error', message)], args)))];
|
|
114
|
+
return [4 /*yield*/, (0, exports.writeStderr)(util_1.format.apply(void 0, (0, tslib_1.__spreadArray)([label('error', message)], args, false)))];
|
|
115
115
|
case 2:
|
|
116
116
|
_a.sent();
|
|
117
|
-
return [4 /*yield*/, exports.writeStderr('\n')];
|
|
117
|
+
return [4 /*yield*/, (0, exports.writeStderr)('\n')];
|
|
118
118
|
case 3:
|
|
119
119
|
_a.sent();
|
|
120
120
|
return [2 /*return*/];
|
package/src/extract.js
CHANGED
|
@@ -6,7 +6,7 @@ var console_utils_1 = require("./console_utils");
|
|
|
6
6
|
var fs_extra_1 = require("fs-extra");
|
|
7
7
|
var ts_transformer_1 = require("@formatjs/ts-transformer");
|
|
8
8
|
var formatters_1 = require("./formatters");
|
|
9
|
-
var json_stable_stringify_1 = tslib_1.__importDefault(require("json-stable-stringify"));
|
|
9
|
+
var json_stable_stringify_1 = (0, tslib_1.__importDefault)(require("json-stable-stringify"));
|
|
10
10
|
var vue_extractor_1 = require("./vue_extractor");
|
|
11
11
|
var parse_script_1 = require("./parse_script");
|
|
12
12
|
var printer_1 = require("@formatjs/icu-messageformat-parser/printer");
|
|
@@ -22,44 +22,44 @@ function calculateLineColFromOffset(text, start) {
|
|
|
22
22
|
return { line: lines.length, col: lastLine.length };
|
|
23
23
|
}
|
|
24
24
|
function processFile(source, fn, _a) {
|
|
25
|
-
var idInterpolationPattern = _a.idInterpolationPattern, opts = tslib_1.__rest(_a, ["idInterpolationPattern"]);
|
|
25
|
+
var idInterpolationPattern = _a.idInterpolationPattern, opts = (0, tslib_1.__rest)(_a, ["idInterpolationPattern"]);
|
|
26
26
|
var messages = [];
|
|
27
27
|
var meta;
|
|
28
|
-
opts = tslib_1.__assign(tslib_1.__assign({}, opts), { additionalComponentNames: tslib_1.__spreadArray([
|
|
28
|
+
opts = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, opts), { additionalComponentNames: (0, tslib_1.__spreadArray)([
|
|
29
29
|
'$formatMessage'
|
|
30
|
-
], (opts.additionalComponentNames || [])), onMsgExtracted: function (_, msgs) {
|
|
30
|
+
], (opts.additionalComponentNames || []), true), onMsgExtracted: function (_, msgs) {
|
|
31
31
|
if (opts.extractSourceLocation) {
|
|
32
|
-
msgs = msgs.map(function (msg) { return (tslib_1.__assign(tslib_1.__assign({}, msg), calculateLineColFromOffset(source, msg.start))); });
|
|
32
|
+
msgs = msgs.map(function (msg) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, msg), calculateLineColFromOffset(source, msg.start))); });
|
|
33
33
|
}
|
|
34
34
|
messages = messages.concat(msgs);
|
|
35
35
|
}, onMetaExtracted: function (_, m) {
|
|
36
36
|
meta = m;
|
|
37
37
|
} });
|
|
38
38
|
if (!opts.overrideIdFn && idInterpolationPattern) {
|
|
39
|
-
opts = tslib_1.__assign(tslib_1.__assign({}, opts), { overrideIdFn: function (id, defaultMessage, description, fileName) {
|
|
39
|
+
opts = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, opts), { overrideIdFn: function (id, defaultMessage, description, fileName) {
|
|
40
40
|
return id ||
|
|
41
|
-
ts_transformer_1.interpolateName({
|
|
41
|
+
(0, ts_transformer_1.interpolateName)({
|
|
42
42
|
resourcePath: fileName,
|
|
43
43
|
}, idInterpolationPattern, {
|
|
44
44
|
content: description
|
|
45
|
-
? defaultMessage
|
|
45
|
+
? "".concat(defaultMessage, "#").concat(description)
|
|
46
46
|
: defaultMessage,
|
|
47
47
|
});
|
|
48
48
|
} });
|
|
49
49
|
}
|
|
50
|
-
console_utils_1.debug('Processing opts for %s: %s', fn, opts);
|
|
51
|
-
var scriptParseFn = parse_script_1.parseScript(opts, fn);
|
|
50
|
+
(0, console_utils_1.debug)('Processing opts for %s: %s', fn, opts);
|
|
51
|
+
var scriptParseFn = (0, parse_script_1.parseScript)(opts, fn);
|
|
52
52
|
if (fn.endsWith('.vue')) {
|
|
53
|
-
console_utils_1.debug('Processing %s using vue extractor', fn);
|
|
54
|
-
vue_extractor_1.parseFile(source, fn, scriptParseFn);
|
|
53
|
+
(0, console_utils_1.debug)('Processing %s using vue extractor', fn);
|
|
54
|
+
(0, vue_extractor_1.parseFile)(source, fn, scriptParseFn);
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
|
-
console_utils_1.debug('Processing %s using typescript extractor', fn);
|
|
57
|
+
(0, console_utils_1.debug)('Processing %s using typescript extractor', fn);
|
|
58
58
|
scriptParseFn(source);
|
|
59
59
|
}
|
|
60
|
-
console_utils_1.debug('Done extracting %s messages: %s', fn, messages);
|
|
60
|
+
(0, console_utils_1.debug)('Done extracting %s messages: %s', fn, messages);
|
|
61
61
|
if (meta) {
|
|
62
|
-
console_utils_1.debug('Extracted meta:', meta);
|
|
62
|
+
(0, console_utils_1.debug)('Extracted meta:', meta);
|
|
63
63
|
messages.forEach(function (m) { return (m.meta = meta); });
|
|
64
64
|
}
|
|
65
65
|
return { messages: messages, meta: meta };
|
|
@@ -72,34 +72,34 @@ function processFile(source, fn, _a) {
|
|
|
72
72
|
* matters for some `format`
|
|
73
73
|
*/
|
|
74
74
|
function extract(files, extractOpts) {
|
|
75
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
75
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
76
76
|
var throws, readFromStdin, flatten, opts, rawResults, stdinSource, formatter, extractionResults, extractedMessages, _i, extractionResults_1, messages_3, _a, messages_1, message, id, description, defaultMessage, error, existing, error, results, messages, _b, messages_2, _c, id, msg;
|
|
77
77
|
var _this = this;
|
|
78
|
-
return tslib_1.__generator(this, function (_d) {
|
|
78
|
+
return (0, tslib_1.__generator)(this, function (_d) {
|
|
79
79
|
switch (_d.label) {
|
|
80
80
|
case 0:
|
|
81
|
-
throws = extractOpts.throws, readFromStdin = extractOpts.readFromStdin, flatten = extractOpts.flatten, opts = tslib_1.__rest(extractOpts, ["throws", "readFromStdin", "flatten"]);
|
|
81
|
+
throws = extractOpts.throws, readFromStdin = extractOpts.readFromStdin, flatten = extractOpts.flatten, opts = (0, tslib_1.__rest)(extractOpts, ["throws", "readFromStdin", "flatten"]);
|
|
82
82
|
if (!readFromStdin) return [3 /*break*/, 2];
|
|
83
|
-
console_utils_1.debug("Reading input from stdin");
|
|
83
|
+
(0, console_utils_1.debug)("Reading input from stdin");
|
|
84
84
|
// Read from stdin
|
|
85
85
|
if (process.stdin.isTTY) {
|
|
86
|
-
console_utils_1.warn('Reading source file from TTY.');
|
|
86
|
+
(0, console_utils_1.warn)('Reading source file from TTY.');
|
|
87
87
|
}
|
|
88
|
-
return [4 /*yield*/, console_utils_1.getStdinAsString()];
|
|
88
|
+
return [4 /*yield*/, (0, console_utils_1.getStdinAsString)()];
|
|
89
89
|
case 1:
|
|
90
90
|
stdinSource = _d.sent();
|
|
91
91
|
rawResults = [processFile(stdinSource, 'dummy', opts)];
|
|
92
92
|
return [3 /*break*/, 4];
|
|
93
|
-
case 2: return [4 /*yield*/, Promise.all(files.map(function (fn) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
93
|
+
case 2: return [4 /*yield*/, Promise.all(files.map(function (fn) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
94
94
|
var source, e_1;
|
|
95
|
-
return tslib_1.__generator(this, function (_a) {
|
|
95
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
96
96
|
switch (_a.label) {
|
|
97
97
|
case 0:
|
|
98
|
-
console_utils_1.debug('Extracting file:', fn);
|
|
98
|
+
(0, console_utils_1.debug)('Extracting file:', fn);
|
|
99
99
|
_a.label = 1;
|
|
100
100
|
case 1:
|
|
101
101
|
_a.trys.push([1, 3, , 4]);
|
|
102
|
-
return [4 /*yield*/, fs_extra_1.readFile(fn, 'utf8')];
|
|
102
|
+
return [4 /*yield*/, (0, fs_extra_1.readFile)(fn, 'utf8')];
|
|
103
103
|
case 2:
|
|
104
104
|
source = _a.sent();
|
|
105
105
|
return [2 /*return*/, processFile(source, fn, opts)];
|
|
@@ -109,7 +109,7 @@ function extract(files, extractOpts) {
|
|
|
109
109
|
throw e_1;
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
112
|
-
console_utils_1.warn(e_1);
|
|
112
|
+
(0, console_utils_1.warn)(String(e_1));
|
|
113
113
|
}
|
|
114
114
|
return [3 /*break*/, 4];
|
|
115
115
|
case 4: return [2 /*return*/];
|
|
@@ -119,7 +119,7 @@ function extract(files, extractOpts) {
|
|
|
119
119
|
case 3:
|
|
120
120
|
rawResults = _d.sent();
|
|
121
121
|
_d.label = 4;
|
|
122
|
-
case 4: return [4 /*yield*/, formatters_1.resolveBuiltinFormatter(opts.format)];
|
|
122
|
+
case 4: return [4 /*yield*/, (0, formatters_1.resolveBuiltinFormatter)(opts.format)];
|
|
123
123
|
case 5:
|
|
124
124
|
formatter = _d.sent();
|
|
125
125
|
extractionResults = rawResults.filter(function (r) { return !!r; });
|
|
@@ -130,12 +130,12 @@ function extract(files, extractOpts) {
|
|
|
130
130
|
message = messages_1[_a];
|
|
131
131
|
id = message.id, description = message.description, defaultMessage = message.defaultMessage;
|
|
132
132
|
if (!id) {
|
|
133
|
-
error = new Error("[FormatJS CLI] Missing message id for message: \n"
|
|
133
|
+
error = new Error("[FormatJS CLI] Missing message id for message: \n".concat(JSON.stringify(message, undefined, 2)));
|
|
134
134
|
if (throws) {
|
|
135
135
|
throw error;
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
138
|
-
console_utils_1.warn(error.message);
|
|
138
|
+
(0, console_utils_1.warn)(error.message);
|
|
139
139
|
}
|
|
140
140
|
continue;
|
|
141
141
|
}
|
|
@@ -143,13 +143,13 @@ function extract(files, extractOpts) {
|
|
|
143
143
|
existing = extractedMessages.get(id);
|
|
144
144
|
if (description !== existing.description ||
|
|
145
145
|
defaultMessage !== existing.defaultMessage) {
|
|
146
|
-
error = new Error("[FormatJS CLI] Duplicate message id: \""
|
|
146
|
+
error = new Error("[FormatJS CLI] Duplicate message id: \"".concat(id, "\", ") +
|
|
147
147
|
'but the `description` and/or `defaultMessage` are different.');
|
|
148
148
|
if (throws) {
|
|
149
149
|
throw error;
|
|
150
150
|
}
|
|
151
151
|
else {
|
|
152
|
-
console_utils_1.warn(error.message);
|
|
152
|
+
(0, console_utils_1.warn)(error.message);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
}
|
|
@@ -160,13 +160,13 @@ function extract(files, extractOpts) {
|
|
|
160
160
|
messages = Array.from(extractedMessages.values());
|
|
161
161
|
for (_b = 0, messages_2 = messages; _b < messages_2.length; _b++) {
|
|
162
162
|
_c = messages_2[_b];
|
|
163
|
-
id = _c.id, msg = tslib_1.__rest(_c, ["id"]);
|
|
163
|
+
id = _c.id, msg = (0, tslib_1.__rest)(_c, ["id"]);
|
|
164
164
|
if (flatten && msg.defaultMessage) {
|
|
165
|
-
msg.defaultMessage = printer_1.printAST(manipulator_1.hoistSelectors(icu_messageformat_parser_1.parse(msg.defaultMessage)));
|
|
165
|
+
msg.defaultMessage = (0, printer_1.printAST)((0, manipulator_1.hoistSelectors)((0, icu_messageformat_parser_1.parse)(msg.defaultMessage)));
|
|
166
166
|
}
|
|
167
167
|
results[id] = msg;
|
|
168
168
|
}
|
|
169
|
-
return [2 /*return*/, json_stable_stringify_1.default(formatter.format(results), {
|
|
169
|
+
return [2 /*return*/, (0, json_stable_stringify_1.default)(formatter.format(results), {
|
|
170
170
|
space: 2,
|
|
171
171
|
cmp: formatter.compareMessages || undefined,
|
|
172
172
|
})];
|
|
@@ -182,20 +182,20 @@ exports.extract = extract;
|
|
|
182
182
|
* @returns A Promise that resolves if output file was written successfully
|
|
183
183
|
*/
|
|
184
184
|
function extractAndWrite(files, extractOpts) {
|
|
185
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
185
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
186
186
|
var outFile, opts, serializedResult;
|
|
187
|
-
return tslib_1.__generator(this, function (_a) {
|
|
187
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
188
188
|
switch (_a.label) {
|
|
189
189
|
case 0:
|
|
190
|
-
outFile = extractOpts.outFile, opts = tslib_1.__rest(extractOpts, ["outFile"]);
|
|
190
|
+
outFile = extractOpts.outFile, opts = (0, tslib_1.__rest)(extractOpts, ["outFile"]);
|
|
191
191
|
return [4 /*yield*/, extract(files, opts)];
|
|
192
192
|
case 1:
|
|
193
193
|
serializedResult = (_a.sent()) + '\n';
|
|
194
194
|
if (outFile) {
|
|
195
|
-
console_utils_1.debug('Writing output file:', outFile);
|
|
196
|
-
return [2 /*return*/, fs_extra_1.outputFile(outFile, serializedResult)];
|
|
195
|
+
(0, console_utils_1.debug)('Writing output file:', outFile);
|
|
196
|
+
return [2 /*return*/, (0, fs_extra_1.outputFile)(outFile, serializedResult)];
|
|
197
197
|
}
|
|
198
|
-
return [4 /*yield*/, console_utils_1.writeStdout(serializedResult)];
|
|
198
|
+
return [4 /*yield*/, (0, console_utils_1.writeStdout)(serializedResult)];
|
|
199
199
|
case 2:
|
|
200
200
|
_a.sent();
|
|
201
201
|
return [2 /*return*/];
|
package/src/formatters/index.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveBuiltinFormatter = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var defaultFormatter = tslib_1.__importStar(require("./default"));
|
|
6
|
-
var transifex = tslib_1.__importStar(require("./transifex"));
|
|
7
|
-
var smartling = tslib_1.__importStar(require("./smartling"));
|
|
8
|
-
var simple = tslib_1.__importStar(require("./simple"));
|
|
9
|
-
var lokalise = tslib_1.__importStar(require("./lokalise"));
|
|
10
|
-
var crowdin = tslib_1.__importStar(require("./crowdin"));
|
|
5
|
+
var defaultFormatter = (0, tslib_1.__importStar)(require("./default"));
|
|
6
|
+
var transifex = (0, tslib_1.__importStar)(require("./transifex"));
|
|
7
|
+
var smartling = (0, tslib_1.__importStar)(require("./smartling"));
|
|
8
|
+
var simple = (0, tslib_1.__importStar)(require("./simple"));
|
|
9
|
+
var lokalise = (0, tslib_1.__importStar)(require("./lokalise"));
|
|
10
|
+
var crowdin = (0, tslib_1.__importStar)(require("./crowdin"));
|
|
11
11
|
var path_1 = require("path");
|
|
12
12
|
function resolveBuiltinFormatter(format) {
|
|
13
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
14
|
-
return tslib_1.__generator(this, function (_a) {
|
|
13
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
14
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
15
15
|
if (!format) {
|
|
16
16
|
return [2 /*return*/, defaultFormatter];
|
|
17
17
|
}
|
|
@@ -32,10 +32,10 @@ function resolveBuiltinFormatter(format) {
|
|
|
32
32
|
}
|
|
33
33
|
try {
|
|
34
34
|
// eslint-disable-next-line import/dynamic-import-chunkname
|
|
35
|
-
return [2 /*return*/, Promise.resolve().then(function () { return tslib_1.__importStar(require(path_1.resolve(process.cwd(), format))); })];
|
|
35
|
+
return [2 /*return*/, Promise.resolve().then(function () { return (0, tslib_1.__importStar)(require((0, path_1.resolve)(process.cwd(), format))); })];
|
|
36
36
|
}
|
|
37
37
|
catch (e) {
|
|
38
|
-
console.error("Cannot resolve formatter "
|
|
38
|
+
console.error("Cannot resolve formatter ".concat(format));
|
|
39
39
|
throw e;
|
|
40
40
|
}
|
|
41
41
|
return [2 /*return*/];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse_script.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli/src/parse_script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAkB,MAAM,0BAA0B,CAAA;AAG9D;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,MAAM,YACjC,MAAM,
|
|
1
|
+
{"version":3,"file":"parse_script.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli/src/parse_script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAkB,MAAM,0BAA0B,CAAA;AAG9D;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,MAAM,YACjC,MAAM,UAuCvB"}
|
package/src/parse_script.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseScript = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var ts_transformer_1 = require("@formatjs/ts-transformer");
|
|
6
|
-
var typescript_1 = tslib_1.__importDefault(require("typescript"));
|
|
6
|
+
var typescript_1 = (0, tslib_1.__importDefault)(require("typescript"));
|
|
7
7
|
var console_utils_1 = require("./console_utils");
|
|
8
8
|
/**
|
|
9
9
|
* Invoid TypeScript module transpilation with our TS transformer
|
|
@@ -14,7 +14,7 @@ function parseScript(opts, fn) {
|
|
|
14
14
|
return function (source) {
|
|
15
15
|
var output;
|
|
16
16
|
try {
|
|
17
|
-
console_utils_1.debug('Using TS compiler to process file', fn);
|
|
17
|
+
(0, console_utils_1.debug)('Using TS compiler to process file', fn);
|
|
18
18
|
output = typescript_1.default.transpileModule(source, {
|
|
19
19
|
compilerOptions: {
|
|
20
20
|
allowJs: true,
|
|
@@ -25,12 +25,14 @@ function parseScript(opts, fn) {
|
|
|
25
25
|
reportDiagnostics: true,
|
|
26
26
|
fileName: fn,
|
|
27
27
|
transformers: {
|
|
28
|
-
before: [ts_transformer_1.transformWithTs(typescript_1.default, opts)],
|
|
28
|
+
before: [(0, ts_transformer_1.transformWithTs)(typescript_1.default, opts)],
|
|
29
29
|
},
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
catch (e) {
|
|
33
|
-
|
|
33
|
+
if (e instanceof Error) {
|
|
34
|
+
e.message = "Error processing file ".concat(fn, " \n").concat(e.message || '');
|
|
35
|
+
}
|
|
34
36
|
throw e;
|
|
35
37
|
}
|
|
36
38
|
if (output.diagnostics) {
|
package/src/pseudo_locale.js
CHANGED
|
@@ -4,28 +4,28 @@ exports.generateENXB = exports.generateENXA = exports.generateXXHA = exports.gen
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
|
|
6
6
|
function generateXXLS(msg) {
|
|
7
|
-
var ast = typeof msg === 'string' ? icu_messageformat_parser_1.parse(msg) : msg;
|
|
7
|
+
var ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
|
|
8
8
|
var lastChunk = ast.pop();
|
|
9
|
-
if (lastChunk && icu_messageformat_parser_1.isLiteralElement(lastChunk)) {
|
|
9
|
+
if (lastChunk && (0, icu_messageformat_parser_1.isLiteralElement)(lastChunk)) {
|
|
10
10
|
lastChunk.value += 'SSSSSSSSSSSSSSSSSSSSSSSSS';
|
|
11
|
-
return tslib_1.__spreadArray(tslib_1.__spreadArray([], ast), [lastChunk]);
|
|
11
|
+
return (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], ast, true), [lastChunk], false);
|
|
12
12
|
}
|
|
13
|
-
return tslib_1.__spreadArray(tslib_1.__spreadArray([], ast), [{ type: icu_messageformat_parser_1.TYPE.literal, value: 'SSSSSSSSSSSSSSSSSSSSSSSSS' }]);
|
|
13
|
+
return (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], ast, true), [{ type: icu_messageformat_parser_1.TYPE.literal, value: 'SSSSSSSSSSSSSSSSSSSSSSSSS' }], false);
|
|
14
14
|
}
|
|
15
15
|
exports.generateXXLS = generateXXLS;
|
|
16
16
|
function generateXXAC(msg) {
|
|
17
|
-
var ast = typeof msg === 'string' ? icu_messageformat_parser_1.parse(msg) : msg;
|
|
17
|
+
var ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
|
|
18
18
|
ast.forEach(function (el) {
|
|
19
|
-
if (icu_messageformat_parser_1.isLiteralElement(el)) {
|
|
19
|
+
if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
|
|
20
20
|
el.value = el.value.toUpperCase();
|
|
21
21
|
}
|
|
22
|
-
else if (icu_messageformat_parser_1.isPluralElement(el) || icu_messageformat_parser_1.isSelectElement(el)) {
|
|
22
|
+
else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
|
|
23
23
|
for (var _i = 0, _a = Object.values(el.options); _i < _a.length; _i++) {
|
|
24
24
|
var opt = _a[_i];
|
|
25
25
|
generateXXAC(opt.value);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
else if (icu_messageformat_parser_1.isTagElement(el)) {
|
|
28
|
+
else if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
|
|
29
29
|
generateXXAC(el.children);
|
|
30
30
|
}
|
|
31
31
|
});
|
|
@@ -33,21 +33,21 @@ function generateXXAC(msg) {
|
|
|
33
33
|
}
|
|
34
34
|
exports.generateXXAC = generateXXAC;
|
|
35
35
|
function generateXXHA(msg) {
|
|
36
|
-
var ast = typeof msg === 'string' ? icu_messageformat_parser_1.parse(msg) : msg;
|
|
36
|
+
var ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
|
|
37
37
|
var firstChunk = ast.shift();
|
|
38
|
-
if (firstChunk && icu_messageformat_parser_1.isLiteralElement(firstChunk)) {
|
|
38
|
+
if (firstChunk && (0, icu_messageformat_parser_1.isLiteralElement)(firstChunk)) {
|
|
39
39
|
firstChunk.value = '[javascript]' + firstChunk.value;
|
|
40
|
-
return tslib_1.__spreadArray([firstChunk], ast);
|
|
40
|
+
return (0, tslib_1.__spreadArray)([firstChunk], ast, true);
|
|
41
41
|
}
|
|
42
|
-
return tslib_1.__spreadArray([{ type: icu_messageformat_parser_1.TYPE.literal, value: '[javascript]' }], ast);
|
|
42
|
+
return (0, tslib_1.__spreadArray)([{ type: icu_messageformat_parser_1.TYPE.literal, value: '[javascript]' }], ast, true);
|
|
43
43
|
}
|
|
44
44
|
exports.generateXXHA = generateXXHA;
|
|
45
45
|
var ASCII = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
46
46
|
var ACCENTED_ASCII = 'âḃćḋèḟĝḫíĵǩĺṁńŏṗɋŕśṭůṿẘẋẏẓḀḂḈḊḔḞḠḢḬĴḴĻḾŊÕṔɊŔṠṮŨṼẄẌŸƵ';
|
|
47
47
|
function generateENXA(msg) {
|
|
48
|
-
var ast = typeof msg === 'string' ? icu_messageformat_parser_1.parse(msg) : msg;
|
|
48
|
+
var ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
|
|
49
49
|
ast.forEach(function (el) {
|
|
50
|
-
if (icu_messageformat_parser_1.isLiteralElement(el)) {
|
|
50
|
+
if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
|
|
51
51
|
el.value = el.value
|
|
52
52
|
.split('')
|
|
53
53
|
.map(function (c) {
|
|
@@ -59,13 +59,13 @@ function generateENXA(msg) {
|
|
|
59
59
|
})
|
|
60
60
|
.join('');
|
|
61
61
|
}
|
|
62
|
-
else if (icu_messageformat_parser_1.isPluralElement(el) || icu_messageformat_parser_1.isSelectElement(el)) {
|
|
62
|
+
else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
|
|
63
63
|
for (var _i = 0, _a = Object.values(el.options); _i < _a.length; _i++) {
|
|
64
64
|
var opt = _a[_i];
|
|
65
65
|
generateENXA(opt.value);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
else if (icu_messageformat_parser_1.isTagElement(el)) {
|
|
68
|
+
else if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
|
|
69
69
|
generateENXA(el.children);
|
|
70
70
|
}
|
|
71
71
|
});
|
|
@@ -73,9 +73,9 @@ function generateENXA(msg) {
|
|
|
73
73
|
}
|
|
74
74
|
exports.generateENXA = generateENXA;
|
|
75
75
|
function generateENXB(msg) {
|
|
76
|
-
var ast = typeof msg === 'string' ? icu_messageformat_parser_1.parse(msg) : msg;
|
|
76
|
+
var ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
|
|
77
77
|
ast.forEach(function (el) {
|
|
78
|
-
if (icu_messageformat_parser_1.isLiteralElement(el)) {
|
|
78
|
+
if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
|
|
79
79
|
var pseudoString = el.value
|
|
80
80
|
.split('')
|
|
81
81
|
.map(function (c, index) {
|
|
@@ -87,15 +87,15 @@ function generateENXB(msg) {
|
|
|
87
87
|
return canPad ? ACCENTED_ASCII[i].repeat(3) : ACCENTED_ASCII[i];
|
|
88
88
|
})
|
|
89
89
|
.join('');
|
|
90
|
-
el.value = "[!! "
|
|
90
|
+
el.value = "[!! ".concat(pseudoString, " !!]");
|
|
91
91
|
}
|
|
92
|
-
else if (icu_messageformat_parser_1.isPluralElement(el) || icu_messageformat_parser_1.isSelectElement(el)) {
|
|
92
|
+
else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
|
|
93
93
|
for (var _i = 0, _a = Object.values(el.options); _i < _a.length; _i++) {
|
|
94
94
|
var opt = _a[_i];
|
|
95
95
|
generateENXB(opt.value);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
else if (icu_messageformat_parser_1.isTagElement(el)) {
|
|
98
|
+
else if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
|
|
99
99
|
generateENXB(el.children);
|
|
100
100
|
}
|
|
101
101
|
});
|
package/src/vue_extractor.js
CHANGED
|
@@ -38,11 +38,11 @@ function templateSimpleExpressionNodeVisitor(parseScriptFn) {
|
|
|
38
38
|
// Wrap this in () since a vue comp node attribute can just be
|
|
39
39
|
// an object literal which, by itself is invalid TS
|
|
40
40
|
// but with () it becomes an ExpressionStatement
|
|
41
|
-
parseScriptFn("("
|
|
41
|
+
parseScriptFn("(".concat(content, ")"));
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
function parseFile(source, filename, parseScriptFn) {
|
|
45
|
-
var _a = compiler_sfc_1.parse(source, {
|
|
45
|
+
var _a = (0, compiler_sfc_1.parse)(source, {
|
|
46
46
|
filename: filename,
|
|
47
47
|
}), descriptor = _a.descriptor, errors = _a.errors;
|
|
48
48
|
if (errors.length) {
|