@formatjs/cli-lib 8.0.8 → 8.1.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/index.d.ts +7 -7
- package/index.js +2 -2
- package/main.d.ts +0 -1
- package/main.js +1 -1
- package/package.json +5 -5
- package/src/cli.js +99 -153
- package/src/compile.d.ts +45 -45
- package/src/compile.js +79 -80
- package/src/compile_folder.d.ts +1 -1
- package/src/compile_folder.js +6 -6
- package/src/console_utils.d.ts +3 -1
- package/src/console_utils.js +44 -46
- package/src/extract.d.ts +68 -68
- package/src/extract.js +165 -182
- package/src/formatters/crowdin.d.ts +3 -3
- package/src/formatters/crowdin.js +19 -20
- package/src/formatters/default.d.ts +1 -1
- package/src/formatters/default.js +8 -7
- package/src/formatters/index.d.ts +6 -6
- package/src/formatters/index.js +29 -34
- package/src/formatters/lokalise.d.ts +5 -5
- package/src/formatters/lokalise.js +16 -17
- package/src/formatters/simple.d.ts +1 -1
- package/src/formatters/simple.js +7 -6
- package/src/formatters/smartling.d.ts +13 -15
- package/src/formatters/smartling.js +35 -40
- package/src/formatters/transifex.d.ts +5 -5
- package/src/formatters/transifex.js +16 -17
- package/src/gts_extractor.js +11 -11
- package/src/hbs_extractor.js +34 -41
- package/src/parse_script.d.ts +5 -5
- package/src/parse_script.js +40 -43
- package/src/pseudo_locale.d.ts +15 -15
- package/src/pseudo_locale.js +210 -94
- package/src/verify/checkExtraKeys.js +28 -32
- package/src/verify/checkMissingKeys.js +29 -33
- package/src/verify/checkStructuralEquality.js +67 -71
- package/src/verify/index.d.ts +5 -5
- package/src/verify/index.js +24 -27
- package/src/vue_extractor.js +52 -62
package/src/verify/index.js
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import { basename } from
|
|
2
|
-
import { debug } from
|
|
3
|
-
import { checkMissingKeys } from
|
|
4
|
-
import { checkExtraKeys } from
|
|
5
|
-
import { readJSON } from
|
|
6
|
-
import { checkStructuralEquality } from
|
|
1
|
+
import { basename } from "path";
|
|
2
|
+
import { debug } from "../console_utils.js";
|
|
3
|
+
import { checkMissingKeys } from "./checkMissingKeys.js";
|
|
4
|
+
import { checkExtraKeys } from "./checkExtraKeys.js";
|
|
5
|
+
import { readJSON } from "fs-extra/esm";
|
|
6
|
+
import { checkStructuralEquality } from "./checkStructuralEquality.js";
|
|
7
7
|
export async function verify(files, { sourceLocale, missingKeys, extraKeys, structuralEquality }) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
exitCode = 1;
|
|
27
|
-
}
|
|
28
|
-
process.exit(exitCode);
|
|
8
|
+
debug("Checking translation files:");
|
|
9
|
+
files.forEach((fn) => debug(fn));
|
|
10
|
+
const translationFilesContents = (await Promise.all(files.map(async (fn) => [basename(fn, ".json"), await readJSON(fn)]))).reduce((all, [locale, content]) => {
|
|
11
|
+
all[locale] = content;
|
|
12
|
+
return all;
|
|
13
|
+
}, {});
|
|
14
|
+
debug("Verifying files:", files);
|
|
15
|
+
let exitCode = 0;
|
|
16
|
+
if (missingKeys && !await checkMissingKeys(translationFilesContents, sourceLocale)) {
|
|
17
|
+
exitCode = 1;
|
|
18
|
+
}
|
|
19
|
+
if (extraKeys && !await checkExtraKeys(translationFilesContents, sourceLocale)) {
|
|
20
|
+
exitCode = 1;
|
|
21
|
+
}
|
|
22
|
+
if (structuralEquality && !await checkStructuralEquality(translationFilesContents, sourceLocale)) {
|
|
23
|
+
exitCode = 1;
|
|
24
|
+
}
|
|
25
|
+
process.exit(exitCode);
|
|
29
26
|
}
|
package/src/vue_extractor.js
CHANGED
|
@@ -1,68 +1,58 @@
|
|
|
1
|
-
import { NodeTypes
|
|
2
|
-
import { parse } from
|
|
1
|
+
import { NodeTypes } from "@vue/compiler-core";
|
|
2
|
+
import { parse } from "vue/compiler-sfc";
|
|
3
3
|
function walk(node, visitor) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.filter((prop) => prop.type === NodeTypes.DIRECTIVE)
|
|
24
|
-
.filter(prop => !!prop.exp)
|
|
25
|
-
.forEach(prop => visitor(prop.exp));
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
node.children.forEach(n => walk(n, visitor));
|
|
29
|
-
}
|
|
4
|
+
if (typeof node !== "object" || node == null) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (node.type === NodeTypes.ROOT) {
|
|
8
|
+
node.children.forEach((n) => walk(n, visitor));
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (node.type !== NodeTypes.ELEMENT && node.type !== NodeTypes.COMPOUND_EXPRESSION && node.type !== NodeTypes.INTERPOLATION) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
visitor(node);
|
|
15
|
+
if (node.type === NodeTypes.INTERPOLATION) {
|
|
16
|
+
visitor(node.content);
|
|
17
|
+
} else if (node.type === NodeTypes.ELEMENT) {
|
|
18
|
+
node.children.forEach((n) => walk(n, visitor));
|
|
19
|
+
node.props.filter((prop) => prop.type === NodeTypes.DIRECTIVE).filter((prop) => !!prop.exp).forEach((prop) => visitor(prop.exp));
|
|
20
|
+
} else {
|
|
21
|
+
node.children.forEach((n) => walk(n, visitor));
|
|
22
|
+
}
|
|
30
23
|
}
|
|
31
24
|
function templateSimpleExpressionNodeVisitor(parseScriptFn) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
25
|
+
return (n) => {
|
|
26
|
+
if (typeof n !== "object") {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (n.type !== NodeTypes.SIMPLE_EXPRESSION) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const { content } = n;
|
|
33
|
+
// Wrap this in () since a vue comp node attribute can just be
|
|
34
|
+
// an object literal which, by itself is invalid TS
|
|
35
|
+
// but with () it becomes an ExpressionStatement
|
|
36
|
+
try {
|
|
37
|
+
parseScriptFn(`(${content})`);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.warn(`Failed to parse "${content}". Ignore this if content has no extractable message`, e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
50
42
|
}
|
|
51
43
|
export function parseFile(source, filename, parseScriptFn) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
parseScriptFn(scriptSetup.content);
|
|
67
|
-
}
|
|
44
|
+
const { descriptor, errors } = parse(source, { filename });
|
|
45
|
+
if (errors.length) {
|
|
46
|
+
throw errors[0];
|
|
47
|
+
}
|
|
48
|
+
const { script, scriptSetup, template } = descriptor;
|
|
49
|
+
if (template) {
|
|
50
|
+
walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn));
|
|
51
|
+
}
|
|
52
|
+
if (script) {
|
|
53
|
+
parseScriptFn(script.content);
|
|
54
|
+
}
|
|
55
|
+
if (scriptSetup) {
|
|
56
|
+
parseScriptFn(scriptSetup.content);
|
|
57
|
+
}
|
|
68
58
|
}
|