@formatjs/cli-lib 5.1.7 → 5.1.8

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 (80) hide show
  1. package/BUILD +118 -0
  2. package/CHANGELOG.md +1147 -0
  3. package/index.ts +7 -0
  4. package/main.ts +5 -0
  5. package/package.json +1 -1
  6. package/src/cli.ts +240 -0
  7. package/src/compile.ts +141 -0
  8. package/src/compile_folder.ts +15 -0
  9. package/src/console_utils.ts +78 -0
  10. package/src/extract.ts +273 -0
  11. package/src/formatters/crowdin.ts +34 -0
  12. package/src/formatters/default.ts +19 -0
  13. package/src/formatters/index.ts +46 -0
  14. package/src/formatters/lokalise.ts +33 -0
  15. package/src/formatters/simple.ts +12 -0
  16. package/src/formatters/smartling.ts +73 -0
  17. package/src/formatters/transifex.ts +33 -0
  18. package/src/parse_script.ts +49 -0
  19. package/src/pseudo_locale.ts +113 -0
  20. package/src/vue_extractor.ts +96 -0
  21. package/tests/unit/__snapshots__/pseudo_locale.test.ts.snap +24 -0
  22. package/tests/unit/__snapshots__/unit.test.ts.snap +42 -0
  23. package/tests/unit/__snapshots__/vue_extractor.test.ts.snap +36 -0
  24. package/tests/unit/fixtures/bind.vue +46 -0
  25. package/tests/unit/fixtures/comp.vue +17 -0
  26. package/tests/unit/pseudo_locale.test.ts +7 -0
  27. package/tests/unit/unit.test.ts +44 -0
  28. package/tests/unit/vue_extractor.test.ts +38 -0
  29. package/tsconfig.json +5 -0
  30. package/index.d.ts +0 -8
  31. package/index.d.ts.map +0 -1
  32. package/index.js +0 -12
  33. package/main.d.ts +0 -2
  34. package/main.d.ts.map +0 -1
  35. package/main.js +0 -3
  36. package/src/cli.d.ts +0 -3
  37. package/src/cli.d.ts.map +0 -1
  38. package/src/cli.js +0 -165
  39. package/src/compile.d.ts +0 -48
  40. package/src/compile.d.ts.map +0 -1
  41. package/src/compile.js +0 -97
  42. package/src/compile_folder.d.ts +0 -3
  43. package/src/compile_folder.d.ts.map +0 -1
  44. package/src/compile_folder.js +0 -11
  45. package/src/console_utils.d.ts +0 -10
  46. package/src/console_utils.d.ts.map +0 -1
  47. package/src/console_utils.js +0 -76
  48. package/src/extract.d.ts +0 -75
  49. package/src/extract.d.ts.map +0 -1
  50. package/src/extract.js +0 -177
  51. package/src/formatters/crowdin.d.ts +0 -8
  52. package/src/formatters/crowdin.d.ts.map +0 -1
  53. package/src/formatters/crowdin.js +0 -27
  54. package/src/formatters/default.d.ts +0 -6
  55. package/src/formatters/default.d.ts.map +0 -1
  56. package/src/formatters/default.js +0 -13
  57. package/src/formatters/index.d.ts +0 -9
  58. package/src/formatters/index.d.ts.map +0 -1
  59. package/src/formatters/index.js +0 -42
  60. package/src/formatters/lokalise.d.ts +0 -10
  61. package/src/formatters/lokalise.d.ts.map +0 -1
  62. package/src/formatters/lokalise.js +0 -24
  63. package/src/formatters/simple.d.ts +0 -5
  64. package/src/formatters/simple.d.ts.map +0 -1
  65. package/src/formatters/simple.js +0 -12
  66. package/src/formatters/smartling.d.ts +0 -24
  67. package/src/formatters/smartling.d.ts.map +0 -1
  68. package/src/formatters/smartling.js +0 -50
  69. package/src/formatters/transifex.d.ts +0 -10
  70. package/src/formatters/transifex.d.ts.map +0 -1
  71. package/src/formatters/transifex.js +0 -24
  72. package/src/parse_script.d.ts +0 -8
  73. package/src/parse_script.d.ts.map +0 -1
  74. package/src/parse_script.js +0 -51
  75. package/src/pseudo_locale.d.ts +0 -7
  76. package/src/pseudo_locale.d.ts.map +0 -1
  77. package/src/pseudo_locale.js +0 -100
  78. package/src/vue_extractor.d.ts +0 -3
  79. package/src/vue_extractor.d.ts.map +0 -1
  80. package/src/vue_extractor.js +0 -62
@@ -1,24 +0,0 @@
1
- import { Comparator } from 'json-stable-stringify';
2
- import { CompileFn, FormatFn } from './default';
3
- export interface SmartlingDirectives {
4
- translate_paths: [
5
- {
6
- path: string;
7
- key: string;
8
- instruction: string;
9
- }
10
- ];
11
- variants_enabled: boolean;
12
- string_format: string;
13
- [k: string]: any;
14
- }
15
- export type SmartlingJson = {
16
- smartling: SmartlingDirectives;
17
- } & Record<string, {
18
- message: string;
19
- description?: string;
20
- }>;
21
- export declare const format: FormatFn<SmartlingJson>;
22
- export declare const compareMessages: Comparator;
23
- export declare const compile: CompileFn<SmartlingJson>;
24
- //# sourceMappingURL=smartling.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"smartling.d.ts","sourceRoot":"","sources":["smartling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,WAAW,CAAA;AAE7C,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE;QACf;YACE,IAAI,EAAE,MAAM,CAAA;YACZ,GAAG,EAAE,MAAM,CAAA;YACX,WAAW,EAAE,MAAM,CAAA;SACpB;KACF,CAAA;IACD,gBAAgB,EAAE,OAAO,CAAA;IACzB,aAAa,EAAE,MAAM,CAAA;IACrB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CACjB;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,mBAAmB,CAAA;CAC/B,GAAG,MAAM,CACR,MAAM,EACN;IACE,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CACF,CAAA;AAED,eAAO,MAAM,MAAM,EAAE,QAAQ,CAAC,aAAa,CAwB1C,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,UAS7B,CAAA;AAED,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,aAAa,CAS5C,CAAA"}
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compile = exports.compareMessages = exports.format = void 0;
4
- const format = msgs => {
5
- const results = {
6
- smartling: {
7
- translate_paths: [
8
- {
9
- path: '*/message',
10
- key: '{*}/message',
11
- instruction: '*/description',
12
- },
13
- ],
14
- variants_enabled: true,
15
- string_format: 'icu',
16
- },
17
- };
18
- for (const [id, msg] of Object.entries(msgs)) {
19
- results[id] = {
20
- message: msg.defaultMessage,
21
- description: typeof msg.description === 'string'
22
- ? msg.description
23
- : JSON.stringify(msg.description),
24
- };
25
- }
26
- return results;
27
- };
28
- exports.format = format;
29
- const compareMessages = (el1, el2) => {
30
- // `smartling` has to be the 1st key
31
- if (el1.key === 'smartling') {
32
- return -1;
33
- }
34
- if (el2.key === 'smartling') {
35
- return 1;
36
- }
37
- return el1.key < el2.key ? -1 : el1.key === el2.key ? 0 : 1;
38
- };
39
- exports.compareMessages = compareMessages;
40
- const compile = msgs => {
41
- const results = {};
42
- for (const [id, msg] of Object.entries(msgs)) {
43
- if (id === 'smartling') {
44
- continue;
45
- }
46
- results[id] = msg.message;
47
- }
48
- return results;
49
- };
50
- exports.compile = compile;
@@ -1,10 +0,0 @@
1
- import { CompileFn, FormatFn } from './default';
2
- export type StructuredJson = Record<string, {
3
- string: string;
4
- developer_comment?: string;
5
- context?: string;
6
- character_limit?: string;
7
- }>;
8
- export declare const format: FormatFn<StructuredJson>;
9
- export declare const compile: CompileFn<StructuredJson>;
10
- //# sourceMappingURL=transifex.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transifex.d.ts","sourceRoot":"","sources":["transifex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,WAAW,CAAA;AAE7C,MAAM,MAAM,cAAc,GAAG,MAAM,CACjC,MAAM,EACN;IACE,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB,CACF,CAAA;AAED,eAAO,MAAM,MAAM,EAAE,QAAQ,CAAC,cAAc,CAY3C,CAAA;AAED,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,cAAc,CAM7C,CAAA"}
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compile = exports.format = void 0;
4
- const format = msgs => {
5
- const results = {};
6
- for (const [id, msg] of Object.entries(msgs)) {
7
- results[id] = {
8
- string: msg.defaultMessage,
9
- developer_comment: typeof msg.description === 'string'
10
- ? msg.description
11
- : JSON.stringify(msg.description),
12
- };
13
- }
14
- return results;
15
- };
16
- exports.format = format;
17
- const compile = msgs => {
18
- const results = {};
19
- for (const [id, msg] of Object.entries(msgs)) {
20
- results[id] = msg.string;
21
- }
22
- return results;
23
- };
24
- exports.compile = compile;
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse_script.d.ts","sourceRoot":"","sources":["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"}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseScript = void 0;
4
- const tslib_1 = require("tslib");
5
- const ts_transformer_1 = require("@formatjs/ts-transformer");
6
- const typescript_1 = tslib_1.__importDefault(require("typescript"));
7
- const console_utils_1 = require("./console_utils");
8
- /**
9
- * Invoid TypeScript module transpilation with our TS transformer
10
- * @param opts Formatjs TS Transformer opt
11
- * @param fn filename
12
- */
13
- function parseScript(opts, fn) {
14
- return (source) => {
15
- let output;
16
- try {
17
- (0, console_utils_1.debug)('Using TS compiler to process file', fn);
18
- output = typescript_1.default.transpileModule(source, {
19
- compilerOptions: {
20
- allowJs: true,
21
- target: typescript_1.default.ScriptTarget.ESNext,
22
- noEmit: true,
23
- experimentalDecorators: true,
24
- },
25
- reportDiagnostics: true,
26
- fileName: fn,
27
- transformers: {
28
- before: [(0, ts_transformer_1.transformWithTs)(typescript_1.default, opts)],
29
- },
30
- });
31
- }
32
- catch (e) {
33
- if (e instanceof Error) {
34
- e.message = `Error processing file ${fn}
35
- ${e.message || ''}`;
36
- }
37
- throw e;
38
- }
39
- if (output.diagnostics) {
40
- const errs = output.diagnostics.filter(d => d.category === typescript_1.default.DiagnosticCategory.Error);
41
- if (errs.length) {
42
- throw new Error(typescript_1.default.formatDiagnosticsWithColorAndContext(errs, {
43
- getCanonicalFileName: fileName => fileName,
44
- getCurrentDirectory: () => process.cwd(),
45
- getNewLine: () => typescript_1.default.sys.newLine,
46
- }));
47
- }
48
- }
49
- };
50
- }
51
- exports.parseScript = parseScript;
@@ -1,7 +0,0 @@
1
- import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
2
- export declare function generateXXLS(msg: string | MessageFormatElement[]): MessageFormatElement[];
3
- export declare function generateXXAC(msg: string | MessageFormatElement[]): MessageFormatElement[];
4
- export declare function generateXXHA(msg: string | MessageFormatElement[]): MessageFormatElement[];
5
- export declare function generateENXA(msg: string | MessageFormatElement[]): MessageFormatElement[];
6
- export declare function generateENXB(msg: string | MessageFormatElement[]): MessageFormatElement[];
7
- //# sourceMappingURL=pseudo_locale.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pseudo_locale.d.ts","sourceRoot":"","sources":["pseudo_locale.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EAMrB,MAAM,oCAAoC,CAAA;AAE3C,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAQxB;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAcxB;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAQxB;AAKD,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAuBxB;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CA4BxB"}
@@ -1,100 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateENXB = exports.generateENXA = exports.generateXXHA = exports.generateXXAC = exports.generateXXLS = void 0;
4
- const icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
5
- function generateXXLS(msg) {
6
- const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
7
- const lastChunk = ast.pop();
8
- if (lastChunk && (0, icu_messageformat_parser_1.isLiteralElement)(lastChunk)) {
9
- lastChunk.value += 'SSSSSSSSSSSSSSSSSSSSSSSSS';
10
- return [...ast, lastChunk];
11
- }
12
- return [...ast, { type: icu_messageformat_parser_1.TYPE.literal, value: 'SSSSSSSSSSSSSSSSSSSSSSSSS' }];
13
- }
14
- exports.generateXXLS = generateXXLS;
15
- function generateXXAC(msg) {
16
- const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
17
- ast.forEach(el => {
18
- if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
19
- el.value = el.value.toUpperCase();
20
- }
21
- else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
22
- for (const opt of Object.values(el.options)) {
23
- generateXXAC(opt.value);
24
- }
25
- }
26
- else if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
27
- generateXXAC(el.children);
28
- }
29
- });
30
- return ast;
31
- }
32
- exports.generateXXAC = generateXXAC;
33
- function generateXXHA(msg) {
34
- const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
35
- const firstChunk = ast.shift();
36
- if (firstChunk && (0, icu_messageformat_parser_1.isLiteralElement)(firstChunk)) {
37
- firstChunk.value = '[javascript]' + firstChunk.value;
38
- return [firstChunk, ...ast];
39
- }
40
- return [{ type: icu_messageformat_parser_1.TYPE.literal, value: '[javascript]' }, ...ast];
41
- }
42
- exports.generateXXHA = generateXXHA;
43
- const ASCII = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
44
- const ACCENTED_ASCII = 'âḃćḋèḟĝḫíĵǩĺṁńŏṗɋŕśṭůṿẘẋẏẓḀḂḈḊḔḞḠḢḬĴḴĻḾŊÕṔɊŔṠṮŨṼẄẌŸƵ';
45
- function generateENXA(msg) {
46
- const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
47
- ast.forEach(el => {
48
- if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
49
- el.value = el.value
50
- .split('')
51
- .map(c => {
52
- const i = ASCII.indexOf(c);
53
- if (i < 0) {
54
- return c;
55
- }
56
- return ACCENTED_ASCII[i];
57
- })
58
- .join('');
59
- }
60
- else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
61
- for (const opt of Object.values(el.options)) {
62
- generateENXA(opt.value);
63
- }
64
- }
65
- else if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
66
- generateENXA(el.children);
67
- }
68
- });
69
- return ast;
70
- }
71
- exports.generateENXA = generateENXA;
72
- function generateENXB(msg) {
73
- const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
74
- ast.forEach(el => {
75
- if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
76
- const pseudoString = el.value
77
- .split('')
78
- .map((c, index) => {
79
- const i = ASCII.indexOf(c);
80
- const canPad = (index + 1) % 3 === 0;
81
- if (i < 0) {
82
- return c;
83
- }
84
- return canPad ? ACCENTED_ASCII[i].repeat(3) : ACCENTED_ASCII[i];
85
- })
86
- .join('');
87
- el.value = `[!! ${pseudoString} !!]`;
88
- }
89
- else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
90
- for (const opt of Object.values(el.options)) {
91
- generateENXB(opt.value);
92
- }
93
- }
94
- else if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
95
- generateENXB(el.children);
96
- }
97
- });
98
- return ast;
99
- }
100
- exports.generateENXB = generateENXB;
@@ -1,3 +0,0 @@
1
- export type ScriptParseFn = (source: string) => void;
2
- export declare function parseFile(source: string, filename: string, parseScriptFn: ScriptParseFn): any;
3
- //# sourceMappingURL=vue_extractor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vue_extractor.d.ts","sourceRoot":"","sources":["vue_extractor.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;AA4DpD,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,aAAa,GAC3B,GAAG,CAoBL"}
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseFile = void 0;
4
- const compiler_sfc_1 = require("@vue/compiler-sfc");
5
- function walk(node, visitor) {
6
- if (typeof node !== 'object') {
7
- return;
8
- }
9
- if (node.type !== 1 /* NodeTypes.ELEMENT */ &&
10
- node.type !== 8 /* NodeTypes.COMPOUND_EXPRESSION */ &&
11
- node.type !== 5 /* NodeTypes.INTERPOLATION */) {
12
- return;
13
- }
14
- visitor(node);
15
- if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
16
- visitor(node.content);
17
- }
18
- else if (node.type === 1 /* NodeTypes.ELEMENT */) {
19
- node.children.forEach(n => walk(n, visitor));
20
- node.props
21
- .filter((prop) => prop.type === 7 /* NodeTypes.DIRECTIVE */)
22
- .filter(prop => !!prop.exp)
23
- .forEach(prop => visitor(prop.exp));
24
- }
25
- else {
26
- node.children.forEach(n => walk(n, visitor));
27
- }
28
- }
29
- function templateSimpleExpressionNodeVisitor(parseScriptFn) {
30
- return (n) => {
31
- if (typeof n !== 'object') {
32
- return;
33
- }
34
- if (n.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
35
- return;
36
- }
37
- const { content } = n;
38
- // Wrap this in () since a vue comp node attribute can just be
39
- // an object literal which, by itself is invalid TS
40
- // but with () it becomes an ExpressionStatement
41
- parseScriptFn(`(${content})`);
42
- };
43
- }
44
- function parseFile(source, filename, parseScriptFn) {
45
- const { descriptor, errors } = (0, compiler_sfc_1.parse)(source, {
46
- filename,
47
- });
48
- if (errors.length) {
49
- throw errors[0];
50
- }
51
- const { script, scriptSetup, template } = descriptor;
52
- if (template) {
53
- walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn));
54
- }
55
- if (script) {
56
- parseScriptFn(script.content);
57
- }
58
- if (scriptSetup) {
59
- parseScriptFn(scriptSetup.content);
60
- }
61
- }
62
- exports.parseFile = parseFile;