@aiot-toolkit/aiotpack 2.0.3-beta.1 → 2.0.3-beta.11

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 (58) hide show
  1. package/lib/afterCompile/ux/UxAfterCompile.js +292 -266
  2. package/lib/afterCompile/xts/entryTemplate.js +111 -113
  3. package/lib/afterCompile/xts/generateRpk.js +25 -54
  4. package/lib/afterCompile/xts/ts2wasm.js +62 -63
  5. package/lib/afterWorks/ux/UxAfterWorks.js +12 -19
  6. package/lib/beforeCompile/ux/UxBeforeCompile.js +26 -28
  7. package/lib/beforeCompile/xts/preInstall.js +50 -55
  8. package/lib/beforeWorks/ux/UxBeforeWorks.js +12 -19
  9. package/lib/compiler/enum/CompileMode.js +16 -23
  10. package/lib/compiler/interface/ICompileParam.js +1 -2
  11. package/lib/compiler/interface/ICompiler.js +1 -2
  12. package/lib/compiler/interface/ISignConfig.js +1 -2
  13. package/lib/compiler/javascript/JavascriptCompiler.js +147 -154
  14. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +20 -16
  15. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +13 -11
  16. package/lib/compiler/javascript/android/plugin/WrapPlugin.js +53 -49
  17. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +1 -2
  18. package/lib/compiler/javascript/interface/IWebpackConfigurator.js +4 -1
  19. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +78 -75
  20. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +30 -41
  21. package/lib/compiler/javascript/vela/enum/EntryType.js +15 -29
  22. package/lib/compiler/javascript/vela/interface/IChunk.js +4 -1
  23. package/lib/compiler/javascript/vela/interface/IManifest.js +1 -2
  24. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js +1 -2
  25. package/lib/compiler/javascript/vela/model/Package.js +80 -51
  26. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +31 -27
  27. package/lib/compiler/javascript/vela/utils/Jsc.js +30 -33
  28. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +152 -130
  29. package/lib/compiler/javascript/vela/utils/ZipUtil.js +282 -276
  30. package/lib/compiler/javascript/vela/utils/signature/Base64.js +65 -67
  31. package/lib/compiler/javascript/vela/utils/signature/CRC32.js +37 -35
  32. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +755 -731
  33. package/lib/compiler/javascript/vela/utils/signature/Signer.js +24 -22
  34. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +47 -52
  35. package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.js +21 -17
  36. package/lib/config/UxConfig.js +145 -173
  37. package/lib/config/XtsConfig.js +30 -40
  38. package/lib/index.js +88 -41
  39. package/lib/interface/ICompileOptions.js +5 -2
  40. package/lib/interface/IDeviceList.js +1 -2
  41. package/lib/loader/ux/JsLoader.js +32 -30
  42. package/lib/loader/ux/PngLoader.js +47 -53
  43. package/lib/loader/ux/android/UxLoader.js +30 -31
  44. package/lib/loader/ux/vela/AppUxLoader.js +23 -24
  45. package/lib/loader/ux/vela/HmlLoader.js +59 -55
  46. package/lib/loader/ux/vela/UxLoader.js +29 -35
  47. package/lib/loader/xts/XtsLoader.js +55 -41
  48. package/lib/utils/BeforeCompileUtils.js +100 -95
  49. package/lib/utils/PngUtils.js +42 -36
  50. package/lib/utils/ux/ManifestSchema.js +198 -194
  51. package/lib/utils/ux/UxFileUtils.d.ts +2 -2
  52. package/lib/utils/ux/UxFileUtils.js +130 -128
  53. package/lib/utils/ux/UxLoaderUtils.d.ts +2 -1
  54. package/lib/utils/ux/UxLoaderUtils.js +295 -307
  55. package/lib/utils/ux/android/AndroidUx.js +88 -90
  56. package/lib/utils/xts/XtsFileLaneUtils.js +58 -65
  57. package/lib/utils/xts/XtsFollowWorks.js +122 -129
  58. package/package.json +6 -6
@@ -1,139 +1,141 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.UxFileUtils = void 0;
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
- const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
10
- const fs_extra_1 = __importDefault(require("fs-extra"));
11
- const path_1 = __importDefault(require("path"));
12
- const ManifestSchema_1 = __importDefault(require("./ManifestSchema"));
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.UxFileUtils = void 0;
7
+ var _CommonUtil = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
8
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _ManifestSchema = _interopRequireDefault(require("./ManifestSchema"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ /**
13
+ * FileUtils
14
+ */
13
15
  class UxFileUtils {
14
- /**
15
- * 获取manifest.json路径
16
- * @param projectPath
17
- * @param sourceRoot
18
- * @returns
19
- */
20
- static getManifestFilePath(projectPath, sourceRoot = 'src') {
21
- return path_1.default.resolve(projectPath, sourceRoot, UxFileUtils.CONFIG_FILE_NAME);
16
+ static CONFIG_FILE_NAME = 'manifest.json';
17
+ /**
18
+ * 获取manifest.json路径
19
+ * @param projectPath
20
+ * @param sourceRoot
21
+ * @returns
22
+ */
23
+ static getManifestFilePath(projectPath) {
24
+ let sourceRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'src';
25
+ return _path.default.resolve(projectPath, sourceRoot, UxFileUtils.CONFIG_FILE_NAME);
26
+ }
27
+ /**
28
+ * 获取manifest.json内容
29
+ * @param projectPath
30
+ * @param sourceRoot
31
+ * @returns
32
+ */
33
+ static getMainfestInfo(projectPath) {
34
+ let sourceRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'src';
35
+ return _fsExtra.default.readJSONSync(UxFileUtils.getManifestFilePath(projectPath, sourceRoot));
36
+ }
37
+
38
+ /**
39
+ * 检查 manifest文件,并显示错误信息
40
+ *
41
+ * 1. 使用ManifestSchema 校验
42
+ * 1. TypeError: Error
43
+ * 2. 其它: Warn
44
+ * 2. 检查 router.entry 是否存在于 router.pages
45
+ *
46
+ * @param projectPath 项目路径
47
+ * @param sourceRoot 源码路径--相对项目根目录
48
+ * @returns
49
+ */
50
+ static validateManifest(projectPath) {
51
+ let sourceRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'src';
52
+ const path = UxFileUtils.getManifestFilePath(projectPath, sourceRoot);
53
+ if (!_fsExtra.default.existsSync(path)) {
54
+ throw new Error(`no such file: '${path}'`);
22
55
  }
23
- /**
24
- * 获取manifest.json内容
25
- * @param projectPath
26
- * @param sourceRoot
27
- * @returns
28
- */
29
- static getMainfestInfo(projectPath, sourceRoot = 'src') {
30
- return fs_extra_1.default.readJSONSync(UxFileUtils.getManifestFilePath(projectPath, sourceRoot));
56
+
57
+ // 1
58
+ const jsonData = this.getMainfestInfo(projectPath, sourceRoot);
59
+ const schema = _ManifestSchema.default;
60
+ const errors = _CommonUtil.default.validateJson(jsonData, schema) || [];
61
+
62
+ // 2
63
+ const {
64
+ entry,
65
+ pages
66
+ } = jsonData.router;
67
+ if (!pages[entry]) {
68
+ errors.push(new TypeError(`router.entry content: ${entry}, is missing in router.pages`));
31
69
  }
32
- /**
33
- * 检查 manifest文件,并显示错误信息
34
- *
35
- * 1. 使用ManifestSchema 校验
36
- * 1. TypeError: Error
37
- * 2. 其它: Warn
38
- * 2. 检查 router.entry 是否存在于 router.pages
39
- *
40
- * @param projectPath 项目路径
41
- * @param sourceRoot 源码路径--相对项目根目录
42
- * @returns
43
- */
44
- static validateManifest(projectPath, sourceRoot = 'src') {
45
- const path = UxFileUtils.getManifestFilePath(projectPath, sourceRoot);
46
- if (!fs_extra_1.default.existsSync(path)) {
47
- ColorConsole_1.default.throw(`file is missing`, {
48
- word: path,
49
- style: ColorConsole_1.default.getStyle(ILog_1.Loglevel.THROW)
50
- });
51
- }
52
- // 1
53
- const jsonData = this.getMainfestInfo(projectPath, sourceRoot);
54
- const schema = ManifestSchema_1.default;
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) {
62
- ColorConsole_1.default.warn(`Manefest.json error: `, ...errors.map((item, index) => {
63
- return {
64
- word: `\r\n${index + 1}. ${item.message}`,
65
- style: item instanceof TypeError
66
- ? ColorConsole_1.default.getStyle(ILog_1.Loglevel.ERROR)
67
- : ColorConsole_1.default.getStyle(ILog_1.Loglevel.WARN)
68
- };
69
- }));
70
- }
71
- return errors.length ? errors : undefined;
70
+ if (errors?.length) {
71
+ const message = `Manifest.json error: ${errors.map((item, index) => {
72
+ return `\r\n${index + 1}. ${item.message}`;
73
+ })}`;
74
+ throw new Error(message);
72
75
  }
73
- /**
74
- * 检查 sitemap.json 文件,并显示错误信息
75
- *
76
- * 1. sitemap.json rules 中配置的page 不存在于 manifest.json 中时,报错并终止程序
77
- * @param projectPath
78
- * @param sourceRoot
79
- */
80
- static validateSitemap(projectPath, sourceRoot = 'src') {
81
- const sitemapPath = path_1.default.join(projectPath, sourceRoot, 'sitemap.json');
82
- if (fs_extra_1.default.existsSync(sitemapPath)) {
83
- try {
84
- const rules = fs_extra_1.default.readJSONSync(sitemapPath).rules;
85
- const manifest = this.getMainfestInfo(projectPath, sourceRoot);
86
- const pages = Object.keys(manifest.router.pages || {});
87
- rules.forEach((item, index) => {
88
- const page = item.page;
89
- if (page !== '*' && !pages.includes(page)) {
90
- ColorConsole_1.default.throw(`The ${index + 1}th item of sitemap rules is configured incorrectly, the page ${page} does not exist`);
91
- }
92
- return page;
93
- });
94
- }
95
- catch (error) {
96
- ColorConsole_1.default.warn(error === null || error === void 0 ? void 0 : error.toString());
97
- }
76
+ }
77
+
78
+ /**
79
+ * 检查 sitemap.json 文件,并显示错误信息
80
+ *
81
+ * 1. 当sitemap.json的 rules 中配置的page 不存在于 manifest.json 中时,报错
82
+ * @param projectPath
83
+ * @param sourceRoot
84
+ */
85
+ static validateSitemap(projectPath) {
86
+ let sourceRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'src';
87
+ const sitemapPath = _path.default.join(projectPath, sourceRoot, 'sitemap.json');
88
+ if (_fsExtra.default.existsSync(sitemapPath)) {
89
+ const rules = _fsExtra.default.readJSONSync(sitemapPath).rules;
90
+ const manifest = this.getMainfestInfo(projectPath, sourceRoot);
91
+ const pages = Object.keys(manifest.router.pages || {});
92
+ const errorList = [];
93
+ rules.forEach((item, index) => {
94
+ const page = item.page;
95
+ if (page !== '*' && !pages.includes(page)) {
96
+ errorList.push(`The ${index + 1}th item of sitemap rules is configured incorrectly, the page ${page} does not exist`);
98
97
  }
98
+ });
99
+ if (errorList.length) {
100
+ throw new Error(errorList.join('\r\n'));
101
+ }
99
102
  }
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
- if (!oldFileList.length) {
114
- return [];
115
- }
116
- let diffList = [];
117
- // 1.
118
- for (let i = 0; i < oldFileList.length; i++) {
119
- const index = newFileList.findIndex((file) => file === oldFileList[i].path);
120
- // 1.3
121
- if (index !== -1) {
122
- // 1.2
123
- const oldContent = (_a = oldFileList[i].content) === null || _a === void 0 ? void 0 : _a.toString('utf-8');
124
- const newContent = fs_extra_1.default.readFileSync(path_1.default.join(buildPath, newFileList[index]), 'utf-8');
125
- if (oldContent !== newContent) {
126
- diffList.push(newFileList[index]);
127
- }
128
- // 从newFileList中移除该项
129
- newFileList.splice(index, 1);
130
- }
103
+ }
104
+ /**
105
+ * 1. 遍历旧文件列表
106
+ * 1.1 若文件路径在新文件列表newFileList中,且内容一致时,从newFileList中移除该项
107
+ * 1.2 若文件路径在新文件列表newFileList中,且内容不一致时,添加到diffList中表示待更新,从newFileList中移除该项
108
+ * 1.3 若文件路径不在新文件列表中,表示该文件待删除(热更新时,可以不做删除,删除耗费性能)
109
+ * 2. 若遍历完旧文件列表后,newFileList长度不为0,表示有文件待新增
110
+ * @param oldFileList 旧文件列表
111
+ * @param newFileList 新文件列表
112
+ * @returns
113
+ */
114
+ static getDiffJSON(compilation, newFileList, buildPath) {
115
+ const oldFileList = compilation.buildFileList;
116
+ if (!oldFileList.length) {
117
+ return [];
118
+ }
119
+ let diffList = [];
120
+ // 1.
121
+ for (let i = 0; i < oldFileList.length; i++) {
122
+ const index = newFileList.findIndex(file => file === oldFileList[i].path);
123
+ // 1.3
124
+ if (index !== -1) {
125
+ // 1.2
126
+ const oldContent = oldFileList[i].content?.toString('utf-8');
127
+ const newContent = _fsExtra.default.readFileSync(_path.default.join(buildPath, newFileList[index]), 'utf-8');
128
+ if (oldContent !== newContent) {
129
+ diffList.push(newFileList[index]);
131
130
  }
132
- // 2.
133
- newFileList.length > 0 && newFileList.forEach((file) => diffList.push(file));
134
- return diffList;
131
+ // 从newFileList中移除该项
132
+ newFileList.splice(index, 1);
133
+ }
135
134
  }
135
+ // 2.
136
+ newFileList.length > 0 && newFileList.forEach(file => diffList.push(file));
137
+ return diffList;
138
+ }
136
139
  }
137
140
  exports.UxFileUtils = UxFileUtils;
138
- UxFileUtils.CONFIG_FILE_NAME = 'manifest.json';
139
- exports.default = UxFileUtils;
141
+ var _default = exports.default = UxFileUtils;
@@ -1,3 +1,4 @@
1
+ import { IStyleNode } from '@aiot-toolkit/parser';
1
2
  import { ILog } from '@aiot-toolkit/shared-utils';
2
3
  import { IFileLaneContext, IFileParam } from 'file-lane';
3
4
  import { SourceFile } from 'ts-morph';
@@ -54,7 +55,7 @@ declare class UxLoaderUtils {
54
55
  * @returns
55
56
  */
56
57
  static wrapTempalte(templateTree: SourceFile, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
57
- static wrapStyle(code: string, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
58
+ static wrapStyle(styleNodes: IStyleNode[], file: IFileParam, compilerOption: IJavascriptCompileOption): string;
58
59
  /**
59
60
  * 给script增加外层包裹内容
60
61
  * @param isPageUx