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