@formatjs/cli-lib 5.0.6 → 5.1.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.
Files changed (54) hide show
  1. package/LICENSE.md +0 -0
  2. package/README.md +0 -0
  3. package/index.d.ts +0 -0
  4. package/index.d.ts.map +1 -1
  5. package/index.js +0 -0
  6. package/main.d.ts +0 -0
  7. package/main.d.ts.map +1 -1
  8. package/main.js +0 -0
  9. package/package.json +61 -61
  10. package/src/cli.d.ts +0 -0
  11. package/src/cli.d.ts.map +1 -1
  12. package/src/cli.js +159 -136
  13. package/src/compile.d.ts +0 -0
  14. package/src/compile.d.ts.map +1 -1
  15. package/src/compile.js +72 -97
  16. package/src/compile_folder.d.ts +0 -0
  17. package/src/compile_folder.d.ts.map +1 -1
  18. package/src/compile_folder.js +7 -18
  19. package/src/console_utils.d.ts +1 -0
  20. package/src/console_utils.d.ts.map +1 -1
  21. package/src/console_utils.js +42 -107
  22. package/src/extract.d.ts +0 -0
  23. package/src/extract.d.ts.map +1 -1
  24. package/src/extract.js +145 -188
  25. package/src/formatters/crowdin.d.ts +0 -0
  26. package/src/formatters/crowdin.d.ts.map +1 -1
  27. package/src/formatters/crowdin.js +6 -8
  28. package/src/formatters/default.d.ts +0 -0
  29. package/src/formatters/default.d.ts.map +1 -1
  30. package/src/formatters/default.js +4 -4
  31. package/src/formatters/index.d.ts +0 -0
  32. package/src/formatters/index.d.ts.map +1 -1
  33. package/src/formatters/index.js +36 -41
  34. package/src/formatters/lokalise.d.ts +0 -0
  35. package/src/formatters/lokalise.d.ts.map +1 -1
  36. package/src/formatters/lokalise.js +6 -8
  37. package/src/formatters/simple.d.ts +0 -0
  38. package/src/formatters/simple.d.ts.map +1 -1
  39. package/src/formatters/simple.js +3 -3
  40. package/src/formatters/smartling.d.ts +0 -0
  41. package/src/formatters/smartling.d.ts.map +1 -1
  42. package/src/formatters/smartling.js +7 -9
  43. package/src/formatters/transifex.d.ts +0 -0
  44. package/src/formatters/transifex.d.ts.map +1 -1
  45. package/src/formatters/transifex.js +6 -8
  46. package/src/parse_script.d.ts +0 -0
  47. package/src/parse_script.d.ts.map +1 -1
  48. package/src/parse_script.js +12 -11
  49. package/src/pseudo_locale.d.ts +0 -0
  50. package/src/pseudo_locale.d.ts.map +1 -1
  51. package/src/pseudo_locale.js +27 -31
  52. package/src/vue_extractor.d.ts +0 -0
  53. package/src/vue_extractor.d.ts.map +1 -1
  54. package/src/vue_extractor.js +19 -19
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"transifex.d.ts","sourceRoot":"","sources":["../../../../../../../packages/cli-lib/src/formatters/transifex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,WAAW,CAAA;AAE7C,oBAAY,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
+ {"version":3,"file":"transifex.d.ts","sourceRoot":"","sources":["transifex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,WAAW,CAAA;AAE7C,oBAAY,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,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compile = exports.format = void 0;
4
- var format = function (msgs) {
5
- var results = {};
6
- for (var _i = 0, _a = Object.entries(msgs); _i < _a.length; _i++) {
7
- var _b = _a[_i], id = _b[0], msg = _b[1];
4
+ const format = msgs => {
5
+ const results = {};
6
+ for (const [id, msg] of Object.entries(msgs)) {
8
7
  results[id] = {
9
8
  string: msg.defaultMessage,
10
9
  developer_comment: typeof msg.description === 'string'
@@ -15,10 +14,9 @@ var format = function (msgs) {
15
14
  return results;
16
15
  };
17
16
  exports.format = format;
18
- var compile = function (msgs) {
19
- var results = {};
20
- for (var _i = 0, _a = Object.entries(msgs); _i < _a.length; _i++) {
21
- var _b = _a[_i], id = _b[0], msg = _b[1];
17
+ const compile = msgs => {
18
+ const results = {};
19
+ for (const [id, msg] of Object.entries(msgs)) {
22
20
  results[id] = msg.string;
23
21
  }
24
22
  return results;
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"parse_script.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli-lib/src/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
+ {"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,18 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScript = void 0;
4
- var tslib_1 = require("tslib");
5
- var ts_transformer_1 = require("@formatjs/ts-transformer");
6
- var typescript_1 = (0, tslib_1.__importDefault)(require("typescript"));
7
- var console_utils_1 = require("./console_utils");
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
8
  /**
9
9
  * Invoid TypeScript module transpilation with our TS transformer
10
10
  * @param opts Formatjs TS Transformer opt
11
11
  * @param fn filename
12
12
  */
13
13
  function parseScript(opts, fn) {
14
- return function (source) {
15
- var output;
14
+ return (source) => {
15
+ let output;
16
16
  try {
17
17
  (0, console_utils_1.debug)('Using TS compiler to process file', fn);
18
18
  output = typescript_1.default.transpileModule(source, {
@@ -31,17 +31,18 @@ function parseScript(opts, fn) {
31
31
  }
32
32
  catch (e) {
33
33
  if (e instanceof Error) {
34
- e.message = "Error processing file ".concat(fn, " \n").concat(e.message || '');
34
+ e.message = `Error processing file ${fn}
35
+ ${e.message || ''}`;
35
36
  }
36
37
  throw e;
37
38
  }
38
39
  if (output.diagnostics) {
39
- var errs = output.diagnostics.filter(function (d) { return d.category === typescript_1.default.DiagnosticCategory.Error; });
40
+ const errs = output.diagnostics.filter(d => d.category === typescript_1.default.DiagnosticCategory.Error);
40
41
  if (errs.length) {
41
42
  throw new Error(typescript_1.default.formatDiagnosticsWithColorAndContext(errs, {
42
- getCanonicalFileName: function (fileName) { return fileName; },
43
- getCurrentDirectory: function () { return process.cwd(); },
44
- getNewLine: function () { return typescript_1.default.sys.newLine; },
43
+ getCanonicalFileName: fileName => fileName,
44
+ getCurrentDirectory: () => process.cwd(),
45
+ getNewLine: () => typescript_1.default.sys.newLine,
45
46
  }));
46
47
  }
47
48
  }
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"pseudo_locale.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli-lib/src/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
+ {"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,27 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateENXB = exports.generateENXA = exports.generateXXHA = exports.generateXXAC = exports.generateXXLS = void 0;
4
- var tslib_1 = require("tslib");
5
- var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
4
+ const icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
6
5
  function generateXXLS(msg) {
7
- var ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
8
- var lastChunk = ast.pop();
6
+ const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
7
+ const lastChunk = ast.pop();
9
8
  if (lastChunk && (0, icu_messageformat_parser_1.isLiteralElement)(lastChunk)) {
10
9
  lastChunk.value += 'SSSSSSSSSSSSSSSSSSSSSSSSS';
11
- return (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], ast, true), [lastChunk], false);
10
+ return [...ast, lastChunk];
12
11
  }
13
- return (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], ast, true), [{ type: icu_messageformat_parser_1.TYPE.literal, value: 'SSSSSSSSSSSSSSSSSSSSSSSSS' }], false);
12
+ return [...ast, { type: icu_messageformat_parser_1.TYPE.literal, value: 'SSSSSSSSSSSSSSSSSSSSSSSSS' }];
14
13
  }
15
14
  exports.generateXXLS = generateXXLS;
16
15
  function generateXXAC(msg) {
17
- var ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
18
- ast.forEach(function (el) {
16
+ const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
17
+ ast.forEach(el => {
19
18
  if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
20
19
  el.value = el.value.toUpperCase();
21
20
  }
22
21
  else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
23
- for (var _i = 0, _a = Object.values(el.options); _i < _a.length; _i++) {
24
- var opt = _a[_i];
22
+ for (const opt of Object.values(el.options)) {
25
23
  generateXXAC(opt.value);
26
24
  }
27
25
  }
@@ -33,25 +31,25 @@ function generateXXAC(msg) {
33
31
  }
34
32
  exports.generateXXAC = generateXXAC;
35
33
  function generateXXHA(msg) {
36
- var ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
37
- var firstChunk = ast.shift();
34
+ const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
35
+ const firstChunk = ast.shift();
38
36
  if (firstChunk && (0, icu_messageformat_parser_1.isLiteralElement)(firstChunk)) {
39
37
  firstChunk.value = '[javascript]' + firstChunk.value;
40
- return (0, tslib_1.__spreadArray)([firstChunk], ast, true);
38
+ return [firstChunk, ...ast];
41
39
  }
42
- return (0, tslib_1.__spreadArray)([{ type: icu_messageformat_parser_1.TYPE.literal, value: '[javascript]' }], ast, true);
40
+ return [{ type: icu_messageformat_parser_1.TYPE.literal, value: '[javascript]' }, ...ast];
43
41
  }
44
42
  exports.generateXXHA = generateXXHA;
45
- var ASCII = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
46
- var ACCENTED_ASCII = 'âḃćḋèḟĝḫíĵǩĺṁńŏṗɋŕśṭůṿẘẋẏẓḀḂḈḊḔḞḠḢḬĴḴĻḾŊÕṔɊŔṠṮŨṼẄẌŸƵ';
43
+ const ASCII = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
44
+ const ACCENTED_ASCII = 'âḃćḋèḟĝḫíĵǩĺṁńŏṗɋŕśṭůṿẘẋẏẓḀḂḈḊḔḞḠḢḬĴḴĻḾŊÕṔɊŔṠṮŨṼẄẌŸƵ';
47
45
  function generateENXA(msg) {
48
- var ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
49
- ast.forEach(function (el) {
46
+ const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
47
+ ast.forEach(el => {
50
48
  if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
51
49
  el.value = el.value
52
50
  .split('')
53
- .map(function (c) {
54
- var i = ASCII.indexOf(c);
51
+ .map(c => {
52
+ const i = ASCII.indexOf(c);
55
53
  if (i < 0) {
56
54
  return c;
57
55
  }
@@ -60,8 +58,7 @@ function generateENXA(msg) {
60
58
  .join('');
61
59
  }
62
60
  else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
63
- for (var _i = 0, _a = Object.values(el.options); _i < _a.length; _i++) {
64
- var opt = _a[_i];
61
+ for (const opt of Object.values(el.options)) {
65
62
  generateENXA(opt.value);
66
63
  }
67
64
  }
@@ -73,25 +70,24 @@ function generateENXA(msg) {
73
70
  }
74
71
  exports.generateENXA = generateENXA;
75
72
  function generateENXB(msg) {
76
- var ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
77
- ast.forEach(function (el) {
73
+ const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
74
+ ast.forEach(el => {
78
75
  if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
79
- var pseudoString = el.value
76
+ const pseudoString = el.value
80
77
  .split('')
81
- .map(function (c, index) {
82
- var i = ASCII.indexOf(c);
83
- var canPad = (index + 1) % 3 === 0;
78
+ .map((c, index) => {
79
+ const i = ASCII.indexOf(c);
80
+ const canPad = (index + 1) % 3 === 0;
84
81
  if (i < 0) {
85
82
  return c;
86
83
  }
87
84
  return canPad ? ACCENTED_ASCII[i].repeat(3) : ACCENTED_ASCII[i];
88
85
  })
89
86
  .join('');
90
- el.value = "[!! ".concat(pseudoString, " !!]");
87
+ el.value = `[!! ${pseudoString} !!]`;
91
88
  }
92
89
  else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
93
- for (var _i = 0, _a = Object.values(el.options); _i < _a.length; _i++) {
94
- var opt = _a[_i];
90
+ for (const opt of Object.values(el.options)) {
95
91
  generateENXB(opt.value);
96
92
  }
97
93
  }
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"vue_extractor.d.ts","sourceRoot":"","sources":["../../../../../../packages/cli-lib/src/vue_extractor.ts"],"names":[],"mappings":"AAWA,oBAAY,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
+ {"version":3,"file":"vue_extractor.d.ts","sourceRoot":"","sources":["vue_extractor.ts"],"names":[],"mappings":"AAWA,oBAAY,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,54 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseFile = void 0;
4
- var compiler_sfc_1 = require("@vue/compiler-sfc");
4
+ const compiler_sfc_1 = require("@vue/compiler-sfc");
5
5
  function walk(node, visitor) {
6
6
  if (typeof node !== 'object') {
7
7
  return;
8
8
  }
9
- if (node.type !== 1 /* ELEMENT */ &&
10
- node.type !== 8 /* COMPOUND_EXPRESSION */ &&
11
- node.type !== 5 /* INTERPOLATION */) {
9
+ if (node.type !== 1 /* NodeTypes.ELEMENT */ &&
10
+ node.type !== 8 /* NodeTypes.COMPOUND_EXPRESSION */ &&
11
+ node.type !== 5 /* NodeTypes.INTERPOLATION */) {
12
12
  return;
13
13
  }
14
14
  visitor(node);
15
- if (node.type === 5 /* INTERPOLATION */) {
15
+ if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
16
16
  visitor(node.content);
17
17
  }
18
- else if (node.type === 1 /* ELEMENT */) {
19
- node.children.forEach(function (n) { return walk(n, visitor); });
18
+ else if (node.type === 1 /* NodeTypes.ELEMENT */) {
19
+ node.children.forEach(n => walk(n, visitor));
20
20
  node.props
21
- .filter(function (prop) { return prop.type === 7 /* DIRECTIVE */; })
22
- .filter(function (prop) { return !!prop.exp; })
23
- .forEach(function (prop) { return visitor(prop.exp); });
21
+ .filter((prop) => prop.type === 7 /* NodeTypes.DIRECTIVE */)
22
+ .filter(prop => !!prop.exp)
23
+ .forEach(prop => visitor(prop.exp));
24
24
  }
25
25
  else {
26
- node.children.forEach(function (n) { return walk(n, visitor); });
26
+ node.children.forEach(n => walk(n, visitor));
27
27
  }
28
28
  }
29
29
  function templateSimpleExpressionNodeVisitor(parseScriptFn) {
30
- return function (n) {
30
+ return (n) => {
31
31
  if (typeof n !== 'object') {
32
32
  return;
33
33
  }
34
- if (n.type !== 4 /* SIMPLE_EXPRESSION */) {
34
+ if (n.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
35
35
  return;
36
36
  }
37
- var content = n.content;
37
+ const { content } = n;
38
38
  // Wrap this in () since a vue comp node attribute can just be
39
39
  // an object literal which, by itself is invalid TS
40
40
  // but with () it becomes an ExpressionStatement
41
- parseScriptFn("(".concat(content, ")"));
41
+ parseScriptFn(`(${content})`);
42
42
  };
43
43
  }
44
44
  function parseFile(source, filename, parseScriptFn) {
45
- var _a = (0, compiler_sfc_1.parse)(source, {
46
- filename: filename,
47
- }), descriptor = _a.descriptor, errors = _a.errors;
45
+ const { descriptor, errors } = (0, compiler_sfc_1.parse)(source, {
46
+ filename,
47
+ });
48
48
  if (errors.length) {
49
49
  throw errors[0];
50
50
  }
51
- var script = descriptor.script, scriptSetup = descriptor.scriptSetup, template = descriptor.template;
51
+ const { script, scriptSetup, template } = descriptor;
52
52
  if (template) {
53
53
  walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn));
54
54
  }