ztxkutils 2.10.66-30 → 2.10.66-31

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 (55) hide show
  1. package/package.json +112 -112
  2. package/zti18n-cli/bin/index.js +3 -3
  3. package/zti18n-cli/index.js +23 -23
  4. package/zti18n-cli/src/command/collect.js +353 -353
  5. package/zti18n-cli/src/command/convert.js +17 -17
  6. package/zti18n-cli/src/command/convert2.js +35 -35
  7. package/zti18n-cli/src/command/initFileConf.js +133 -133
  8. package/zti18n-cli/src/command/publish.js +24 -24
  9. package/zti18n-cli/src/conf/BaseConf.js +21 -21
  10. package/zti18n-cli/src/conf/FileConf.js +116 -116
  11. package/zti18n-cli/src/index.js +75 -75
  12. package/zti18n-cli/src/translate/google.js +87 -87
  13. package/zti18n-cli/src/utils/isChinese.js +3 -3
  14. package/zti18n-cli/src/utils/log.js +8 -8
  15. package/zti18n-cli/src/utils/mergeOptions.js +45 -45
  16. package/zti18n-cli/src/utils/reactOptions.js +73 -73
  17. package/zti18n-cli/src/utils/vueOptions.js +69 -69
  18. package/zti18n-core/index.js +1 -1
  19. package/zti18n-core/src/index.js +5 -5
  20. package/zti18n-core/src/plugin/reactIntlToReactIntlUniversal.js +224 -224
  21. package/zti18n-core/src/plugin/reactIntlUniversalToDi18n.js +64 -64
  22. package/zti18n-core/src/transform/defaultPkMap.js +79 -79
  23. package/zti18n-core/src/transform/transformHtml.js +271 -271
  24. package/zti18n-core/src/transform/transformJs.js +489 -489
  25. package/zti18n-core/src/transform/transformPug.js +272 -272
  26. package/zti18n-core/src/transform/transformReactIntlToReactIntlUniversal.js +96 -96
  27. package/zti18n-core/src/transform/transformReactIntlUniveralToDi18n.js +90 -90
  28. package/zti18n-core/src/transform/transformToDi18n.js +22 -22
  29. package/zti18n-core/src/transform/transformTs.js +41 -41
  30. package/zti18n-core/src/transform/transformVue.js +126 -126
  31. package/zti18n-core/src/transform/transformZeroToDi18n.js +105 -105
  32. package/zti18n-core/src/translate/google.js +6 -6
  33. package/zti18n-core/src/utils/constants.js +3 -3
  34. package/zti18n-core/src/utils/getIgnoreLines.js +14 -14
  35. package/zti18n-core/src/utils/isChinese.js +3 -3
  36. package/zti18n-core/src/utils/log.js +8 -8
  37. package/dist/dataModel-1fbaff40.js +0 -24
  38. package/dist/dataModel-6c68c88f.js +0 -26
  39. package/dist/dataModel-914b6226.js +0 -26
  40. package/dist/dataModel-b3629ef3.js +0 -26
  41. package/dist/reqUrl-22b880a4.js +0 -82
  42. package/dist/request-1e442d5d.js +0 -2982
  43. package/dist/request-4c29d6de.js +0 -2977
  44. package/dist/request-80d1ac80.js +0 -2992
  45. package/dist/request-986d7090.js +0 -2923
  46. package/dist/request-c0970aae.js +0 -2917
  47. package/dist/request-d1972b41.js +0 -2992
  48. package/dist/request-d8d72b87.js +0 -2982
  49. package/dist/request-f600ad7a.js +0 -2992
  50. package/dist/tools-16a7fb45.js +0 -2446
  51. package/dist/validate-18e52490.js +0 -249
  52. package/dist/validate-21164759.js +0 -260
  53. package/dist/validate-21b58a69.js +0 -260
  54. package/dist/validate-2de5a28f.js +0 -260
  55. package/dist/validate-ab47ebe9.js +0 -260
@@ -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
+ };