@tarojs/cli-convertor 4.0.0-beta.2 → 4.0.0-beta.20

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