@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,27 +1,31 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@rspack/core");
4
- const webpack_sources_1 = require("webpack-sources");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _core = require("@rspack/core");
8
+ var _webpackSources = require("webpack-sources");
5
9
  class WrapPlugin {
6
- apply(compiler) {
7
- // 给入口文件加上包裹函数
8
- compiler.hooks.compilation.tap('WrapPlugin', (compilation) => {
9
- compilation.hooks.processAssets.tap({
10
- name: 'WrapPlugin',
11
- stage: core_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
12
- }, () => {
13
- this.wrap(compilation);
14
- });
15
- });
16
- }
17
- wrap(compilation) {
18
- // 获取入口文件
19
- const entrys = Object.keys(compilation.options.entry).map((item) => `${item}.js`);
20
- // 从chunk找到所有入口文件,添加包裹函数
21
- entrys.forEach((entry) => {
22
- if (compilation.assets[entry]) {
23
- const source = compilation.assets[entry];
24
- compilation.assets[entry] = new webpack_sources_1.ConcatSource(`
10
+ apply(compiler) {
11
+ // 给入口文件加上包裹函数
12
+ compiler.hooks.compilation.tap('WrapPlugin', compilation => {
13
+ compilation.hooks.processAssets.tap({
14
+ name: 'WrapPlugin',
15
+ stage: _core.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
16
+ }, () => {
17
+ this.wrap(compilation);
18
+ });
19
+ });
20
+ }
21
+ wrap(compilation) {
22
+ // 获取入口文件
23
+ const entrys = Object.keys(compilation.options.entry).map(item => `${item}.js`);
24
+ // 从chunk找到所有入口文件,添加包裹函数
25
+ entrys.forEach(entry => {
26
+ if (compilation.assets[entry]) {
27
+ const source = compilation.assets[entry];
28
+ compilation.assets[entry] = new _webpackSources.ConcatSource(`
25
29
  export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
26
30
  var org_app_require = $app_require$;
27
31
 
@@ -38,7 +42,7 @@ class WrapPlugin {
38
42
  return Object.fromEntries(value.split(';').filter(item => Boolean(item && item.trim())).map(
39
43
  item => {
40
44
  const matchs = item.match(/([^:]+):(.*)/)
41
- if (matchs && matchs.lenth> 2) {
45
+ if (matchs && matchs.length> 2) {
42
46
  return [matchs[1].trim().replace(/-([a-z])/g, (_, match) => match.toUpperCase()), matchs[2].trim()]
43
47
  }
44
48
  return []
@@ -53,8 +57,8 @@ class WrapPlugin {
53
57
  return createPageHandler();
54
58
  })(global, globalThis, window, $app_exports$, $app_evaluate$)
55
59
  }`);
56
- }
57
- });
58
- }
60
+ }
61
+ });
62
+ }
59
63
  }
60
- exports.default = WrapPlugin;
64
+ var _default = exports.default = WrapPlugin;
@@ -1,39 +1,36 @@
1
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _sharedUtils = require("@aiot-toolkit/shared-utils");
13
8
  /**
14
9
  * Jsc
15
10
  */
16
11
  class Jsc {
17
- constructor(projectPath, buildPath) {
18
- this.projectPath = projectPath;
19
- this.buildPath = buildPath;
20
- }
21
- jsc() {
22
- const { projectPath, buildPath } = this;
23
- return shared_utils_1.CommonUtil.requireNodeModule(projectPath, `@aiot-toolkit/jsc`)
24
- .then((module) => __awaiter(this, void 0, void 0, function* () {
25
- const msg = yield module.default(buildPath);
26
- if (msg) {
27
- shared_utils_1.ColorConsole.success({ word: 'jsc command' }, msg);
28
- }
29
- }))
30
- .then(() => {
31
- return shared_utils_1.FileUtil.del(`${buildPath}/**/*.js`);
32
- })
33
- .catch((error) => {
34
- shared_utils_1.ColorConsole.throw(error.message);
35
- return Promise.reject(error);
36
- });
37
- }
12
+ constructor(projectPath, buildPath) {
13
+ this.projectPath = projectPath;
14
+ this.buildPath = buildPath;
15
+ }
16
+ jsc() {
17
+ const {
18
+ projectPath,
19
+ buildPath
20
+ } = this;
21
+ return _sharedUtils.CommonUtil.requireNodeModule(projectPath, `@aiot-toolkit/jsc`).then(async module => {
22
+ const msg = await module.default(buildPath);
23
+ if (msg) {
24
+ _sharedUtils.ColorConsole.success({
25
+ word: 'jsc command'
26
+ }, msg);
27
+ }
28
+ }).then(() => {
29
+ return _sharedUtils.FileUtil.del(`${buildPath}/**/*.js`);
30
+ }).catch(error => {
31
+ _sharedUtils.ColorConsole.throw(error.message);
32
+ return Promise.reject(error);
33
+ });
34
+ }
38
35
  }
39
- exports.default = Jsc;
36
+ var _default = exports.default = Jsc;
@@ -1,142 +1,164 @@
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
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const path_1 = __importDefault(require("path"));
9
- const EntryType_1 = __importDefault(require("../enum/EntryType"));
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _EntryType = _interopRequireDefault(require("../enum/EntryType"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
12
  class UxCompileUtil {
11
- static clean(dirList) {
12
- if (!dirList) {
13
- return;
14
- }
15
- dirList.forEach((item) => {
16
- if (fs_extra_1.default.existsSync(item)) {
17
- if (fs_extra_1.default.statSync(item).isFile()) {
18
- fs_extra_1.default.unlinkSync(item);
19
- }
20
- else {
21
- fs_extra_1.default.rmSync(item, { recursive: true, force: true });
22
- }
23
- }
24
- });
13
+ // 摘要文件夹
14
+ static DIGEST_ZIP_DIR = 'META-INF';
15
+ static clean(dirList) {
16
+ if (!dirList) {
17
+ return;
25
18
  }
26
- /**
27
- * 从项目配置文件中解析出入口文件
28
- * @param config 项目配置文件的内容,应为json对象
29
- * @param codeDir 源码目录
30
- * @param projectPath 项目目录
31
- * @returns {[入口名]:源文件路径}
32
- */
33
- static resolveEntries(config, codeDir, projectPath) {
34
- const { router } = config;
35
- if (!router) {
36
- throw Error('No routing configured in manifest.json!');
37
- }
38
- const appFile = this.resolveFile(path_1.default.join(codeDir, 'app'));
39
- if (!fs_extra_1.default.existsSync(appFile)) {
40
- shared_utils_1.ColorConsole.throw(`App file does not exist`);
19
+ dirList.forEach(item => {
20
+ if (_fsExtra.default.existsSync(item)) {
21
+ if (_fsExtra.default.statSync(item).isFile()) {
22
+ _fsExtra.default.unlinkSync(item);
23
+ } else {
24
+ _fsExtra.default.rmSync(item, {
25
+ recursive: true,
26
+ force: true
27
+ });
41
28
  }
42
- const { pages = {}, widgets = {}, floatingWindows = {} } = router;
43
- const confsList = [
44
- {
45
- confs: pages,
46
- type: EntryType_1.default.PAGE
47
- },
48
- {
49
- confs: floatingWindows,
50
- type: EntryType_1.default.FLOAT
51
- },
52
- {
53
- confs: widgets,
54
- type: EntryType_1.default.CARD
55
- }
56
- ];
57
- // 1. 添加app
58
- const result = {
59
- app: `./${path_1.default.relative(projectPath, appFile)}?uxType=${EntryType_1.default.APP}`
60
- };
61
- // 2. 添加 route 配置的文件
62
- confsList.forEach((item) => {
63
- const { confs, type } = item;
64
- Object.keys(confs).forEach((routePath) => {
65
- if (/^\//.test(routePath)) {
66
- throw new Error(`Compilation failed: please confirm that '${routePath}' configured by router.pages in manifest.json is the directory name`);
67
- }
68
- const conf = confs[routePath];
69
- const entryKey = path_1.default.join(routePath, conf.component);
70
- const filePath = this.resolveFile(path_1.default.join(codeDir, entryKey));
71
- if (!filePath) {
72
- throw new Error(`Compilation failed: please confirm that the file path ${entryKey} configured in manifest.json exists`);
73
- }
74
- let sourceFile = `./${path_1.default.relative(projectPath, filePath)}?uxType=${type}`;
75
- sourceFile = sourceFile.replace(/\\/g, '/');
76
- result[entryKey] = sourceFile;
77
- });
78
- });
79
- // 3. 添加 workers
80
- const { workers } = config;
81
- if (workers && workers.entries && Array.isArray(workers.entries)) {
82
- workers.entries
83
- .filter((worker) => worker.file)
84
- .forEach((worker) => {
85
- result[worker.file.replace(/\.js$/, '')] = './src/' + worker.file;
86
- });
87
- }
88
- // 4. 添加 services
89
- const { services } = config;
90
- // 数组格式
91
- if (Array.isArray(services)) {
92
- services.forEach((item) => {
93
- const { name, path } = item;
94
- if (name && path) {
95
- result['services/' + name] = './src/' + path + `?uxType=${EntryType_1.default.APP}`;
96
- }
97
- });
29
+ }
30
+ });
31
+ }
32
+
33
+ /**
34
+ * 从项目配置文件中解析出入口文件
35
+ * @param config 项目配置文件的内容,应为json对象
36
+ * @param codeDir 源码目录
37
+ * @param projectPath 项目目录
38
+ * @returns {[入口名]:源文件路径}
39
+ */
40
+ static resolveEntries(config, codeDir, projectPath) {
41
+ const {
42
+ router
43
+ } = config;
44
+ if (!router) {
45
+ throw Error('No routing configured in manifest.json!');
46
+ }
47
+ const appFile = this.resolveFile(_path.default.join(codeDir, 'app'));
48
+ if (!_fsExtra.default.existsSync(appFile)) {
49
+ _sharedUtils.ColorConsole.throw(`App file does not exist`);
50
+ }
51
+ const {
52
+ pages = {},
53
+ widgets = {},
54
+ floatingWindows = {}
55
+ } = router;
56
+ const confsList = [{
57
+ confs: pages,
58
+ type: _EntryType.default.PAGE
59
+ }, {
60
+ confs: floatingWindows,
61
+ type: _EntryType.default.FLOAT
62
+ }, {
63
+ confs: widgets,
64
+ type: _EntryType.default.CARD
65
+ }];
66
+
67
+ // 1. 添加app
68
+ const result = {
69
+ app: `./${_path.default.relative(projectPath, appFile)}?uxType=${_EntryType.default.APP}`
70
+ };
71
+
72
+ // 2. 添加 route 配置的文件
73
+ confsList.forEach(item => {
74
+ const {
75
+ confs,
76
+ type
77
+ } = item;
78
+ Object.keys(confs).forEach(routePath => {
79
+ if (/^\//.test(routePath)) {
80
+ throw new Error(`Compilation failed: please confirm that '${routePath}' configured by router.pages in manifest.json is the directory name`);
98
81
  }
99
- // 字典格式
100
- else {
101
- for (const key in services) {
102
- if (Object.hasOwnProperty.call(services, key)) {
103
- result['services/' + key] = './src/' + services[key].path + `?uxType=${EntryType_1.default.APP}`;
104
- }
105
- }
82
+ const conf = confs[routePath];
83
+ const entryKey = _path.default.join(routePath, conf.component);
84
+ const filePath = this.resolveFile(_path.default.join(codeDir, entryKey));
85
+ if (!filePath) {
86
+ throw new Error(`Compilation failed: please confirm that the file path ${entryKey} configured in manifest.json exists`);
106
87
  }
107
- return result;
88
+ let sourceFile = `./${_path.default.relative(projectPath, filePath)}?uxType=${type}`;
89
+ sourceFile = sourceFile.replace(/\\/g, '/');
90
+ result[entryKey] = sourceFile;
91
+ });
92
+ });
93
+
94
+ // 3. 添加 workers
95
+ const {
96
+ workers
97
+ } = config;
98
+ if (workers && workers.entries && Array.isArray(workers.entries)) {
99
+ workers.entries.filter(worker => worker.file).forEach(worker => {
100
+ result[worker.file.replace(/\.js$/, '')] = './src/' + worker.file;
101
+ });
108
102
  }
109
- /**
110
- * 通过无后缀的文件名路径获取存在的文件路径
111
- *
112
- * @example
113
- * const path = resolveFile('/project/a')
114
- * // path = '/project/a.ux'
115
- * @param filePath
116
- */
117
- static resolveFile(filePath) {
118
- const extensionList = this.getExtensionList();
119
- for (const item of extensionList) {
120
- const currentPath = `${filePath}${item}`;
121
- if (fs_extra_1.default.existsSync(currentPath)) {
122
- return currentPath;
123
- }
103
+
104
+ // 4. 添加 services
105
+ const {
106
+ services
107
+ } = config;
108
+ // 数组格式
109
+ if (Array.isArray(services)) {
110
+ services.forEach(item => {
111
+ const {
112
+ name,
113
+ path
114
+ } = item;
115
+ if (name && path) {
116
+ result['services/' + name] = './src/' + path + `?uxType=${_EntryType.default.APP}`;
124
117
  }
125
- return '';
118
+ });
126
119
  }
127
- /**
128
- * 获取ux文件支持的后缀列表
129
- * @param withDot
130
- * @returns
131
- */
132
- static getExtensionList(withDot = true) {
133
- const result = ['ux', 'hml'];
134
- if (withDot) {
135
- return result.map((item) => `.${item}`);
120
+ // 字典格式
121
+ else {
122
+ for (const key in services) {
123
+ if (Object.hasOwnProperty.call(services, key)) {
124
+ result['services/' + key] = './src/' + services[key].path + `?uxType=${_EntryType.default.APP}`;
136
125
  }
137
- return result;
126
+ }
127
+ }
128
+ return result;
129
+ }
130
+
131
+ /**
132
+ * 通过无后缀的文件名路径获取存在的文件路径
133
+ *
134
+ * @example
135
+ * const path = resolveFile('/project/a')
136
+ * // path = '/project/a.ux'
137
+ * @param filePath
138
+ */
139
+ static resolveFile(filePath) {
140
+ const extensionList = this.getExtensionList();
141
+ for (const item of extensionList) {
142
+ const currentPath = `${filePath}${item}`;
143
+ if (_fsExtra.default.existsSync(currentPath)) {
144
+ return currentPath;
145
+ }
146
+ }
147
+ return '';
148
+ }
149
+
150
+ /**
151
+ * 获取ux文件支持的后缀列表
152
+ * @param withDot
153
+ * @returns
154
+ */
155
+ static getExtensionList() {
156
+ let withDot = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
157
+ const result = ['ux', 'hml'];
158
+ if (withDot) {
159
+ return result.map(item => `.${item}`);
138
160
  }
161
+ return result;
162
+ }
139
163
  }
140
- // 摘要文件夹
141
- UxCompileUtil.DIGEST_ZIP_DIR = 'META-INF';
142
- exports.default = UxCompileUtil;
164
+ var _default = exports.default = UxCompileUtil;