ztxkutils 2.10.66-15 → 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 (79) 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/convert.js +17 -17
  9. package/zti18n-cli/src/command/convert2.js +35 -35
  10. package/zti18n-cli/src/command/initFileConf.js +133 -133
  11. package/zti18n-cli/src/command/publish.js +24 -24
  12. package/zti18n-cli/src/conf/BaseConf.js +21 -21
  13. package/zti18n-cli/src/conf/FileConf.js +116 -116
  14. package/zti18n-cli/src/index.js +75 -75
  15. package/zti18n-cli/src/translate/google.js +6 -6
  16. package/zti18n-cli/src/utils/isChinese.js +3 -3
  17. package/zti18n-cli/src/utils/log.js +8 -8
  18. package/zti18n-cli/src/utils/mergeOptions.js +45 -45
  19. package/zti18n-cli/src/utils/reactOptions.js +73 -73
  20. package/zti18n-cli/src/utils/vueOptions.js +69 -69
  21. package/zti18n-core/index.js +1 -1
  22. package/zti18n-core/src/index.js +5 -5
  23. package/zti18n-core/src/plugin/reactIntlToReactIntlUniversal.js +224 -224
  24. package/zti18n-core/src/plugin/reactIntlUniversalToDi18n.js +64 -64
  25. package/zti18n-core/src/transform/defaultPkMap.js +79 -79
  26. package/zti18n-core/src/transform/transformHtml.js +271 -271
  27. package/zti18n-core/src/transform/transformPug.js +272 -272
  28. package/zti18n-core/src/transform/transformReactIntlToReactIntlUniversal.js +96 -96
  29. package/zti18n-core/src/transform/transformReactIntlUniveralToDi18n.js +90 -90
  30. package/zti18n-core/src/transform/transformToDi18n.js +22 -22
  31. package/zti18n-core/src/transform/transformTs.js +41 -41
  32. package/zti18n-core/src/transform/transformVue.js +126 -126
  33. package/zti18n-core/src/translate/google.js +6 -6
  34. package/zti18n-core/src/utils/constants.js +3 -3
  35. package/zti18n-core/src/utils/getIgnoreLines.js +14 -14
  36. package/zti18n-core/src/utils/isChinese.js +3 -3
  37. package/zti18n-core/src/utils/log.js +8 -8
  38. package/dist/authority-e6bde99f.js +0 -423
  39. package/dist/reqUrl-3792afcd.js +0 -82
  40. package/dist/reqUrl-787dd9e5.js +0 -82
  41. package/dist/request-ef290b9a.js +0 -2838
  42. package/dist/tools-09a4d620.js +0 -2445
  43. package/dist/tools-0ca888cd.js +0 -2473
  44. package/dist/validate-6e735536.js +0 -79
  45. package/dist/zti18n-cli/bin/index.d.ts +0 -2
  46. package/dist/zti18n-cli/index.d.ts +0 -1
  47. package/dist/zti18n-cli/src/command/collect.d.ts +0 -2
  48. package/dist/zti18n-cli/src/command/convert.d.ts +0 -2
  49. package/dist/zti18n-cli/src/command/convert2.d.ts +0 -2
  50. package/dist/zti18n-cli/src/command/initFileConf.d.ts +0 -2
  51. package/dist/zti18n-cli/src/command/publish.d.ts +0 -2
  52. package/dist/zti18n-cli/src/conf/BaseConf.d.ts +0 -8
  53. package/dist/zti18n-cli/src/conf/FileConf.d.ts +0 -6
  54. package/dist/zti18n-cli/src/index.d.ts +0 -1
  55. package/dist/zti18n-cli/src/translate/google.d.ts +0 -2
  56. package/dist/zti18n-cli/src/utils/isChinese.d.ts +0 -2
  57. package/dist/zti18n-cli/src/utils/log.d.ts +0 -4
  58. package/dist/zti18n-cli/src/utils/mergeOptions.d.ts +0 -24
  59. package/dist/zti18n-cli/src/utils/reactOptions.d.ts +0 -21
  60. package/dist/zti18n-cli/src/utils/vueOptions.d.ts +0 -17
  61. package/dist/zti18n-core/index.d.ts +0 -2
  62. package/dist/zti18n-core/src/index.d.ts +0 -8
  63. package/dist/zti18n-core/src/plugin/reactIntlToReactIntlUniversal.d.ts +0 -19
  64. package/dist/zti18n-core/src/plugin/reactIntlUniversalToDi18n.d.ts +0 -9
  65. package/dist/zti18n-core/src/transform/defaultPkMap.d.ts +0 -75
  66. package/dist/zti18n-core/src/transform/transformHtml.d.ts +0 -5
  67. package/dist/zti18n-core/src/transform/transformJs.d.ts +0 -5
  68. package/dist/zti18n-core/src/transform/transformPug.d.ts +0 -5
  69. package/dist/zti18n-core/src/transform/transformReactIntlToReactIntlUniversal.d.ts +0 -2
  70. package/dist/zti18n-core/src/transform/transformReactIntlUniveralToDi18n.d.ts +0 -2
  71. package/dist/zti18n-core/src/transform/transformToDi18n.d.ts +0 -5
  72. package/dist/zti18n-core/src/transform/transformTs.d.ts +0 -5
  73. package/dist/zti18n-core/src/transform/transformVue.d.ts +0 -5
  74. package/dist/zti18n-core/src/transform/transformZeroToDi18n.d.ts +0 -2
  75. package/dist/zti18n-core/src/translate/google.d.ts +0 -2
  76. package/dist/zti18n-core/src/utils/constants.d.ts +0 -3
  77. package/dist/zti18n-core/src/utils/getIgnoreLines.d.ts +0 -2
  78. package/dist/zti18n-core/src/utils/isChinese.d.ts +0 -2
  79. package/dist/zti18n-core/src/utils/log.d.ts +0 -4
@@ -1,224 +1,224 @@
1
- const t = require('@babel/types');
2
- const log = require('../utils/log');
3
-
4
- const isChinese = function (text) {
5
- return /[\u4e00-\u9fa5]/.test(text);
6
- };
7
-
8
- /**
9
- * 替换为 intl.get('xxxxxxxx').d('基本信息')
10
- */
11
- function makeReplace({ value, variableObj, id }) {
12
- let key = id;
13
-
14
- // 用于防止中文转码为 unicode
15
- const v = Object.assign(t.StringLiteral(value), {
16
- extra: {
17
- raw: `'${value}'`,
18
- rawValue: value,
19
- },
20
- });
21
-
22
- return t.CallExpression(
23
- t.MemberExpression(
24
- t.CallExpression(
25
- t.MemberExpression(t.Identifier('intl'), t.Identifier('get')),
26
- variableObj
27
- ? [typeof key === 'string' ? t.StringLiteral(key) : key, variableObj]
28
- : [typeof key === 'string' ? t.StringLiteral(key) : key]
29
- ),
30
- t.Identifier('d')
31
- ),
32
- [v]
33
- );
34
- }
35
-
36
- /**
37
- * 获取代码转换的插件
38
- * @param {object} zhData 中文文案资源
39
- * @param {object} outObj 传出的参数对象
40
- */
41
- function getPlugin(zhData, outObj) {
42
- const cache = {};
43
-
44
- // 防止中文转码为 unicode
45
- function handleChinese(value, key) {
46
- cache[key] = true;
47
- return Object.assign(t.StringLiteral(value), {
48
- extra: {
49
- raw: `'${value}'`,
50
- rawValue: value,
51
- },
52
- });
53
- }
54
-
55
- const plugin = function ({ types: t }) {
56
- return {
57
- visitor: {
58
- ImportDeclaration(path) {
59
- const { node } = path;
60
- if (node.source.value === 'di18n-react') {
61
- outObj.hasReactIntlUniversal = true;
62
- }
63
-
64
- if (node.source.value === 'react-intl') {
65
- outObj.needRewrite = true;
66
- log.info('remove: injectIntl');
67
- path.remove();
68
- }
69
- },
70
- Decorator(path) {
71
- const { node } = path;
72
- if (node.expression.name === 'injectIntl') {
73
- outObj.needRewrite = true;
74
- log.info('remove: injectIntl decorator');
75
- path.remove();
76
- }
77
- },
78
- BinaryExpression(path) {
79
- const { node } = path;
80
-
81
- // 替换类似 this.props.intl.locale === 'en' 为 intl.options.currentLocale === 'en-US'
82
- if (
83
- node.operator === '===' &&
84
- node.right.type === 'StringLiteral' &&
85
- node.right.value === 'en' &&
86
- node.left.type === 'MemberExpression' &&
87
- node.left.property.name === 'locale'
88
- ) {
89
- outObj.needRewrite = true;
90
- log.info("replace intl.locale === 'en'");
91
-
92
- node.left = t.MemberExpression(
93
- t.MemberExpression(t.Identifier('intl'), t.Identifier('options')),
94
- t.Identifier('currentLocale')
95
- );
96
- node.right = t.StringLiteral('en-US');
97
- }
98
- },
99
- ObjectPattern(path) {
100
- const { node } = path;
101
-
102
- const parent = path.parent;
103
- if (!parent.init) {
104
- return;
105
- }
106
-
107
- if (
108
- (parent.init.type === 'Identifier' &&
109
- parent.init.name === 'props') ||
110
- (parent.init.type === 'MemberExpression' &&
111
- parent.init.property.name === 'props')
112
- ) {
113
- // 处理掉 let { params, intl } = this.props; 中的 intl
114
- log.info('remove: this.props.intl');
115
- node.properties = node.properties.filter(
116
- (p) => !p.value || p.value.name !== 'intl'
117
- );
118
- }
119
- },
120
- JSXElement(path) {
121
- const { node } = path;
122
- const { openingElement } = node;
123
- if (openingElement.name.name === 'FormattedMessage') {
124
- outObj.needRewrite = true;
125
-
126
- const idNode = openingElement.attributes.find(
127
- (atr) => atr.name.name === 'id'
128
- );
129
-
130
- const id = idNode.value.value
131
- ? idNode.value.value
132
- : idNode.value.expression;
133
-
134
- const valuesNode = openingElement.attributes.find(
135
- (atr) => atr.name.name === 'values'
136
- );
137
- let callExpression;
138
-
139
- if (valuesNode) {
140
- callExpression = makeReplace({
141
- value: zhData[id] || 'TBD',
142
- id: id,
143
- variableObj: valuesNode.value.expression,
144
- });
145
- } else {
146
- callExpression = makeReplace({
147
- value: zhData[id] || 'TBD',
148
- id: id,
149
- });
150
- }
151
-
152
- if (path.parent.type === 'JSXExpressionContainer') {
153
- path.replaceWith(callExpression);
154
- } else if (path.parent.type === 'JSXElement') {
155
- path.replaceWith(t.JSXExpressionContainer(callExpression));
156
- } else {
157
- path.replaceWith(callExpression);
158
- }
159
- }
160
- },
161
- StringLiteral(path) {
162
- const { node } = path;
163
- const { value } = node;
164
- const key = value + node.start + node.end;
165
- if (isChinese(value) && !cache[key]) {
166
- if (path.parent.type === 'JSXAttribute') {
167
- path.replaceWith(handleChinese(value, key));
168
- }
169
- }
170
- },
171
- CallExpression(path) {
172
- const { node } = path;
173
-
174
- const handleFormatMessageMethod = () => {
175
- const id = node.arguments[0].properties.find(
176
- (prop) => prop.key.name === 'id'
177
- ).value.value;
178
- outObj.needRewrite = true;
179
-
180
- log.info(`replace: ${id}`);
181
-
182
- if (node.arguments.length === 1) {
183
- path.replaceWith(
184
- makeReplace({ value: zhData[id] || 'TBD', id: id })
185
- );
186
- } else {
187
- path.replaceWith(
188
- makeReplace({
189
- value: zhData[id] || 'TBD',
190
- id: id,
191
- variableObj: node.arguments[1],
192
- })
193
- );
194
- }
195
- };
196
-
197
- if (node.callee.type === 'MemberExpression') {
198
- if (node.callee.property.name === 'formatMessage') {
199
- if (
200
- (node.callee.object.property &&
201
- node.callee.object.property.name === 'intl') ||
202
- (node.callee.object.type === 'Identifier' &&
203
- node.callee.object.name === 'intl')
204
- ) {
205
- handleFormatMessageMethod();
206
- }
207
- }
208
- } else {
209
- if (node.callee.name === 'formatMessage') {
210
- handleFormatMessageMethod();
211
- } else if (node.callee.name === 'injectIntl') {
212
- outObj.needRewrite = true;
213
- path.replaceWith(node.arguments[0]);
214
- }
215
- }
216
- },
217
- },
218
- };
219
- };
220
-
221
- return plugin;
222
- }
223
-
224
- module.exports = getPlugin;
1
+ const t = require('@babel/types');
2
+ const log = require('../utils/log');
3
+
4
+ const isChinese = function (text) {
5
+ return /[\u4e00-\u9fa5]/.test(text);
6
+ };
7
+
8
+ /**
9
+ * 替换为 intl.get('xxxxxxxx').d('基本信息')
10
+ */
11
+ function makeReplace({ value, variableObj, id }) {
12
+ let key = id;
13
+
14
+ // 用于防止中文转码为 unicode
15
+ const v = Object.assign(t.StringLiteral(value), {
16
+ extra: {
17
+ raw: `'${value}'`,
18
+ rawValue: value,
19
+ },
20
+ });
21
+
22
+ return t.CallExpression(
23
+ t.MemberExpression(
24
+ t.CallExpression(
25
+ t.MemberExpression(t.Identifier('intl'), t.Identifier('get')),
26
+ variableObj
27
+ ? [typeof key === 'string' ? t.StringLiteral(key) : key, variableObj]
28
+ : [typeof key === 'string' ? t.StringLiteral(key) : key]
29
+ ),
30
+ t.Identifier('d')
31
+ ),
32
+ [v]
33
+ );
34
+ }
35
+
36
+ /**
37
+ * 获取代码转换的插件
38
+ * @param {object} zhData 中文文案资源
39
+ * @param {object} outObj 传出的参数对象
40
+ */
41
+ function getPlugin(zhData, outObj) {
42
+ const cache = {};
43
+
44
+ // 防止中文转码为 unicode
45
+ function handleChinese(value, key) {
46
+ cache[key] = true;
47
+ return Object.assign(t.StringLiteral(value), {
48
+ extra: {
49
+ raw: `'${value}'`,
50
+ rawValue: value,
51
+ },
52
+ });
53
+ }
54
+
55
+ const plugin = function ({ types: t }) {
56
+ return {
57
+ visitor: {
58
+ ImportDeclaration(path) {
59
+ const { node } = path;
60
+ if (node.source.value === 'di18n-react') {
61
+ outObj.hasReactIntlUniversal = true;
62
+ }
63
+
64
+ if (node.source.value === 'react-intl') {
65
+ outObj.needRewrite = true;
66
+ log.info('remove: injectIntl');
67
+ path.remove();
68
+ }
69
+ },
70
+ Decorator(path) {
71
+ const { node } = path;
72
+ if (node.expression.name === 'injectIntl') {
73
+ outObj.needRewrite = true;
74
+ log.info('remove: injectIntl decorator');
75
+ path.remove();
76
+ }
77
+ },
78
+ BinaryExpression(path) {
79
+ const { node } = path;
80
+
81
+ // 替换类似 this.props.intl.locale === 'en' 为 intl.options.currentLocale === 'en-US'
82
+ if (
83
+ node.operator === '===' &&
84
+ node.right.type === 'StringLiteral' &&
85
+ node.right.value === 'en' &&
86
+ node.left.type === 'MemberExpression' &&
87
+ node.left.property.name === 'locale'
88
+ ) {
89
+ outObj.needRewrite = true;
90
+ log.info("replace intl.locale === 'en'");
91
+
92
+ node.left = t.MemberExpression(
93
+ t.MemberExpression(t.Identifier('intl'), t.Identifier('options')),
94
+ t.Identifier('currentLocale')
95
+ );
96
+ node.right = t.StringLiteral('en-US');
97
+ }
98
+ },
99
+ ObjectPattern(path) {
100
+ const { node } = path;
101
+
102
+ const parent = path.parent;
103
+ if (!parent.init) {
104
+ return;
105
+ }
106
+
107
+ if (
108
+ (parent.init.type === 'Identifier' &&
109
+ parent.init.name === 'props') ||
110
+ (parent.init.type === 'MemberExpression' &&
111
+ parent.init.property.name === 'props')
112
+ ) {
113
+ // 处理掉 let { params, intl } = this.props; 中的 intl
114
+ log.info('remove: this.props.intl');
115
+ node.properties = node.properties.filter(
116
+ (p) => !p.value || p.value.name !== 'intl'
117
+ );
118
+ }
119
+ },
120
+ JSXElement(path) {
121
+ const { node } = path;
122
+ const { openingElement } = node;
123
+ if (openingElement.name.name === 'FormattedMessage') {
124
+ outObj.needRewrite = true;
125
+
126
+ const idNode = openingElement.attributes.find(
127
+ (atr) => atr.name.name === 'id'
128
+ );
129
+
130
+ const id = idNode.value.value
131
+ ? idNode.value.value
132
+ : idNode.value.expression;
133
+
134
+ const valuesNode = openingElement.attributes.find(
135
+ (atr) => atr.name.name === 'values'
136
+ );
137
+ let callExpression;
138
+
139
+ if (valuesNode) {
140
+ callExpression = makeReplace({
141
+ value: zhData[id] || 'TBD',
142
+ id: id,
143
+ variableObj: valuesNode.value.expression,
144
+ });
145
+ } else {
146
+ callExpression = makeReplace({
147
+ value: zhData[id] || 'TBD',
148
+ id: id,
149
+ });
150
+ }
151
+
152
+ if (path.parent.type === 'JSXExpressionContainer') {
153
+ path.replaceWith(callExpression);
154
+ } else if (path.parent.type === 'JSXElement') {
155
+ path.replaceWith(t.JSXExpressionContainer(callExpression));
156
+ } else {
157
+ path.replaceWith(callExpression);
158
+ }
159
+ }
160
+ },
161
+ StringLiteral(path) {
162
+ const { node } = path;
163
+ const { value } = node;
164
+ const key = value + node.start + node.end;
165
+ if (isChinese(value) && !cache[key]) {
166
+ if (path.parent.type === 'JSXAttribute') {
167
+ path.replaceWith(handleChinese(value, key));
168
+ }
169
+ }
170
+ },
171
+ CallExpression(path) {
172
+ const { node } = path;
173
+
174
+ const handleFormatMessageMethod = () => {
175
+ const id = node.arguments[0].properties.find(
176
+ (prop) => prop.key.name === 'id'
177
+ ).value.value;
178
+ outObj.needRewrite = true;
179
+
180
+ log.info(`replace: ${id}`);
181
+
182
+ if (node.arguments.length === 1) {
183
+ path.replaceWith(
184
+ makeReplace({ value: zhData[id] || 'TBD', id: id })
185
+ );
186
+ } else {
187
+ path.replaceWith(
188
+ makeReplace({
189
+ value: zhData[id] || 'TBD',
190
+ id: id,
191
+ variableObj: node.arguments[1],
192
+ })
193
+ );
194
+ }
195
+ };
196
+
197
+ if (node.callee.type === 'MemberExpression') {
198
+ if (node.callee.property.name === 'formatMessage') {
199
+ if (
200
+ (node.callee.object.property &&
201
+ node.callee.object.property.name === 'intl') ||
202
+ (node.callee.object.type === 'Identifier' &&
203
+ node.callee.object.name === 'intl')
204
+ ) {
205
+ handleFormatMessageMethod();
206
+ }
207
+ }
208
+ } else {
209
+ if (node.callee.name === 'formatMessage') {
210
+ handleFormatMessageMethod();
211
+ } else if (node.callee.name === 'injectIntl') {
212
+ outObj.needRewrite = true;
213
+ path.replaceWith(node.arguments[0]);
214
+ }
215
+ }
216
+ },
217
+ },
218
+ };
219
+ };
220
+
221
+ return plugin;
222
+ }
223
+
224
+ module.exports = getPlugin;
@@ -1,64 +1,64 @@
1
- const t = require('@babel/types');
2
-
3
- const replaceLineBreak = function (value) {
4
- if (typeof value !== 'string') return value;
5
- return value.replace(/\n/g, ' ');
6
- };
7
-
8
- /**
9
- * 获取代码转换的插件
10
- */
11
- function getPlugin(outObj, allConverted, intlAlias = 'intl') {
12
- function makeReplace({ orignKey, value, variableObj }) {
13
- outObj.translateWordsNum++;
14
-
15
- const value2 = replaceLineBreak(value);
16
-
17
- // 用于防止中文转码为 unicode
18
- const v = Object.assign(t.StringLiteral(value2), {
19
- extra: {
20
- raw: `'${value2}'`,
21
- rawValue: value2,
22
- },
23
- });
24
-
25
- allConverted[orignKey] = value;
26
-
27
- return t.CallExpression(
28
- t.MemberExpression(t.Identifier(intlAlias), t.Identifier('t')),
29
- variableObj ? [v, variableObj] : [v]
30
- );
31
- }
32
-
33
- const plugin = function () {
34
- return {
35
- visitor: {
36
- CallExpression(path) {
37
- const { node } = path;
38
-
39
- if (node.callee.type === 'MemberExpression') {
40
- if (
41
- path.node.callee.object.name === intlAlias &&
42
- path.node.callee.property.name === 'get'
43
- ) {
44
- const args = path.node.arguments;
45
-
46
- const orignKey = args[0].value;
47
- const variableObj = args[1] ? args[1] : null;
48
-
49
- const value = path.parentPath.parent.arguments[0].value;
50
-
51
- path.parentPath.parentPath.replaceWith(
52
- makeReplace({ orignKey, value, variableObj })
53
- );
54
- }
55
- }
56
- },
57
- },
58
- };
59
- };
60
-
61
- return plugin;
62
- }
63
-
64
- module.exports = getPlugin;
1
+ const t = require('@babel/types');
2
+
3
+ const replaceLineBreak = function (value) {
4
+ if (typeof value !== 'string') return value;
5
+ return value.replace(/\n/g, ' ');
6
+ };
7
+
8
+ /**
9
+ * 获取代码转换的插件
10
+ */
11
+ function getPlugin(outObj, allConverted, intlAlias = 'intl') {
12
+ function makeReplace({ orignKey, value, variableObj }) {
13
+ outObj.translateWordsNum++;
14
+
15
+ const value2 = replaceLineBreak(value);
16
+
17
+ // 用于防止中文转码为 unicode
18
+ const v = Object.assign(t.StringLiteral(value2), {
19
+ extra: {
20
+ raw: `'${value2}'`,
21
+ rawValue: value2,
22
+ },
23
+ });
24
+
25
+ allConverted[orignKey] = value;
26
+
27
+ return t.CallExpression(
28
+ t.MemberExpression(t.Identifier(intlAlias), t.Identifier('t')),
29
+ variableObj ? [v, variableObj] : [v]
30
+ );
31
+ }
32
+
33
+ const plugin = function () {
34
+ return {
35
+ visitor: {
36
+ CallExpression(path) {
37
+ const { node } = path;
38
+
39
+ if (node.callee.type === 'MemberExpression') {
40
+ if (
41
+ path.node.callee.object.name === intlAlias &&
42
+ path.node.callee.property.name === 'get'
43
+ ) {
44
+ const args = path.node.arguments;
45
+
46
+ const orignKey = args[0].value;
47
+ const variableObj = args[1] ? args[1] : null;
48
+
49
+ const value = path.parentPath.parent.arguments[0].value;
50
+
51
+ path.parentPath.parentPath.replaceWith(
52
+ makeReplace({ orignKey, value, variableObj })
53
+ );
54
+ }
55
+ }
56
+ },
57
+ },
58
+ };
59
+ };
60
+
61
+ return plugin;
62
+ }
63
+
64
+ module.exports = getPlugin;