@tarojs/cli-convertor 3.6.22 → 3.6.23-nightly.0
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/LICENSE +14 -0
- package/dist/index.js +259 -96
- package/dist/index.js.map +1 -1
- package/dist/util/global.js +4 -0
- package/dist/util/global.js.map +1 -1
- package/dist/util/index.js +278 -38
- package/dist/util/index.js.map +1 -1
- package/package.json +12 -11
package/dist/index.js
CHANGED
|
@@ -89,7 +89,6 @@ class Convertor {
|
|
|
89
89
|
this.hadBeenCopyedFiles = new Set();
|
|
90
90
|
this.hadBeenBuiltComponents = new Set();
|
|
91
91
|
this.hadBeenBuiltImports = new Set();
|
|
92
|
-
this.reportErroMsg = [];
|
|
93
92
|
this.projectConfig = { pluginRoot: '', compileType: '' };
|
|
94
93
|
this.pluginInfo = {
|
|
95
94
|
pluginRoot: '',
|
|
@@ -111,6 +110,8 @@ class Convertor {
|
|
|
111
110
|
this.getSubPackages();
|
|
112
111
|
}
|
|
113
112
|
catch (error) {
|
|
113
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] init - 初始化异常 ${(0, util_1.getLineBreak)()}${error} ${(0, util_1.getLineBreak)()}`);
|
|
114
|
+
(0, util_1.printToLogFile)();
|
|
114
115
|
throw new Error(`初始化失败 ${(0, util_1.getLineBreak)()} ${error.message}`);
|
|
115
116
|
}
|
|
116
117
|
}
|
|
@@ -123,11 +124,11 @@ class Convertor {
|
|
|
123
124
|
else {
|
|
124
125
|
helper_1.fs.ensureDirSync(this.convertRoot);
|
|
125
126
|
}
|
|
126
|
-
// 转换自定义配置文件,如:tsconfig.json
|
|
127
|
-
this.convertSelfDefinedConfig();
|
|
128
127
|
// 创建.convert目录,存放转换中间数据,如日志数据
|
|
129
128
|
(0, util_1.generateDir)(path.join(this.convertRoot, '.convert'));
|
|
130
129
|
global_1.globals.logFilePath = path.join(this.convertRoot, '.convert', 'convert.log');
|
|
130
|
+
// 转换自定义配置文件,如:tsconfig.json
|
|
131
|
+
this.convertSelfDefinedConfig();
|
|
131
132
|
// 读取convert.config.json配置文件
|
|
132
133
|
this.getConvertConfig();
|
|
133
134
|
// 读取project.config.json文件
|
|
@@ -138,6 +139,7 @@ class Convertor {
|
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
catch (error) {
|
|
142
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] init - 初始化convert异常 ${(0, util_1.getLineBreak)()}${error} ${(0, util_1.getLineBreak)()}`);
|
|
141
143
|
throw new Error(`初始化convert失败 ${(0, util_1.getLineBreak)()} ${error.message}`);
|
|
142
144
|
}
|
|
143
145
|
}
|
|
@@ -151,6 +153,7 @@ class Convertor {
|
|
|
151
153
|
const thisData = new Set();
|
|
152
154
|
(0, traverse_1.default)(ast, {
|
|
153
155
|
ObjectProperty(astPath) {
|
|
156
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] convertToOptional - 解析ObjectProperty ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
154
157
|
// xxx({ data: {...} }),获取data属性中符合的数据
|
|
155
158
|
const node = astPath.node;
|
|
156
159
|
const key = node.key;
|
|
@@ -183,6 +186,7 @@ class Convertor {
|
|
|
183
186
|
});
|
|
184
187
|
},
|
|
185
188
|
CallExpression(astPath) {
|
|
189
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] convertToOptional - 解析CallExpression ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
186
190
|
// 用setData进行初始化的数据
|
|
187
191
|
const node = astPath.node;
|
|
188
192
|
const callee = node.callee;
|
|
@@ -216,9 +220,11 @@ class Convertor {
|
|
|
216
220
|
}
|
|
217
221
|
},
|
|
218
222
|
ClassBody(astPath) {
|
|
223
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] convertToOptional - 解析ClassBody ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
219
224
|
astPath.traverse({
|
|
220
225
|
MemberExpression(path) {
|
|
221
226
|
var _a, _b, _c;
|
|
227
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] convertToOptional - 解析MemberExpression ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
222
228
|
// 遇到成员表达式,抽取表达式的来源数据
|
|
223
229
|
const code = path.toString();
|
|
224
230
|
const optionMatch = (_a = code.match(/^(.*?)\./)) === null || _a === void 0 ? void 0 : _a[1];
|
|
@@ -255,6 +261,14 @@ class Convertor {
|
|
|
255
261
|
});
|
|
256
262
|
}
|
|
257
263
|
parseAst({ ast, sourceFilePath, outputFilePath, importStylePath, depComponents, imports = [], pluginComponents, }) {
|
|
264
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 入参 ${(0, util_1.getLineBreak)()}${JSON.stringify({
|
|
265
|
+
sourceFilePath,
|
|
266
|
+
outputFilePath,
|
|
267
|
+
importStylePath,
|
|
268
|
+
depComponents,
|
|
269
|
+
imports,
|
|
270
|
+
pluginComponents,
|
|
271
|
+
})} ${(0, util_1.getLineBreak)()}`);
|
|
258
272
|
const scriptFiles = new Set();
|
|
259
273
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
260
274
|
const self = this;
|
|
@@ -272,6 +286,7 @@ class Convertor {
|
|
|
272
286
|
enter(astPath) {
|
|
273
287
|
astPath.traverse({
|
|
274
288
|
ClassDeclaration(astPath) {
|
|
289
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析ClassDeclaration ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
275
290
|
const node = astPath.node;
|
|
276
291
|
let isTaroComponent = false;
|
|
277
292
|
if (node.superClass) {
|
|
@@ -291,36 +306,38 @@ class Convertor {
|
|
|
291
306
|
}
|
|
292
307
|
}
|
|
293
308
|
},
|
|
294
|
-
ClassExpression(astPath) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
309
|
+
// ClassExpression (astPath) {
|
|
310
|
+
// updateLogFileContent(
|
|
311
|
+
// `INFO [taro-cli-convertor] parseAst - 解析ClassExpression ${getLineBreak()}${astPath} ${getLineBreak()}`
|
|
312
|
+
// )
|
|
313
|
+
// const node = astPath.node
|
|
314
|
+
// if (node.superClass) {
|
|
315
|
+
// let isTaroComponent = false
|
|
316
|
+
// astPath.traverse({
|
|
317
|
+
// ClassMethod (astPath) {
|
|
318
|
+
// if (astPath.get('key').isIdentifier({ name: 'render' })) {
|
|
319
|
+
// astPath.traverse({
|
|
320
|
+
// JSXElement () {
|
|
321
|
+
// isTaroComponent = true
|
|
322
|
+
// },
|
|
323
|
+
// })
|
|
324
|
+
// }
|
|
325
|
+
// },
|
|
326
|
+
// })
|
|
327
|
+
// if (isTaroComponent) {
|
|
328
|
+
// if (node.id === null) {
|
|
329
|
+
// const parentNode = astPath.parentPath.node as t.VariableDeclarator
|
|
330
|
+
// if (t.isVariableDeclarator(astPath.parentPath)) {
|
|
331
|
+
// componentClassName = (parentNode.id as t.Identifier).name
|
|
332
|
+
// }
|
|
333
|
+
// } else {
|
|
334
|
+
// componentClassName = node.id!.name
|
|
335
|
+
// }
|
|
336
|
+
// }
|
|
337
|
+
// }
|
|
338
|
+
// },
|
|
323
339
|
ExportDefaultDeclaration(astPath) {
|
|
340
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析ExportDefaultDeclaration ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
324
341
|
const node = astPath.node;
|
|
325
342
|
const declaration = node.declaration;
|
|
326
343
|
if (declaration && (declaration.type === 'ClassDeclaration' || declaration.type === 'ClassExpression')) {
|
|
@@ -345,10 +362,12 @@ class Convertor {
|
|
|
345
362
|
}
|
|
346
363
|
},
|
|
347
364
|
ImportDeclaration(astPath) {
|
|
365
|
+
var _a;
|
|
366
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析ImportDeclaration ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
348
367
|
const node = astPath.node;
|
|
349
368
|
const source = node.source;
|
|
350
369
|
const value = source.value;
|
|
351
|
-
(0, util_1.analyzeImportUrl)(self.root, sourceFilePath, scriptFiles, source, value, self.isTsProject, self.pluginInfo.pluginName);
|
|
370
|
+
(0, util_1.analyzeImportUrl)(self.root, sourceFilePath, scriptFiles, source, value, self.isTsProject, self.pluginInfo.pluginName, (_a = self.entryJSON) === null || _a === void 0 ? void 0 : _a.resolveAlias);
|
|
352
371
|
// 获取导入语句中的所有导入名称(importName)并将其添加到scriptImports里面
|
|
353
372
|
const specifiers = node.specifiers;
|
|
354
373
|
specifiers.forEach((specifier) => {
|
|
@@ -356,8 +375,27 @@ class Convertor {
|
|
|
356
375
|
scriptImports.push(importName);
|
|
357
376
|
});
|
|
358
377
|
},
|
|
378
|
+
// export全部导入写法
|
|
379
|
+
ExportAllDeclaration(astPath) {
|
|
380
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析ExportAllDeclaration ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
381
|
+
const node = astPath.node;
|
|
382
|
+
const source = node.source;
|
|
383
|
+
const value = source.value;
|
|
384
|
+
(0, util_1.analyzeImportUrl)(self.root, sourceFilePath, scriptFiles, source, value, self.isTsProject, self.pluginInfo.pluginName);
|
|
385
|
+
},
|
|
386
|
+
// export部分导入写法
|
|
387
|
+
ExportNamedDeclaration(astPath) {
|
|
388
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析ExportNamedDeclaration ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
389
|
+
const node = astPath.node;
|
|
390
|
+
const source = node.source || '';
|
|
391
|
+
if (source) {
|
|
392
|
+
const value = source.value;
|
|
393
|
+
(0, util_1.analyzeImportUrl)(self.root, sourceFilePath, scriptFiles, source, value, self.isTsProject, self.pluginInfo.pluginName);
|
|
394
|
+
}
|
|
395
|
+
},
|
|
359
396
|
CallExpression(astPath) {
|
|
360
|
-
|
|
397
|
+
var _a, _b, _c, _d, _e;
|
|
398
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析CallExpression ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
361
399
|
const node = astPath.node;
|
|
362
400
|
const calleePath = astPath.get('callee');
|
|
363
401
|
const callee = calleePath.node;
|
|
@@ -370,11 +408,15 @@ class Convertor {
|
|
|
370
408
|
return;
|
|
371
409
|
}
|
|
372
410
|
if (!t.isStringLiteral(args[0])) {
|
|
373
|
-
|
|
374
|
-
|
|
411
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] parseAst - require 暂不支持动态导入 ${(0, util_1.getLineBreak)()}filePath: ${sourceFilePath} ${(0, util_1.getLineBreak)()}context: ${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
412
|
+
const position = {
|
|
413
|
+
col: ((_b = (_a = astPath.node.loc) === null || _a === void 0 ? void 0 : _a.start) === null || _b === void 0 ? void 0 : _b.column) || 0,
|
|
414
|
+
row: ((_d = (_c = astPath.node.loc) === null || _c === void 0 ? void 0 : _c.start) === null || _d === void 0 ? void 0 : _d.line) || 0,
|
|
415
|
+
};
|
|
416
|
+
throw new util_1.IReportError(`require暂不支持动态导入, filePath: ${sourceFilePath}, context: ${astPath}`, 'DynamicImportNotSupportedError', sourceFilePath, (0, util_1.astToCode)(astPath.node) || '', position);
|
|
375
417
|
}
|
|
376
418
|
const value = args[0].value;
|
|
377
|
-
(0, util_1.analyzeImportUrl)(self.root, sourceFilePath, scriptFiles, args[0], value, self.isTsProject, self.pluginInfo.pluginName);
|
|
419
|
+
(0, util_1.analyzeImportUrl)(self.root, sourceFilePath, scriptFiles, args[0], value, self.isTsProject, self.pluginInfo.pluginName, (_e = self.entryJSON) === null || _e === void 0 ? void 0 : _e.resolveAlias);
|
|
378
420
|
}
|
|
379
421
|
else if (WX_GLOBAL_FN.has(callee.name)) {
|
|
380
422
|
calleePath.replaceWith(t.memberExpression(t.identifier('Taro'), callee));
|
|
@@ -411,6 +453,7 @@ class Convertor {
|
|
|
411
453
|
}
|
|
412
454
|
},
|
|
413
455
|
MemberExpression(astPath) {
|
|
456
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析MemberExpression ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
414
457
|
const node = astPath.node;
|
|
415
458
|
const object = node.object;
|
|
416
459
|
const prettier = node.property;
|
|
@@ -434,7 +477,7 @@ class Convertor {
|
|
|
434
477
|
}
|
|
435
478
|
},
|
|
436
479
|
OptionalMemberExpression(astPath) {
|
|
437
|
-
(0, util_1.
|
|
480
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析OptionalMemberExpression ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
438
481
|
const node = astPath.node;
|
|
439
482
|
const object = node.object;
|
|
440
483
|
const prettier = node.property;
|
|
@@ -455,6 +498,7 @@ class Convertor {
|
|
|
455
498
|
},
|
|
456
499
|
// 获取js界面所有用到的自定义标签,不重复
|
|
457
500
|
JSXElement(astPath) {
|
|
501
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析JSXElement ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
458
502
|
const openingElement = astPath.get('openingElement');
|
|
459
503
|
const jsxName = openingElement.get('name');
|
|
460
504
|
if (jsxName.isJSXIdentifier()) {
|
|
@@ -543,6 +587,7 @@ class Convertor {
|
|
|
543
587
|
},
|
|
544
588
|
// 处理this.data.xx = XXX 的情况,因为此表达式在taro暂不支持, 转为setData
|
|
545
589
|
AssignmentExpression(astPath) {
|
|
590
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析AssignmentExpression ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
546
591
|
const node = astPath.node;
|
|
547
592
|
if (t.isMemberExpression(node.left) &&
|
|
548
593
|
t.isMemberExpression(node.left.object) &&
|
|
@@ -579,6 +624,8 @@ class Convertor {
|
|
|
579
624
|
}
|
|
580
625
|
astPath.traverse({
|
|
581
626
|
StringLiteral(astPath) {
|
|
627
|
+
var _a, _b, _c, _d;
|
|
628
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析StringLiteral ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
582
629
|
const value = astPath.node.value;
|
|
583
630
|
const extname = path.extname(value);
|
|
584
631
|
if (extname && helper_1.REG_IMAGE.test(extname) && !helper_1.REG_URL.test(value)) {
|
|
@@ -587,7 +634,7 @@ class Convertor {
|
|
|
587
634
|
sourceImagePath = path.join(self.root, value);
|
|
588
635
|
}
|
|
589
636
|
else {
|
|
590
|
-
sourceImagePath = path.
|
|
637
|
+
sourceImagePath = path.join(sourceFilePath, '..', value);
|
|
591
638
|
}
|
|
592
639
|
const imageRelativePath = (0, helper_1.promoteRelativePath)(path.relative(sourceFilePath, sourceImagePath));
|
|
593
640
|
const outputImagePath = self.getDistFilePath(sourceImagePath);
|
|
@@ -596,7 +643,13 @@ class Convertor {
|
|
|
596
643
|
(0, helper_1.printLog)("copy" /* processTypeEnum.COPY */, '图片', self.generateShowPath(outputImagePath));
|
|
597
644
|
}
|
|
598
645
|
else if (!t.isBinaryExpression(astPath.parent) || astPath.parent.operator !== '+') {
|
|
646
|
+
const position = {
|
|
647
|
+
row: ((_b = (_a = astPath.node.loc) === null || _a === void 0 ? void 0 : _a.start) === null || _b === void 0 ? void 0 : _b.line) || 0,
|
|
648
|
+
col: ((_d = (_c = astPath.node.loc) === null || _c === void 0 ? void 0 : _c.start) === null || _d === void 0 ? void 0 : _d.column) || 0
|
|
649
|
+
};
|
|
650
|
+
(0, util_1.createErrorCodeMsg)('ImageNotFound', '图片不存在', (0, util_1.astToCode)(astPath.node) || '', sourceFilePath, position);
|
|
599
651
|
(0, helper_1.printLog)("error" /* processTypeEnum.ERROR */, '图片不存在', self.generateShowPath(sourceImagePath));
|
|
652
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] parseAst - 图片不存在 ${(0, util_1.getLineBreak)()}${self.generateShowPath(sourceImagePath)} ${(0, util_1.getLineBreak)()}`);
|
|
600
653
|
}
|
|
601
654
|
if (astPath.parentPath.isVariableDeclarator()) {
|
|
602
655
|
astPath.replaceWith(t.callExpression(t.identifier('require'), [t.stringLiteral(imageRelativePath)]));
|
|
@@ -649,7 +702,9 @@ class Convertor {
|
|
|
649
702
|
}
|
|
650
703
|
let componentPath = componentObj.path;
|
|
651
704
|
if (!componentPath.startsWith(self.root) && !componentPath.startsWith(self.pluginInfo.pluginRoot)) {
|
|
705
|
+
(0, util_1.createErrorCodeMsg)('invalidComponentPath', `exception: 无效的组件路径,componentPath: ${componentPath}, 请在${outputFilePath}中手动引入`, `${componentObj.name}: ${componentObj.path}`, global_1.globals.currentParseFile);
|
|
652
706
|
console.error(`exception: 无效的组件路径,componentPath: ${componentPath}, 请在${outputFilePath}中手动引入`);
|
|
707
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] parseAst - 无效的组件路径 ${(0, util_1.getLineBreak)()}${componentPath} ${(0, util_1.getLineBreak)()}`);
|
|
653
708
|
return;
|
|
654
709
|
}
|
|
655
710
|
componentPath = path.relative(sourceFilePath, componentPath);
|
|
@@ -663,6 +718,7 @@ class Convertor {
|
|
|
663
718
|
const componentPath = pluginComponent.path;
|
|
664
719
|
if (!componentPath.startsWith(self.pluginInfo.pluginRoot)) {
|
|
665
720
|
console.error(`exception: 在页面${sourceFilePath}引用了无效的插件组件路径${componentPath}, 请在${outputFilePath}中手动引入`);
|
|
721
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] parseAst - ${sourceFilePath} 页面引用了无效的插件组件路径 ${(0, util_1.getLineBreak)()}${componentPath} ${(0, util_1.getLineBreak)()}`);
|
|
666
722
|
return;
|
|
667
723
|
}
|
|
668
724
|
// 插件组件转换后的绝对路径
|
|
@@ -680,6 +736,7 @@ class Convertor {
|
|
|
680
736
|
// 遍历 ast ,将多次 const { xxx } = require('@tarojs/with-weapp') 引入压缩为一次引入
|
|
681
737
|
(0, traverse_1.default)(ast, {
|
|
682
738
|
VariableDeclaration(astPath) {
|
|
739
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] parseAst - 解析VariableDeclaration ${(0, util_1.getLineBreak)()}${astPath} ${(0, util_1.getLineBreak)()}`);
|
|
683
740
|
const { kind, declarations } = astPath.node;
|
|
684
741
|
let currentAstIsWithWeapp = false;
|
|
685
742
|
if (kind === 'const') {
|
|
@@ -760,8 +817,10 @@ class Convertor {
|
|
|
760
817
|
(0, util_1.copyFileToTaro)(tempConfigPath, outputFilePath);
|
|
761
818
|
}
|
|
762
819
|
catch (err) {
|
|
820
|
+
(0, util_1.createErrorCodeMsg)('TsConfigCopyError', `tsconfig${this.fileTypes.CONFIG} 拷贝失败,请检查!`, '', path.join(this.root, `tsconfig${this.fileTypes.CONFIG}`));
|
|
763
821
|
// 失败不退出,仅提示
|
|
764
822
|
console.log(helper_1.chalk.red(`tsconfig${this.fileTypes.CONFIG} 拷贝失败,请检查!`));
|
|
823
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] convertSelfDefinedConfig - tsconfig${this.fileTypes.CONFIG} 文件拷贝异常 ${err} ${(0, util_1.getLineBreak)()}`);
|
|
765
824
|
}
|
|
766
825
|
}
|
|
767
826
|
}
|
|
@@ -776,7 +835,9 @@ class Convertor {
|
|
|
776
835
|
this.convertConfig.external = (0, util_1.transRelToAbsPath)(convertJsonPath, this.convertConfig.external);
|
|
777
836
|
}
|
|
778
837
|
catch (err) {
|
|
838
|
+
(0, util_1.createErrorCodeMsg)('ConvertConfigReadError', `convert.config${this.fileTypes.CONFIG} 读取失败,请检查!`, '', convertJsonPath);
|
|
779
839
|
console.log(helper_1.chalk.red(`convert.config${this.fileTypes.CONFIG} 读取失败,请检查!`));
|
|
840
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] getConvertConfig - convert.config${this.fileTypes.CONFIG} 文件读取异常 ${(0, util_1.getLineBreak)()}${err} ${(0, util_1.getLineBreak)()}`);
|
|
780
841
|
process.exit(1);
|
|
781
842
|
}
|
|
782
843
|
}
|
|
@@ -794,7 +855,9 @@ class Convertor {
|
|
|
794
855
|
if (projectConfigJson && projectConfigJson.compileType === "plugin" /* Constants.PLUGIN */) {
|
|
795
856
|
const pluginRoot = projectConfigJson.pluginRoot;
|
|
796
857
|
if (pluginRoot === '' || (0, shared_1.isNull)(pluginRoot) || (0, shared_1.isUndefined)(pluginRoot)) {
|
|
797
|
-
|
|
858
|
+
(0, util_1.createErrorCodeMsg)('emptyPluginRoot', 'project.config,json中pluginRoot为空或未配置,请确认配置是否正确', '', projectConfigFilePath);
|
|
859
|
+
console.log('project.config.json中pluginRoot为空或未配置,请确认配置是否正确');
|
|
860
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] parseProjectConfig - project.config.json 中 pluginRoot 为空或未配置 ${(0, util_1.getLineBreak)()}`);
|
|
798
861
|
process.exit(1);
|
|
799
862
|
}
|
|
800
863
|
this.projectConfig = Object.assign({}, projectConfigJson);
|
|
@@ -806,7 +869,8 @@ class Convertor {
|
|
|
806
869
|
}
|
|
807
870
|
}
|
|
808
871
|
catch (err) {
|
|
809
|
-
|
|
872
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] parseProjectConfig - project.config${this.fileTypes.CONFIG} 文件解析异常 ${(0, util_1.getLineBreak)()}${err} ${(0, util_1.getLineBreak)()}`);
|
|
873
|
+
throw new util_1.IReportError(`project.config${this.fileTypes.CONFIG} 解析失败,请检查!`, 'ProjectConfigParsingError', projectConfigFilePath, '');
|
|
810
874
|
}
|
|
811
875
|
}
|
|
812
876
|
}
|
|
@@ -850,7 +914,9 @@ class Convertor {
|
|
|
850
914
|
}
|
|
851
915
|
catch (err) {
|
|
852
916
|
this.entryJSON = {};
|
|
917
|
+
(0, util_1.createErrorCodeMsg)('AppConfigReadError', `app${this.fileTypes.CONFIG} 读取失败,请检查!`, '', this.entryJSONPath);
|
|
853
918
|
console.log(helper_1.chalk.red(`app${this.fileTypes.CONFIG} 读取失败,请检查!`));
|
|
919
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] getApp - app${this.fileTypes.CONFIG} 文件读取异常 ${(0, util_1.getLineBreak)()}${err} ${(0, util_1.getLineBreak)()}`);
|
|
854
920
|
process.exit(1);
|
|
855
921
|
}
|
|
856
922
|
}
|
|
@@ -865,14 +931,18 @@ class Convertor {
|
|
|
865
931
|
this.pluginInfo.pluginName = Object.keys(plugins)[0];
|
|
866
932
|
}
|
|
867
933
|
else {
|
|
934
|
+
(0, util_1.createErrorCodeMsg)('unregisteredPlugin', '当前应用没有注册插件,请检查app.json中的plugins字段是否配置正确', '', this.entryJSONPath);
|
|
868
935
|
console.log('当前应用没有注册插件,请检查app.json中的plugins字段是否配置正确');
|
|
936
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] parsePluginName - 当前应用没有注册插件,请检查 app.json 中的 plugins 字段 ${(0, util_1.getLineBreak)()}`);
|
|
869
937
|
process.exit(1);
|
|
870
938
|
}
|
|
871
939
|
}
|
|
872
940
|
getPages() {
|
|
873
941
|
const pages = this.entryJSON.pages;
|
|
874
942
|
if (!pages || !pages.length) {
|
|
943
|
+
(0, util_1.createErrorCodeMsg)('missingPageConfig', `app${this.fileTypes.CONFIG} 配置有误,缺少页面相关配置`, '', this.entryJSONPath);
|
|
875
944
|
console.log(helper_1.chalk.red(`app${this.fileTypes.CONFIG} 配置有误,缺少页面相关配置`));
|
|
945
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] getPages - app${this.fileTypes.CONFIG} 文件配置异常 ${(0, util_1.getLineBreak)()}`);
|
|
876
946
|
return;
|
|
877
947
|
}
|
|
878
948
|
this.pages = new Set(pages);
|
|
@@ -906,6 +976,7 @@ class Convertor {
|
|
|
906
976
|
}
|
|
907
977
|
generateScriptFiles(files) {
|
|
908
978
|
if (!files) {
|
|
979
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] generateScriptFiles - 文件不存在 ${(0, util_1.getLineBreak)()}`);
|
|
909
980
|
return;
|
|
910
981
|
}
|
|
911
982
|
if (files.size) {
|
|
@@ -948,10 +1019,13 @@ class Convertor {
|
|
|
948
1019
|
this.writeFileToTaro(outputFilePath, prettier.format(jsCode, prettierJSConfig));
|
|
949
1020
|
(0, helper_1.printLog)("copy" /* processTypeEnum.COPY */, 'JS 文件', this.generateShowPath(outputFilePath));
|
|
950
1021
|
this.hadBeenCopyedFiles.add(file);
|
|
1022
|
+
global_1.globals.currentParseFile = file;
|
|
951
1023
|
this.generateScriptFiles(scriptFiles);
|
|
952
1024
|
}
|
|
953
1025
|
catch (error) {
|
|
1026
|
+
(0, util_1.parseError)(error, file, '');
|
|
954
1027
|
console.log(`转换文件${file}异常,errorMessage:${error}`);
|
|
1028
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] generateScriptFiles - ${file} 文件转换异常 ${(0, util_1.getLineBreak)()}${error} ${(0, util_1.getLineBreak)()}`);
|
|
955
1029
|
}
|
|
956
1030
|
});
|
|
957
1031
|
}
|
|
@@ -1027,6 +1101,7 @@ ${code}
|
|
|
1027
1101
|
isApp: true,
|
|
1028
1102
|
logFilePath: global_1.globals.logFilePath,
|
|
1029
1103
|
});
|
|
1104
|
+
global_1.globals.errCodeMsgs.push(...taroizeResult.errCodeMsgs);
|
|
1030
1105
|
const { ast, scriptFiles } = this.parseAst({
|
|
1031
1106
|
ast: taroizeResult.ast,
|
|
1032
1107
|
sourceFilePath: this.entryJSPath,
|
|
@@ -1047,6 +1122,7 @@ ${code}
|
|
|
1047
1122
|
if (this.entryStyle) {
|
|
1048
1123
|
this.traverseStyle(this.entryStylePath, this.entryStyle);
|
|
1049
1124
|
}
|
|
1125
|
+
global_1.globals.currentParseFile = this.entryJSPath;
|
|
1050
1126
|
this.generateScriptFiles(scriptFiles);
|
|
1051
1127
|
if (this.entryJSON.tabBar) {
|
|
1052
1128
|
this.generateTabBarIcon(this.entryJSON.tabBar);
|
|
@@ -1054,7 +1130,8 @@ ${code}
|
|
|
1054
1130
|
}
|
|
1055
1131
|
}
|
|
1056
1132
|
catch (err) {
|
|
1057
|
-
|
|
1133
|
+
(0, util_1.parseError)(err, this.entryJSPath, '');
|
|
1134
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] generateEntry - ${this.entryJSPath} 入口文件生成异常 ${(0, util_1.getLineBreak)()}${err} ${(0, util_1.getLineBreak)()}`);
|
|
1058
1135
|
}
|
|
1059
1136
|
}
|
|
1060
1137
|
/**
|
|
@@ -1144,22 +1221,22 @@ ${code}
|
|
|
1144
1221
|
return true;
|
|
1145
1222
|
}
|
|
1146
1223
|
// 判断三方库是否安装
|
|
1147
|
-
isInNodeModule(modulePath) {
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
}
|
|
1224
|
+
// isInNodeModule (modulePath: string) {
|
|
1225
|
+
// const nodeModules = path.resolve(this.root, 'node_modules')
|
|
1226
|
+
// if (!fs.existsSync(nodeModules)) {
|
|
1227
|
+
// return false
|
|
1228
|
+
// }
|
|
1229
|
+
// const modules = fs.readdirSync(nodeModules)
|
|
1230
|
+
// const parts = modulePath.split('/')
|
|
1231
|
+
// if (modules.indexOf(parts[0]) === -1) {
|
|
1232
|
+
// return false
|
|
1233
|
+
// }
|
|
1234
|
+
// return true
|
|
1235
|
+
// }
|
|
1159
1236
|
traversePages(root, pages) {
|
|
1160
1237
|
pages.forEach((page) => {
|
|
1161
1238
|
var _a;
|
|
1162
|
-
(0, util_1.
|
|
1239
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] traversePages - 开始转换页面 ${(0, util_1.getLineBreak)()}${page} ${(0, util_1.getLineBreak)()}`);
|
|
1163
1240
|
const pagePath = this.isTsProject ? path.join(this.miniprogramRoot, page) : path.join(root, page);
|
|
1164
1241
|
// 处理不转换的页面,可在convert.config.json中external字段配置
|
|
1165
1242
|
const matchUnconvertDir = (0, util_1.getMatchUnconvertDir)(pagePath, (_a = this.convertConfig) === null || _a === void 0 ? void 0 : _a.external);
|
|
@@ -1167,14 +1244,15 @@ ${code}
|
|
|
1167
1244
|
(0, util_1.handleUnconvertDir)(matchUnconvertDir, root, this.convertDir);
|
|
1168
1245
|
return;
|
|
1169
1246
|
}
|
|
1170
|
-
const pageJSPath = pagePath + this.fileTypes.SCRIPT;
|
|
1247
|
+
const pageJSPath = pagePath + this.fileTypes.SCRIPT; // .js文件
|
|
1171
1248
|
const pageDistJSPath = this.getDistFilePath(pageJSPath);
|
|
1172
|
-
const pageConfigPath = pagePath + this.fileTypes.CONFIG;
|
|
1173
|
-
const pageStylePath = pagePath + this.fileTypes.STYLE;
|
|
1174
|
-
const pageTemplPath = pagePath + this.fileTypes.TEMPL;
|
|
1249
|
+
const pageConfigPath = pagePath + this.fileTypes.CONFIG; // .json文件
|
|
1250
|
+
const pageStylePath = pagePath + this.fileTypes.STYLE; // .wxss文件
|
|
1251
|
+
const pageTemplPath = pagePath + this.fileTypes.TEMPL; // .wxml文件
|
|
1175
1252
|
try {
|
|
1176
1253
|
if (!helper_1.fs.existsSync(pageJSPath)) {
|
|
1177
|
-
|
|
1254
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] traversePages - 页面 ${page} 没有 JS 文件 ${(0, util_1.getLineBreak)()}`);
|
|
1255
|
+
throw new util_1.IReportError(`页面 ${page} 没有 JS 文件!`, 'MissingJSFileError', pagePath, '');
|
|
1178
1256
|
}
|
|
1179
1257
|
const param = {};
|
|
1180
1258
|
(0, helper_1.printLog)("convert" /* processTypeEnum.CONVERT */, '页面文件', this.generateShowPath(pageJSPath));
|
|
@@ -1203,6 +1281,7 @@ ${code}
|
|
|
1203
1281
|
const unResolveComponentPath = pageUsingComponents[component];
|
|
1204
1282
|
let componentPath;
|
|
1205
1283
|
if (unResolveComponentPath.startsWith('plugin://')) {
|
|
1284
|
+
global_1.globals.currentParseFile = pageConfigPath;
|
|
1206
1285
|
componentPath = (0, util_1.replacePluginComponentUrl)(unResolveComponentPath, this.pluginInfo);
|
|
1207
1286
|
pluginComponents.add({
|
|
1208
1287
|
name: component,
|
|
@@ -1210,6 +1289,7 @@ ${code}
|
|
|
1210
1289
|
});
|
|
1211
1290
|
}
|
|
1212
1291
|
else if (this.isThirdPartyLib(unResolveComponentPath, path.resolve(pagePath, '..'))) {
|
|
1292
|
+
global_1.globals.currentParseFile = pageConfigPath;
|
|
1213
1293
|
(0, util_1.handleThirdPartyLib)(unResolveComponentPath, (_a = this.convertConfig) === null || _a === void 0 ? void 0 : _a.nodePath, root, this.convertRoot);
|
|
1214
1294
|
}
|
|
1215
1295
|
else {
|
|
@@ -1253,7 +1333,10 @@ ${code}
|
|
|
1253
1333
|
param.rootPath = root;
|
|
1254
1334
|
param.pluginInfo = this.pluginInfo;
|
|
1255
1335
|
param.logFilePath = global_1.globals.logFilePath;
|
|
1336
|
+
param.templatePath = pageTemplPath;
|
|
1256
1337
|
const taroizeResult = taroize(Object.assign(Object.assign({}, param), { framework: this.framework }));
|
|
1338
|
+
global_1.globals.errCodeMsgs.push(...taroizeResult.errCodeMsgs);
|
|
1339
|
+
global_1.globals.currentParseFile = pageConfigPath;
|
|
1257
1340
|
const { ast, scriptFiles } = this.parseAst({
|
|
1258
1341
|
ast: taroizeResult.ast,
|
|
1259
1342
|
sourceFilePath: pageJSPath,
|
|
@@ -1271,13 +1354,15 @@ ${code}
|
|
|
1271
1354
|
if (pageStyle) {
|
|
1272
1355
|
this.traverseStyle(pageStylePath, pageStyle);
|
|
1273
1356
|
}
|
|
1357
|
+
global_1.globals.currentParseFile = pageJSPath;
|
|
1274
1358
|
this.generateScriptFiles(scriptFiles);
|
|
1275
1359
|
this.traverseComponents(depComponents);
|
|
1276
1360
|
}
|
|
1277
1361
|
catch (err) {
|
|
1278
1362
|
(0, helper_1.printLog)("error" /* processTypeEnum.ERROR */, '页面转换', this.generateShowPath(pageJSPath));
|
|
1279
|
-
|
|
1280
|
-
(0, util_1.
|
|
1363
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] processStyleAssets - 页面转换异常 ${(0, util_1.getLineBreak)()}Path: ${this.generateShowPath(pageJSPath)} ${(0, util_1.getLineBreak)()}${err.message} ${(0, util_1.getLineBreak)()}`);
|
|
1364
|
+
(0, util_1.parseError)(err, pageJSPath, pageTemplPath);
|
|
1365
|
+
console.log(`页面: ${page}转换失败 ${err.message}`);
|
|
1281
1366
|
}
|
|
1282
1367
|
});
|
|
1283
1368
|
}
|
|
@@ -1286,7 +1371,7 @@ ${code}
|
|
|
1286
1371
|
return;
|
|
1287
1372
|
}
|
|
1288
1373
|
components.forEach((componentObj) => {
|
|
1289
|
-
(0, util_1.
|
|
1374
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] traverseComponents - 开始转换组件 ${(0, util_1.getLineBreak)()}${componentObj.path} ${(0, util_1.getLineBreak)()}`);
|
|
1290
1375
|
const component = componentObj.path;
|
|
1291
1376
|
if (this.hadBeenBuiltComponents.has(component))
|
|
1292
1377
|
return;
|
|
@@ -1299,31 +1384,69 @@ ${code}
|
|
|
1299
1384
|
try {
|
|
1300
1385
|
const param = {};
|
|
1301
1386
|
const depComponents = new Set();
|
|
1387
|
+
const pluginComponents = new Set();
|
|
1302
1388
|
if (!helper_1.fs.existsSync(componentJSPath)) {
|
|
1303
|
-
|
|
1389
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] traverseComponents - 自定义组件 ${component} 没有 JS 文件 ${(0, util_1.getLineBreak)()}`);
|
|
1390
|
+
throw new util_1.IReportError(`自定义组件 ${component} 没有 JS 文件!`, 'MissingJSFileError', componentJSPath, '');
|
|
1304
1391
|
}
|
|
1305
1392
|
(0, helper_1.printLog)("convert" /* processTypeEnum.CONVERT */, '组件文件', this.generateShowPath(componentJSPath));
|
|
1393
|
+
let componentConfig;
|
|
1306
1394
|
if (helper_1.fs.existsSync(componentConfigPath)) {
|
|
1307
1395
|
(0, helper_1.printLog)("convert" /* processTypeEnum.CONVERT */, '组件配置', this.generateShowPath(componentConfigPath));
|
|
1308
1396
|
const componentConfigStr = String(helper_1.fs.readFileSync(componentConfigPath));
|
|
1309
|
-
|
|
1397
|
+
componentConfig = JSON.parse(componentConfigStr);
|
|
1398
|
+
}
|
|
1399
|
+
else if (this.entryUsingComponents) {
|
|
1400
|
+
componentConfig = {};
|
|
1401
|
+
}
|
|
1402
|
+
if (componentConfig) {
|
|
1403
|
+
// app.json中注册的组件为公共组件
|
|
1404
|
+
if (this.entryUsingComponents && !this.isTraversePlugin) {
|
|
1405
|
+
componentConfig.usingComponents = Object.assign(Object.assign({}, componentConfig.usingComponents), this.entryUsingComponents);
|
|
1406
|
+
}
|
|
1310
1407
|
const componentUsingComponnets = componentConfig.usingComponents;
|
|
1311
1408
|
if (componentUsingComponnets) {
|
|
1312
1409
|
// 页面依赖组件
|
|
1410
|
+
const usingComponents = {};
|
|
1313
1411
|
Object.keys(componentUsingComponnets).forEach((component) => {
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1412
|
+
var _a;
|
|
1413
|
+
const unResolveUseComponentPath = componentUsingComponnets[component];
|
|
1414
|
+
let componentPath;
|
|
1415
|
+
if (unResolveUseComponentPath.startsWith('plugin://')) {
|
|
1416
|
+
componentPath = (0, util_1.replacePluginComponentUrl)(unResolveUseComponentPath, this.pluginInfo);
|
|
1417
|
+
pluginComponents.add({
|
|
1418
|
+
name: component,
|
|
1419
|
+
path: componentPath,
|
|
1420
|
+
});
|
|
1317
1421
|
}
|
|
1318
|
-
if (
|
|
1319
|
-
|
|
1422
|
+
else if (this.isThirdPartyLib(unResolveUseComponentPath, path.resolve(component, '..'))) {
|
|
1423
|
+
(0, util_1.handleThirdPartyLib)(unResolveUseComponentPath, (_a = this.convertConfig) === null || _a === void 0 ? void 0 : _a.nodePath, this.root, this.convertRoot);
|
|
1424
|
+
}
|
|
1425
|
+
else {
|
|
1426
|
+
if (unResolveUseComponentPath.startsWith(this.root)) {
|
|
1427
|
+
componentPath = unResolveUseComponentPath;
|
|
1428
|
+
}
|
|
1429
|
+
else {
|
|
1430
|
+
componentPath = path.join(componentConfigPath, '..', componentUsingComponnets[component]);
|
|
1431
|
+
if (!helper_1.fs.existsSync((0, helper_1.resolveScriptPath)(componentPath))) {
|
|
1432
|
+
componentPath = path.join(this.root, componentUsingComponnets[component]);
|
|
1433
|
+
}
|
|
1434
|
+
if (!helper_1.fs.existsSync(componentPath + this.fileTypes.SCRIPT)) {
|
|
1435
|
+
componentPath = path.join(componentPath, `/index`);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
depComponents.add({
|
|
1439
|
+
name: component,
|
|
1440
|
+
path: componentPath,
|
|
1441
|
+
});
|
|
1320
1442
|
}
|
|
1321
|
-
depComponents.add({
|
|
1322
|
-
name: component,
|
|
1323
|
-
path: componentPath,
|
|
1324
|
-
});
|
|
1325
1443
|
});
|
|
1326
|
-
|
|
1444
|
+
if (Object.keys(usingComponents).length === 0) {
|
|
1445
|
+
delete componentConfig.usingComponents;
|
|
1446
|
+
}
|
|
1447
|
+
else {
|
|
1448
|
+
componentConfig.usingComponents = usingComponents;
|
|
1449
|
+
}
|
|
1327
1450
|
}
|
|
1328
1451
|
param.json = JSON.stringify(componentConfig);
|
|
1329
1452
|
}
|
|
@@ -1340,7 +1463,10 @@ ${code}
|
|
|
1340
1463
|
param.path = path.dirname(componentJSPath);
|
|
1341
1464
|
param.rootPath = this.root;
|
|
1342
1465
|
param.logFilePath = global_1.globals.logFilePath;
|
|
1466
|
+
param.templatePath = componentTemplPath;
|
|
1343
1467
|
const taroizeResult = taroize(Object.assign(Object.assign({}, param), { framework: this.framework }));
|
|
1468
|
+
global_1.globals.errCodeMsgs.push(...taroizeResult.errCodeMsgs);
|
|
1469
|
+
global_1.globals.currentParseFile = componentConfigPath;
|
|
1344
1470
|
const { ast, scriptFiles } = this.parseAst({
|
|
1345
1471
|
ast: taroizeResult.ast,
|
|
1346
1472
|
sourceFilePath: componentJSPath,
|
|
@@ -1350,6 +1476,7 @@ ${code}
|
|
|
1350
1476
|
: null,
|
|
1351
1477
|
depComponents,
|
|
1352
1478
|
imports: taroizeResult.imports,
|
|
1479
|
+
pluginComponents: pluginComponents,
|
|
1353
1480
|
});
|
|
1354
1481
|
const jsCode = (0, astConvert_1.generateMinimalEscapeCode)(ast);
|
|
1355
1482
|
this.writeFileToTaro(this.getComponentDest(componentDistJSPath), this.formatFile(jsCode, taroizeResult.template));
|
|
@@ -1357,13 +1484,15 @@ ${code}
|
|
|
1357
1484
|
if (componentStyle) {
|
|
1358
1485
|
this.traverseStyle(componentStylePath, componentStyle);
|
|
1359
1486
|
}
|
|
1487
|
+
global_1.globals.currentParseFile = componentJSPath;
|
|
1360
1488
|
this.generateScriptFiles(scriptFiles);
|
|
1361
1489
|
this.traverseComponents(depComponents);
|
|
1362
1490
|
}
|
|
1363
1491
|
catch (err) {
|
|
1364
1492
|
(0, helper_1.printLog)("error" /* processTypeEnum.ERROR */, '组件转换', this.generateShowPath(componentJSPath));
|
|
1365
|
-
|
|
1366
|
-
|
|
1493
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] traverseComponents - 组件转换异常 ${(0, util_1.getLineBreak)()}Path: ${this.generateShowPath(componentJSPath)} ${(0, util_1.getLineBreak)()}${err} ${(0, util_1.getLineBreak)()}`);
|
|
1494
|
+
console.log(`组件转换失败 ${err.message}`);
|
|
1495
|
+
(0, util_1.parseError)(err, componentJSPath, componentTemplPath);
|
|
1367
1496
|
}
|
|
1368
1497
|
});
|
|
1369
1498
|
}
|
|
@@ -1387,11 +1516,12 @@ ${code}
|
|
|
1387
1516
|
url.replace(/[/\\]/g, path.sep);
|
|
1388
1517
|
url = url.split('?')[0];
|
|
1389
1518
|
url = url.split('#')[0];
|
|
1390
|
-
const originPath = path.
|
|
1391
|
-
const destPath = path.
|
|
1519
|
+
const originPath = path.join(stylePath, url);
|
|
1520
|
+
const destPath = path.join(styleDist, url);
|
|
1392
1521
|
const destDir = path.dirname(destPath);
|
|
1393
1522
|
if (!helper_1.fs.existsSync(originPath)) {
|
|
1394
1523
|
(0, helper_1.printLog)("warning" /* processTypeEnum.WARNING */, '静态资源', `找不到资源:${originPath}`);
|
|
1524
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] processStyleAssets - 找不到资源 ${(0, util_1.getLineBreak)()}${originPath} ${(0, util_1.getLineBreak)()}`);
|
|
1395
1525
|
}
|
|
1396
1526
|
else if (!helper_1.fs.existsSync(destPath)) {
|
|
1397
1527
|
helper_1.fs.ensureDirSync(destDir);
|
|
@@ -1404,7 +1534,7 @@ ${code}
|
|
|
1404
1534
|
}
|
|
1405
1535
|
traverseStyle(filePath, style) {
|
|
1406
1536
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1407
|
-
(0, util_1.
|
|
1537
|
+
(0, util_1.updateLogFileContent)(`INFO [taro-cli-convertor] traverseStyle - 开始转换样式 ${(0, util_1.getLineBreak)()}${filePath} ${(0, util_1.getLineBreak)()}`);
|
|
1408
1538
|
const { imports, content } = processStyleImports(style, (str, stylePath) => {
|
|
1409
1539
|
let relativePath = stylePath;
|
|
1410
1540
|
if (path.isAbsolute(relativePath)) {
|
|
@@ -1421,7 +1551,7 @@ ${code}
|
|
|
1421
1551
|
imports.forEach((importItem) => {
|
|
1422
1552
|
const importPath = path.isAbsolute(importItem)
|
|
1423
1553
|
? path.join(this.root, importItem)
|
|
1424
|
-
: path.
|
|
1554
|
+
: path.join(path.dirname(filePath), importItem);
|
|
1425
1555
|
if (helper_1.fs.existsSync(importPath)) {
|
|
1426
1556
|
const styleText = helper_1.fs.readFileSync(importPath).toString();
|
|
1427
1557
|
this.traverseStyle(importPath, styleText);
|
|
@@ -1443,6 +1573,7 @@ ${code}
|
|
|
1443
1573
|
// 转换插件plugin.json中导出的组件
|
|
1444
1574
|
this.traverseComponents(this.pluginInfo.publicComponents);
|
|
1445
1575
|
// 转换插件的工具文件
|
|
1576
|
+
global_1.globals.currentParseFile = this.pluginInfo.entryFilePath;
|
|
1446
1577
|
this.generateScriptFiles(new Set([this.pluginInfo.entryFilePath]));
|
|
1447
1578
|
}
|
|
1448
1579
|
/**
|
|
@@ -1457,7 +1588,9 @@ ${code}
|
|
|
1457
1588
|
try {
|
|
1458
1589
|
const pluginConfigJson = JSON.parse(String(helper_1.fs.readFileSync(pluginConfigPath)));
|
|
1459
1590
|
if (!pluginConfigJson) {
|
|
1591
|
+
(0, util_1.createErrorCodeMsg)('emptyPluginConfig', '插件配置信息为空,请检查!', '', pluginConfigPath);
|
|
1460
1592
|
console.log('插件配置信息为空,请检查!');
|
|
1593
|
+
(0, util_1.updateLogFileContent)(`WARN [taro-cli-convertor] parsePluginConfig - 插件配置信息为空 ${(0, util_1.getLineBreak)()}`);
|
|
1461
1594
|
return;
|
|
1462
1595
|
}
|
|
1463
1596
|
// 解析publicComponents信息
|
|
@@ -1486,6 +1619,8 @@ ${code}
|
|
|
1486
1619
|
}
|
|
1487
1620
|
}
|
|
1488
1621
|
catch (err) {
|
|
1622
|
+
(0, util_1.createErrorCodeMsg)('PluginJsonParsingError', '解析plugin.json失败,请检查!', '', pluginConfigPath);
|
|
1623
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] parsePluginConfig - plugin.json 解析异常 ${(0, util_1.getLineBreak)()}${err} ${(0, util_1.getLineBreak)()}`);
|
|
1489
1624
|
console.log('解析plugin.json失败,请检查!');
|
|
1490
1625
|
process.exit(1);
|
|
1491
1626
|
}
|
|
@@ -1517,9 +1652,9 @@ ${code}
|
|
|
1517
1652
|
ps.push(creator.createFileFromTemplate(templateName, 'config/dev.js', 'config/dev.js', createOpts));
|
|
1518
1653
|
ps.push(creator.createFileFromTemplate(templateName, 'config/prod.js', 'config/prod.js', createOpts));
|
|
1519
1654
|
ps.push(creator.createFileFromTemplate(templateName, 'project.config.json', 'project.config.json', createOpts));
|
|
1520
|
-
ps.push(creator.createFileFromTemplate(templateName, '
|
|
1521
|
-
ps.push(creator.createFileFromTemplate(templateName, '
|
|
1522
|
-
ps.push(creator.createFileFromTemplate(templateName, '
|
|
1655
|
+
ps.push(creator.createFileFromTemplate(templateName, '_gitignore', '.gitignore', createOpts));
|
|
1656
|
+
ps.push(creator.createFileFromTemplate(templateName, '_editorconfig', '.editorconfig', createOpts));
|
|
1657
|
+
ps.push(creator.createFileFromTemplate(templateName, '_eslintrc', '.eslintrc', createOpts));
|
|
1523
1658
|
ps.push(creator.createFileFromTemplate(templateName, 'babel.config.js', 'babel.config.js', createOpts));
|
|
1524
1659
|
ps.push(creator.createFileFromTemplate(templateName, 'src/index.html', 'src/index.html', createOpts));
|
|
1525
1660
|
Promise.all(ps).then(() => {
|
|
@@ -1546,23 +1681,51 @@ ${code}
|
|
|
1546
1681
|
*/
|
|
1547
1682
|
generateReport() {
|
|
1548
1683
|
const reportDir = path.join(this.convertRoot, 'report');
|
|
1549
|
-
const
|
|
1550
|
-
const reportIndexFilePath = path.
|
|
1551
|
-
|
|
1552
|
-
|
|
1684
|
+
const iconFilePath = path.join(__dirname, '../', 'report/favicon.ico');
|
|
1685
|
+
const reportIndexFilePath = path.join(__dirname, '../', 'report/index.html');
|
|
1686
|
+
const reportBundleFilePath = path.join(__dirname, '../', 'report/static/js/bundle.js');
|
|
1687
|
+
const reportStyleFilePath = path.join(__dirname, '../', 'report/static/css/main.css');
|
|
1688
|
+
const fontBlodFilePath = path.join(__dirname, '../', 'report/static/media/HarmonyOS_Sans_SC_Bold.ttf');
|
|
1689
|
+
const fontMediumFilePath = path.join(__dirname, '../', 'report/static/media/HarmonyOS_Sans_SC_Medium.ttf');
|
|
1690
|
+
const errMsgList = (0, util_1.paseGlobalErrMsgs)(global_1.globals.errCodeMsgs);
|
|
1691
|
+
const reportData = {
|
|
1692
|
+
projectName: (0, util_1.parseProjectName)(this.root),
|
|
1693
|
+
projectPath: this.root,
|
|
1694
|
+
pagesNum: this.pages.size,
|
|
1695
|
+
filesNum: (0, util_1.computeProjectFileNums)(this.root),
|
|
1696
|
+
errMsgList: errMsgList
|
|
1697
|
+
};
|
|
1698
|
+
try {
|
|
1699
|
+
(0, util_1.generateReportFile)(iconFilePath, reportDir, 'favicon.ico');
|
|
1700
|
+
(0, util_1.generateReportFile)(reportIndexFilePath, reportDir, 'index.html');
|
|
1701
|
+
(0, util_1.generateReportFile)(reportBundleFilePath, path.join(reportDir, '/static/js'), 'bundle.js', reportData);
|
|
1702
|
+
(0, util_1.generateReportFile)(reportStyleFilePath, path.join(reportDir, '/static/css'), 'main.css');
|
|
1703
|
+
(0, util_1.generateReportFile)(fontBlodFilePath, path.join(reportDir, '/static/media'), 'HarmonyOS_Sans_SC_Bold.ttf');
|
|
1704
|
+
(0, util_1.generateReportFile)(fontMediumFilePath, path.join(reportDir, '/static/media'), 'HarmonyOS_Sans_SC_Medium.ttf');
|
|
1705
|
+
console.log(`转换报告已生成,请在浏览器中打开 ${path.join(this.convertRoot, 'report', 'report.html')} 查看转换报告`);
|
|
1706
|
+
}
|
|
1707
|
+
catch (error) {
|
|
1708
|
+
console.log(`报告生成失败 ${error.message}`);
|
|
1709
|
+
}
|
|
1553
1710
|
}
|
|
1554
1711
|
showLog() {
|
|
1555
|
-
console.log();
|
|
1556
1712
|
console.log(`${helper_1.chalk.green('✔ ')} 转换成功,请进入 ${helper_1.chalk.bold('taroConvert')} 目录下使用 npm 或者 yarn 安装项目依赖后再运行!`);
|
|
1557
|
-
console.log(`转换报告已生成,请在浏览器中打开 ${path.join(this.convertRoot, 'report', 'report.html')} 查看转换报告`);
|
|
1558
1713
|
}
|
|
1559
1714
|
run() {
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1715
|
+
try {
|
|
1716
|
+
this.framework = "React" /* FrameworkType.React */;
|
|
1717
|
+
this.generateEntry();
|
|
1718
|
+
this.traversePages(this.root, this.pages);
|
|
1719
|
+
this.traversePlugin();
|
|
1720
|
+
this.generateConfigFiles();
|
|
1721
|
+
}
|
|
1722
|
+
catch (error) {
|
|
1723
|
+
(0, util_1.updateLogFileContent)(`ERROR [taro-cli-convertor] run - 转换异常 ${(0, util_1.getLineBreak)()}${error} ${(0, util_1.getLineBreak)()}`);
|
|
1724
|
+
}
|
|
1725
|
+
finally {
|
|
1726
|
+
(0, util_1.printToLogFile)();
|
|
1727
|
+
this.generateReport();
|
|
1728
|
+
}
|
|
1566
1729
|
}
|
|
1567
1730
|
}
|
|
1568
1731
|
exports.default = Convertor;
|