@formatjs/cli 2.13.16 → 2.15.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.
- package/package.json +5 -3
- package/src/cli.d.ts.map +1 -1
- package/src/cli.js +3 -1
- package/src/extract.d.ts.map +1 -1
- package/src/extract.js +10 -30
- package/src/parse_script.d.ts +8 -0
- package/src/parse_script.d.ts.map +1 -0
- package/src/parse_script.js +46 -0
- package/src/vue_extractor.d.ts +3 -0
- package/src/vue_extractor.d.ts.map +1 -0
- package/src/vue_extractor.js +44 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"description": "A CLI for formatjs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intl",
|
|
@@ -31,16 +31,18 @@
|
|
|
31
31
|
"url": "git+ssh://git@github.com/formatjs/formatjs.git"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@formatjs/ts-transformer": "2.
|
|
34
|
+
"@formatjs/ts-transformer": "2.13.0",
|
|
35
35
|
"@types/json-stable-stringify": "^1.0.32",
|
|
36
36
|
"@types/lodash": "^4.14.150",
|
|
37
37
|
"@types/loud-rejection": "^2.0.0",
|
|
38
38
|
"@types/node": "14",
|
|
39
|
+
"@vue/compiler-core": "^3.0.0",
|
|
40
|
+
"@vue/compiler-sfc": "^3.0.5",
|
|
39
41
|
"chalk": "^4.0.0",
|
|
40
42
|
"commander": "^6.1.0",
|
|
41
43
|
"fast-glob": "^3.2.4",
|
|
42
44
|
"fs-extra": "^9.0.0",
|
|
43
|
-
"intl-messageformat-parser": "6.1.
|
|
45
|
+
"intl-messageformat-parser": "6.1.2",
|
|
44
46
|
"json-stable-stringify": "^1.0.1",
|
|
45
47
|
"lodash": "^4.17.15",
|
|
46
48
|
"loud-rejection": "^2.2.0",
|
package/src/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli/src/cli.ts"],"names":[],"mappings":"AASA,iBAAe,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli/src/cli.ts"],"names":[],"mappings":"AASA,iBAAe,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,iBAsNjC;AACD,eAAe,IAAI,CAAC"}
|
package/src/cli.js
CHANGED
|
@@ -28,7 +28,7 @@ function main(argv) {
|
|
|
28
28
|
.description('Show this help message.')
|
|
29
29
|
.action(function () { return commander_1.default.help(); });
|
|
30
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-
|
|
31
|
+
// NOTE: please keep the help text in sync with babel-plugin-formatjs documentation.
|
|
32
32
|
commander_1.default
|
|
33
33
|
.command('extract [files...]')
|
|
34
34
|
.description("Extract string messages from React components that use react-intl.\nThe input language is expected to be TypeScript or ES2017 with JSX.")
|
|
@@ -38,6 +38,7 @@ function main(argv) {
|
|
|
38
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
39
|
.option('--remove-default-message', 'Remove `defaultMessage` field in generated js after extraction', false)
|
|
40
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(','); })
|
|
41
42
|
.option('--extract-from-format-message-call', "Opt-in to extract from `intl.formatMessage` call with the same restrictions, e.g: has \nto be called with object literal such as `intl.formatMessage({ id: 'foo', defaultMessage: \n'bar', description: 'baz'})", true)
|
|
42
43
|
.option('--ignore <files...>', 'List of glob paths to **not** extract translations from.')
|
|
43
44
|
.option('--throws', 'Whether to throw an exception when we fail to process any file in the batch.')
|
|
@@ -60,6 +61,7 @@ function main(argv) {
|
|
|
60
61
|
extractSourceLocation: cmdObj.extractSourceLocation,
|
|
61
62
|
removeDefaultMessage: cmdObj.removeDefaultMessage,
|
|
62
63
|
additionalComponentNames: cmdObj.additionalComponentNames,
|
|
64
|
+
additionalFunctionNames: cmdObj.additionalFunctionNames,
|
|
63
65
|
extractFromFormatMessageCall: cmdObj.extractFromFormatMessageCall,
|
|
64
66
|
throws: cmdObj.throws,
|
|
65
67
|
pragma: cmdObj.pragma,
|
package/src/extract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli/src/extract.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli/src/extract.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,IAAI,EACJ,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAA0B,SAAS,EAAC,MAAM,cAAc,CAAC;AAIhE,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAC1D;;OAEG;IACH,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B;;OAEG;IACH,IAAI,CAAC,EAAE,CAAC,CAAC;CACV;AAED,MAAM,WAAW,0BAA2B,SAAQ,iBAAiB;IACnE;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,oBAAY,iBAAiB,GAAG,IAAI,CAClC,WAAW,EACX,cAAc,GAAG,gBAAgB,GAAG,iBAAiB,CACtD,GAAG;IACF;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF,oBAAY,WAAW,GAAG,IAAI,GAAG;IAC/B;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,GAAG,IAAI,CAAC,IAAI,EAAE,gBAAgB,GAAG,iBAAiB,CAAC,CAAC;AA2ErD;;;;;;GAMG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,WAAW,EAAE,WAAW,mBAgFzB;AAED;;;;;GAKG;AACH,wBAA8B,eAAe,CAC3C,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,WAAW,EAAE,iBAAiB,iBAS/B"}
|
package/src/extract.js
CHANGED
|
@@ -5,9 +5,10 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
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
|
-
var typescript_1 = tslib_1.__importDefault(require("typescript"));
|
|
9
8
|
var formatters_1 = require("./formatters");
|
|
10
9
|
var json_stable_stringify_1 = tslib_1.__importDefault(require("json-stable-stringify"));
|
|
10
|
+
var vue_extractor_1 = require("./vue_extractor");
|
|
11
|
+
var parse_script_1 = require("./parse_script");
|
|
11
12
|
function calculateLineColFromOffset(text, start) {
|
|
12
13
|
if (!start) {
|
|
13
14
|
return { line: 1, col: 1 };
|
|
@@ -21,7 +22,9 @@ function processFile(source, fn, _a) {
|
|
|
21
22
|
var idInterpolationPattern = _a.idInterpolationPattern, opts = tslib_1.__rest(_a, ["idInterpolationPattern"]);
|
|
22
23
|
var messages = [];
|
|
23
24
|
var meta;
|
|
24
|
-
opts = tslib_1.__assign(tslib_1.__assign({}, opts), {
|
|
25
|
+
opts = tslib_1.__assign(tslib_1.__assign({}, opts), { additionalComponentNames: tslib_1.__spreadArrays([
|
|
26
|
+
'$formatMessage'
|
|
27
|
+
], (opts.additionalComponentNames || [])), onMsgExtracted: function (_, msgs) {
|
|
25
28
|
if (opts.extractSourceLocation) {
|
|
26
29
|
msgs = msgs.map(function (msg) { return (tslib_1.__assign(tslib_1.__assign({}, msg), calculateLineColFromOffset(source, msg.start))); });
|
|
27
30
|
}
|
|
@@ -42,35 +45,12 @@ function processFile(source, fn, _a) {
|
|
|
42
45
|
});
|
|
43
46
|
} });
|
|
44
47
|
}
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
compilerOptions: {
|
|
49
|
-
allowJs: true,
|
|
50
|
-
target: typescript_1.default.ScriptTarget.ESNext,
|
|
51
|
-
noEmit: true,
|
|
52
|
-
experimentalDecorators: true,
|
|
53
|
-
},
|
|
54
|
-
reportDiagnostics: true,
|
|
55
|
-
fileName: fn,
|
|
56
|
-
transformers: {
|
|
57
|
-
before: [ts_transformer_1.transform(opts)],
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
catch (e) {
|
|
62
|
-
e.message = "Error processing file " + fn + " \n" + (e.message || '');
|
|
63
|
-
throw e;
|
|
48
|
+
var scriptParseFn = parse_script_1.parseScript(opts, fn);
|
|
49
|
+
if (fn.endsWith('.vue')) {
|
|
50
|
+
vue_extractor_1.parseFile(source, fn, scriptParseFn);
|
|
64
51
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (errs.length) {
|
|
68
|
-
throw new Error(typescript_1.default.formatDiagnosticsWithColorAndContext(errs, {
|
|
69
|
-
getCanonicalFileName: function (fileName) { return fileName; },
|
|
70
|
-
getCurrentDirectory: function () { return process.cwd(); },
|
|
71
|
-
getNewLine: function () { return typescript_1.default.sys.newLine; },
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
52
|
+
else {
|
|
53
|
+
scriptParseFn(source);
|
|
74
54
|
}
|
|
75
55
|
if (meta) {
|
|
76
56
|
messages.forEach(function (m) { return (m.meta = meta); });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Opts } from '@formatjs/ts-transformer';
|
|
2
|
+
/**
|
|
3
|
+
* Invoid TypeScript module transpilation with our TS transformer
|
|
4
|
+
* @param opts Formatjs TS Transformer opt
|
|
5
|
+
* @param fn filename
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseScript(opts: Opts, fn?: string): (source: string) => void;
|
|
8
|
+
//# sourceMappingURL=parse_script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse_script.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli/src/parse_script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAY,MAAM,0BAA0B,CAAC;AAGzD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,MAAM,YACjC,MAAM,UAoCvB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseScript = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var ts_transformer_1 = require("@formatjs/ts-transformer");
|
|
6
|
+
var typescript_1 = tslib_1.__importDefault(require("typescript"));
|
|
7
|
+
/**
|
|
8
|
+
* Invoid TypeScript module transpilation with our TS transformer
|
|
9
|
+
* @param opts Formatjs TS Transformer opt
|
|
10
|
+
* @param fn filename
|
|
11
|
+
*/
|
|
12
|
+
function parseScript(opts, fn) {
|
|
13
|
+
return function (source) {
|
|
14
|
+
var output;
|
|
15
|
+
try {
|
|
16
|
+
output = typescript_1.default.transpileModule(source, {
|
|
17
|
+
compilerOptions: {
|
|
18
|
+
allowJs: true,
|
|
19
|
+
target: typescript_1.default.ScriptTarget.ESNext,
|
|
20
|
+
noEmit: true,
|
|
21
|
+
experimentalDecorators: true,
|
|
22
|
+
},
|
|
23
|
+
reportDiagnostics: true,
|
|
24
|
+
fileName: fn,
|
|
25
|
+
transformers: {
|
|
26
|
+
before: [ts_transformer_1.transform(opts)],
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
e.message = "Error processing file " + fn + " \n" + (e.message || '');
|
|
32
|
+
throw e;
|
|
33
|
+
}
|
|
34
|
+
if (output.diagnostics) {
|
|
35
|
+
var errs = output.diagnostics.filter(function (d) { return d.category === typescript_1.default.DiagnosticCategory.Error; });
|
|
36
|
+
if (errs.length) {
|
|
37
|
+
throw new Error(typescript_1.default.formatDiagnosticsWithColorAndContext(errs, {
|
|
38
|
+
getCanonicalFileName: function (fileName) { return fileName; },
|
|
39
|
+
getCurrentDirectory: function () { return process.cwd(); },
|
|
40
|
+
getNewLine: function () { return typescript_1.default.sys.newLine; },
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.parseScript = parseScript;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue_extractor.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli/src/vue_extractor.ts"],"names":[],"mappings":"AAOA,oBAAY,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;AA+BrD,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,aAAa,GAC3B,GAAG,CAgBL"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseFile = void 0;
|
|
4
|
+
var compiler_sfc_1 = require("@vue/compiler-sfc");
|
|
5
|
+
function walk(node, visitor) {
|
|
6
|
+
if (node.type === 2 /* TEXT */ ||
|
|
7
|
+
node.type === 3 /* COMMENT */ ||
|
|
8
|
+
node.type === 9 /* IF */ ||
|
|
9
|
+
node.type === 12 /* TEXT_CALL */) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
visitor(node);
|
|
13
|
+
if (node.type === 5 /* INTERPOLATION */) {
|
|
14
|
+
visitor(node.content);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
node.children.forEach(function (n) { return walk(n, visitor); });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function templateSimpleExpressionNodeVisitor(parseScriptFn) {
|
|
21
|
+
return function (n) {
|
|
22
|
+
if (n.type !== 4 /* SIMPLE_EXPRESSION */) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
var content = n.content;
|
|
26
|
+
parseScriptFn(content);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function parseFile(source, filename, parseScriptFn) {
|
|
30
|
+
var _a = compiler_sfc_1.parse(source, {
|
|
31
|
+
filename: filename,
|
|
32
|
+
}), descriptor = _a.descriptor, errors = _a.errors;
|
|
33
|
+
if (errors.length) {
|
|
34
|
+
throw errors[0];
|
|
35
|
+
}
|
|
36
|
+
var script = descriptor.script, template = descriptor.template;
|
|
37
|
+
if (template) {
|
|
38
|
+
walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn));
|
|
39
|
+
}
|
|
40
|
+
if (script) {
|
|
41
|
+
parseScriptFn(script.content);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.parseFile = parseFile;
|