b28-cli 1.6.6 → 1.6.8

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.
package/README.MD CHANGED
@@ -256,21 +256,23 @@ module.exports = {
256
256
 
257
257
  ### 原厂代码添加翻译函数
258
258
 
259
- 在原厂代码中添加翻译函数`_()`,实现多语言产品需求
259
+ 在原厂代码中添加翻译函数`_()`,实现多语言产品需求,同时生成初始的语言包`json`文件,对于无法识别的内容,输出到`人工检查词条.txt`文件,手动检查是否需要添加翻译函数。
260
260
 
261
261
  | 属性 | 值类型 | 默认值 | 说明 |
262
262
  | -------------- | --------------------------- | -------------------- | --------------------------------------------------- |
263
- | baseProPath | String | `必填` | 原厂代码地址 |
264
- | baseProOutPath | String | `baseProPath` | 添加翻译函数后文件输出地址 |
265
- | ignoreCode | `String`/`Regexp` | `/<!--\s*hide|-->/g` | 需要注释的代码正则 |
266
- | templateExp | `String`/`Regexp` | `/<%([^\n]*?)%>/g` | JS 文件中后台用于插入替换的模板表达式对应的正则 |
267
- | customRules | `Array`/`Function`/`Regexp` | `[]` | 自定义不提词条规则列表,可以是正则也可以是 function |
263
+ | baseProPath | `String` | `必填` | 原厂代码地址 |
264
+ | baseProOutPath | `String` | `baseProPath` | 添加翻译函数后文件输出地址 |
265
+ | templateExp | `String`/`Regexp` | `/<%\s*multilang\(([^\n]*?)\);*\s*%>/g` | JS 文件中后台用于插入替换的模板表达式对应的正则 |
266
+ | enPath | `String` | `必填` | 原厂代码存储英文词条的C文件地址: |
267
+ | otherLangPath | `String` | - | 原厂代码存储其它语言词条的C文件地址 |
268
268
 
269
- > `ignoreCode`: 原厂代码中需要注释的代码对应的`正则`,不注释对应的 js 代码会有语法错误,例如部分原厂代码中在代码开头会包含`<!--\s*hide`代码段等
269
+ > `templateExp`: 原厂中没有实现前后端分离,通过特定的模板语法注入参数的代码段对应的`正则`,如`/<%\s*multilang\(([^\n]*?)\);*\s*%>/g`,正则只能存在一个捕获组。捕获组的内容为占位符,例如源码占位符`<% multilang(LANG_LOGIN_USER); %>`中的`LANG_LOGIN_USER`为捕获组的内容
270
270
  >
271
- > `templateExp`: 原厂中没有实现前后端分离,通过特定的模板语法注入参数的代码段对应的`正则`,如`<%ejGetOther(sessionKey)%>`
271
+ > `enPath`: 原原厂代码存储英文词条的C文件地址,用于找到模板语法中的占位符对应的词条,例如`multilang_en_EN.c`文件
272
272
  >
273
- > `customRules`: 用于设置默认规则外,不进行提取的词条
273
+ > `otherLangPath`: 原厂代码存储其它语言词条的C文件地址,多个文件用逗号连接,用于生成初始语言包json文件
274
+
275
+
274
276
 
275
277
  **预设不进行翻译配置如下**
276
278
 
@@ -282,6 +284,7 @@ module.exports = {
282
284
  - 全大写字母
283
285
  - url
284
286
  - 数字,字母,特殊符号(不包含空格)组成的字符串,必须包含[数字,=,?]中的一个
287
+ >>>>>>> 7b6d160444e451fcb078542162ed451f53be2fb9
285
288
 
286
289
  ### 提取全部词条及其对应全部翻译
287
290
 
@@ -380,6 +383,10 @@ b28-cli
380
383
 
381
384
  ## 更新日志
382
385
 
386
+ #### 【2021.8.19】
387
+
388
+ - 添加`Vue`自定义指令支持
389
+ - 修复已知bug(Vue bind中使用运算符词条解析出错)
383
390
  #### 【2020.11.19】
384
391
 
385
392
  - 添加`ts`语法支持
@@ -41,13 +41,18 @@ var ExtractFile = function () {
41
41
 
42
42
  this.option = Object.assign({}, {
43
43
  baseReadPath: "",
44
- baseWritePath: ""
44
+ baseWritePath: "",
45
+ enPath: "",
46
+ otherLangPath: [""]
45
47
  }, option);
46
48
 
47
49
  this.option.baseReadPath = (0, _index.correctPath)(this.option.baseReadPath);
48
- this.option.baseWritePath = (0, _index.correctPath)(this.option.baseWritePath);
49
- this.option.baseWritePath = _path2.default.join(this.option.baseWritePath, "outSrc");
50
+ this.option.baseWritePath = _path2.default.join((0, _index.correctPath)(this.option.baseWritePath), "outSrc");
50
51
  this.option.needCopy = true;
52
+ this.enPath = (0, _index.correctPath)(this.option.enPath);
53
+ this.otherLangPath = this.option.otherLangPath.map(function (item) {
54
+ return (0, _index.correctPath)(item);
55
+ });
51
56
 
52
57
  this.fileList = {
53
58
  // 需要进行提取和翻译的文件
@@ -69,13 +74,16 @@ var ExtractFile = function () {
69
74
  this.option.ignoreCode && (obj.ignoreCode = this.option.ignoreCode);
70
75
  this.option.templateExp && (obj.templateExp = this.option.templateExp);
71
76
 
72
- this.extractHTML = new _extract_html_ori2.default(obj);
73
-
74
- this.extractJS = new _extract_js_ori2.default(obj);
77
+ this.getWord();
78
+ this.extractHTML = new _extract_html_ori2.default(obj, this.words);
79
+ this.extractJS = new _extract_js_ori2.default(obj, this.words);
75
80
 
76
81
  (0, _index.createFolder)(this.option.baseWritePath);
77
82
  };
78
83
 
84
+ // 入口函数
85
+
86
+
79
87
  ExtractFile.prototype.scanFile = function scanFile() {
80
88
  var _this = this;
81
89
 
@@ -106,7 +114,15 @@ var ExtractFile = function () {
106
114
 
107
115
  // 将提取的词条文件,输出为excel
108
116
  return Promise.all([this.handleHtml(), this.handleJs()]).then(function (data) {
117
+ var suspectLine = "";
118
+ data.forEach(function (item) {
119
+ suspectLine += item.join("\n\r");
120
+ });
121
+ var suspectPath = _path2.default.join(_this.option.baseWritePath, "人工检查词条.txt");
122
+ (0, _index.writeTextFile)(suspectPath, suspectLine);
123
+ (0, _index.log)("\u8F93\u51FA\u6587\u4EF6\u4E2D\u7684\u8BCD\u6761\u9700\u8981\u5355\u72EC\u68C0\u67E5\uFF1A" + suspectPath, _index.LOG_TYPE.DONE);
109
124
  //重置
125
+ _this.exportLangs();
110
126
  _this.reset();
111
127
  (0, _index.log)("\u5904\u7406\u5B8C\u6210", _index.LOG_TYPE.DONE);
112
128
  return _this.outData;
@@ -181,6 +197,80 @@ var ExtractFile = function () {
181
197
  }
182
198
  };
183
199
 
200
+ ExtractFile.prototype.getWord = function getWord() {
201
+ var _this4 = this;
202
+
203
+ this.words = this.analyseWord(this.enPath);
204
+ this.otherLang = {};
205
+ this.otherLangPath.forEach(function (filePath) {
206
+ var lang = _path2.default.basename(filePath, _path2.default.extname(filePath));
207
+ _this4.otherLang[lang] = _this4.analyseWord(filePath);
208
+ });
209
+ };
210
+
211
+ ExtractFile.prototype.analyseWord = function analyseWord(filePath) {
212
+ var str = (0, _index.loadFileSync)(filePath);
213
+
214
+ if (typeof str !== "string") {
215
+ (0, _index.log)("\u6587\u4EF6[" + filePath + "]\u5904\u7406\u51FA\u9519- " + str.message, _index.LOG_TYPE.ERROR);
216
+ this.copyFile(filePath);
217
+ return {};
218
+ }
219
+
220
+ var obj = {};
221
+ str = str.match(/\{([\s\S]*?)\}/g);
222
+ if (str === null) {
223
+ return obj;
224
+ }
225
+ str = str[0];
226
+ str = str.replace(/(^\s*\{})|(\s*\}$)/g, "").split(/\n|\r/);
227
+ str.forEach(function (item) {
228
+ item.replace(/\[(.*?)\]\s*=\s*"(.*?)"/g, function (m, a, b) {
229
+ if (b !== "") {
230
+ obj[a] = b;
231
+ }
232
+ return m;
233
+ });
234
+ });
235
+ return obj;
236
+ };
237
+
238
+ ExtractFile.prototype.exportLangs = function exportLangs() {
239
+ if (this.otherLangPath.length === 0) {
240
+ return;
241
+ }
242
+ var outJson = {};
243
+ for (var key in this.otherLang) {
244
+ outJson[key] = {};
245
+ }
246
+ for (var _iterator = Object.entries(this.words), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
247
+ var _ref;
248
+
249
+ if (_isArray) {
250
+ if (_i >= _iterator.length) break;
251
+ _ref = _iterator[_i++];
252
+ } else {
253
+ _i = _iterator.next();
254
+ if (_i.done) break;
255
+ _ref = _i.value;
256
+ }
257
+
258
+ var _ref2 = _ref,
259
+ _key2 = _ref2[0],
260
+ value = _ref2[1];
261
+
262
+ for (var lang in this.otherLang) {
263
+ outJson[lang][value] = this.otherLang[lang][_key2];
264
+ }
265
+ }
266
+
267
+ for (var _key in outJson) {
268
+ var filePath = _path2.default.join(this.option.baseWritePath, "exportLang", _key + ".json");
269
+ (0, _index.log)("\u5199\u5165\u8BED\u8A00\u5305\u6587\u4EF6[" + filePath + "]", _index.LOG_TYPE.DONE);
270
+ (0, _index.writeJson)(outJson[_key], filePath);
271
+ }
272
+ };
273
+
184
274
  return ExtractFile;
185
275
  }();
186
276
 
package/dist/cmd.js CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
 
5
- var _ref;
6
-
7
5
  var _package = require("../package.json");
8
6
 
9
7
  var _package2 = _interopRequireDefault(_package);
@@ -72,161 +70,256 @@ var comments = {
72
70
  /**
73
71
  * 命令行手动输入参数逐条配置
74
72
  */
75
- var questions = [[{
76
- type: "confirm",
77
- name: "onlyZH",
78
- message: "只提取中文?"
79
- }, {
80
- type: "input",
81
- name: "baseReadPath",
82
- message: "待提取文件地址:"
83
- }, {
84
- type: "input",
85
- name: "baseOutPath",
86
- message: "提取的Excel文件输出地址:"
87
- }, {
88
- type: "input",
89
- name: "hongPath",
90
- message: "宏文件地址:"
91
- }], [{
92
- type: "input",
93
- name: "baseTranslatePath",
94
- message: "待翻译文件根目录:"
95
- }, {
96
- type: "input",
97
- name: "baseTransOutPath",
98
- message: "翻译后文件输出根目录:"
99
- }, {
100
- type: "input",
101
- name: "hongPath",
102
- message: "宏文件地址:"
103
- }, {
104
- type: "input",
105
- name: "languagePath",
106
- message: "语言包文件地址:"
107
- }, {
108
- type: "input",
109
- name: "sheetName",
110
- message: "Excel中对应的sheet:"
111
- }, {
112
- type: "input",
113
- name: "keyName",
114
- message: "key对应列:", //指代代码中的词条需要被那一列的数据替换
115
- default: "EN"
116
- }, (_ref = {
117
- type: "input",
118
- name: "valueName",
119
- message: "value对应列:", //指代代码中目前需要被替换的语言
120
- default: "CN" }, _ref["default"] = "", _ref)], [{
121
- type: "input",
122
- name: "baseCheckPath",
123
- message: "待检查文件根目录:"
124
- }, {
125
- type: "input",
126
- name: "langJsonPath",
127
- message: "语言包json文件地址:"
128
- }, {
129
- type: "input",
130
- name: "hongPath",
131
- message: "宏文件地址:"
132
- }, {
133
- type: "input",
134
- name: "logPath",
135
- message: "检查信息输出路径:"
136
- }], [{
137
- type: "input",
138
- name: "excelPath",
139
- message: "Excel文件地址:"
140
- }, {
141
- type: "input",
142
- name: "sheetName",
143
- message: "Excel中对应的sheet:"
144
- }, {
145
- type: "input",
146
- name: "keyName",
147
- message: "key对应列:",
148
- default: "EN"
149
- }, {
150
- type: "input",
151
- name: "valueName",
152
- message: "value对应列:" // ALL代表所有
153
- }, {
154
- type: "input",
155
- name: "outJsonPath",
156
- message: "输出json文件目录:"
157
- }], [{
158
- type: "input",
159
- name: "jsonPath",
160
- message: "json文件地址:"
161
- }, {
162
- type: "input",
163
- name: "outExcelPath",
164
- message: "输出Excel文件目录:"
165
- }], [{
166
- type: "input",
167
- name: "mainJsonPath",
168
- message: "主json文件地址:"
169
- }, {
170
- type: "input",
171
- name: "mergeJsonPath",
172
- message: "次json文件地址:"
173
- }, {
174
- type: "input",
175
- name: "outMergeJsonPath",
176
- message: "合并后输出的地址:"
177
- }], [{
178
- type: "input",
179
- name: "baseProPath",
180
- message: "原厂代码地址:"
181
- }, {
182
- type: "input",
183
- name: "baseProOutPath",
184
- message: "添加翻译函数后文件输出地址:"
185
- }, {
186
- type: "input",
187
- name: "ignoreCode",
188
- message: "需要注释的代码正则:",
189
- default: "/<!--s*hide|-->/g"
190
- }, {
191
- type: "input",
192
- name: "templateExp",
193
- message: "后台插入表达式正则:",
194
- default: "/<%([^\n]*?)%>/g"
195
- }], [{
196
- type: "input",
197
- name: "outExcel",
198
- message: "输出的excel文件地址:",
199
- default: "C:\\Users\\Administrator\\Desktop\\a.xlsx"
200
- }, {
201
- type: "input",
202
- name: "inExcel",
203
- message: "最终excel文件地址:",
204
- default: "C:\\Users\\Administrator\\Desktop\\b.xlsx"
205
- }, {
206
- type: "input",
207
- name: "baseCheckPath",
208
- message: "待检查文件根目录:"
209
- }, {
210
- type: "input",
211
- name: "jsonPath",
212
- message: "语言包文件夹地址:"
213
- }, {
214
- type: "input",
215
- name: "outExcelPath",
216
- message: "输出Excel文件目录:"
217
- }], [{
218
- type: "input",
219
- name: "transFilePath",
220
- message: "待转码文件地址"
221
- }, {
222
- type: "input",
223
- name: "transOutPath",
224
- message: "转码后文件输出地址"
225
- }, {
226
- type: "input",
227
- name: "transEncode",
228
- message: "转码后文件的编码方式(默认UTF-8)"
229
- }]];
73
+ // let questions = [
74
+ // // 提取词条
75
+ // [
76
+ // {
77
+ // type: "confirm",
78
+ // name: "onlyZH",
79
+ // message: "只提取中文?"
80
+ // },
81
+ // {
82
+ // type: "input",
83
+ // name: "baseReadPath",
84
+ // message: "待提取文件地址:"
85
+ // },
86
+ // {
87
+ // type: "input",
88
+ // name: "baseOutPath",
89
+ // message: "提取的Excel文件输出地址:"
90
+ // },
91
+ // {
92
+ // type: "input",
93
+ // name: "hongPath",
94
+ // message: "宏文件地址:"
95
+ // }
96
+ // ],
97
+ // // 翻译文件
98
+ // [
99
+ // {
100
+ // type: "input",
101
+ // name: "baseTranslatePath",
102
+ // message: "待翻译文件根目录:"
103
+ // },
104
+ // {
105
+ // type: "input",
106
+ // name: "baseTransOutPath",
107
+ // message: "翻译后文件输出根目录:"
108
+ // },
109
+ // {
110
+ // type: "input",
111
+ // name: "hongPath",
112
+ // message: "宏文件地址:"
113
+ // },
114
+ // {
115
+ // type: "input",
116
+ // name: "languagePath",
117
+ // message: "语言包文件地址:"
118
+ // },
119
+ // {
120
+ // type: "input",
121
+ // name: "sheetName",
122
+ // message: "Excel中对应的sheet:"
123
+ // },
124
+ // {
125
+ // type: "input",
126
+ // name: "keyName",
127
+ // message: "key对应列:", //指代代码中的词条需要被那一列的数据替换
128
+ // default: "EN"
129
+ // },
130
+ // {
131
+ // type: "input",
132
+ // name: "valueName",
133
+ // message: "value对应列:", //指代代码中目前需要被替换的语言
134
+ // default: "CN", // ALL代表所有
135
+ // default: ""
136
+ // }
137
+ // ],
138
+ // // 翻译检查
139
+ // [
140
+ // {
141
+ // type: "input",
142
+ // name: "baseCheckPath",
143
+ // message: "待检查文件根目录:"
144
+ // },
145
+ // {
146
+ // type: "input",
147
+ // name: "langJsonPath",
148
+ // message: "语言包json文件地址:"
149
+ // },
150
+ // {
151
+ // type: "input",
152
+ // name: "hongPath",
153
+ // message: "宏文件地址:"
154
+ // },
155
+ // {
156
+ // type: "input",
157
+ // name: "logPath",
158
+ // message: "检查信息输出路径:"
159
+ // }
160
+ // ],
161
+ // // excel转json
162
+ // [
163
+ // {
164
+ // type: "input",
165
+ // name: "excelPath",
166
+ // message: "Excel文件地址:"
167
+ // },
168
+ // {
169
+ // type: "input",
170
+ // name: "sheetName",
171
+ // message: "Excel中对应的sheet:"
172
+ // },
173
+ // {
174
+ // type: "input",
175
+ // name: "keyName",
176
+ // message: "key对应列:",
177
+ // default: "EN"
178
+ // },
179
+ // {
180
+ // type: "input",
181
+ // name: "valueName",
182
+ // message: "value对应列:" // ALL代表所有
183
+ // },
184
+ // {
185
+ // type: "input",
186
+ // name: "outJsonPath",
187
+ // message: "输出json文件目录:"
188
+ // }
189
+ // ],
190
+ // // json转excel
191
+ // [
192
+ // {
193
+ // type: "input",
194
+ // name: "jsonPath",
195
+ // message: "json文件地址:"
196
+ // },
197
+ // {
198
+ // type: "input",
199
+ // name: "outExcelPath",
200
+ // message: "输出Excel文件目录:"
201
+ // }
202
+ // ],
203
+ // // json文件合并
204
+ // [
205
+ // {
206
+ // type: "input",
207
+ // name: "mainJsonPath",
208
+ // message: "主json文件地址:"
209
+ // },
210
+ // {
211
+ // type: "input",
212
+ // name: "mergeJsonPath",
213
+ // message: "次json文件地址:"
214
+ // },
215
+ // {
216
+ // type: "input",
217
+ // name: "outMergeJsonPath",
218
+ // message: "合并后输出的地址:"
219
+ // }
220
+ // ],
221
+ // // 原厂代码添加翻译函数
222
+ // [
223
+ // {
224
+ // type: "input",
225
+ // name: "baseProPath",
226
+ // message: "原厂代码地址:"
227
+ // },
228
+ // {
229
+ // type: "input",
230
+ // name: "baseProOutPath",
231
+ // message: "添加翻译函数后文件输出地址:"
232
+ // },
233
+ // {
234
+ // type: "input",
235
+ // name: "ignoreCode",
236
+ // message: "需要注释的代码正则:",
237
+ // default: "/<!--s*hide|-->/g"
238
+ // },
239
+ // {
240
+ // type: "input",
241
+ // name: "templateExp",
242
+ // message: "后台插入表达式正则:",
243
+ // default: "/<%([^\n]*?)%>/g"
244
+ // }
245
+ // ],
246
+ // // 提取json文件,生成一个excel表格
247
+ // [
248
+ // {
249
+ // type: "input",
250
+ // name: "baseReadPath",
251
+ // message: "待提取文件地址:",
252
+ // validate: valid.folder // 必填,可以是文件也可以是文件夹
253
+ // },
254
+ // {
255
+ // type: "input",
256
+ // name: "languagePath",
257
+ // message: "语言包文地址(文件夹):"
258
+ // },
259
+ // {
260
+ // type: "input",
261
+ // name: "baseOutPath",
262
+ // message: "提取的Excel文件输出地址:",
263
+ // default(answers) {
264
+ // return getDirname(answers.baseReadPath);
265
+ // }
266
+ // },
267
+ // {
268
+ // type: "input",
269
+ // name: "hongPath",
270
+ // message: "宏文件地址:",
271
+ // default: ""
272
+ // }
273
+ // ],
274
+ // // 翻译文件检查
275
+ // [
276
+ // {
277
+ // type: "input",
278
+ // name: "outExcel",
279
+ // message: "输出的excel文件地址:",
280
+ // default: "C:\\Users\\Administrator\\Desktop\\a.xlsx"
281
+ // },
282
+ // {
283
+ // type: "input",
284
+ // name: "inExcel",
285
+ // message: "最终excel文件地址:",
286
+ // default: "C:\\Users\\Administrator\\Desktop\\b.xlsx"
287
+ // },
288
+ // {
289
+ // type: "input",
290
+ // name: "baseCheckPath",
291
+ // message: "待检查文件根目录:"
292
+ // },
293
+ // {
294
+ // type: "input",
295
+ // name: "jsonPath",
296
+ // message: "语言包文件夹地址:"
297
+ // },
298
+ // {
299
+ // type: "input",
300
+ // name: "outExcelPath",
301
+ // message: "输出Excel文件目录:"
302
+ // }
303
+ // ],
304
+ // // 文件转码
305
+ // [
306
+ // {
307
+ // type: "input",
308
+ // name: "transFilePath",
309
+ // message: "待转码文件地址"
310
+ // },
311
+ // {
312
+ // type: "input",
313
+ // name: "transOutPath",
314
+ // message: "转码后文件输出地址"
315
+ // },
316
+ // {
317
+ // type: "input",
318
+ // name: "transEncode",
319
+ // message: "转码后文件的编码方式(默认UTF-8)"
320
+ // }
321
+ // ]
322
+ // ];
230
323
 
231
324
  /**
232
325
  * 初始化b28.config.js文件
@@ -235,7 +328,7 @@ function handleInit() {
235
328
  var config = {};
236
329
  inquirer.prompt(_config.baseQuestions).then(function (answers) {
237
330
  config.commandType = answers.commandType;
238
- return inquirer.prompt(questions[answers.commandType]);
331
+ return inquirer.prompt(_config.questions[answers.commandType]);
239
332
  }).then(function (answers) {
240
333
  answers = Object.assign({}, config, answers);
241
334
  return answers;