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,272 +1,272 @@
1
- const lex = require('pug-lexer');
2
- const parse = require('pug-parser');
3
- const genSource = require('pug-source-gen');
4
- const mustache = require('mustache');
5
- const prettier = require('prettier');
6
- const transformJs = require('./transformJs');
7
- const getIgnoreLines = require('../utils/getIgnoreLines');
8
-
9
- /* eslint-disable */
10
- // override to avoid unneeded escape: pug-source-gen/lib/code-generator.js
11
- genSource.CodeGenerator.prototype.attrs = function (attrs) {
12
- var regularAttrs = [];
13
- var classes = '';
14
- var id;
15
- attrs.forEach(
16
- function (attr) {
17
- var constVal = '';
18
- try {
19
- constVal = constantinople.toConstant(attr.val);
20
- } catch (ex) {}
21
-
22
- if (
23
- attr.name === 'class' &&
24
- !attr.escaped &&
25
- constVal &&
26
- /^\-?[_a-z][_a-z0-9\-]*$/i.test(constVal)
27
- ) {
28
- classes += '.' + constVal;
29
- } else if (
30
- attr.name === 'id' &&
31
- !id &&
32
- !attr.escaped &&
33
- constVal &&
34
- /^[\w-]+$/.test(constVal)
35
- ) {
36
- id = constVal;
37
- } else {
38
- var attrOut = '';
39
-
40
- // name
41
- if (/^\w[^()[\]=!,`'"\s]*$/.test(attr.name)) {
42
- attrOut += attr.name;
43
- } else {
44
- var name = attr.name.replace(/\\/g, '\\\\');
45
- attrOut += name;
46
- }
47
-
48
- if (!(typeof constVal === 'boolean' && constVal === true)) {
49
- // operator
50
- attrOut += '=';
51
-
52
- // value
53
- attrOut += attr.val;
54
- }
55
-
56
- regularAttrs.push(attrOut);
57
- }
58
- }.bind(this)
59
- );
60
-
61
- var out = '';
62
- if (id) out += '#' + id;
63
- out += classes;
64
- if (regularAttrs.length) out += '(' + regularAttrs.join(' ') + ')';
65
-
66
- return out;
67
- };
68
- /* eslint-enable */
69
-
70
- function traversePug(ast, { primaryRegx, i18nMethod, ignoreLines }, returns) {
71
- // returesallTranslatedWord, updatedTranslatedWord, keysInUse, ignores) {
72
- const { allTranslated, allUpdated, allUsedKeys } = returns;
73
- const existValues = Object.keys(allTranslated);
74
-
75
- function shouldIgnore(node) {
76
- return node.line && ignoreLines.includes(node.line);
77
- }
78
-
79
- function isPrimary(str) {
80
- return primaryRegx.test(str);
81
- }
82
-
83
- function formatValue(value) {
84
- // 去掉首尾空白字符,中间的连续空白字符替换成一个空格
85
- value = value.trim().replace(/\s+/g, ' ');
86
-
87
- // 去掉首尾引号
88
- if (['"', "'"].includes(value.charAt(0))) {
89
- value = value.substring(1, value.length - 1);
90
- }
91
-
92
- return value;
93
- }
94
-
95
- // 更新2个 `all*` 数组
96
- function updateLocaleInfo(key, value) {
97
- if (!Array.isArray(allTranslated[value])) {
98
- // 如果该文字没有存在于已翻译列表
99
- allTranslated[value] = [key];
100
- existValues.push(key);
101
- }
102
-
103
- if (!allUsedKeys.includes(key)) {
104
- allUsedKeys.push(key);
105
- }
106
- }
107
-
108
- function transformJsExpression(source) {
109
- const { source: source1 } = transformJs(
110
- source,
111
- {
112
- allTranslated,
113
- allUpdated,
114
- allUsedKeys,
115
- },
116
- {
117
- primaryRegx,
118
- i18nObject: '',
119
- i18nMethod,
120
- importCode: '',
121
- }
122
- );
123
-
124
- let code = prettier.format(source1, {
125
- parser: 'babel',
126
- singleQuote: true,
127
- semi: false,
128
- });
129
-
130
- code = code.trim().replace(/\s+/g, ' ');
131
-
132
- // 去掉开头的分号
133
- if (code[0] === ';') code = code.slice(1);
134
-
135
- return code;
136
- }
137
-
138
- function traverse(node) {
139
- if (node.type === 'Tag' && node.block) {
140
- traverse(node.block);
141
- }
142
-
143
- if (node.type === 'Block' && node.nodes) {
144
- node.nodes.forEach((nd) => traverse(nd));
145
- }
146
-
147
- // 处理属性
148
- if (!shouldIgnore(node) && node.attrs) {
149
- node.attrs.forEach((attr) => {
150
- const { name, val } = attr;
151
-
152
- // 非主语言,跳过
153
- if (!isPrimary(val)) return;
154
-
155
- if (
156
- name.startsWith('v-') ||
157
- name.startsWith(':') ||
158
- name.startsWith('@')
159
- ) {
160
- // vue 指令
161
- let value = val;
162
- if (['"', "'"].includes(val.charAt(0))) {
163
- value = val.substring(1, val.length - 1);
164
- }
165
-
166
- // 引号里是 js 表达式,直接调用 transformJs 来转换
167
- const source = transformJsExpression(value);
168
-
169
- if (`"${source}"` !== val) {
170
- attr.val = `"${source}"`;
171
- returns.hasTouch = true;
172
- }
173
- } else {
174
- // 普通属性(应该不会有人在模板里写 onclick 等事件吧,故不考虑事件)
175
- let key = formatValue(val);
176
-
177
- if (allUpdated.hasOwnProperty(key)) {
178
- key = allUpdated[key];
179
- }
180
-
181
- attr.val = `"${i18nMethod}('${key}')"`;
182
- attr.name = `:${name}`;
183
- returns.hasTouch = true;
184
- }
185
- });
186
- }
187
-
188
- // 处理 innerText
189
- if (!shouldIgnore(node) && node.type === 'Text') {
190
- if (!isPrimary(node.val)) return;
191
-
192
- let value = '';
193
- const tokens = mustache.parse(node.val);
194
-
195
- for (const token of tokens) {
196
- // token 结构:[类型(text|name), 值, 起始位置(包含), 终止位置(不包含)]
197
- if (!isPrimary(token[1])) {
198
- if (token[0] === 'text') value += token[1];
199
- else if (token[0] === 'name') value += `{{${token[1]}}}`;
200
- } else {
201
- if (token[0] === 'text') {
202
- const key = token[1].trim();
203
- value += `{{${i18nMethod}('${key}')}}`;
204
-
205
- updateLocaleInfo(key, key);
206
- } else if (token[0] === 'name') {
207
- const source = transformJsExpression(token[1]);
208
- value += `{{${source}}}`;
209
- }
210
- }
211
- }
212
-
213
- if (node.val !== value) {
214
- node.val = value;
215
- returns.hasTouch = true;
216
- }
217
- }
218
- }
219
-
220
- // 执行遍历
221
- traverse(ast);
222
- }
223
-
224
- module.exports = function transformPug(source, localeInfo = {}, options = {}) {
225
- const { allTranslated = {}, allUpdated = {}, allUsedKeys = [] } = localeInfo;
226
-
227
- const {
228
- primaryRegx = /[\u4e00-\u9fa5]/,
229
- i18nMethod = '$t',
230
-
231
- /* 以下暂时不需要
232
- i18nObject = '',
233
- importCode = '',
234
- babelPresets = [],
235
- babelPlugins = [],
236
- ignoreComponents = [],
237
- ignoreMethods = [],
238
- 以上暂时不需要 */
239
- } = options;
240
-
241
- const opts = {
242
- primaryRegx,
243
- i18nMethod,
244
- ignoreLines: [],
245
- };
246
-
247
- const r = {
248
- allTranslated,
249
- allUpdated,
250
- allUsedKeys,
251
- hasTouch: false,
252
- };
253
-
254
- opts.ignoreLines = getIgnoreLines(source);
255
- const tokens = lex(source.trim());
256
-
257
- const ast = parse(tokens);
258
- traversePug(ast, opts, r);
259
-
260
- let code = source;
261
- if (r.hasTouch) {
262
- const genCode = genSource(ast);
263
- code = prettier
264
- .format(genCode, {
265
- filepath: 'xxx.pug',
266
- pugAttributeSeparator: 'none',
267
- })
268
- .trim();
269
- }
270
-
271
- return { source: code, hasTouch: r.hasTouch };
272
- };
1
+ const lex = require('pug-lexer');
2
+ const parse = require('pug-parser');
3
+ const genSource = require('pug-source-gen');
4
+ const mustache = require('mustache');
5
+ const prettier = require('prettier');
6
+ const transformJs = require('./transformJs');
7
+ const getIgnoreLines = require('../utils/getIgnoreLines');
8
+
9
+ /* eslint-disable */
10
+ // override to avoid unneeded escape: pug-source-gen/lib/code-generator.js
11
+ genSource.CodeGenerator.prototype.attrs = function (attrs) {
12
+ var regularAttrs = [];
13
+ var classes = '';
14
+ var id;
15
+ attrs.forEach(
16
+ function (attr) {
17
+ var constVal = '';
18
+ try {
19
+ constVal = constantinople.toConstant(attr.val);
20
+ } catch (ex) {}
21
+
22
+ if (
23
+ attr.name === 'class' &&
24
+ !attr.escaped &&
25
+ constVal &&
26
+ /^\-?[_a-z][_a-z0-9\-]*$/i.test(constVal)
27
+ ) {
28
+ classes += '.' + constVal;
29
+ } else if (
30
+ attr.name === 'id' &&
31
+ !id &&
32
+ !attr.escaped &&
33
+ constVal &&
34
+ /^[\w-]+$/.test(constVal)
35
+ ) {
36
+ id = constVal;
37
+ } else {
38
+ var attrOut = '';
39
+
40
+ // name
41
+ if (/^\w[^()[\]=!,`'"\s]*$/.test(attr.name)) {
42
+ attrOut += attr.name;
43
+ } else {
44
+ var name = attr.name.replace(/\\/g, '\\\\');
45
+ attrOut += name;
46
+ }
47
+
48
+ if (!(typeof constVal === 'boolean' && constVal === true)) {
49
+ // operator
50
+ attrOut += '=';
51
+
52
+ // value
53
+ attrOut += attr.val;
54
+ }
55
+
56
+ regularAttrs.push(attrOut);
57
+ }
58
+ }.bind(this)
59
+ );
60
+
61
+ var out = '';
62
+ if (id) out += '#' + id;
63
+ out += classes;
64
+ if (regularAttrs.length) out += '(' + regularAttrs.join(' ') + ')';
65
+
66
+ return out;
67
+ };
68
+ /* eslint-enable */
69
+
70
+ function traversePug(ast, { primaryRegx, i18nMethod, ignoreLines }, returns) {
71
+ // returesallTranslatedWord, updatedTranslatedWord, keysInUse, ignores) {
72
+ const { allTranslated, allUpdated, allUsedKeys } = returns;
73
+ const existValues = Object.keys(allTranslated);
74
+
75
+ function shouldIgnore(node) {
76
+ return node.line && ignoreLines.includes(node.line);
77
+ }
78
+
79
+ function isPrimary(str) {
80
+ return primaryRegx.test(str);
81
+ }
82
+
83
+ function formatValue(value) {
84
+ // 去掉首尾空白字符,中间的连续空白字符替换成一个空格
85
+ value = value.trim().replace(/\s+/g, ' ');
86
+
87
+ // 去掉首尾引号
88
+ if (['"', "'"].includes(value.charAt(0))) {
89
+ value = value.substring(1, value.length - 1);
90
+ }
91
+
92
+ return value;
93
+ }
94
+
95
+ // 更新2个 `all*` 数组
96
+ function updateLocaleInfo(key, value) {
97
+ if (!Array.isArray(allTranslated[value])) {
98
+ // 如果该文字没有存在于已翻译列表
99
+ allTranslated[value] = [key];
100
+ existValues.push(key);
101
+ }
102
+
103
+ if (!allUsedKeys.includes(key)) {
104
+ allUsedKeys.push(key);
105
+ }
106
+ }
107
+
108
+ function transformJsExpression(source) {
109
+ const { source: source1 } = transformJs(
110
+ source,
111
+ {
112
+ allTranslated,
113
+ allUpdated,
114
+ allUsedKeys,
115
+ },
116
+ {
117
+ primaryRegx,
118
+ i18nObject: '',
119
+ i18nMethod,
120
+ importCode: '',
121
+ }
122
+ );
123
+
124
+ let code = prettier.format(source1, {
125
+ parser: 'babel',
126
+ singleQuote: true,
127
+ semi: false,
128
+ });
129
+
130
+ code = code.trim().replace(/\s+/g, ' ');
131
+
132
+ // 去掉开头的分号
133
+ if (code[0] === ';') code = code.slice(1);
134
+
135
+ return code;
136
+ }
137
+
138
+ function traverse(node) {
139
+ if (node.type === 'Tag' && node.block) {
140
+ traverse(node.block);
141
+ }
142
+
143
+ if (node.type === 'Block' && node.nodes) {
144
+ node.nodes.forEach((nd) => traverse(nd));
145
+ }
146
+
147
+ // 处理属性
148
+ if (!shouldIgnore(node) && node.attrs) {
149
+ node.attrs.forEach((attr) => {
150
+ const { name, val } = attr;
151
+
152
+ // 非主语言,跳过
153
+ if (!isPrimary(val)) return;
154
+
155
+ if (
156
+ name.startsWith('v-') ||
157
+ name.startsWith(':') ||
158
+ name.startsWith('@')
159
+ ) {
160
+ // vue 指令
161
+ let value = val;
162
+ if (['"', "'"].includes(val.charAt(0))) {
163
+ value = val.substring(1, val.length - 1);
164
+ }
165
+
166
+ // 引号里是 js 表达式,直接调用 transformJs 来转换
167
+ const source = transformJsExpression(value);
168
+
169
+ if (`"${source}"` !== val) {
170
+ attr.val = `"${source}"`;
171
+ returns.hasTouch = true;
172
+ }
173
+ } else {
174
+ // 普通属性(应该不会有人在模板里写 onclick 等事件吧,故不考虑事件)
175
+ let key = formatValue(val);
176
+
177
+ if (allUpdated.hasOwnProperty(key)) {
178
+ key = allUpdated[key];
179
+ }
180
+
181
+ attr.val = `"${i18nMethod}('${key}')"`;
182
+ attr.name = `:${name}`;
183
+ returns.hasTouch = true;
184
+ }
185
+ });
186
+ }
187
+
188
+ // 处理 innerText
189
+ if (!shouldIgnore(node) && node.type === 'Text') {
190
+ if (!isPrimary(node.val)) return;
191
+
192
+ let value = '';
193
+ const tokens = mustache.parse(node.val);
194
+
195
+ for (const token of tokens) {
196
+ // token 结构:[类型(text|name), 值, 起始位置(包含), 终止位置(不包含)]
197
+ if (!isPrimary(token[1])) {
198
+ if (token[0] === 'text') value += token[1];
199
+ else if (token[0] === 'name') value += `{{${token[1]}}}`;
200
+ } else {
201
+ if (token[0] === 'text') {
202
+ const key = token[1].trim();
203
+ value += `{{${i18nMethod}('${key}')}}`;
204
+
205
+ updateLocaleInfo(key, key);
206
+ } else if (token[0] === 'name') {
207
+ const source = transformJsExpression(token[1]);
208
+ value += `{{${source}}}`;
209
+ }
210
+ }
211
+ }
212
+
213
+ if (node.val !== value) {
214
+ node.val = value;
215
+ returns.hasTouch = true;
216
+ }
217
+ }
218
+ }
219
+
220
+ // 执行遍历
221
+ traverse(ast);
222
+ }
223
+
224
+ module.exports = function transformPug(source, localeInfo = {}, options = {}) {
225
+ const { allTranslated = {}, allUpdated = {}, allUsedKeys = [] } = localeInfo;
226
+
227
+ const {
228
+ primaryRegx = /[\u4e00-\u9fa5]/,
229
+ i18nMethod = '$t',
230
+
231
+ /* 以下暂时不需要
232
+ i18nObject = '',
233
+ importCode = '',
234
+ babelPresets = [],
235
+ babelPlugins = [],
236
+ ignoreComponents = [],
237
+ ignoreMethods = [],
238
+ 以上暂时不需要 */
239
+ } = options;
240
+
241
+ const opts = {
242
+ primaryRegx,
243
+ i18nMethod,
244
+ ignoreLines: [],
245
+ };
246
+
247
+ const r = {
248
+ allTranslated,
249
+ allUpdated,
250
+ allUsedKeys,
251
+ hasTouch: false,
252
+ };
253
+
254
+ opts.ignoreLines = getIgnoreLines(source);
255
+ const tokens = lex(source.trim());
256
+
257
+ const ast = parse(tokens);
258
+ traversePug(ast, opts, r);
259
+
260
+ let code = source;
261
+ if (r.hasTouch) {
262
+ const genCode = genSource(ast);
263
+ code = prettier
264
+ .format(genCode, {
265
+ filepath: 'xxx.pug',
266
+ pugAttributeSeparator: 'none',
267
+ })
268
+ .trim();
269
+ }
270
+
271
+ return { source: code, hasTouch: r.hasTouch };
272
+ };