@aiot-toolkit/aiotpack 2.0.2-dev.7 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/lib/{utils/ux/UxFollowWorks.d.ts → afterCompile/ux/UxAfterCompile.d.ts} +11 -4
  2. package/lib/{utils/ux/UxFollowWorks.js → afterCompile/ux/UxAfterCompile.js} +68 -43
  3. package/lib/{followWorks → afterCompile}/xts/entryTemplate.d.ts +1 -1
  4. package/lib/{followWorks → afterCompile}/xts/entryTemplate.js +14 -13
  5. package/lib/{followWorks → afterCompile}/xts/generateRpk.d.ts +1 -1
  6. package/lib/{followWorks → afterCompile}/xts/generateRpk.js +5 -4
  7. package/lib/{followWorks → afterCompile}/xts/ts2wasm.d.ts +1 -1
  8. package/lib/{followWorks → afterCompile}/xts/ts2wasm.js +7 -6
  9. package/lib/afterWorks/ux/UxAfterWorks.d.ts +5 -0
  10. package/lib/afterWorks/ux/UxAfterWorks.js +22 -0
  11. package/lib/{utils/ux/UxPreWorks.d.ts → beforeCompile/ux/UxBeforeCompile.d.ts} +4 -4
  12. package/lib/{utils/ux/UxPreWorks.js → beforeCompile/ux/UxBeforeCompile.js} +11 -8
  13. package/lib/{preWorks → beforeCompile}/xts/preInstall.d.ts +1 -1
  14. package/lib/{preWorks → beforeCompile}/xts/preInstall.js +6 -5
  15. package/lib/beforeWorks/ux/UxBeforeWorks.d.ts +5 -0
  16. package/lib/beforeWorks/ux/UxBeforeWorks.js +22 -0
  17. package/lib/compiler/interface/ICompileParam.d.ts +1 -1
  18. package/lib/compiler/interface/ISignConfig.d.ts +6 -1
  19. package/lib/compiler/javascript/JavascriptCompiler.js +45 -12
  20. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +1 -2
  21. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.d.ts +9 -0
  22. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +16 -0
  23. package/lib/compiler/javascript/android/plugin/WrapPlugin.d.ts +20 -0
  24. package/lib/compiler/javascript/android/plugin/WrapPlugin.js +91 -0
  25. package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +16 -1
  26. package/lib/compiler/javascript/interface/IWebpackConfigurator.d.ts +4 -4
  27. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +4 -2
  28. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +18 -5
  29. package/lib/compiler/javascript/vela/interface/IChunk.d.ts +6 -1
  30. package/lib/compiler/javascript/vela/interface/IManifest.d.ts +1 -1
  31. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.d.ts +1 -1
  32. package/lib/compiler/javascript/vela/model/Package.d.ts +2 -2
  33. package/lib/compiler/javascript/vela/model/Package.js +5 -5
  34. package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +1 -1
  35. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +16 -2
  36. package/lib/compiler/javascript/vela/utils/Jsc.d.ts +1 -1
  37. package/lib/compiler/javascript/vela/utils/Jsc.js +19 -11
  38. package/lib/compiler/javascript/vela/utils/UxCompileUtil.d.ts +1 -1
  39. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +4 -4
  40. package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +19 -3
  41. package/lib/compiler/javascript/vela/utils/ZipUtil.js +34 -29
  42. package/lib/compiler/javascript/vela/utils/signature/Base64.d.ts +0 -1
  43. package/lib/compiler/javascript/vela/utils/signature/SignUtil.d.ts +23 -7
  44. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +94 -45
  45. package/lib/compiler/javascript/vela/utils/signature/Signer.d.ts +0 -1
  46. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.d.ts +3 -0
  47. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +56 -0
  48. package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.d.ts +3 -0
  49. package/lib/compiler/javascript/vela/utils/webpackLoader/{splitMap.js → extractMapData.js} +2 -2
  50. package/lib/config/UxConfig.d.ts +45 -7
  51. package/lib/config/UxConfig.js +156 -40
  52. package/lib/config/XtsConfig.d.ts +6 -4
  53. package/lib/config/XtsConfig.js +22 -7
  54. package/lib/index.d.ts +9 -1
  55. package/lib/index.js +35 -1
  56. package/lib/loader/ux/JsLoader.d.ts +2 -0
  57. package/lib/loader/ux/JsLoader.js +6 -9
  58. package/lib/loader/ux/PngLoader.js +4 -5
  59. package/lib/loader/ux/android/UxLoader.d.ts +11 -0
  60. package/lib/loader/ux/android/UxLoader.js +39 -0
  61. package/lib/loader/ux/{AppUxLoader.d.ts → vela/AppUxLoader.d.ts} +1 -1
  62. package/lib/loader/ux/{AppUxLoader.js → vela/AppUxLoader.js} +6 -3
  63. package/lib/loader/ux/vela/HmlLoader.d.ts +24 -0
  64. package/lib/loader/ux/vela/HmlLoader.js +63 -0
  65. package/lib/loader/ux/{UxLoader.d.ts → vela/UxLoader.d.ts} +1 -1
  66. package/lib/loader/ux/{UxLoader.js → vela/UxLoader.js} +12 -13
  67. package/lib/loader/xts/XtsLoader.js +6 -7
  68. package/lib/utils/BeforeCompileUtils.d.ts +21 -0
  69. package/lib/utils/BeforeCompileUtils.js +118 -0
  70. package/lib/utils/ux/ManifestSchema.d.ts +1 -1
  71. package/lib/utils/ux/UxFileUtils.d.ts +16 -3
  72. package/lib/utils/ux/UxFileUtils.js +50 -17
  73. package/lib/utils/ux/UxLoaderUtils.d.ts +7 -4
  74. package/lib/utils/ux/UxLoaderUtils.js +43 -25
  75. package/lib/utils/ux/android/AndroidUx.d.ts +27 -0
  76. package/lib/utils/ux/android/AndroidUx.js +98 -0
  77. package/lib/utils/xts/XtsFileLaneUtils.d.ts +10 -0
  78. package/lib/utils/xts/XtsFileLaneUtils.js +68 -0
  79. package/lib/utils/xts/XtsFollowWorks.js +8 -8
  80. package/package.json +16 -8
  81. package/lib/compiler/javascript/vela/utils/webpackLoader/splitMap.d.ts +0 -3
  82. package/lib/utils/PreWorkUtils.d.ts +0 -22
  83. package/lib/utils/PreWorkUtils.js +0 -106
@@ -13,9 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
17
16
  const path_1 = __importDefault(require("path"));
18
- const UxLoaderUtils_1 = __importDefault(require("../../utils/ux/UxLoaderUtils"));
17
+ const UxLoaderUtils_1 = __importDefault(require("../../../utils/ux/UxLoaderUtils"));
19
18
  class UxLoader {
20
19
  parser(files) {
21
20
  return __awaiter(this, void 0, void 0, function* () {
@@ -23,17 +22,17 @@ class UxLoader {
23
22
  const { projectPath } = this.context;
24
23
  for (const file of files) {
25
24
  // 转换每个文件
26
- const { files, logs } = yield UxLoaderUtils_1.default.compileUxToJavascript(file, this.context, false, this.compilerOption);
27
- if (logs) {
28
- logs.forEach((item) => {
29
- ColorConsole_1.default.logger(Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' }));
30
- });
31
- // 如果有 error throw,则停止
32
- if (logs.some((item) => item.level && [shared_utils_1.LOG_LEVEL.Throw].includes(item.level))) {
33
- throw new Error('stop!');
34
- }
35
- }
36
- resultFiles.push(...files);
25
+ const { files: compiledFiles, logs } = yield UxLoaderUtils_1.default.compileUxToJavascript(file, this.context, false, this.compilerOption);
26
+ // style报错中,@import导入的文件报错路径存储在item.position.source中
27
+ shared_utils_1.CommonUtil.processingLogsInTerminal(logs.map((item) => {
28
+ var _a;
29
+ return (Object.assign(Object.assign({}, item), { filePath: ((_a = item.position) === null || _a === void 0 ? void 0 : _a.source)
30
+ ? item.position.source
31
+ : item.filePath
32
+ ? path_1.default.relative(projectPath, item.filePath)
33
+ : '' }));
34
+ }));
35
+ resultFiles.push(...compiledFiles);
37
36
  }
38
37
  return resultFiles;
39
38
  });
@@ -5,8 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const generator_1 = require("@aiot-toolkit/generator");
7
7
  const parser_1 = require("@aiot-toolkit/parser");
8
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
9
- const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
8
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
10
9
  const path_1 = __importDefault(require("path"));
11
10
  const ts_morph_1 = require("ts-morph");
12
11
  /**
@@ -23,11 +22,11 @@ class XtsLoader {
23
22
  const newFileName = `${name}.ts`;
24
23
  //判断文本,空文本则结束该文件处理
25
24
  if (!content) {
26
- ColorConsole_1.default.warn(`The file '${fullName}' under the path '${path}' has no content `);
25
+ shared_utils_1.ColorConsole.warn(`The file '${fullName}' under the path '${path}' has no content `);
27
26
  return [];
28
27
  }
29
- const parserResult = new parser_1.XtsParser(project, ColorConsole_1.default.logger).parser(content.toString(), fullName);
30
- const { ast, mapList } = new parser_1.XtsToTypescript(project, ColorConsole_1.default.logger, this.context, path).translate(parserResult.ast, parserResult.offsetList);
28
+ const parserResult = new parser_1.XtsParser(project, shared_utils_1.ColorConsole.logger).parser(content.toString(), fullName);
29
+ const { ast, mapList } = new parser_1.XtsToTypescript(project, shared_utils_1.ColorConsole.logger, this.context, path).translate(parserResult.ast, parserResult.offsetList);
31
30
  const { code, sourcemap } = new generator_1.TypescriptGenerator().generate({
32
31
  sourceFilePath: fullName,
33
32
  targetFilePath: newFileName,
@@ -35,10 +34,10 @@ class XtsLoader {
35
34
  mapList
36
35
  });
37
36
  resultFiles.push({
38
- path: FileUtil_1.default.updatePath(path, newFileName),
37
+ path: shared_utils_1.FileUtil.updateFileName(path, newFileName),
39
38
  content: code
40
39
  }, {
41
- path: FileUtil_1.default.updatePath(path, `${name}.map.ts`),
40
+ path: shared_utils_1.FileUtil.updateFileName(path, `${name}.map.ts`),
42
41
  content: sourcemap
43
42
  });
44
43
  }
@@ -0,0 +1,21 @@
1
+ import { PreWork } from 'file-lane';
2
+ import IJavascriptCompileOption from '../compiler/javascript/interface/IJavascriptCompileOption';
3
+ /**
4
+ * BeforeCompileUtils
5
+ */
6
+ declare class BeforeCompileUtils {
7
+ /**
8
+ * 获取ux项目的路由入口
9
+ * @param context
10
+ * @param fileList
11
+ * @returns
12
+ */
13
+ static getEntries: PreWork;
14
+ static clean: PreWork;
15
+ /**
16
+ * 获取项目的全局样式变量配置
17
+ * @param context
18
+ */
19
+ static getGlobalVar: PreWork<IJavascriptCompileOption>;
20
+ }
21
+ export default BeforeCompileUtils;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ var _a;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ const parser_1 = require("@aiot-toolkit/parser");
17
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
18
+ const fs_extra_1 = __importDefault(require("fs-extra"));
19
+ const path_1 = __importDefault(require("path"));
20
+ const TranslateCache_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/TranslateCache"));
21
+ const UxFileUtils_1 = __importDefault(require("./ux/UxFileUtils"));
22
+ const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
23
+ /**
24
+ * BeforeCompileUtils
25
+ */
26
+ class BeforeCompileUtils {
27
+ }
28
+ _a = BeforeCompileUtils;
29
+ /**
30
+ * 获取ux项目的路由入口
31
+ * @param context
32
+ * @param fileList
33
+ * @returns
34
+ */
35
+ BeforeCompileUtils.getEntries = (params) => {
36
+ const { context, compilerOption } = params;
37
+ const { projectPath } = context;
38
+ const srcPath = path_1.default.join(projectPath, compilerOption.sourceRoot);
39
+ // 判断路径是否真实存在
40
+ const manifestContent = UxFileUtils_1.default.getMainfestInfo(projectPath);
41
+ // 存储entries
42
+ let entryList = [];
43
+ const { router } = manifestContent;
44
+ if (router) {
45
+ const { pages } = router;
46
+ if (pages) {
47
+ Object.keys(pages).map((page) => {
48
+ const pageContent = pages[page];
49
+ const entryDir = path_1.default.join(srcPath, page);
50
+ const entryPages = parser_1.ExtensionConfig.TEMPLATES.map((item) => `${pageContent.component}${item}`);
51
+ const entry = entryPages.find((item) => fs_extra_1.default.existsSync(path_1.default.join(entryDir, item)));
52
+ if (entry) {
53
+ entryList.push(path_1.default.join(entryDir, entry));
54
+ }
55
+ else {
56
+ // 路径不存在
57
+ shared_utils_1.ColorConsole.throw(`### manifest ### path '${path_1.default.join(entryDir, entryPages.join(' | '))}' does not exist`);
58
+ }
59
+ });
60
+ }
61
+ else {
62
+ // 没有pages配置
63
+ shared_utils_1.ColorConsole.throw(`### manifest ### No pages configuration`);
64
+ }
65
+ }
66
+ else {
67
+ // 没有router配置
68
+ shared_utils_1.ColorConsole.throw(`### manifest ### No router configuration`);
69
+ }
70
+ context['entries'] = entryList;
71
+ return Promise.resolve();
72
+ };
73
+ BeforeCompileUtils.clean = (params) => __awaiter(void 0, void 0, void 0, function* () {
74
+ const { context, compilerOption, compalition } = params;
75
+ if (compilerOption) {
76
+ // 存储build中的文件列表
77
+ const buildPath = path_1.default.join(context.projectPath, compilerOption.outputPath);
78
+ const buildFileList = fs_extra_1.default.existsSync(buildPath)
79
+ ? shared_utils_1.FileUtil.readAlldirSync(buildPath).map((filePath) => {
80
+ const relativePath = path_1.default.relative(buildPath, filePath);
81
+ const fileContent = fs_extra_1.default.readFileSync(filePath);
82
+ return { path: relativePath, content: fileContent };
83
+ })
84
+ : [];
85
+ if (compalition) {
86
+ compalition.buildFileList = buildFileList;
87
+ }
88
+ // 清空build文件夹、dist文件夹
89
+ yield shared_utils_1.FileUtil.del(path_1.default.join(context.projectPath, compilerOption.outputPath));
90
+ yield shared_utils_1.FileUtil.del(path_1.default.join(context.projectPath, compilerOption.releasePath));
91
+ }
92
+ context.translateCache = new TranslateCache_1.default();
93
+ BinaryPlugin.reset();
94
+ BinaryPlugin.config = {
95
+ projectPath: context.projectPath,
96
+ outputProjectPath: path_1.default.join(context.projectPath, context.output),
97
+ source: compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.sourceRoot,
98
+ output: compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.outputPath
99
+ };
100
+ });
101
+ /**
102
+ * 获取项目的全局样式变量配置
103
+ * @param context
104
+ */
105
+ BeforeCompileUtils.getGlobalVar = (params) => {
106
+ const { context, compilerOption } = params;
107
+ const { projectPath } = context;
108
+ const filePath = path_1.default.join(projectPath, (compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.sourceRoot) || '', 'globalVar.json');
109
+ let globalVar = {};
110
+ // 判断文件是否存在
111
+ if (fs_extra_1.default.existsSync(filePath)) {
112
+ // 存在则取内容,否则内容为空
113
+ globalVar = fs_extra_1.default.readJSONSync(filePath);
114
+ }
115
+ context.globalVar = globalVar;
116
+ return Promise.resolve();
117
+ };
118
+ exports.default = BeforeCompileUtils;
@@ -1,3 +1,3 @@
1
- import { JSONSchemaType } from '@aiot-toolkit/shared-utils/lib/utils/CommonUtil';
1
+ import { JSONSchemaType } from '@aiot-toolkit/shared-utils';
2
2
  declare const ManifestSchema: JSONSchemaType;
3
3
  export default ManifestSchema;
@@ -1,3 +1,4 @@
1
+ import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
1
2
  import IManifest from '../../compiler/javascript/vela/interface/IManifest';
2
3
  export declare class UxFileUtils {
3
4
  static readonly CONFIG_FILE_NAME = "manifest.json";
@@ -18,9 +19,10 @@ export declare class UxFileUtils {
18
19
  /**
19
20
  * 检查 manifest文件,并显示错误信息
20
21
  *
21
- * 1. TypeError,使用Error 样式
22
- * 2. 其它错误,使用 Warn 样式
23
- * 3. 如果存在TypeError,则终止程序
22
+ * 1. 使用ManifestSchema 校验
23
+ * 1. TypeError: Error
24
+ * 2. 其它: Warn
25
+ * 2. 检查 router.entry 是否存在于 router.pages
24
26
  *
25
27
  * @param projectPath 项目路径
26
28
  * @param sourceRoot 源码路径--相对项目根目录
@@ -35,5 +37,16 @@ export declare class UxFileUtils {
35
37
  * @param sourceRoot
36
38
  */
37
39
  static validateSitemap(projectPath: string, sourceRoot?: string): void;
40
+ /**
41
+ * 1. 遍历旧文件列表
42
+ * 1.1 若文件路径在新文件列表newFileList中,且内容一致时,从newFileList中移除该项
43
+ * 1.2 若文件路径在新文件列表newFileList中,且内容不一致时,添加到diffList中表示待更新,从newFileList中移除该项
44
+ * 1.3 若文件路径不在新文件列表中,表示该文件待删除(热更新时,可以不做删除,删除耗费性能)
45
+ * 2. 若遍历完旧文件列表后,newFileList长度不为0,表示有文件待新增
46
+ * @param oldFileList 旧文件列表
47
+ * @param newFileList 新文件列表
48
+ * @returns
49
+ */
50
+ static getDiffJSON(compilation: FileLaneCompilation, newFileList: string[], buildPath: string): void;
38
51
  }
39
52
  export default UxFileUtils;
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.UxFileUtils = void 0;
7
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
8
7
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
8
+ const ILog_1 = require("@aiot-toolkit/shared-utils/lib/interface/ILog");
9
9
  const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
10
10
  const fs_extra_1 = __importDefault(require("fs-extra"));
11
11
  const path_1 = __importDefault(require("path"));
@@ -32,9 +32,10 @@ class UxFileUtils {
32
32
  /**
33
33
  * 检查 manifest文件,并显示错误信息
34
34
  *
35
- * 1. TypeError,使用Error 样式
36
- * 2. 其它错误,使用 Warn 样式
37
- * 3. 如果存在TypeError,则终止程序
35
+ * 1. 使用ManifestSchema 校验
36
+ * 1. TypeError: Error
37
+ * 2. 其它: Warn
38
+ * 2. 检查 router.entry 是否存在于 router.pages
38
39
  *
39
40
  * @param projectPath 项目路径
40
41
  * @param sourceRoot 源码路径--相对项目根目录
@@ -45,30 +46,29 @@ class UxFileUtils {
45
46
  if (!fs_extra_1.default.existsSync(path)) {
46
47
  ColorConsole_1.default.throw(`file is missing`, {
47
48
  word: path,
48
- style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw)
49
+ style: ColorConsole_1.default.getStyle(ILog_1.Loglevel.THROW)
49
50
  });
50
51
  }
52
+ // 1
51
53
  const jsonData = this.getMainfestInfo(projectPath, sourceRoot);
52
54
  const schema = ManifestSchema_1.default;
53
- const errors = CommonUtil_1.default.validateJson(jsonData, schema);
54
- if (errors) {
55
+ const errors = CommonUtil_1.default.validateJson(jsonData, schema) || [];
56
+ // 2
57
+ const { entry, pages } = jsonData.router;
58
+ if (!pages[entry]) {
59
+ errors.push(new TypeError(`router.entry content: ${entry}, is missing in router.pages`));
60
+ }
61
+ if (errors === null || errors === void 0 ? void 0 : errors.length) {
55
62
  ColorConsole_1.default.warn(`Manefest.json error: `, ...errors.map((item, index) => {
56
63
  return {
57
64
  word: `\r\n${index + 1}. ${item.message}`,
58
65
  style: item instanceof TypeError
59
- ? ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Error)
60
- : ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Warn)
66
+ ? ColorConsole_1.default.getStyle(ILog_1.Loglevel.ERROR)
67
+ : ColorConsole_1.default.getStyle(ILog_1.Loglevel.WARN)
61
68
  };
62
69
  }));
63
- const stop = Boolean(errors.find((item) => item instanceof TypeError));
64
- if (stop) {
65
- ColorConsole_1.default.throw({
66
- word: `missing required content, program stoped`,
67
- style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw)
68
- });
69
- }
70
70
  }
71
- return errors;
71
+ return errors.length ? errors : undefined;
72
72
  }
73
73
  /**
74
74
  * 检查 sitemap.json 文件,并显示错误信息
@@ -97,6 +97,39 @@ class UxFileUtils {
97
97
  }
98
98
  }
99
99
  }
100
+ /**
101
+ * 1. 遍历旧文件列表
102
+ * 1.1 若文件路径在新文件列表newFileList中,且内容一致时,从newFileList中移除该项
103
+ * 1.2 若文件路径在新文件列表newFileList中,且内容不一致时,添加到diffList中表示待更新,从newFileList中移除该项
104
+ * 1.3 若文件路径不在新文件列表中,表示该文件待删除(热更新时,可以不做删除,删除耗费性能)
105
+ * 2. 若遍历完旧文件列表后,newFileList长度不为0,表示有文件待新增
106
+ * @param oldFileList 旧文件列表
107
+ * @param newFileList 新文件列表
108
+ * @returns
109
+ */
110
+ static getDiffJSON(compilation, newFileList, buildPath) {
111
+ var _a;
112
+ const oldFileList = compilation.buildFileList;
113
+ let diffList = [];
114
+ // 1.
115
+ for (let i = 0; i < oldFileList.length; i++) {
116
+ const index = newFileList.findIndex((file) => file === oldFileList[i].path);
117
+ // 1.3
118
+ if (index !== -1) {
119
+ // 1.2
120
+ const oldContent = (_a = oldFileList[i].content) === null || _a === void 0 ? void 0 : _a.toString('utf-8');
121
+ const newContent = fs_extra_1.default.readFileSync(path_1.default.join(buildPath, newFileList[index]), 'utf-8');
122
+ if (oldContent !== newContent) {
123
+ diffList.push(newFileList[index]);
124
+ }
125
+ // 从newFileList中移除该项
126
+ newFileList.splice(index, 1);
127
+ }
128
+ }
129
+ // 2.
130
+ newFileList.length > 0 && newFileList.forEach((file) => diffList.push(file));
131
+ compilation.diffJson = diffList;
132
+ }
100
133
  }
101
134
  exports.UxFileUtils = UxFileUtils;
102
135
  UxFileUtils.CONFIG_FILE_NAME = 'manifest.json';
@@ -24,7 +24,10 @@ declare class UxLoaderUtils {
24
24
  * @param resultFiles
25
25
  * @param context
26
26
  */
27
- static compileAppUxToJavascript(file: IFileParam, resultFiles: IFileParam[], context: IFileLaneContext, compileOption: IJavascriptCompileOption): Promise<void>;
27
+ static compileAppUxToJavascript(file: IFileParam, context: IFileLaneContext, compileOption: IJavascriptCompileOption): Promise<{
28
+ files: IFileParam[];
29
+ logs: ILog[];
30
+ }>;
28
31
  /**
29
32
  * 判断是否为src/app.ux
30
33
  * @param filePath
@@ -37,7 +40,7 @@ declare class UxLoaderUtils {
37
40
  * @param filePath
38
41
  * @returns
39
42
  */
40
- static isPageUx(context: IFileLaneContext, filePath: string): any;
43
+ static isPageUx(context: IFileLaneContext, filePath: string): boolean;
41
44
  /**
42
45
  * 获取app.ux的内容,且只返回script和style内容
43
46
  * @param fileContent
@@ -51,14 +54,14 @@ declare class UxLoaderUtils {
51
54
  * @returns
52
55
  */
53
56
  static wrapTempalte(templateTree: SourceFile, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
54
- private static wrapStyle;
57
+ static wrapStyle(code: string, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
55
58
  /**
56
59
  * 给script增加外层包裹内容
57
60
  * @param isPageUx
58
61
  * @param appScriptTree
59
62
  * @returns
60
63
  */
61
- static handleScriptContent(isPageUx: boolean, appScriptTree: SourceFile): string;
64
+ static wrapScript(isPageUx: boolean, appScriptTree: SourceFile): string;
62
65
  static getReturnType(isPageUx: boolean): "$app_exports$['entry'] =" | "module.exports = ";
63
66
  }
64
67
  export default UxLoaderUtils;
@@ -36,14 +36,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const generator_1 = require("@aiot-toolkit/generator");
39
- const UxParser_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/parser/UxParser"));
39
+ const parser_1 = require("@aiot-toolkit/parser");
40
40
  const UxToTypescript_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/UxToTypescript"));
41
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
42
- const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
43
- const StringUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/StringUtil"));
44
- const parse5 = __importStar(require("parse5"));
41
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
42
+ const parse5 = __importStar(require("aiot-parse5"));
43
+ const fs_extra_1 = __importDefault(require("fs-extra"));
45
44
  const path_1 = __importDefault(require("path"));
46
- const ts_morph_1 = require("ts-morph");
47
45
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
48
46
  const { extractFunctions } = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/protobufControl');
49
47
  /**
@@ -59,7 +57,6 @@ class UxLoaderUtils {
59
57
  */
60
58
  static compileUxToJavascript(file, context, isAppUx, compilerOption) {
61
59
  return __awaiter(this, void 0, void 0, function* () {
62
- const project = new ts_morph_1.Project();
63
60
  const logs = [];
64
61
  const { path: filePath, content } = file;
65
62
  const { name, ext } = path_1.default.parse(filePath);
@@ -68,44 +65,63 @@ class UxLoaderUtils {
68
65
  const newFileName = `${name}.js`;
69
66
  //判断文本,空文本则结束该文件处理
70
67
  if (!content) {
71
- ColorConsole_1.default.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
68
+ shared_utils_1.ColorConsole.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
72
69
  return {
73
70
  files: [],
74
71
  logs
75
72
  };
76
73
  }
74
+ // 区分页面组件和子组件
75
+ const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
77
76
  // 配置转换参数
78
77
  const options = {
79
78
  projectPath: context.projectPath,
79
+ projectType: shared_utils_1.ProjectType.VELA_UX,
80
80
  filePath,
81
+ fileType: isAppUx ? 'app' : isPageUx ? 'page' : '',
82
+ content: content.toString(),
81
83
  onLog: (log) => {
82
84
  logs.push(log);
83
85
  }
84
86
  };
87
+ // 收集图片资源
88
+ const ImageResources = [];
89
+ const collectImageResource = (originFilePath) => {
90
+ const assetDir = 'dynamicAssets';
91
+ const sourcePath = path_1.default.resolve(options.projectPath, compilerOption.sourceRoot);
92
+ const assetPath = path_1.default.resolve(sourcePath, assetDir);
93
+ const { name, ext } = path_1.default.parse(originFilePath);
94
+ const hashName = shared_utils_1.CommonUtil.calcImageDigest(originFilePath);
95
+ const newFilePath = path_1.default.join(assetPath, `${name}-${hashName}${ext}`);
96
+ const relativePath = path_1.default.posix.sep + path_1.default.relative(sourcePath, newFilePath).split(path_1.default.sep).join(path_1.default.posix.sep);
97
+ ImageResources.push({
98
+ path: newFilePath,
99
+ content: fs_extra_1.default.readFileSync(originFilePath)
100
+ });
101
+ return relativePath;
102
+ };
85
103
  // 开始转换
86
104
  const globalVar = ('globalVar' in context && context.globalVar) || {};
87
- const parserResult = yield new UxParser_1.default(options, globalVar).parser(content.toString(), fullName);
105
+ const parserResult = yield new parser_1.UxParser(options, compilerOption, globalVar, collectImageResource).parser();
88
106
  // 区分app.ux和一般ux
89
107
  // app.ux解析结果中加上manifest.json的内容
90
108
  const manifestJson = `require('./manifest.json')`;
91
- // 区分页面组件和子组件
92
- const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
93
109
  const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
94
110
  // script代码放在第三个位置不能变化,影响更新source map
95
111
  return isAppUx
96
112
  ? [
97
113
  `${appImport.join('\n')}`,
98
- `var $app_style$ = ${UxLoaderUtils.wrapStyle(StringUtil_1.default.arrayTostring(appStyleTree, true), file, compilerOption)}`,
99
- `var $app_script$ = ${UxLoaderUtils.handleScriptContent(false, appScriptTree)}\n`,
100
- `$app_script$({}, $app_exports$, $app_require$);\n\n`,
114
+ `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
115
+ `var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}`,
116
+ `$app_script$({}, $app_exports$, $app_require$);`,
101
117
  `$app_exports$.default.style = $app_style$;`,
102
118
  `$app_exports$.default.manifest = ${manifestJson}`
103
119
  ]
104
120
  : [
105
121
  `${appImport.join('\n')}`,
106
- `var $app_style$ = ${UxLoaderUtils.wrapStyle(StringUtil_1.default.arrayTostring(appStyleTree, true), file, compilerOption)}\n`,
107
- `var $app_script$ = ${UxLoaderUtils.handleScriptContent(isPageUx, appScriptTree)}`,
108
- `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}\n`,
122
+ `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
123
+ `var $app_script$ = ${UxLoaderUtils.wrapScript(isPageUx, appScriptTree)}`,
124
+ `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}`,
109
125
  `${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`,
110
126
  `$app_script$({}, $app_exports$, $app_require$);`,
111
127
  `$app_exports$.default.template = $app_template$;`,
@@ -113,7 +129,7 @@ class UxLoaderUtils {
113
129
  `}`
114
130
  ];
115
131
  };
116
- const { targetTree, mapList, sourceMap } = yield new UxToTypescript_1.default(options, project, integrateFunction, compilerOption).translate(parserResult.ast, []);
132
+ const { targetTree, mapList, sourceMap } = yield new UxToTypescript_1.default(options, integrateFunction, compilerOption, context).translate(parserResult.ast, []);
117
133
  const { code } = new generator_1.TypescriptGenerator().generate({
118
134
  sourceFilePath: fullName,
119
135
  targetFilePath: newFileName,
@@ -124,13 +140,14 @@ class UxLoaderUtils {
124
140
  return {
125
141
  files: [
126
142
  {
127
- path: FileUtil_1.default.updatePath(filePath, newFileName),
143
+ path: filePath,
128
144
  content: code
129
145
  },
130
146
  {
131
- path: FileUtil_1.default.updatePath(filePath, `${name}.js.map`),
147
+ path: shared_utils_1.FileUtil.updateFileName(filePath, `${name}${ext}.map`),
132
148
  content: sourceMap.toString()
133
- }
149
+ },
150
+ ...ImageResources
134
151
  ],
135
152
  logs
136
153
  };
@@ -142,7 +159,7 @@ class UxLoaderUtils {
142
159
  * @param resultFiles
143
160
  * @param context
144
161
  */
145
- static compileAppUxToJavascript(file, resultFiles, context, compileOption) {
162
+ static compileAppUxToJavascript(file, context, compileOption) {
146
163
  return __awaiter(this, void 0, void 0, function* () {
147
164
  const { path: filePath, content } = file;
148
165
  let appContent = content;
@@ -153,7 +170,7 @@ class UxLoaderUtils {
153
170
  }
154
171
  // 解析script和style两部分
155
172
  const compileResult = yield UxLoaderUtils.compileUxToJavascript({ path: filePath, content: appContent }, context, isAppUx, compileOption);
156
- resultFiles.push(...compileResult.files);
173
+ return compileResult;
157
174
  });
158
175
  }
159
176
  /**
@@ -173,7 +190,8 @@ class UxLoaderUtils {
173
190
  * @returns
174
191
  */
175
192
  static isPageUx(context, filePath) {
176
- return ('entries' in context && context.entries.find((entryItem) => entryItem === filePath));
193
+ var _a;
194
+ return Boolean((_a = context.entries) === null || _a === void 0 ? void 0 : _a.includes(filePath));
177
195
  }
178
196
  /**
179
197
  * 获取app.ux的内容,且只返回script和style内容
@@ -289,7 +307,7 @@ class UxLoaderUtils {
289
307
  * @param appScriptTree
290
308
  * @returns
291
309
  */
292
- static handleScriptContent(isPageUx, appScriptTree) {
310
+ static wrapScript(isPageUx, appScriptTree) {
293
311
  if (isPageUx) {
294
312
  // 页面组件添加ViewModel处理代码
295
313
  appScriptTree.addStatements(UxLoaderUtils.contenAccess);
@@ -0,0 +1,27 @@
1
+ import { ILog } from '@aiot-toolkit/shared-utils';
2
+ import { IFileLaneContext, IFileParam } from 'file-lane';
3
+ import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
4
+ /**
5
+ * AndroidUx
6
+ */
7
+ declare class AndroidUx {
8
+ /**
9
+ *
10
+ * 编译 ux 文件
11
+ * 1. 获取文件类型:app page 普通ux
12
+ * 2. 使用`UxParse`解析
13
+ * 3. 使用`UxToTypeScript`转换
14
+ * 4. 使用`TypeScriptGenerator`生成
15
+ * @param params
16
+ */
17
+ compileUx(params: {
18
+ context: IFileLaneContext;
19
+ file: IFileParam;
20
+ compilerOption: IJavascriptCompileOption;
21
+ }): Promise<{
22
+ files: IFileParam[];
23
+ logs: ILog[];
24
+ }>;
25
+ private getFileType;
26
+ }
27
+ export default AndroidUx;