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