@formatjs/cli-lib 6.3.8 → 6.4.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 +27 -3
- package/src/extract.js +34 -24
- package/src/gts_extractor.d.ts +1 -0
- package/src/gts_extractor.js +18 -0
- package/src/hbs_extractor.d.ts +1 -0
- package/src/hbs_extractor.js +49 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/cli-lib",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"description": "Lib for CLI for formatjs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intl",
|
|
@@ -43,11 +43,17 @@
|
|
|
43
43
|
"loud-rejection": "^2.2.0",
|
|
44
44
|
"tslib": "^2.4.0",
|
|
45
45
|
"typescript": "5",
|
|
46
|
-
"@formatjs/
|
|
47
|
-
"@formatjs/
|
|
46
|
+
"@formatjs/icu-messageformat-parser": "2.7.6",
|
|
47
|
+
"@formatjs/ts-transformer": "3.13.12"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
+
"@glimmer/env": "^0.1.7",
|
|
51
|
+
"@glimmer/reference": "^0.91.1",
|
|
52
|
+
"@glimmer/syntax": "^0.91.1",
|
|
53
|
+
"@glimmer/validator": "^0.91.1",
|
|
50
54
|
"@vue/compiler-core": "^3.4.0",
|
|
55
|
+
"content-tag": "^2.0.1",
|
|
56
|
+
"ember-template-recast": "^6.1.4",
|
|
51
57
|
"vue": "^3.4.0"
|
|
52
58
|
},
|
|
53
59
|
"peerDependenciesMeta": {
|
|
@@ -56,6 +62,24 @@
|
|
|
56
62
|
},
|
|
57
63
|
"@vue/compiler-core": {
|
|
58
64
|
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"@glimmer/env": {
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"@glimmer/reference": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
72
|
+
"@glimmer/syntax": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"@glimmer/validator": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"ember-template-recast": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"content-tag": {
|
|
82
|
+
"optional": true
|
|
59
83
|
}
|
|
60
84
|
},
|
|
61
85
|
"engines": {
|
package/src/extract.js
CHANGED
|
@@ -72,6 +72,16 @@ async function processFile(source, fn, { idInterpolationPattern, ...opts }) {
|
|
|
72
72
|
const { parseFile } = await import('./vue_extractor.js');
|
|
73
73
|
parseFile(source, fn, scriptParseFn);
|
|
74
74
|
}
|
|
75
|
+
else if (fn.endsWith('.hbs')) {
|
|
76
|
+
(0, console_utils_1.debug)('Processing %s using hbs extractor', fn);
|
|
77
|
+
const { parseFile } = await import('./hbs_extractor.js');
|
|
78
|
+
parseFile(source, fn, opts);
|
|
79
|
+
}
|
|
80
|
+
else if (fn.endsWith('.gts') || fn.endsWith('.gjs')) {
|
|
81
|
+
(0, console_utils_1.debug)('Processing %s as gts/gjs file', fn);
|
|
82
|
+
const { parseFile } = await import('./gts_extractor.js');
|
|
83
|
+
parseFile(source, fn, opts);
|
|
84
|
+
}
|
|
75
85
|
else {
|
|
76
86
|
(0, console_utils_1.debug)('Processing %s using typescript extractor', fn);
|
|
77
87
|
scriptParseFn(source);
|
|
@@ -92,32 +102,32 @@ async function processFile(source, fn, { idInterpolationPattern, ...opts }) {
|
|
|
92
102
|
*/
|
|
93
103
|
async function extract(files, extractOpts) {
|
|
94
104
|
const { throws, readFromStdin, flatten, ...opts } = extractOpts;
|
|
95
|
-
let rawResults;
|
|
96
|
-
|
|
97
|
-
(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
(
|
|
105
|
+
let rawResults = [];
|
|
106
|
+
try {
|
|
107
|
+
if (readFromStdin) {
|
|
108
|
+
(0, console_utils_1.debug)(`Reading input from stdin`);
|
|
109
|
+
// Read from stdin
|
|
110
|
+
if (process.stdin.isTTY) {
|
|
111
|
+
(0, console_utils_1.warn)('Reading source file from TTY.');
|
|
112
|
+
}
|
|
113
|
+
const stdinSource = await (0, console_utils_1.getStdinAsString)();
|
|
114
|
+
rawResults = [await processFile(stdinSource, 'dummy', opts)];
|
|
101
115
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
else {
|
|
106
|
-
rawResults = await Promise.all(files.map(async (fn) => {
|
|
107
|
-
(0, console_utils_1.debug)('Extracting file:', fn);
|
|
108
|
-
try {
|
|
116
|
+
else {
|
|
117
|
+
rawResults = await Promise.all(files.map(async (fn) => {
|
|
118
|
+
(0, console_utils_1.debug)('Extracting file:', fn);
|
|
109
119
|
const source = await (0, fs_extra_1.readFile)(fn, 'utf8');
|
|
110
120
|
return processFile(source, fn, opts);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
if (throws) {
|
|
126
|
+
throw e;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
(0, console_utils_1.warn)(String(e));
|
|
130
|
+
}
|
|
121
131
|
}
|
|
122
132
|
const formatter = await (0, formatters_1.resolveBuiltinFormatter)(opts.format);
|
|
123
133
|
const extractionResults = rawResults.filter((r) => !!r);
|
|
@@ -126,7 +136,7 @@ async function extract(files, extractOpts) {
|
|
|
126
136
|
for (const message of messages) {
|
|
127
137
|
const { id, description, defaultMessage } = message;
|
|
128
138
|
if (!id) {
|
|
129
|
-
const error = new Error(`[FormatJS CLI] Missing message id for message:
|
|
139
|
+
const error = new Error(`[FormatJS CLI] Missing message id for message:
|
|
130
140
|
${JSON.stringify(message, undefined, 2)}`);
|
|
131
141
|
if (throws) {
|
|
132
142
|
throw error;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseFile(source: string, fileName: string, options: any): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseFile = void 0;
|
|
4
|
+
const content_tag_1 = require("content-tag");
|
|
5
|
+
const hbs_extractor_1 = require("./hbs_extractor");
|
|
6
|
+
const parse_script_1 = require("./parse_script");
|
|
7
|
+
let p = new content_tag_1.Preprocessor();
|
|
8
|
+
function parseFile(source, fileName, options) {
|
|
9
|
+
const scriptParseFn = (0, parse_script_1.parseScript)(options, fileName);
|
|
10
|
+
const transformedSource = p.process(source, { filename: fileName });
|
|
11
|
+
scriptParseFn(transformedSource);
|
|
12
|
+
// extract template from transformed source to then run through hbs processor
|
|
13
|
+
const parseResult = p.parse(source, { filename: fileName });
|
|
14
|
+
for (let parsed of parseResult) {
|
|
15
|
+
(0, hbs_extractor_1.parseFile)(parsed.contents, fileName, options);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.parseFile = parseFile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseFile(source: string, fileName: string, options: any): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseFile = void 0;
|
|
4
|
+
const ember_template_recast_1 = require("ember-template-recast");
|
|
5
|
+
function extractText(node, fileName, options) {
|
|
6
|
+
if (!options.onMsgExtracted)
|
|
7
|
+
return;
|
|
8
|
+
if (!options.overrideIdFn)
|
|
9
|
+
return;
|
|
10
|
+
if (node.path.type !== 'PathExpression')
|
|
11
|
+
return;
|
|
12
|
+
if (['format-message', 'formatMessage'].includes(node.path.original)) {
|
|
13
|
+
let [first, second] = node.params;
|
|
14
|
+
if (first.type !== 'StringLiteral')
|
|
15
|
+
return;
|
|
16
|
+
let message = first?.value;
|
|
17
|
+
let desc;
|
|
18
|
+
if (second?.type === 'StringLiteral') {
|
|
19
|
+
desc = second.value?.trim().replace(/\s+/gm, ' ');
|
|
20
|
+
}
|
|
21
|
+
let defaultMessage = message?.trim().replace(/\s+/gm, ' ');
|
|
22
|
+
let id = typeof options.overrideIdFn === 'string'
|
|
23
|
+
? options.overrideIdFn
|
|
24
|
+
: options.overrideIdFn(undefined, defaultMessage, desc, fileName);
|
|
25
|
+
options.onMsgExtracted(fileName, [
|
|
26
|
+
{
|
|
27
|
+
id: id,
|
|
28
|
+
defaultMessage: defaultMessage,
|
|
29
|
+
description: desc,
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function parseFile(source, fileName, options) {
|
|
35
|
+
let visitor = function () {
|
|
36
|
+
return {
|
|
37
|
+
MustacheStatement(node) {
|
|
38
|
+
extractText(node, fileName, options);
|
|
39
|
+
},
|
|
40
|
+
SubExpression(node) {
|
|
41
|
+
extractText(node, fileName, options);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
// SAFETY: ember-template-recast's types are out of date,
|
|
46
|
+
// but it does not affect runtime
|
|
47
|
+
(0, ember_template_recast_1.transform)(source, visitor);
|
|
48
|
+
}
|
|
49
|
+
exports.parseFile = parseFile;
|