ztxkutils 2.10.66-14 → 2.10.66-16

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 (82) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/{request-ba8abf99.js → request-588c90ec.js} +92 -18
  3. package/dist/{request-0cc024b1.js → request-dc69f021.js} +68 -13
  4. package/dist/request.js +1 -1
  5. package/package.json +1 -1
  6. package/zti18n-cli/bin/index.js +3 -3
  7. package/zti18n-cli/index.js +23 -23
  8. package/zti18n-cli/src/command/collect.js +351 -342
  9. package/zti18n-cli/src/command/convert.js +17 -17
  10. package/zti18n-cli/src/command/convert2.js +35 -35
  11. package/zti18n-cli/src/command/initFileConf.js +133 -133
  12. package/zti18n-cli/src/command/publish.js +24 -24
  13. package/zti18n-cli/src/conf/BaseConf.js +21 -21
  14. package/zti18n-cli/src/conf/FileConf.js +116 -116
  15. package/zti18n-cli/src/index.js +75 -75
  16. package/zti18n-cli/src/translate/google.js +6 -6
  17. package/zti18n-cli/src/utils/isChinese.js +3 -3
  18. package/zti18n-cli/src/utils/log.js +8 -8
  19. package/zti18n-cli/src/utils/mergeOptions.js +45 -45
  20. package/zti18n-cli/src/utils/reactOptions.js +73 -73
  21. package/zti18n-cli/src/utils/vueOptions.js +69 -69
  22. package/zti18n-core/index.js +1 -1
  23. package/zti18n-core/src/index.js +5 -5
  24. package/zti18n-core/src/plugin/reactIntlToReactIntlUniversal.js +224 -224
  25. package/zti18n-core/src/plugin/reactIntlUniversalToDi18n.js +64 -64
  26. package/zti18n-core/src/transform/defaultPkMap.js +79 -79
  27. package/zti18n-core/src/transform/transformHtml.js +271 -271
  28. package/zti18n-core/src/transform/transformJs.js +488 -488
  29. package/zti18n-core/src/transform/transformPug.js +272 -272
  30. package/zti18n-core/src/transform/transformReactIntlToReactIntlUniversal.js +96 -96
  31. package/zti18n-core/src/transform/transformReactIntlUniveralToDi18n.js +90 -90
  32. package/zti18n-core/src/transform/transformToDi18n.js +22 -22
  33. package/zti18n-core/src/transform/transformTs.js +41 -41
  34. package/zti18n-core/src/transform/transformVue.js +126 -126
  35. package/zti18n-core/src/transform/transformZeroToDi18n.js +105 -105
  36. package/zti18n-core/src/translate/google.js +6 -6
  37. package/zti18n-core/src/utils/constants.js +3 -3
  38. package/zti18n-core/src/utils/getIgnoreLines.js +14 -14
  39. package/zti18n-core/src/utils/isChinese.js +3 -3
  40. package/zti18n-core/src/utils/log.js +8 -8
  41. package/dist/authority-e6bde99f.js +0 -423
  42. package/dist/reqUrl-3792afcd.js +0 -82
  43. package/dist/reqUrl-787dd9e5.js +0 -82
  44. package/dist/request-ef290b9a.js +0 -2838
  45. package/dist/tools-09a4d620.js +0 -2445
  46. package/dist/tools-0ca888cd.js +0 -2473
  47. package/dist/validate-6e735536.js +0 -79
  48. package/dist/zti18n-cli/bin/index.d.ts +0 -2
  49. package/dist/zti18n-cli/index.d.ts +0 -1
  50. package/dist/zti18n-cli/src/command/collect.d.ts +0 -2
  51. package/dist/zti18n-cli/src/command/convert.d.ts +0 -2
  52. package/dist/zti18n-cli/src/command/convert2.d.ts +0 -2
  53. package/dist/zti18n-cli/src/command/initFileConf.d.ts +0 -2
  54. package/dist/zti18n-cli/src/command/publish.d.ts +0 -2
  55. package/dist/zti18n-cli/src/conf/BaseConf.d.ts +0 -8
  56. package/dist/zti18n-cli/src/conf/FileConf.d.ts +0 -6
  57. package/dist/zti18n-cli/src/index.d.ts +0 -1
  58. package/dist/zti18n-cli/src/translate/google.d.ts +0 -2
  59. package/dist/zti18n-cli/src/utils/isChinese.d.ts +0 -2
  60. package/dist/zti18n-cli/src/utils/log.d.ts +0 -4
  61. package/dist/zti18n-cli/src/utils/mergeOptions.d.ts +0 -24
  62. package/dist/zti18n-cli/src/utils/reactOptions.d.ts +0 -21
  63. package/dist/zti18n-cli/src/utils/vueOptions.d.ts +0 -17
  64. package/dist/zti18n-core/index.d.ts +0 -2
  65. package/dist/zti18n-core/src/index.d.ts +0 -8
  66. package/dist/zti18n-core/src/plugin/reactIntlToReactIntlUniversal.d.ts +0 -19
  67. package/dist/zti18n-core/src/plugin/reactIntlUniversalToDi18n.d.ts +0 -9
  68. package/dist/zti18n-core/src/transform/defaultPkMap.d.ts +0 -75
  69. package/dist/zti18n-core/src/transform/transformHtml.d.ts +0 -5
  70. package/dist/zti18n-core/src/transform/transformJs.d.ts +0 -5
  71. package/dist/zti18n-core/src/transform/transformPug.d.ts +0 -5
  72. package/dist/zti18n-core/src/transform/transformReactIntlToReactIntlUniversal.d.ts +0 -2
  73. package/dist/zti18n-core/src/transform/transformReactIntlUniveralToDi18n.d.ts +0 -2
  74. package/dist/zti18n-core/src/transform/transformToDi18n.d.ts +0 -5
  75. package/dist/zti18n-core/src/transform/transformTs.d.ts +0 -5
  76. package/dist/zti18n-core/src/transform/transformVue.d.ts +0 -5
  77. package/dist/zti18n-core/src/transform/transformZeroToDi18n.d.ts +0 -2
  78. package/dist/zti18n-core/src/translate/google.d.ts +0 -2
  79. package/dist/zti18n-core/src/utils/constants.d.ts +0 -3
  80. package/dist/zti18n-core/src/utils/getIgnoreLines.d.ts +0 -2
  81. package/dist/zti18n-core/src/utils/isChinese.d.ts +0 -2
  82. package/dist/zti18n-core/src/utils/log.d.ts +0 -4
@@ -1,96 +1,96 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const glob = require('glob');
4
- const prettier = require('prettier');
5
- const babel = require('@babel/core');
6
- const pluginSyntaxJSX = require('@babel/plugin-syntax-jsx');
7
- const pluginSyntaxProposalOptionalChaining = require('@babel/plugin-proposal-optional-chaining');
8
- const pluginSyntaxClassProperties = require('@babel/plugin-syntax-class-properties');
9
- const pluginSyntaxDecorators = require('@babel/plugin-syntax-decorators');
10
- const pluginSyntaxObjectRestSpread = require('@babel/plugin-syntax-object-rest-spread');
11
- const pluginSyntaxAsyncGenerators = require('@babel/plugin-syntax-async-generators');
12
- const pluginSyntaxDoExpressions = require('@babel/plugin-syntax-do-expressions');
13
- const pluginSyntaxDynamicImport = require('@babel/plugin-syntax-dynamic-import');
14
- const pluginSyntaxFunctionBind = require('@babel/plugin-syntax-function-bind');
15
- const reactIntlToReactIntlUniversal = require('../plugin/reactIntlToReactIntlUniversal');
16
- const log = require('../utils/log');
17
-
18
- function getSourceFiles({ path, exclude }) {
19
- return glob.sync(`${path}/**/*.{js,jsx}`, {
20
- ignore: exclude || [],
21
- });
22
- }
23
-
24
- function getLocaleFiles({ path, exclude }) {
25
- return glob.sync(`${path}/**/zh-CN.{js,json}`, {
26
- ignore: exclude || [],
27
- });
28
- }
29
-
30
- /**
31
- * 代码转换为使用 react-intl-universal 版本
32
- * @param {object} option 命令行或者配置文件中传入的参数信息
33
- */
34
- module.exports = function transformReactIntlToReactIntlUniversal(option) {
35
- const { entry, localeConf, exclude, importCode } = option;
36
-
37
- const targetFiles = getSourceFiles({ path: entry, exclude });
38
- const targetLocales = getLocaleFiles({ path: localeConf.folder, exclude });
39
-
40
- let zhData = {};
41
-
42
- targetLocales.forEach((element) => {
43
- if (path.extname(element) === '.json') {
44
- const json = fs.readFileSync(element, {
45
- encoding: 'utf-8',
46
- });
47
- zhData = JSON.parse(json);
48
- } else if (path.extname(element) === '.js') {
49
- zhData = require(path.resolve(path.resolve(), element));
50
- }
51
- });
52
-
53
- function transformFile(filePath) {
54
- let outObj = {
55
- hasReactIntlUniversal: false,
56
- needRewrite: false,
57
- };
58
-
59
- const transformOptions = {
60
- babelrc: false,
61
- sourceType: 'module',
62
- plugins: [
63
- pluginSyntaxJSX,
64
- pluginSyntaxProposalOptionalChaining,
65
- pluginSyntaxClassProperties,
66
- [pluginSyntaxDecorators, { legacy: true }],
67
- pluginSyntaxObjectRestSpread,
68
- pluginSyntaxAsyncGenerators,
69
- pluginSyntaxDoExpressions,
70
- pluginSyntaxDynamicImport,
71
- pluginSyntaxFunctionBind,
72
- reactIntlToReactIntlUniversal(zhData, outObj),
73
- ],
74
- generatorOpts: {},
75
- };
76
-
77
- const bableObj = babel.transformFileSync(filePath, transformOptions);
78
- let { code } = bableObj;
79
-
80
- if (outObj.needRewrite) {
81
- if (!outObj.hasReactIntlUniversal) {
82
- code = importCode + '\n' + code;
83
- }
84
-
85
- code = prettier.format(code, option.prettier);
86
-
87
- fs.writeFileSync(filePath, code, { encoding: 'utf-8' });
88
- }
89
- }
90
-
91
- targetFiles.forEach((element) => {
92
- log.info(`start: ${element}`);
93
- transformFile(element);
94
- log.success(`done: ${element}`);
95
- });
96
- };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const glob = require('glob');
4
+ const prettier = require('prettier');
5
+ const babel = require('@babel/core');
6
+ const pluginSyntaxJSX = require('@babel/plugin-syntax-jsx');
7
+ const pluginSyntaxProposalOptionalChaining = require('@babel/plugin-proposal-optional-chaining');
8
+ const pluginSyntaxClassProperties = require('@babel/plugin-syntax-class-properties');
9
+ const pluginSyntaxDecorators = require('@babel/plugin-syntax-decorators');
10
+ const pluginSyntaxObjectRestSpread = require('@babel/plugin-syntax-object-rest-spread');
11
+ const pluginSyntaxAsyncGenerators = require('@babel/plugin-syntax-async-generators');
12
+ const pluginSyntaxDoExpressions = require('@babel/plugin-syntax-do-expressions');
13
+ const pluginSyntaxDynamicImport = require('@babel/plugin-syntax-dynamic-import');
14
+ const pluginSyntaxFunctionBind = require('@babel/plugin-syntax-function-bind');
15
+ const reactIntlToReactIntlUniversal = require('../plugin/reactIntlToReactIntlUniversal');
16
+ const log = require('../utils/log');
17
+
18
+ function getSourceFiles({ path, exclude }) {
19
+ return glob.sync(`${path}/**/*.{js,jsx}`, {
20
+ ignore: exclude || [],
21
+ });
22
+ }
23
+
24
+ function getLocaleFiles({ path, exclude }) {
25
+ return glob.sync(`${path}/**/zh-CN.{js,json}`, {
26
+ ignore: exclude || [],
27
+ });
28
+ }
29
+
30
+ /**
31
+ * 代码转换为使用 react-intl-universal 版本
32
+ * @param {object} option 命令行或者配置文件中传入的参数信息
33
+ */
34
+ module.exports = function transformReactIntlToReactIntlUniversal(option) {
35
+ const { entry, localeConf, exclude, importCode } = option;
36
+
37
+ const targetFiles = getSourceFiles({ path: entry, exclude });
38
+ const targetLocales = getLocaleFiles({ path: localeConf.folder, exclude });
39
+
40
+ let zhData = {};
41
+
42
+ targetLocales.forEach((element) => {
43
+ if (path.extname(element) === '.json') {
44
+ const json = fs.readFileSync(element, {
45
+ encoding: 'utf-8',
46
+ });
47
+ zhData = JSON.parse(json);
48
+ } else if (path.extname(element) === '.js') {
49
+ zhData = require(path.resolve(path.resolve(), element));
50
+ }
51
+ });
52
+
53
+ function transformFile(filePath) {
54
+ let outObj = {
55
+ hasReactIntlUniversal: false,
56
+ needRewrite: false,
57
+ };
58
+
59
+ const transformOptions = {
60
+ babelrc: false,
61
+ sourceType: 'module',
62
+ plugins: [
63
+ pluginSyntaxJSX,
64
+ pluginSyntaxProposalOptionalChaining,
65
+ pluginSyntaxClassProperties,
66
+ [pluginSyntaxDecorators, { legacy: true }],
67
+ pluginSyntaxObjectRestSpread,
68
+ pluginSyntaxAsyncGenerators,
69
+ pluginSyntaxDoExpressions,
70
+ pluginSyntaxDynamicImport,
71
+ pluginSyntaxFunctionBind,
72
+ reactIntlToReactIntlUniversal(zhData, outObj),
73
+ ],
74
+ generatorOpts: {},
75
+ };
76
+
77
+ const bableObj = babel.transformFileSync(filePath, transformOptions);
78
+ let { code } = bableObj;
79
+
80
+ if (outObj.needRewrite) {
81
+ if (!outObj.hasReactIntlUniversal) {
82
+ code = importCode + '\n' + code;
83
+ }
84
+
85
+ code = prettier.format(code, option.prettier);
86
+
87
+ fs.writeFileSync(filePath, code, { encoding: 'utf-8' });
88
+ }
89
+ }
90
+
91
+ targetFiles.forEach((element) => {
92
+ log.info(`start: ${element}`);
93
+ transformFile(element);
94
+ log.success(`done: ${element}`);
95
+ });
96
+ };
@@ -1,90 +1,90 @@
1
- const glob = require('glob');
2
- const fs = require('fs');
3
- const prettier = require('prettier');
4
- const babel = require('@babel/core');
5
- const pluginSyntaxJSX = require('@babel/plugin-syntax-jsx');
6
- const pluginSyntaxProposalOptionalChaining = require('@babel/plugin-proposal-optional-chaining');
7
- const pluginSyntaxClassProperties = require('@babel/plugin-syntax-class-properties');
8
- const pluginSyntaxDecorators = require('@babel/plugin-syntax-decorators');
9
- const pluginSyntaxObjectRestSpread = require('@babel/plugin-syntax-object-rest-spread');
10
- const pluginSyntaxAsyncGenerators = require('@babel/plugin-syntax-async-generators');
11
- const pluginSyntaxDoExpressions = require('@babel/plugin-syntax-do-expressions');
12
- const pluginSyntaxDynamicImport = require('@babel/plugin-syntax-dynamic-import');
13
- const pluginSyntaxFunctionBind = require('@babel/plugin-syntax-function-bind');
14
- const getConvert2Plugin = require('../plugin/reactIntlUniversalToDi18n');
15
- const log = require('../utils/log');
16
-
17
- function getSourceFiles({ entry, exclude }) {
18
- return glob.sync(`${entry}/**/*.{js,jsx}`, {
19
- ignore: exclude || [],
20
- });
21
- }
22
-
23
- function translate(codeFileInfo, allConverted, option) {
24
- const { filePath, currentEntry, currentOutput } = codeFileInfo;
25
- const { intlAlias } = option;
26
-
27
- const sourceCode = fs.readFileSync(filePath, 'utf8');
28
-
29
- let outObj = {
30
- translateWordsNum: 0,
31
- };
32
-
33
- const transformOptions = {
34
- sourceType: 'module',
35
- plugins: [
36
- pluginSyntaxJSX,
37
- pluginSyntaxProposalOptionalChaining,
38
- pluginSyntaxClassProperties,
39
- [pluginSyntaxDecorators, { legacy: true }],
40
- pluginSyntaxObjectRestSpread,
41
- pluginSyntaxAsyncGenerators,
42
- pluginSyntaxDoExpressions,
43
- pluginSyntaxDynamicImport,
44
- pluginSyntaxFunctionBind,
45
- getConvert2Plugin(outObj, allConverted, intlAlias),
46
- ],
47
- generatorOpts: {},
48
- };
49
-
50
- const bableObj = babel.transform(sourceCode, transformOptions);
51
- let { code } = bableObj;
52
-
53
- if (outObj.translateWordsNum > 0) {
54
- code = prettier.format(code, option.prettier);
55
-
56
- const target = currentOutput
57
- ? filePath.replace(currentEntry, currentOutput)
58
- : filePath;
59
- fs.writeFileSync(target, code, { encoding: 'utf-8' });
60
- log.success(`done: ${outObj.translateWordsNum} words collected`);
61
- }
62
- }
63
-
64
- module.exports = function transformReactIntlUniveralToDi18n(option) {
65
- const { entry, output, exclude } = option;
66
-
67
- if (!Array.isArray(entry) && typeof entry !== 'string') {
68
- log.error('entry must be a string or array');
69
- process.exit(2);
70
- }
71
-
72
- const allConverted = {};
73
-
74
- const outputs = output ? [].concat(output) : [];
75
- const targetFiles = [].concat(entry).reduce((prev, cur, index) => {
76
- const files = getSourceFiles({ entry: cur, exclude }).map((file) => ({
77
- filePath: file,
78
- currentEntry: cur,
79
- currentOutput: outputs[index],
80
- }));
81
- return prev.concat(files);
82
- }, []);
83
-
84
- targetFiles.forEach((codeFileInfo) => {
85
- translate(codeFileInfo, allConverted, option);
86
- log.success(`done: ${codeFileInfo.filePath}`);
87
- });
88
-
89
- return allConverted;
90
- };
1
+ const glob = require('glob');
2
+ const fs = require('fs');
3
+ const prettier = require('prettier');
4
+ const babel = require('@babel/core');
5
+ const pluginSyntaxJSX = require('@babel/plugin-syntax-jsx');
6
+ const pluginSyntaxProposalOptionalChaining = require('@babel/plugin-proposal-optional-chaining');
7
+ const pluginSyntaxClassProperties = require('@babel/plugin-syntax-class-properties');
8
+ const pluginSyntaxDecorators = require('@babel/plugin-syntax-decorators');
9
+ const pluginSyntaxObjectRestSpread = require('@babel/plugin-syntax-object-rest-spread');
10
+ const pluginSyntaxAsyncGenerators = require('@babel/plugin-syntax-async-generators');
11
+ const pluginSyntaxDoExpressions = require('@babel/plugin-syntax-do-expressions');
12
+ const pluginSyntaxDynamicImport = require('@babel/plugin-syntax-dynamic-import');
13
+ const pluginSyntaxFunctionBind = require('@babel/plugin-syntax-function-bind');
14
+ const getConvert2Plugin = require('../plugin/reactIntlUniversalToDi18n');
15
+ const log = require('../utils/log');
16
+
17
+ function getSourceFiles({ entry, exclude }) {
18
+ return glob.sync(`${entry}/**/*.{js,jsx}`, {
19
+ ignore: exclude || [],
20
+ });
21
+ }
22
+
23
+ function translate(codeFileInfo, allConverted, option) {
24
+ const { filePath, currentEntry, currentOutput } = codeFileInfo;
25
+ const { intlAlias } = option;
26
+
27
+ const sourceCode = fs.readFileSync(filePath, 'utf8');
28
+
29
+ let outObj = {
30
+ translateWordsNum: 0,
31
+ };
32
+
33
+ const transformOptions = {
34
+ sourceType: 'module',
35
+ plugins: [
36
+ pluginSyntaxJSX,
37
+ pluginSyntaxProposalOptionalChaining,
38
+ pluginSyntaxClassProperties,
39
+ [pluginSyntaxDecorators, { legacy: true }],
40
+ pluginSyntaxObjectRestSpread,
41
+ pluginSyntaxAsyncGenerators,
42
+ pluginSyntaxDoExpressions,
43
+ pluginSyntaxDynamicImport,
44
+ pluginSyntaxFunctionBind,
45
+ getConvert2Plugin(outObj, allConverted, intlAlias),
46
+ ],
47
+ generatorOpts: {},
48
+ };
49
+
50
+ const bableObj = babel.transform(sourceCode, transformOptions);
51
+ let { code } = bableObj;
52
+
53
+ if (outObj.translateWordsNum > 0) {
54
+ code = prettier.format(code, option.prettier);
55
+
56
+ const target = currentOutput
57
+ ? filePath.replace(currentEntry, currentOutput)
58
+ : filePath;
59
+ fs.writeFileSync(target, code, { encoding: 'utf-8' });
60
+ log.success(`done: ${outObj.translateWordsNum} words collected`);
61
+ }
62
+ }
63
+
64
+ module.exports = function transformReactIntlUniveralToDi18n(option) {
65
+ const { entry, output, exclude } = option;
66
+
67
+ if (!Array.isArray(entry) && typeof entry !== 'string') {
68
+ log.error('entry must be a string or array');
69
+ process.exit(2);
70
+ }
71
+
72
+ const allConverted = {};
73
+
74
+ const outputs = output ? [].concat(output) : [];
75
+ const targetFiles = [].concat(entry).reduce((prev, cur, index) => {
76
+ const files = getSourceFiles({ entry: cur, exclude }).map((file) => ({
77
+ filePath: file,
78
+ currentEntry: cur,
79
+ currentOutput: outputs[index],
80
+ }));
81
+ return prev.concat(files);
82
+ }, []);
83
+
84
+ targetFiles.forEach((codeFileInfo) => {
85
+ translate(codeFileInfo, allConverted, option);
86
+ log.success(`done: ${codeFileInfo.filePath}`);
87
+ });
88
+
89
+ return allConverted;
90
+ };
@@ -1,22 +1,22 @@
1
- const transformTs = require('./transformTs');
2
- const transformJs = require('./transformJs');
3
- const transformVue = require('./transformVue');
4
- const { REACT_JS, REACT_TS, VUE } = require('../utils/constants');
5
-
6
- module.exports = function transformDi18n(
7
- source,
8
- sourceType,
9
- localeInfo,
10
- options
11
- ) {
12
- switch (sourceType) {
13
- case REACT_JS:
14
- return transformJs(source, localeInfo, options);
15
- case REACT_TS:
16
- return transformTs(source, localeInfo, options);
17
- case VUE:
18
- return transformVue(source, localeInfo, options);
19
- default:
20
- throw new Error(`Unsupport sourceType: ${sourceType}`);
21
- }
22
- };
1
+ const transformTs = require('./transformTs');
2
+ const transformJs = require('./transformJs');
3
+ const transformVue = require('./transformVue');
4
+ const { REACT_JS, REACT_TS, VUE } = require('../utils/constants');
5
+
6
+ module.exports = function transformDi18n(
7
+ source,
8
+ sourceType,
9
+ localeInfo,
10
+ options
11
+ ) {
12
+ switch (sourceType) {
13
+ case REACT_JS:
14
+ return transformJs(source, localeInfo, options);
15
+ case REACT_TS:
16
+ return transformTs(source, localeInfo, options);
17
+ case VUE:
18
+ return transformVue(source, localeInfo, options);
19
+ default:
20
+ throw new Error(`Unsupport sourceType: ${sourceType}`);
21
+ }
22
+ };
@@ -1,41 +1,41 @@
1
- const presetTypescript = require('@babel/preset-typescript').default;
2
- const transformJs = require('./transformJs');
3
-
4
- module.exports = function transformTs(code, localeInfo = {}, options = {}) {
5
- const { allTranslated = {}, allUpdated = {}, allUsedKeys = [] } = localeInfo;
6
-
7
- const {
8
- primaryRegx = /[\u4e00-\u9fa5]/,
9
- i18nObject = 'intl',
10
- i18nMethod = 't',
11
- importCode = "import { intl } from 'di18n-react';",
12
- babelPresets = [],
13
- babelPlugins = [],
14
- ignoreComponents = [],
15
- ignoreMethods = [],
16
- ignoreAttributes = ['style', 'className'],
17
- } = options;
18
-
19
- return transformJs(
20
- code,
21
- {
22
- allTranslated,
23
- allUpdated,
24
- allUsedKeys,
25
- },
26
- {
27
- primaryRegx,
28
- i18nObject,
29
- i18nMethod,
30
- importCode,
31
- babelPresets: [
32
- ...babelPresets,
33
- [presetTypescript, { isTSX: true, allExtensions: true }],
34
- ],
35
- babelPlugins,
36
- ignoreComponents,
37
- ignoreMethods,
38
- ignoreAttributes,
39
- }
40
- );
41
- };
1
+ const presetTypescript = require('@babel/preset-typescript').default;
2
+ const transformJs = require('./transformJs');
3
+
4
+ module.exports = function transformTs(code, localeInfo = {}, options = {}) {
5
+ const { allTranslated = {}, allUpdated = {}, allUsedKeys = [] } = localeInfo;
6
+
7
+ const {
8
+ primaryRegx = /[\u4e00-\u9fa5]/,
9
+ i18nObject = 'intl',
10
+ i18nMethod = 't',
11
+ importCode = "import { intl } from 'di18n-react';",
12
+ babelPresets = [],
13
+ babelPlugins = [],
14
+ ignoreComponents = [],
15
+ ignoreMethods = [],
16
+ ignoreAttributes = ['style', 'className'],
17
+ } = options;
18
+
19
+ return transformJs(
20
+ code,
21
+ {
22
+ allTranslated,
23
+ allUpdated,
24
+ allUsedKeys,
25
+ },
26
+ {
27
+ primaryRegx,
28
+ i18nObject,
29
+ i18nMethod,
30
+ importCode,
31
+ babelPresets: [
32
+ ...babelPresets,
33
+ [presetTypescript, { isTSX: true, allExtensions: true }],
34
+ ],
35
+ babelPlugins,
36
+ ignoreComponents,
37
+ ignoreMethods,
38
+ ignoreAttributes,
39
+ }
40
+ );
41
+ };