@aiot-toolkit/aiotpack 2.0.3-beta.7 → 2.0.3-beta.9

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 (56) hide show
  1. package/lib/afterCompile/ux/UxAfterCompile.js +303 -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 -25
  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 +52 -48
  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 +30 -26
  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 -92
  49. package/lib/utils/PngUtils.js +42 -36
  50. package/lib/utils/ux/ManifestSchema.js +198 -194
  51. package/lib/utils/ux/UxFileUtils.js +130 -116
  52. package/lib/utils/ux/UxLoaderUtils.js +292 -307
  53. package/lib/utils/ux/android/AndroidUx.js +88 -90
  54. package/lib/utils/xts/XtsFileLaneUtils.js +58 -65
  55. package/lib/utils/xts/XtsFollowWorks.js +122 -129
  56. package/package.json +6 -6
@@ -1,207 +1,211 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
3
7
  const ManifestSchema = {
4
- type: 'object',
5
- required: ['package', 'name', 'icon', 'versionCode', 'config', 'router'],
6
- properties: {
7
- package: {
8
+ type: 'object',
9
+ required: ['package', 'name', 'icon', 'versionCode', 'config', 'router'],
10
+ properties: {
11
+ package: {
12
+ type: 'string'
13
+ },
14
+ name: {
15
+ type: 'string'
16
+ },
17
+ icon: {
18
+ type: 'string'
19
+ },
20
+ banner: {
21
+ type: 'string'
22
+ },
23
+ versionName: {
24
+ type: 'string'
25
+ },
26
+ versionCode: {
27
+ type: ['number']
28
+ },
29
+ minPlatformVersion: {
30
+ type: ['number']
31
+ },
32
+ features: {
33
+ type: 'array',
34
+ items: {
35
+ type: 'object',
36
+ properties: {
37
+ name: {
8
38
  type: 'string'
39
+ }
40
+ }
41
+ }
42
+ },
43
+ config: {
44
+ type: 'object',
45
+ properties: {
46
+ logLevel: {
47
+ enum: ['off', 'error', 'warn', 'info', 'log', 'debug']
9
48
  },
10
- name: {
11
- type: 'string'
49
+ designWidth: {
50
+ type: ['number', 'string']
12
51
  },
13
- icon: {
14
- type: 'string'
52
+ data: {
53
+ // TODO 全局数据对象,属性名不能以$或_开头,
54
+ type: 'object'
15
55
  },
16
- banner: {
17
- type: 'string'
56
+ background: {
57
+ // TODO 更详细的后台运行配置信息,
58
+ type: 'object'
18
59
  },
19
- versionName: {
20
- type: 'string'
60
+ network: {
61
+ // TODO 更详细的网络配置信息,
62
+ type: 'object'
63
+ }
64
+ }
65
+ },
66
+ router: {
67
+ // TODO 更详细的后台运行配置信息,
68
+ type: 'object',
69
+ required: ['entry', 'pages'],
70
+ properties: {
71
+ entry: {
72
+ type: 'string'
73
+ },
74
+ // TODO 看下 key 不确定能否校验值,
75
+ pages: {
76
+ type: 'object'
77
+ },
78
+ errorPage: {
79
+ type: 'string'
80
+ },
81
+ // TODO 看下 key 不确定能否校验值,
82
+ widgets: {
83
+ type: 'object'
84
+ }
85
+ }
86
+ },
87
+ display: {
88
+ type: 'object',
89
+ properties: {
90
+ backgroundColor: {
91
+ // TODO HEXColor
92
+ type: 'string'
93
+ },
94
+ fullScreen: {
95
+ type: 'boolean'
96
+ },
97
+ titleBar: {
98
+ type: 'boolean'
99
+ },
100
+ titleBarBackgroundColor: {
101
+ // TODO HEXColor
102
+ type: 'string'
103
+ },
104
+ titleBarTextColor: {
105
+ // TODO HEXColor
106
+ type: 'string'
107
+ },
108
+ menu: {
109
+ type: 'boolean'
110
+ },
111
+ windowSoftInputMode: {
112
+ enum: ['adjustPan', 'adjustResize']
113
+ },
114
+ pages: {
115
+ type: 'object'
116
+ },
117
+ orientation: {
118
+ enum: ['portrait', 'landscape']
119
+ },
120
+ statusBarImmersive: {
121
+ type: 'boolean'
21
122
  },
22
- versionCode: {
23
- type: ['number']
24
- },
25
- minPlatformVersion: {
26
- type: ['number']
27
- },
28
- features: {
29
- type: 'array',
30
- items: {
31
- type: 'object',
32
- properties: {
33
- name: {
34
- type: 'string'
35
- }
36
- }
37
- }
38
- },
39
- config: {
40
- type: 'object',
41
- properties: {
42
- logLevel: {
43
- enum: ['off', 'error', 'warn', 'info', 'log', 'debug']
44
- },
45
- designWidth: {
46
- type: ['number', 'string']
47
- },
48
- data: {
49
- // TODO 全局数据对象,属性名不能以$或_开头,
50
- type: 'object'
51
- },
52
- background: {
53
- // TODO 更详细的后台运行配置信息,
54
- type: 'object'
55
- },
56
- network: {
57
- // TODO 更详细的网络配置信息,
58
- type: 'object'
59
- }
60
- }
61
- },
62
- router: {
63
- // TODO 更详细的后台运行配置信息,
64
- type: 'object',
65
- required: ['entry', 'pages'],
66
- properties: {
67
- entry: {
68
- type: 'string'
69
- },
70
- // TODO 看下 key 不确定能否校验值,
71
- pages: {
72
- type: 'object'
73
- },
74
- errorPage: {
75
- type: 'string'
76
- },
77
- // TODO 看下 key 不确定能否校验值,
78
- widgets: {
79
- type: 'object'
80
- }
81
- }
82
- },
83
- display: {
84
- type: 'object',
85
- properties: {
86
- backgroundColor: {
87
- // TODO HEXColor
88
- type: 'string'
89
- },
90
- fullScreen: {
91
- type: 'boolean'
92
- },
93
- titleBar: {
94
- type: 'boolean'
95
- },
96
- titleBarBackgroundColor: {
97
- // TODO HEXColor
98
- type: 'string'
99
- },
100
- titleBarTextColor: {
101
- // TODO HEXColor
102
- type: 'string'
103
- },
104
- menu: {
105
- type: 'boolean'
106
- },
107
- windowSoftInputMode: {
108
- enum: ['adjustPan', 'adjustResize']
109
- },
110
- pages: {
111
- type: 'object'
112
- },
113
- orientation: {
114
- enum: ['portrait', 'landscape']
115
- },
116
- statusBarImmersive: {
117
- type: 'boolean'
118
- },
119
- statusBarTextStyle: {
120
- enum: ['light', 'dark', 'auto']
121
- },
122
- statusBarBackgroundColor: {
123
- type: 'string'
124
- },
125
- statusBarBackgroundOpacity: {
126
- type: 'number'
127
- },
128
- fitCutout: {
129
- enum: ['none', 'portrait', 'landscape']
130
- },
131
- textSizeAdjust: {
132
- enum: ['none', 'auto']
133
- },
134
- themeMode: {
135
- enum: [-1, 0, 1]
136
- },
137
- menuBarData: {
138
- // TODO 详细校验
139
- type: 'object'
140
- },
141
- forceDark: {
142
- type: 'boolean'
143
- },
144
- pageCache: {
145
- type: 'boolean'
146
- },
147
- cacheDuration: {
148
- type: 'number'
149
- }
150
- }
151
- },
152
- subpackages: {
153
- // TODO 与后面的分包校验融合
154
- type: 'array',
155
- items: {
156
- type: 'object',
157
- properties: {
158
- name: {
159
- type: 'string'
160
- },
161
- // TODO 详细的规则校验
162
- resource: {
163
- type: 'string'
164
- }
165
- },
166
- // 是否必须?
167
- required: ['name', 'resource']
168
- }
123
+ statusBarTextStyle: {
124
+ enum: ['light', 'dark', 'auto']
125
+ },
126
+ statusBarBackgroundColor: {
127
+ type: 'string'
128
+ },
129
+ statusBarBackgroundOpacity: {
130
+ type: 'number'
131
+ },
132
+ fitCutout: {
133
+ enum: ['none', 'portrait', 'landscape']
134
+ },
135
+ textSizeAdjust: {
136
+ enum: ['none', 'auto']
137
+ },
138
+ themeMode: {
139
+ enum: [-1, 0, 1]
169
140
  },
170
141
  menuBarData: {
171
- type: 'object',
172
- properties: {
173
- menuBar: {
174
- type: 'boolean'
175
- },
176
- menuBarStyle: {
177
- enum: ['dark', 'light']
178
- },
179
- shareTitle: {
180
- type: 'string'
181
- },
182
- shareDescription: {
183
- type: 'string'
184
- },
185
- shareIcon: {
186
- type: 'string'
187
- },
188
- shareCurrentPage: {
189
- type: 'string'
190
- },
191
- shareParams: {
192
- type: 'string'
193
- },
194
- shareUrl: {
195
- type: 'string'
196
- }
197
- }
198
- },
199
- deviceTypeList: {
200
- type: 'array',
201
- items: {
202
- type: 'string'
203
- }
142
+ // TODO 详细校验
143
+ type: 'object'
144
+ },
145
+ forceDark: {
146
+ type: 'boolean'
147
+ },
148
+ pageCache: {
149
+ type: 'boolean'
150
+ },
151
+ cacheDuration: {
152
+ type: 'number'
153
+ }
154
+ }
155
+ },
156
+ subpackages: {
157
+ // TODO 与后面的分包校验融合
158
+ type: 'array',
159
+ items: {
160
+ type: 'object',
161
+ properties: {
162
+ name: {
163
+ type: 'string'
164
+ },
165
+ // TODO 详细的规则校验
166
+ resource: {
167
+ type: 'string'
168
+ }
169
+ },
170
+ // 是否必须?
171
+ required: ['name', 'resource']
172
+ }
173
+ },
174
+ menuBarData: {
175
+ type: 'object',
176
+ properties: {
177
+ menuBar: {
178
+ type: 'boolean'
179
+ },
180
+ menuBarStyle: {
181
+ enum: ['dark', 'light']
182
+ },
183
+ shareTitle: {
184
+ type: 'string'
185
+ },
186
+ shareDescription: {
187
+ type: 'string'
188
+ },
189
+ shareIcon: {
190
+ type: 'string'
191
+ },
192
+ shareCurrentPage: {
193
+ type: 'string'
194
+ },
195
+ shareParams: {
196
+ type: 'string'
197
+ },
198
+ shareUrl: {
199
+ type: 'string'
204
200
  }
201
+ }
202
+ },
203
+ deviceTypeList: {
204
+ type: 'array',
205
+ items: {
206
+ type: 'string'
207
+ }
205
208
  }
209
+ }
206
210
  };
207
- exports.default = ManifestSchema;
211
+ var _default = exports.default = ManifestSchema;
@@ -1,127 +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 CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const path_1 = __importDefault(require("path"));
10
- 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
+ */
11
15
  class UxFileUtils {
12
- /**
13
- * 获取manifest.json路径
14
- * @param projectPath
15
- * @param sourceRoot
16
- * @returns
17
- */
18
- static getManifestFilePath(projectPath, sourceRoot = 'src') {
19
- 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}'`);
20
55
  }
21
- /**
22
- * 获取manifest.json内容
23
- * @param projectPath
24
- * @param sourceRoot
25
- * @returns
26
- */
27
- static getMainfestInfo(projectPath, sourceRoot = 'src') {
28
- 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`));
29
69
  }
30
- /**
31
- * 检查 manifest文件,并显示错误信息
32
- *
33
- * 1. 使用ManifestSchema 校验
34
- * 1. TypeError: Error
35
- * 2. 其它: Warn
36
- * 2. 检查 router.entry 是否存在于 router.pages
37
- *
38
- * @param projectPath 项目路径
39
- * @param sourceRoot 源码路径--相对项目根目录
40
- * @returns
41
- */
42
- static validateManifest(projectPath, sourceRoot = 'src') {
43
- const path = UxFileUtils.getManifestFilePath(projectPath, sourceRoot);
44
- if (!fs_extra_1.default.existsSync(path)) {
45
- throw new Error(`no such file: '${path}'`);
46
- }
47
- // 1
48
- const jsonData = this.getMainfestInfo(projectPath, sourceRoot);
49
- const schema = ManifestSchema_1.default;
50
- const errors = CommonUtil_1.default.validateJson(jsonData, schema) || [];
51
- // 2
52
- const { entry, pages } = jsonData.router;
53
- if (!pages[entry]) {
54
- errors.push(new TypeError(`router.entry content: ${entry}, is missing in router.pages`));
55
- }
56
- if (errors === null || errors === void 0 ? void 0 : errors.length) {
57
- const message = `Manifest.json error: ${errors.map((item, index) => {
58
- return `\r\n${index + 1}. ${item.message}`;
59
- })}`;
60
- throw new Error(message);
61
- }
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);
62
75
  }
63
- /**
64
- * 检查 sitemap.json 文件,并显示错误信息
65
- *
66
- * 1. sitemap.json rules 中配置的page 不存在于 manifest.json 中时,报错
67
- * @param projectPath
68
- * @param sourceRoot
69
- */
70
- static validateSitemap(projectPath, sourceRoot = 'src') {
71
- const sitemapPath = path_1.default.join(projectPath, sourceRoot, 'sitemap.json');
72
- if (fs_extra_1.default.existsSync(sitemapPath)) {
73
- const rules = fs_extra_1.default.readJSONSync(sitemapPath).rules;
74
- const manifest = this.getMainfestInfo(projectPath, sourceRoot);
75
- const pages = Object.keys(manifest.router.pages || {});
76
- const errorList = [];
77
- rules.forEach((item, index) => {
78
- const page = item.page;
79
- if (page !== '*' && !pages.includes(page)) {
80
- errorList.push(`The ${index + 1}th item of sitemap rules is configured incorrectly, the page ${page} does not exist`);
81
- }
82
- });
83
- if (errorList.length) {
84
- throw new Error(errorList.join('\r\n'));
85
- }
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`);
86
97
  }
98
+ });
99
+ if (errorList.length) {
100
+ throw new Error(errorList.join('\r\n'));
101
+ }
87
102
  }
88
- /**
89
- * 1. 遍历旧文件列表
90
- * 1.1 若文件路径在新文件列表newFileList中,且内容一致时,从newFileList中移除该项
91
- * 1.2 若文件路径在新文件列表newFileList中,且内容不一致时,添加到diffList中表示待更新,从newFileList中移除该项
92
- * 1.3 若文件路径不在新文件列表中,表示该文件待删除(热更新时,可以不做删除,删除耗费性能)
93
- * 2. 若遍历完旧文件列表后,newFileList长度不为0,表示有文件待新增
94
- * @param oldFileList 旧文件列表
95
- * @param newFileList 新文件列表
96
- * @returns
97
- */
98
- static getDiffJSON(compilation, newFileList, buildPath) {
99
- var _a;
100
- const oldFileList = compilation.buildFileList;
101
- if (!oldFileList.length) {
102
- return [];
103
- }
104
- let diffList = [];
105
- // 1.
106
- for (let i = 0; i < oldFileList.length; i++) {
107
- const index = newFileList.findIndex((file) => file === oldFileList[i].path);
108
- // 1.3
109
- if (index !== -1) {
110
- // 1.2
111
- const oldContent = (_a = oldFileList[i].content) === null || _a === void 0 ? void 0 : _a.toString('utf-8');
112
- const newContent = fs_extra_1.default.readFileSync(path_1.default.join(buildPath, newFileList[index]), 'utf-8');
113
- if (oldContent !== newContent) {
114
- diffList.push(newFileList[index]);
115
- }
116
- // 从newFileList中移除该项
117
- newFileList.splice(index, 1);
118
- }
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]);
119
130
  }
120
- // 2.
121
- newFileList.length > 0 && newFileList.forEach((file) => diffList.push(file));
122
- return diffList;
131
+ // 从newFileList中移除该项
132
+ newFileList.splice(index, 1);
133
+ }
123
134
  }
135
+ // 2.
136
+ newFileList.length > 0 && newFileList.forEach(file => diffList.push(file));
137
+ return diffList;
138
+ }
124
139
  }
125
140
  exports.UxFileUtils = UxFileUtils;
126
- UxFileUtils.CONFIG_FILE_NAME = 'manifest.json';
127
- exports.default = UxFileUtils;
141
+ var _default = exports.default = UxFileUtils;