@aiot-toolkit/aiotpack 2.0.2 → 2.0.3-beta.10

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 (63) hide show
  1. package/lib/afterCompile/ux/UxAfterCompile.d.ts +1 -1
  2. package/lib/afterCompile/ux/UxAfterCompile.js +295 -243
  3. package/lib/afterCompile/xts/entryTemplate.js +111 -113
  4. package/lib/afterCompile/xts/generateRpk.js +25 -54
  5. package/lib/afterCompile/xts/ts2wasm.js +62 -63
  6. package/lib/afterWorks/ux/UxAfterWorks.js +12 -19
  7. package/lib/beforeCompile/ux/UxBeforeCompile.js +26 -28
  8. package/lib/beforeCompile/xts/preInstall.js +50 -55
  9. package/lib/beforeWorks/ux/UxBeforeWorks.js +12 -19
  10. package/lib/compiler/enum/CompileMode.js +16 -23
  11. package/lib/compiler/interface/ICompileParam.js +1 -2
  12. package/lib/compiler/interface/ICompiler.js +1 -2
  13. package/lib/compiler/interface/ISignConfig.js +1 -2
  14. package/lib/compiler/javascript/JavascriptCompiler.js +147 -154
  15. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +20 -16
  16. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +13 -11
  17. package/lib/compiler/javascript/android/plugin/WrapPlugin.js +53 -49
  18. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +1 -2
  19. package/lib/compiler/javascript/interface/IWebpackConfigurator.js +4 -1
  20. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +78 -75
  21. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +30 -41
  22. package/lib/compiler/javascript/vela/enum/EntryType.js +15 -29
  23. package/lib/compiler/javascript/vela/interface/IChunk.js +4 -1
  24. package/lib/compiler/javascript/vela/interface/IManifest.js +1 -2
  25. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js +1 -2
  26. package/lib/compiler/javascript/vela/model/Package.js +80 -51
  27. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +31 -27
  28. package/lib/compiler/javascript/vela/utils/Jsc.js +30 -33
  29. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +152 -130
  30. package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +10 -2
  31. package/lib/compiler/javascript/vela/utils/ZipUtil.js +282 -267
  32. package/lib/compiler/javascript/vela/utils/signature/Base64.js +65 -67
  33. package/lib/compiler/javascript/vela/utils/signature/CRC32.js +37 -35
  34. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +755 -731
  35. package/lib/compiler/javascript/vela/utils/signature/Signer.js +24 -22
  36. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +47 -52
  37. package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.js +21 -17
  38. package/lib/config/UxConfig.js +145 -173
  39. package/lib/config/XtsConfig.d.ts +2 -0
  40. package/lib/config/XtsConfig.js +30 -39
  41. package/lib/index.js +88 -41
  42. package/lib/interface/ICompileOptions.js +5 -2
  43. package/lib/interface/IDeviceList.js +1 -2
  44. package/lib/loader/ux/JsLoader.js +32 -30
  45. package/lib/loader/ux/PngLoader.js +47 -53
  46. package/lib/loader/ux/android/UxLoader.d.ts +2 -0
  47. package/lib/loader/ux/android/UxLoader.js +30 -32
  48. package/lib/loader/ux/vela/AppUxLoader.d.ts +2 -0
  49. package/lib/loader/ux/vela/AppUxLoader.js +23 -25
  50. package/lib/loader/ux/vela/HmlLoader.js +59 -55
  51. package/lib/loader/ux/vela/UxLoader.d.ts +2 -0
  52. package/lib/loader/ux/vela/UxLoader.js +29 -37
  53. package/lib/loader/xts/XtsLoader.js +55 -41
  54. package/lib/utils/BeforeCompileUtils.js +100 -95
  55. package/lib/utils/PngUtils.js +42 -36
  56. package/lib/utils/ux/ManifestSchema.js +198 -194
  57. package/lib/utils/ux/UxFileUtils.d.ts +3 -3
  58. package/lib/utils/ux/UxFileUtils.js +130 -125
  59. package/lib/utils/ux/UxLoaderUtils.js +292 -307
  60. package/lib/utils/ux/android/AndroidUx.js +88 -90
  61. package/lib/utils/xts/XtsFileLaneUtils.js +58 -65
  62. package/lib/utils/xts/XtsFollowWorks.js +122 -129
  63. package/package.json +6 -6
@@ -16,7 +16,7 @@ declare class UxAfterCompile {
16
16
  */
17
17
  static copyResource: FollowWork<IJavascriptCompileOption>;
18
18
  /**
19
- * 对比 临时项目build文件夹 和 项目build文件夹,生成diff.json
19
+ * 如果是更新触发,则对比临时项目build文件夹 和 项目build文件夹,生成diff.json
20
20
  * @param context
21
21
  * @param config
22
22
  * @param compilerOption
@@ -1,278 +1,330 @@
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
- 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 shared_utils_1 = require("@aiot-toolkit/shared-utils");
17
- const fs_extra_1 = __importDefault(require("fs-extra"));
18
- const lodash_1 = __importDefault(require("lodash"));
19
- const path_1 = __importDefault(require("path"));
20
- const CompileMode_1 = __importDefault(require("../../compiler/enum/CompileMode"));
21
- const JavascriptCompiler_1 = __importDefault(require("../../compiler/javascript/JavascriptCompiler"));
22
- const JavascriptDefaultCompileOption_1 = __importDefault(require("../../compiler/javascript/JavascriptDefaultCompileOption"));
23
- const Jsc_1 = __importDefault(require("../../compiler/javascript/vela/utils/Jsc"));
24
- const ZipUtil_1 = __importDefault(require("../../compiler/javascript/vela/utils/ZipUtil"));
25
- const UxFileUtils_1 = __importDefault(require("../../utils/ux/UxFileUtils"));
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 _lodash = _interopRequireDefault(require("lodash"));
10
+ var _path = _interopRequireDefault(require("path"));
11
+ var _CompileMode = _interopRequireDefault(require("../../compiler/enum/CompileMode"));
12
+ var _JavascriptCompiler = _interopRequireDefault(require("../../compiler/javascript/JavascriptCompiler"));
13
+ var _JavascriptDefaultCompileOption = _interopRequireDefault(require("../../compiler/javascript/JavascriptDefaultCompileOption"));
14
+ var _Jsc = _interopRequireDefault(require("../../compiler/javascript/vela/utils/Jsc"));
15
+ var _ZipUtil = _interopRequireDefault(require("../../compiler/javascript/vela/utils/ZipUtil"));
16
+ var _UxFileUtils = _interopRequireDefault(require("../../utils/ux/UxFileUtils"));
17
+ var _FileLaneTriggerType = _interopRequireDefault(require("file-lane/lib/enum/FileLaneTriggerType"));
18
+ var _ZipFileUtil = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/utils/ZipFileUtil"));
19
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
26
20
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
21
+
27
22
  /**
28
23
  * UxAfterCompile
29
24
  */
30
25
  class UxAfterCompile {
31
- }
32
- _a = UxAfterCompile;
33
- UxAfterCompile.webpack = (params) => __awaiter(void 0, void 0, void 0, function* () {
34
- const { context, compilerOption } = params;
35
- return new JavascriptCompiler_1.default()
36
- .compile(Object.assign(Object.assign({ projectPath: path_1.default.join(context.projectPath, context.output), mode: CompileMode_1.default.DEVELOPMENT, devtool: false, platform: 'vela' }, JavascriptDefaultCompileOption_1.default), compilerOption))
37
- .then(() => {
38
- shared_utils_1.ColorConsole.info(`webpack complete`);
39
- })
40
- .catch(({ errors, warnings }) => {
41
- const errorLength = (errors === null || errors === void 0 ? void 0 : errors.length) || 0;
42
- const messages = [`webpack error:\r\n`];
43
- if (errors === null || errors === void 0 ? void 0 : errors.length) {
44
- messages.push({
45
- word: errors
46
- .map((item, index) => {
47
- return `${index + 1}. ${item.message}`;
48
- })
49
- .join('\r\n'),
50
- style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.THROW)
51
- });
52
- }
53
- if (warnings === null || warnings === void 0 ? void 0 : warnings.length) {
54
- messages.push({
55
- word: warnings
56
- .map((item, index) => {
57
- return `${errorLength + index + 1}. ${item.message}`;
58
- })
59
- .join('\r\n'),
60
- style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.WARN)
61
- });
62
- }
63
- if (errors === null || errors === void 0 ? void 0 : errors.length) {
64
- shared_utils_1.ColorConsole.throw(...messages);
65
- throw new Error();
66
- }
67
- else {
68
- shared_utils_1.ColorConsole.warn(...messages);
69
- }
26
+ static webpack = async params => {
27
+ const {
28
+ context,
29
+ compilerOption
30
+ } = params;
31
+ return new _JavascriptCompiler.default().compile({
32
+ projectPath: _path.default.join(context.projectPath, context.output),
33
+ mode: _CompileMode.default.DEVELOPMENT,
34
+ devtool: false,
35
+ platform: 'vela',
36
+ ..._JavascriptDefaultCompileOption.default,
37
+ ...compilerOption
38
+ }).then(() => {
39
+ _sharedUtils.ColorConsole.info(`webpack complete`);
40
+ }).catch(_ref => {
41
+ let {
42
+ errors,
43
+ warnings
44
+ } = _ref;
45
+ const errorLength = errors?.length || 0;
46
+ const messages = [`webpack error:\r\n`];
47
+ if (errors?.length) {
48
+ messages.push({
49
+ word: errors.map((item, index) => {
50
+ return `${index + 1}. ${item.message}`;
51
+ }).join('\r\n'),
52
+ style: _sharedUtils.ColorConsole.getStyle(_sharedUtils.Loglevel.THROW)
53
+ });
54
+ }
55
+ if (warnings?.length) {
56
+ messages.push({
57
+ word: warnings.map((item, index) => {
58
+ return `${errorLength + index + 1}. ${item.message}`;
59
+ }).join('\r\n'),
60
+ style: _sharedUtils.ColorConsole.getStyle(_sharedUtils.Loglevel.WARN)
61
+ });
62
+ }
63
+ if (errors?.length) {
64
+ _sharedUtils.ColorConsole.throw(...messages);
65
+ throw new Error();
66
+ } else {
67
+ _sharedUtils.ColorConsole.warn(...messages);
68
+ }
70
69
  });
71
- });
72
- UxAfterCompile.protobuf = (params) => __awaiter(void 0, void 0, void 0, function* () {
73
- const { compilerOption } = params;
74
- if (compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.enableProtobuf) {
75
- BinaryPlugin.createBinFiles();
70
+ };
71
+ static protobuf = async params => {
72
+ const {
73
+ compilerOption
74
+ } = params;
75
+ if (compilerOption?.enableProtobuf) {
76
+ BinaryPlugin.createBinFiles();
76
77
  }
77
- });
78
- UxAfterCompile.jsc = (params) => __awaiter(void 0, void 0, void 0, function* () {
79
- const { context, compilerOption } = params;
78
+ };
79
+ static jsc = async params => {
80
+ const {
81
+ context,
82
+ compilerOption
83
+ } = params;
80
84
  if (compilerOption && compilerOption.enableJsc === true) {
81
- return new Jsc_1.default(context.projectPath, path_1.default.join(context.projectPath, context.output, compilerOption.outputPath)).jsc();
85
+ return new _Jsc.default(context.projectPath, _path.default.join(context.projectPath, context.output, compilerOption.outputPath)).jsc();
82
86
  }
83
- });
84
- UxAfterCompile.toRpk = (params) => __awaiter(void 0, void 0, void 0, function* () {
85
- const { compilerOption } = params;
87
+ };
88
+ static toRpk = async params => {
89
+ const {
90
+ compilerOption,
91
+ compalition,
92
+ config
93
+ } = params;
86
94
  if (compilerOption) {
87
- return ZipUtil_1.default.createRpk(path_1.default.join(compilerOption.projectPath, compilerOption.outputPath), compilerOption);
95
+ const fileName = await _ZipUtil.default.createRpk(_path.default.join(compilerOption.projectPath, compilerOption.outputPath), compilerOption);
96
+ if (compalition && fileName) {
97
+ compalition.info.rpk = _path.default.join(config.projectPath, compilerOption.releasePath, fileName);
98
+ }
99
+ return fileName;
88
100
  }
89
- });
90
- /**
91
- * 复制各类资源文件,例如图片、视频等
92
- * @param context
93
- * @param config
94
- * @param compilerOption
95
- */
96
- UxAfterCompile.copyResource = (params) => __awaiter(void 0, void 0, void 0, function* () {
97
- const { context, compilerOption } = params;
98
- const genDeviceManifests = (compilerOption) => {
99
- const { projectPath, sourceRoot, outputPath } = compilerOption;
100
- const manifest = fs_extra_1.default.readJSONSync(path_1.default.join(projectPath, sourceRoot, 'manifest.json'));
101
- const { deviceTypeList } = manifest;
102
- // 生成设备的 manifest 文件,规则为:manifest.json + config-设备类型.json
103
- if (deviceTypeList) {
104
- deviceTypeList.forEach((deviceType) => {
105
- let data = Object.assign({}, manifest);
106
- const deviceConfigPath = path_1.default.join(projectPath, sourceRoot, `config-${deviceType}.json`);
107
- if (fs_extra_1.default.existsSync(deviceConfigPath)) {
108
- const deviceJson = fs_extra_1.default.readJSONSync(deviceConfigPath);
109
- data = lodash_1.default.merge({}, data, deviceJson);
110
- }
111
- const buildPath = path_1.default.join(projectPath, outputPath, `manifest-${deviceType}.json`);
112
- fs_extra_1.default.writeFileSync(buildPath, JSON.stringify(data, undefined, 2));
113
- });
114
- }
101
+ };
102
+
103
+ /**
104
+ * 复制各类资源文件,例如图片、视频等
105
+ * @param context
106
+ * @param config
107
+ * @param compilerOption
108
+ */
109
+ static copyResource = async params => {
110
+ const {
111
+ context,
112
+ compilerOption
113
+ } = params;
114
+ const genDeviceManifests = compilerOption => {
115
+ const {
116
+ projectPath,
117
+ sourceRoot,
118
+ outputPath
119
+ } = compilerOption;
120
+ const manifest = _fsExtra.default.readJSONSync(_path.default.join(projectPath, sourceRoot, 'manifest.json'));
121
+ const {
122
+ deviceTypeList
123
+ } = manifest;
124
+ // 生成设备的 manifest 文件,规则为:manifest.json + config-设备类型.json
125
+ if (deviceTypeList) {
126
+ deviceTypeList.forEach(deviceType => {
127
+ let data = {
128
+ ...manifest
129
+ };
130
+ const deviceConfigPath = _path.default.join(projectPath, sourceRoot, `config-${deviceType}.json`);
131
+ if (_fsExtra.default.existsSync(deviceConfigPath)) {
132
+ const deviceJson = _fsExtra.default.readJSONSync(deviceConfigPath);
133
+ data = _lodash.default.merge({}, data, deviceJson);
134
+ }
135
+ const buildPath = _path.default.join(projectPath, outputPath, `manifest-${deviceType}.json`);
136
+ _fsExtra.default.writeFileSync(buildPath, JSON.stringify(data, undefined, 2));
137
+ });
138
+ }
115
139
  };
116
- const copyResourceFiles = (compilerOption) => {
117
- // 复制除 js/jsx/ts/tsx/json 外,但是包含manifest.json、sitemap.json的文件
118
- const { projectPath, sourceRoot, outputPath } = compilerOption;
119
- const includeList = [/sitemap\.json$/, /i18n(.+)\.json/];
120
- const excludeExtList = [
121
- 'js',
122
- 'jsx',
123
- 'coffee',
124
- 'ts',
125
- 'tsx',
126
- 'vue',
127
- 'css',
128
- 'less',
129
- 'sass',
130
- 'styl',
131
- 'html',
132
- 'md',
133
- 'ux',
134
- 'mix',
135
- 'DS_Store',
136
- 'map'
137
- ];
138
- const excludeReg = `\\.(${excludeExtList.join('|')})$`;
139
- shared_utils_1.FileUtil.copyFiles(path_1.default.join(projectPath, sourceRoot), path_1.default.join(projectPath, outputPath), new RegExp(excludeReg));
140
- shared_utils_1.FileUtil.copyFiles(path_1.default.join(projectPath, sourceRoot), path_1.default.join(projectPath, outputPath), undefined, includeList);
140
+ const copyResourceFiles = compilerOption => {
141
+ // 复制除 js/jsx/ts/tsx/json 外,但是包含manifest.json、sitemap.json的文件
142
+ const {
143
+ projectPath,
144
+ sourceRoot,
145
+ outputPath
146
+ } = compilerOption;
147
+ const includeList = [/sitemap\.json$/, /i18n(.+)\.json/];
148
+ const excludeExtList = ['js', 'jsx', 'coffee', 'ts', 'tsx', 'vue', 'css', 'less', 'sass', 'styl', 'html', 'md', 'ux', 'mix', 'DS_Store', 'map'];
149
+ const excludeReg = `\\.(${excludeExtList.join('|')})$`;
150
+ _sharedUtils.FileUtil.copyFiles(_path.default.join(projectPath, sourceRoot), _path.default.join(projectPath, outputPath), new RegExp(excludeReg));
151
+ _sharedUtils.FileUtil.copyFiles(_path.default.join(projectPath, sourceRoot), _path.default.join(projectPath, outputPath), undefined, includeList);
141
152
  };
153
+
142
154
  /**
143
155
  * 写入 manifest.json 文件
144
156
  *
145
157
  * 需要在源码manifest.json基础加一些额外的内容
146
158
  * @param compilerOption
147
159
  */
148
- const updateManifest = (compilerOption) => {
149
- const { projectPath, sourceRoot, outputPath, completeFeature } = compilerOption;
150
- const content = UxFileUtils_1.default.getMainfestInfo(projectPath, sourceRoot);
151
- const translateCache = context.translateCache;
152
- if (!content.minAPILevel) {
153
- content.minAPILevel = 1;
154
- }
155
- if (!content.packageInfo) {
156
- content.packageInfo = ZipUtil_1.default.createComment(compilerOption);
157
- }
158
- if (completeFeature && (translateCache === null || translateCache === void 0 ? void 0 : translateCache.featureCache.size)) {
159
- const featureSet = new Set([
160
- ...Array.from(translateCache.featureCache),
161
- ...(content.features || []).map((item) => item.name)
162
- ]);
163
- content.features = Array.from(featureSet).map((item) => {
164
- return { name: item };
165
- });
166
- }
167
- fs_extra_1.default.writeJSONSync(path_1.default.join(projectPath, outputPath, UxFileUtils_1.default.CONFIG_FILE_NAME), content, {
168
- spaces: 2
160
+ const updateManifest = compilerOption => {
161
+ const {
162
+ projectPath,
163
+ sourceRoot,
164
+ outputPath,
165
+ completeFeature
166
+ } = compilerOption;
167
+ const content = _UxFileUtils.default.getMainfestInfo(projectPath, sourceRoot);
168
+ const translateCache = context.translateCache;
169
+ if (!content.minAPILevel) {
170
+ content.minAPILevel = 1;
171
+ }
172
+ if (!content.packageInfo) {
173
+ content.packageInfo = _ZipUtil.default.createComment(compilerOption);
174
+ }
175
+ if (completeFeature && translateCache?.featureCache.size) {
176
+ const featureSet = new Set([...Array.from(translateCache.featureCache), ...(content.features || []).map(item => item.name)]);
177
+ content.features = Array.from(featureSet).map(item => {
178
+ return {
179
+ name: item
180
+ };
169
181
  });
182
+ }
183
+ _fsExtra.default.writeJSONSync(_path.default.join(projectPath, outputPath, _UxFileUtils.default.CONFIG_FILE_NAME), content, {
184
+ spaces: 2
185
+ });
186
+ };
187
+ const genMetaFiles = async compilerOption => {
188
+ const {
189
+ projectPath,
190
+ outputPath,
191
+ sourceRoot
192
+ } = compilerOption;
193
+ const outputAbsPath = _path.default.join(projectPath, outputPath);
194
+ const comment = _ZipUtil.default.createComment(compilerOption);
195
+
196
+ // build.txt
197
+ const content = Object.keys(comment).map(key => `${key}=${comment[key]}`).join('\n');
198
+ _fsExtra.default.outputFileSync(_path.default.join(outputAbsPath, _ZipUtil.default.BUILD_FILE_PATH), content);
199
+ // cert
200
+ const files = _ZipUtil.default.getSortedFiles(outputAbsPath, compilerOption, _UxFileUtils.default.getMainfestInfo(projectPath, sourceRoot));
201
+ const digestDic = Object.fromEntries(files.map(item => [item, _sharedUtils.CommonUtil.calcDataDigest(_fsExtra.default.readFileSync(_path.default.join(outputAbsPath, item))).toString('hex')]));
202
+ const hashJson = [{
203
+ path: _ZipUtil.default.DIGEST_HASH_JSON,
204
+ content: JSON.stringify({
205
+ algorithm: 'SHA-256',
206
+ digests: digestDic
207
+ })
208
+ }];
209
+ const buffer = await _ZipUtil.default.createZipBufferFromFileList(hashJson, JSON.stringify(comment));
210
+ _fsExtra.default.outputFileSync(_path.default.join(outputAbsPath, _ZipUtil.default.CERT_PATH), buffer);
170
211
  };
171
- const genMetaFiles = (compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
172
- const { projectPath, outputPath, sourceRoot } = compilerOption;
173
- const outputAbsPath = path_1.default.join(projectPath, outputPath);
174
- const comment = ZipUtil_1.default.createComment(compilerOption);
175
- // build.txt
176
- const content = Object.keys(comment)
177
- .map((key) => `${key}=${comment[key]}`)
178
- .join('\n');
179
- fs_extra_1.default.outputFileSync(path_1.default.join(outputAbsPath, ZipUtil_1.default.BUILD_FILE_PATH), content);
180
- // cert
181
- const files = ZipUtil_1.default.getSortedFiles(outputAbsPath, compilerOption, UxFileUtils_1.default.getMainfestInfo(projectPath, sourceRoot));
182
- const digestDic = Object.fromEntries(files.map((item) => [
183
- item,
184
- shared_utils_1.CommonUtil.calcDataDigest(fs_extra_1.default.readFileSync(path_1.default.join(outputAbsPath, item))).toString('hex')
185
- ]));
186
- const hashJson = [
187
- {
188
- path: ZipUtil_1.default.DIGEST_HASH_JSON,
189
- content: JSON.stringify({
190
- algorithm: 'SHA-256',
191
- digests: digestDic
192
- })
193
- }
194
- ];
195
- const buffer = yield ZipUtil_1.default.createZipBufferFromFileList(hashJson, JSON.stringify(comment));
196
- fs_extra_1.default.outputFileSync(path_1.default.join(outputAbsPath, ZipUtil_1.default.CERT_PATH), buffer);
197
- });
198
212
  if (compilerOption) {
199
- yield copyResourceFiles(compilerOption);
200
- yield updateManifest(compilerOption);
201
- yield genDeviceManifests(compilerOption);
202
- yield genMetaFiles(compilerOption);
213
+ await copyResourceFiles(compilerOption);
214
+ await updateManifest(compilerOption);
215
+ await genDeviceManifests(compilerOption);
216
+ await genMetaFiles(compilerOption);
203
217
  }
204
- });
205
- /**
206
- * 对比 临时项目build文件夹 和 项目build文件夹,生成diff.json
207
- * @param context
208
- * @param config
209
- * @param compilerOption
210
- */
211
- UxAfterCompile.generateDiff = (params) => __awaiter(void 0, void 0, void 0, function* () {
212
- const { compilerOption, compalition } = params;
218
+ };
219
+ /**
220
+ * 如果是更新触发,则对比临时项目build文件夹 和 项目build文件夹,生成diff.json
221
+ * @param context
222
+ * @param config
223
+ * @param compilerOption
224
+ */
225
+ static generateDiff = async params => {
226
+ const {
227
+ compilerOption,
228
+ compalition,
229
+ config
230
+ } = params;
213
231
  if (!compilerOption || !compalition) {
214
- return;
232
+ return;
215
233
  }
216
- const { outputPath, projectPath } = compilerOption;
234
+ if (compalition.trigger === _FileLaneTriggerType.default.START) {
235
+ return;
236
+ }
237
+ const {
238
+ outputPath,
239
+ projectPath
240
+ } = compilerOption;
217
241
  // 读取临时项目build文件夹中所有文件路径
218
- const tempBuildPath = path_1.default.join(projectPath, outputPath);
242
+ const tempBuildPath = _path.default.join(projectPath, outputPath);
219
243
  // 待优化,map文件跟随源文件变化,与时间戳有关文件无需对比
220
- const tempFileList = shared_utils_1.FileUtil.readAlldirSync(tempBuildPath).map((filePath) => path_1.default.relative(tempBuildPath, filePath));
221
- UxFileUtils_1.default.getDiffJSON(compalition, tempFileList, tempBuildPath);
222
- });
223
- /**
224
- * 打包结果移回源码项目,并删除中间项目
225
- *
226
- * 1. 把 build和rpk 目录从**中间项目**移回**源码项目**
227
- * 2. 删除中间项目
228
- * @param context
229
- * @param config
230
- * @param compilerOption
231
- */
232
- UxAfterCompile.moveBackResult = (params) => __awaiter(void 0, void 0, void 0, function* () {
233
- const { context, compilerOption } = params;
244
+ const tempFileList = _sharedUtils.FileUtil.readAlldirSync(tempBuildPath).map(filePath => _path.default.relative(tempBuildPath, filePath));
245
+ const diffList = _UxFileUtils.default.getDiffJSON(compalition, tempFileList, tempBuildPath);
246
+
247
+ // 所有差异文件,压缩到 .diff.rpk 中
248
+ if (diffList?.length) {
249
+ const buildFold = _path.default.join(compilerOption.projectPath, compilerOption.outputPath);
250
+ const distFold = _path.default.join(compilerOption.projectPath, compilerOption.releasePath);
251
+ const diffFileName = `.diff.rpk`;
252
+ const diffPath = _path.default.join(distFold, diffFileName);
253
+ await _ZipFileUtil.default.createZipFile(diffPath, diffList.map(item => ({
254
+ filePath: _path.default.join(buildFold, item),
255
+ zipFilePath: item
256
+ })));
257
+ compalition.info.diffList = diffList;
258
+ compalition.info.diffFile = _path.default.join(config.projectPath, compilerOption.releasePath, diffFileName);
259
+ }
260
+ };
261
+
262
+ /**
263
+ * 打包结果移回源码项目,并删除中间项目
264
+ *
265
+ * 1. 把 build和rpk 目录从**中间项目**移回**源码项目**
266
+ * 2. 删除中间项目
267
+ * @param context
268
+ * @param config
269
+ * @param compilerOption
270
+ */
271
+ static moveBackResult = async params => {
272
+ const {
273
+ context,
274
+ compilerOption
275
+ } = params;
234
276
  if (!compilerOption) {
235
- return;
277
+ return;
236
278
  }
237
- const { outputPath, releasePath, projectPath } = compilerOption;
238
- const { projectPath: orgProjectPath } = context;
239
- const targetList = [
240
- {
241
- from: path_1.default.join(projectPath, outputPath),
242
- to: path_1.default.join(orgProjectPath, outputPath)
243
- },
244
- {
245
- from: path_1.default.join(projectPath, releasePath),
246
- to: path_1.default.join(orgProjectPath, releasePath)
247
- }
248
- ];
249
- targetList.forEach((item) => {
250
- fs_extra_1.default.moveSync(item.from, item.to, { overwrite: true });
279
+ const {
280
+ outputPath,
281
+ releasePath,
282
+ projectPath
283
+ } = compilerOption;
284
+ const {
285
+ projectPath: orgProjectPath
286
+ } = context;
287
+ const targetList = [{
288
+ from: _path.default.join(projectPath, outputPath),
289
+ to: _path.default.join(orgProjectPath, outputPath)
290
+ }, {
291
+ from: _path.default.join(projectPath, releasePath),
292
+ to: _path.default.join(orgProjectPath, releasePath)
293
+ }];
294
+ targetList.forEach(item => {
295
+ _fsExtra.default.removeSync(item.to);
296
+ _fsExtra.default.moveSync(item.from, item.to, {
297
+ overwrite: true
298
+ });
251
299
  });
252
- });
253
- /**
254
- * 创建 node_module 软链
255
- * @param context
256
- * @param config
257
- * @param compilerOption
258
- */
259
- UxAfterCompile.symlinkNodeModule = (params) => __awaiter(void 0, void 0, void 0, function* () {
260
- const { context, compilerOption } = params;
300
+ };
301
+
302
+ /**
303
+ * 创建 node_module 软链
304
+ * @param context
305
+ * @param config
306
+ * @param compilerOption
307
+ */
308
+ static symlinkNodeModule = async params => {
309
+ const {
310
+ context,
311
+ compilerOption
312
+ } = params;
261
313
  if (!compilerOption) {
262
- return;
314
+ return;
263
315
  }
264
316
  try {
265
- const foldList = ['node_modules'];
266
- foldList.forEach((item) => {
267
- const sourcePath = path_1.default.join(context.projectPath, item);
268
- const targetPath = path_1.default.join(compilerOption.projectPath, item);
269
- if (fs_extra_1.default.existsSync(sourcePath) && !fs_extra_1.default.existsSync(targetPath)) {
270
- fs_extra_1.default.symlinkSync(sourcePath, targetPath, 'junction');
271
- }
272
- });
273
- }
274
- catch (error) {
275
- throw new Error(`${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}. Please check whether the file system of the current disk supports the creation of soft links.`);
317
+ const foldList = ['node_modules'];
318
+ foldList.forEach(item => {
319
+ const sourcePath = _path.default.join(context.projectPath, item);
320
+ const targetPath = _path.default.join(compilerOption.projectPath, item);
321
+ if (_fsExtra.default.existsSync(sourcePath) && !_fsExtra.default.existsSync(targetPath)) {
322
+ _fsExtra.default.symlinkSync(sourcePath, targetPath, 'junction');
323
+ }
324
+ });
325
+ } catch (error) {
326
+ throw new Error(`${error?.toString() || 'unknown error'}. Please check whether the file system of the current disk supports the creation of soft links.`);
276
327
  }
277
- });
278
- exports.default = UxAfterCompile;
328
+ };
329
+ }
330
+ var _default = exports.default = UxAfterCompile;