@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,304 +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"));
26
- const archiver_1 = __importDefault(require("archiver"));
27
- const FileLaneTriggerType_1 = __importDefault(require("file-lane/lib/enum/FileLaneTriggerType"));
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 }; }
28
20
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
21
+
29
22
  /**
30
23
  * UxAfterCompile
31
24
  */
32
25
  class UxAfterCompile {
33
- }
34
- _a = UxAfterCompile;
35
- UxAfterCompile.webpack = (params) => __awaiter(void 0, void 0, void 0, function* () {
36
- const { context, compilerOption } = params;
37
- return new JavascriptCompiler_1.default()
38
- .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))
39
- .then(() => {
40
- shared_utils_1.ColorConsole.info(`webpack complete`);
41
- })
42
- .catch(({ errors, warnings }) => {
43
- const errorLength = (errors === null || errors === void 0 ? void 0 : errors.length) || 0;
44
- const messages = [`webpack error:\r\n`];
45
- if (errors === null || errors === void 0 ? void 0 : errors.length) {
46
- messages.push({
47
- word: errors
48
- .map((item, index) => {
49
- return `${index + 1}. ${item.message}`;
50
- })
51
- .join('\r\n'),
52
- style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.THROW)
53
- });
54
- }
55
- if (warnings === null || warnings === void 0 ? void 0 : warnings.length) {
56
- messages.push({
57
- word: warnings
58
- .map((item, index) => {
59
- return `${errorLength + index + 1}. ${item.message}`;
60
- })
61
- .join('\r\n'),
62
- style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.WARN)
63
- });
64
- }
65
- if (errors === null || errors === void 0 ? void 0 : errors.length) {
66
- shared_utils_1.ColorConsole.throw(...messages);
67
- throw new Error();
68
- }
69
- else {
70
- shared_utils_1.ColorConsole.warn(...messages);
71
- }
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
+ }
72
69
  });
73
- });
74
- UxAfterCompile.protobuf = (params) => __awaiter(void 0, void 0, void 0, function* () {
75
- const { compilerOption } = params;
76
- if (compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.enableProtobuf) {
77
- BinaryPlugin.createBinFiles();
70
+ };
71
+ static protobuf = async params => {
72
+ const {
73
+ compilerOption
74
+ } = params;
75
+ if (compilerOption?.enableProtobuf) {
76
+ BinaryPlugin.createBinFiles();
78
77
  }
79
- });
80
- UxAfterCompile.jsc = (params) => __awaiter(void 0, void 0, void 0, function* () {
81
- const { context, compilerOption } = params;
78
+ };
79
+ static jsc = async params => {
80
+ const {
81
+ context,
82
+ compilerOption
83
+ } = params;
82
84
  if (compilerOption && compilerOption.enableJsc === true) {
83
- 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();
84
86
  }
85
- });
86
- UxAfterCompile.toRpk = (params) => __awaiter(void 0, void 0, void 0, function* () {
87
- const { compilerOption, compalition, config } = params;
87
+ };
88
+ static toRpk = async params => {
89
+ const {
90
+ compilerOption,
91
+ compalition,
92
+ config
93
+ } = params;
88
94
  if (compilerOption) {
89
- const fileName = yield ZipUtil_1.default.createRpk(path_1.default.join(compilerOption.projectPath, compilerOption.outputPath), compilerOption);
90
- if (compalition && fileName) {
91
- compalition.info.rpk = path_1.default.join(config.projectPath, compilerOption.releasePath, fileName);
92
- }
93
- return fileName;
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;
94
100
  }
95
- });
96
- /**
97
- * 复制各类资源文件,例如图片、视频等
98
- * @param context
99
- * @param config
100
- * @param compilerOption
101
- */
102
- UxAfterCompile.copyResource = (params) => __awaiter(void 0, void 0, void 0, function* () {
103
- const { context, compilerOption } = params;
104
- const genDeviceManifests = (compilerOption) => {
105
- const { projectPath, sourceRoot, outputPath } = compilerOption;
106
- const manifest = fs_extra_1.default.readJSONSync(path_1.default.join(projectPath, sourceRoot, 'manifest.json'));
107
- const { deviceTypeList } = manifest;
108
- // 生成设备的 manifest 文件,规则为:manifest.json + config-设备类型.json
109
- if (deviceTypeList) {
110
- deviceTypeList.forEach((deviceType) => {
111
- let data = Object.assign({}, manifest);
112
- const deviceConfigPath = path_1.default.join(projectPath, sourceRoot, `config-${deviceType}.json`);
113
- if (fs_extra_1.default.existsSync(deviceConfigPath)) {
114
- const deviceJson = fs_extra_1.default.readJSONSync(deviceConfigPath);
115
- data = lodash_1.default.merge({}, data, deviceJson);
116
- }
117
- const buildPath = path_1.default.join(projectPath, outputPath, `manifest-${deviceType}.json`);
118
- fs_extra_1.default.writeFileSync(buildPath, JSON.stringify(data, undefined, 2));
119
- });
120
- }
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
+ }
121
139
  };
122
- const copyResourceFiles = (compilerOption) => {
123
- // 复制除 js/jsx/ts/tsx/json 外,但是包含manifest.json、sitemap.json的文件
124
- const { projectPath, sourceRoot, outputPath } = compilerOption;
125
- const includeList = [/sitemap\.json$/, /i18n(.+)\.json/];
126
- const excludeExtList = [
127
- 'js',
128
- 'jsx',
129
- 'coffee',
130
- 'ts',
131
- 'tsx',
132
- 'vue',
133
- 'css',
134
- 'less',
135
- 'sass',
136
- 'styl',
137
- 'html',
138
- 'md',
139
- 'ux',
140
- 'mix',
141
- 'DS_Store',
142
- 'map'
143
- ];
144
- const excludeReg = `\\.(${excludeExtList.join('|')})$`;
145
- shared_utils_1.FileUtil.copyFiles(path_1.default.join(projectPath, sourceRoot), path_1.default.join(projectPath, outputPath), new RegExp(excludeReg));
146
- 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);
147
152
  };
153
+
148
154
  /**
149
155
  * 写入 manifest.json 文件
150
156
  *
151
157
  * 需要在源码manifest.json基础加一些额外的内容
152
158
  * @param compilerOption
153
159
  */
154
- const updateManifest = (compilerOption) => {
155
- const { projectPath, sourceRoot, outputPath, completeFeature } = compilerOption;
156
- const content = UxFileUtils_1.default.getMainfestInfo(projectPath, sourceRoot);
157
- const translateCache = context.translateCache;
158
- if (!content.minAPILevel) {
159
- content.minAPILevel = 1;
160
- }
161
- if (!content.packageInfo) {
162
- content.packageInfo = ZipUtil_1.default.createComment(compilerOption);
163
- }
164
- if (completeFeature && (translateCache === null || translateCache === void 0 ? void 0 : translateCache.featureCache.size)) {
165
- const featureSet = new Set([
166
- ...Array.from(translateCache.featureCache),
167
- ...(content.features || []).map((item) => item.name)
168
- ]);
169
- content.features = Array.from(featureSet).map((item) => {
170
- return { name: item };
171
- });
172
- }
173
- fs_extra_1.default.writeJSONSync(path_1.default.join(projectPath, outputPath, UxFileUtils_1.default.CONFIG_FILE_NAME), content, {
174
- 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
+ };
175
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);
176
211
  };
177
- const genMetaFiles = (compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
178
- const { projectPath, outputPath, sourceRoot } = compilerOption;
179
- const outputAbsPath = path_1.default.join(projectPath, outputPath);
180
- const comment = ZipUtil_1.default.createComment(compilerOption);
181
- // build.txt
182
- const content = Object.keys(comment)
183
- .map((key) => `${key}=${comment[key]}`)
184
- .join('\n');
185
- fs_extra_1.default.outputFileSync(path_1.default.join(outputAbsPath, ZipUtil_1.default.BUILD_FILE_PATH), content);
186
- // cert
187
- const files = ZipUtil_1.default.getSortedFiles(outputAbsPath, compilerOption, UxFileUtils_1.default.getMainfestInfo(projectPath, sourceRoot));
188
- const digestDic = Object.fromEntries(files.map((item) => [
189
- item,
190
- shared_utils_1.CommonUtil.calcDataDigest(fs_extra_1.default.readFileSync(path_1.default.join(outputAbsPath, item))).toString('hex')
191
- ]));
192
- const hashJson = [
193
- {
194
- path: ZipUtil_1.default.DIGEST_HASH_JSON,
195
- content: JSON.stringify({
196
- algorithm: 'SHA-256',
197
- digests: digestDic
198
- })
199
- }
200
- ];
201
- const buffer = yield ZipUtil_1.default.createZipBufferFromFileList(hashJson, JSON.stringify(comment));
202
- fs_extra_1.default.outputFileSync(path_1.default.join(outputAbsPath, ZipUtil_1.default.CERT_PATH), buffer);
203
- });
204
212
  if (compilerOption) {
205
- yield copyResourceFiles(compilerOption);
206
- yield updateManifest(compilerOption);
207
- yield genDeviceManifests(compilerOption);
208
- yield genMetaFiles(compilerOption);
213
+ await copyResourceFiles(compilerOption);
214
+ await updateManifest(compilerOption);
215
+ await genDeviceManifests(compilerOption);
216
+ await genMetaFiles(compilerOption);
209
217
  }
210
- });
211
- /**
212
- * 如果是更新触发,则对比临时项目build文件夹 和 项目build文件夹,生成diff.json
213
- * @param context
214
- * @param config
215
- * @param compilerOption
216
- */
217
- UxAfterCompile.generateDiff = (params) => __awaiter(void 0, void 0, void 0, function* () {
218
- const { compilerOption, compalition, config } = 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;
219
231
  if (!compilerOption || !compalition) {
220
- return;
232
+ return;
221
233
  }
222
- if (compalition.trigger === FileLaneTriggerType_1.default.START) {
223
- return;
234
+ if (compalition.trigger === _FileLaneTriggerType.default.START) {
235
+ return;
224
236
  }
225
- const { outputPath, projectPath } = compilerOption;
237
+ const {
238
+ outputPath,
239
+ projectPath
240
+ } = compilerOption;
226
241
  // 读取临时项目build文件夹中所有文件路径
227
- const tempBuildPath = path_1.default.join(projectPath, outputPath);
242
+ const tempBuildPath = _path.default.join(projectPath, outputPath);
228
243
  // 待优化,map文件跟随源文件变化,与时间戳有关文件无需对比
229
- const tempFileList = shared_utils_1.FileUtil.readAlldirSync(tempBuildPath).map((filePath) => path_1.default.relative(tempBuildPath, filePath));
230
- const diffList = UxFileUtils_1.default.getDiffJSON(compalition, tempFileList, tempBuildPath);
244
+ const tempFileList = _sharedUtils.FileUtil.readAlldirSync(tempBuildPath).map(filePath => _path.default.relative(tempBuildPath, filePath));
245
+ const diffList = _UxFileUtils.default.getDiffJSON(compalition, tempFileList, tempBuildPath);
246
+
231
247
  // 所有差异文件,压缩到 .diff.rpk 中
232
- if (diffList === null || diffList === void 0 ? void 0 : diffList.length) {
233
- const buildFold = path_1.default.join(compilerOption.projectPath, compilerOption.outputPath);
234
- const distFold = path_1.default.join(compilerOption.projectPath, compilerOption.releasePath);
235
- const diffFileName = `.diff.rpk`;
236
- const diffPath = path_1.default.join(distFold, diffFileName);
237
- const diffStream = fs_extra_1.default.createWriteStream(diffPath);
238
- const archiver = (0, archiver_1.default)('zip', { zlib: { level: 9 } });
239
- archiver.pipe(diffStream);
240
- diffList.forEach((item) => {
241
- const filePath = path_1.default.join(buildFold, item);
242
- archiver.append(fs_extra_1.default.createReadStream(filePath), { name: item });
243
- });
244
- yield archiver.finalize();
245
- compalition.info.diffList = diffList;
246
- compalition.info.diffFile = path_1.default.join(config.projectPath, compilerOption.releasePath, diffFileName);
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);
247
259
  }
248
- });
249
- /**
250
- * 打包结果移回源码项目,并删除中间项目
251
- *
252
- * 1. 把 build和rpk 目录从**中间项目**移回**源码项目**
253
- * 2. 删除中间项目
254
- * @param context
255
- * @param config
256
- * @param compilerOption
257
- */
258
- UxAfterCompile.moveBackResult = (params) => __awaiter(void 0, void 0, void 0, function* () {
259
- const { context, compilerOption } = params;
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;
260
276
  if (!compilerOption) {
261
- return;
277
+ return;
262
278
  }
263
- const { outputPath, releasePath, projectPath } = compilerOption;
264
- const { projectPath: orgProjectPath } = context;
265
- const targetList = [
266
- {
267
- from: path_1.default.join(projectPath, outputPath),
268
- to: path_1.default.join(orgProjectPath, outputPath)
269
- },
270
- {
271
- from: path_1.default.join(projectPath, releasePath),
272
- to: path_1.default.join(orgProjectPath, releasePath)
273
- }
274
- ];
275
- targetList.forEach((item) => {
276
- 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
+ });
277
299
  });
278
- });
279
- /**
280
- * 创建 node_module 软链
281
- * @param context
282
- * @param config
283
- * @param compilerOption
284
- */
285
- UxAfterCompile.symlinkNodeModule = (params) => __awaiter(void 0, void 0, void 0, function* () {
286
- 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;
287
313
  if (!compilerOption) {
288
- return;
314
+ return;
289
315
  }
290
316
  try {
291
- const foldList = ['node_modules'];
292
- foldList.forEach((item) => {
293
- const sourcePath = path_1.default.join(context.projectPath, item);
294
- const targetPath = path_1.default.join(compilerOption.projectPath, item);
295
- if (fs_extra_1.default.existsSync(sourcePath) && !fs_extra_1.default.existsSync(targetPath)) {
296
- fs_extra_1.default.symlinkSync(sourcePath, targetPath, 'junction');
297
- }
298
- });
299
- }
300
- catch (error) {
301
- 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.`);
302
327
  }
303
- });
304
- exports.default = UxAfterCompile;
328
+ };
329
+ }
330
+ var _default = exports.default = UxAfterCompile;