@aiot-toolkit/aiotpack 2.0.2-dev.7 → 2.0.2

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 (83) hide show
  1. package/lib/{utils/ux/UxFollowWorks.d.ts → afterCompile/ux/UxAfterCompile.d.ts} +11 -4
  2. package/lib/{utils/ux/UxFollowWorks.js → afterCompile/ux/UxAfterCompile.js} +68 -43
  3. package/lib/{followWorks → afterCompile}/xts/entryTemplate.d.ts +1 -1
  4. package/lib/{followWorks → afterCompile}/xts/entryTemplate.js +14 -13
  5. package/lib/{followWorks → afterCompile}/xts/generateRpk.d.ts +1 -1
  6. package/lib/{followWorks → afterCompile}/xts/generateRpk.js +5 -4
  7. package/lib/{followWorks → afterCompile}/xts/ts2wasm.d.ts +1 -1
  8. package/lib/{followWorks → afterCompile}/xts/ts2wasm.js +7 -6
  9. package/lib/afterWorks/ux/UxAfterWorks.d.ts +5 -0
  10. package/lib/afterWorks/ux/UxAfterWorks.js +22 -0
  11. package/lib/{utils/ux/UxPreWorks.d.ts → beforeCompile/ux/UxBeforeCompile.d.ts} +4 -4
  12. package/lib/{utils/ux/UxPreWorks.js → beforeCompile/ux/UxBeforeCompile.js} +11 -8
  13. package/lib/{preWorks → beforeCompile}/xts/preInstall.d.ts +1 -1
  14. package/lib/{preWorks → beforeCompile}/xts/preInstall.js +6 -5
  15. package/lib/beforeWorks/ux/UxBeforeWorks.d.ts +5 -0
  16. package/lib/beforeWorks/ux/UxBeforeWorks.js +22 -0
  17. package/lib/compiler/interface/ICompileParam.d.ts +1 -1
  18. package/lib/compiler/interface/ISignConfig.d.ts +6 -1
  19. package/lib/compiler/javascript/JavascriptCompiler.js +45 -12
  20. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +1 -2
  21. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.d.ts +9 -0
  22. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +16 -0
  23. package/lib/compiler/javascript/android/plugin/WrapPlugin.d.ts +20 -0
  24. package/lib/compiler/javascript/android/plugin/WrapPlugin.js +91 -0
  25. package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +16 -1
  26. package/lib/compiler/javascript/interface/IWebpackConfigurator.d.ts +4 -4
  27. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +4 -2
  28. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +18 -5
  29. package/lib/compiler/javascript/vela/interface/IChunk.d.ts +6 -1
  30. package/lib/compiler/javascript/vela/interface/IManifest.d.ts +1 -1
  31. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.d.ts +1 -1
  32. package/lib/compiler/javascript/vela/model/Package.d.ts +2 -2
  33. package/lib/compiler/javascript/vela/model/Package.js +5 -5
  34. package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +1 -1
  35. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +16 -2
  36. package/lib/compiler/javascript/vela/utils/Jsc.d.ts +1 -1
  37. package/lib/compiler/javascript/vela/utils/Jsc.js +19 -11
  38. package/lib/compiler/javascript/vela/utils/UxCompileUtil.d.ts +1 -1
  39. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +4 -4
  40. package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +19 -3
  41. package/lib/compiler/javascript/vela/utils/ZipUtil.js +34 -29
  42. package/lib/compiler/javascript/vela/utils/signature/Base64.d.ts +0 -1
  43. package/lib/compiler/javascript/vela/utils/signature/SignUtil.d.ts +23 -7
  44. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +94 -45
  45. package/lib/compiler/javascript/vela/utils/signature/Signer.d.ts +0 -1
  46. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.d.ts +3 -0
  47. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +56 -0
  48. package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.d.ts +3 -0
  49. package/lib/compiler/javascript/vela/utils/webpackLoader/{splitMap.js → extractMapData.js} +2 -2
  50. package/lib/config/UxConfig.d.ts +45 -7
  51. package/lib/config/UxConfig.js +156 -40
  52. package/lib/config/XtsConfig.d.ts +6 -4
  53. package/lib/config/XtsConfig.js +22 -7
  54. package/lib/index.d.ts +9 -1
  55. package/lib/index.js +35 -1
  56. package/lib/loader/ux/JsLoader.d.ts +2 -0
  57. package/lib/loader/ux/JsLoader.js +6 -9
  58. package/lib/loader/ux/PngLoader.js +4 -5
  59. package/lib/loader/ux/android/UxLoader.d.ts +11 -0
  60. package/lib/loader/ux/android/UxLoader.js +39 -0
  61. package/lib/loader/ux/{AppUxLoader.d.ts → vela/AppUxLoader.d.ts} +1 -1
  62. package/lib/loader/ux/{AppUxLoader.js → vela/AppUxLoader.js} +6 -3
  63. package/lib/loader/ux/vela/HmlLoader.d.ts +24 -0
  64. package/lib/loader/ux/vela/HmlLoader.js +63 -0
  65. package/lib/loader/ux/{UxLoader.d.ts → vela/UxLoader.d.ts} +1 -1
  66. package/lib/loader/ux/{UxLoader.js → vela/UxLoader.js} +12 -13
  67. package/lib/loader/xts/XtsLoader.js +6 -7
  68. package/lib/utils/BeforeCompileUtils.d.ts +21 -0
  69. package/lib/utils/BeforeCompileUtils.js +118 -0
  70. package/lib/utils/ux/ManifestSchema.d.ts +1 -1
  71. package/lib/utils/ux/UxFileUtils.d.ts +16 -3
  72. package/lib/utils/ux/UxFileUtils.js +50 -17
  73. package/lib/utils/ux/UxLoaderUtils.d.ts +7 -4
  74. package/lib/utils/ux/UxLoaderUtils.js +43 -25
  75. package/lib/utils/ux/android/AndroidUx.d.ts +27 -0
  76. package/lib/utils/ux/android/AndroidUx.js +98 -0
  77. package/lib/utils/xts/XtsFileLaneUtils.d.ts +10 -0
  78. package/lib/utils/xts/XtsFileLaneUtils.js +68 -0
  79. package/lib/utils/xts/XtsFollowWorks.js +8 -8
  80. package/package.json +16 -8
  81. package/lib/compiler/javascript/vela/utils/webpackLoader/splitMap.d.ts +0 -3
  82. package/lib/utils/PreWorkUtils.d.ts +0 -22
  83. package/lib/utils/PreWorkUtils.js +0 -106
@@ -13,9 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  var _a;
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
17
- const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
18
- const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
16
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
19
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
20
18
  const jszip_1 = __importDefault(require("jszip"));
21
19
  const path_1 = __importDefault(require("path"));
@@ -51,17 +49,14 @@ class ZipUtil {
51
49
  // 1
52
50
  const files = this.getSortedFiles(dist, param, config);
53
51
  if (!files.length) {
54
- ColorConsole_1.default.error(`The build file is missing, stop generating the application package, please check carefully`);
52
+ shared_utils_1.ColorConsole.error(`The build file is missing, stop generating the application package, please check carefully`);
55
53
  return;
56
54
  }
57
55
  // 2
58
56
  const { fullPackage } = yield this.createPackagesDefinition(param, config, files);
59
- const zipBuffer = yield this.packageToZipBuffer(fullPackage);
60
57
  // 生产出带签名的rpk文件buffer
61
58
  const signConfig = SignUtil_1.default.getProjectSignConfig(param);
62
- const { rpkBuffer } = yield ZipUtil.buildProjectAndOutput(zipBuffer, signConfig);
63
- // IDE 扫码预览打包 todo
64
- // IDE 重置包名
59
+ const rpkBuffer = yield _a.buildProjectAndOutput(fullPackage, signConfig);
65
60
  // 3
66
61
  this.generateDistFile(rpkBuffer, param, this.getFileName(param, config, 'rpk'));
67
62
  });
@@ -72,7 +67,7 @@ class ZipUtil {
72
67
  return [
73
68
  packageName,
74
69
  mode === CompileMode_1.default.DEVELOPMENT ? 'debug' : 'release',
75
- buildNameFormat === BuildNameFormatType_1.default.DEFAULT ? config.versionName : '',
70
+ buildNameFormat === BuildNameFormatType_1.default.ORIGINAL ? '' : config.versionName,
76
71
  ext
77
72
  ]
78
73
  .filter(Boolean)
@@ -95,9 +90,15 @@ class ZipUtil {
95
90
  const { releasePath, projectPath } = param;
96
91
  const filePath = path_1.default.join(projectPath, releasePath, fileName);
97
92
  fs_extra_1.default.outputFileSync(filePath, buffer);
98
- ColorConsole_1.default.success(`Project build and generate files:${fileName}`);
93
+ shared_utils_1.ColorConsole.success(`Project build and generate files:${fileName}`);
99
94
  });
100
95
  }
96
+ /**
97
+ * 根据文件列表创建 zip 的 Buffer
98
+ * @param fileList 文件列表
99
+ * @param comment zip 的注释
100
+ * @returns
101
+ */
101
102
  static createZipBufferFromFileList(fileList, comment) {
102
103
  return __awaiter(this, void 0, void 0, function* () {
103
104
  const zip = new jszip_1.default();
@@ -129,11 +130,11 @@ class ZipUtil {
129
130
  for (let fileBuildPath of files) {
130
131
  const absPath = path_1.default.join(projectPath, outputPath, fileBuildPath);
131
132
  let fileContentBuffer = fs_extra_1.default.readFileSync(absPath);
132
- if (fileBuildPath === ZipUtil.CERT_PATH) {
133
+ if (fileBuildPath === _a.CERT_PATH) {
133
134
  let metaZip = yield jszip_1.default.loadAsync(fileContentBuffer);
134
- fileContentBuffer = (yield metaZip.generateAsync(Object.assign(Object.assign({}, ZipUtil.ZIP_OPTION), { comment: null })));
135
+ fileContentBuffer = (yield metaZip.generateAsync(Object.assign(Object.assign({}, _a.ZIP_OPTION), { comment: null })));
135
136
  }
136
- const fileContentDigest = CommonUtil_1.default.calcDataDigest(fileContentBuffer);
137
+ const fileContentDigest = shared_utils_1.CommonUtil.calcDataDigest(fileContentBuffer);
137
138
  const resourceInfo = {
138
139
  fileBuildPath,
139
140
  fileContentBuffer,
@@ -174,13 +175,13 @@ class ZipUtil {
174
175
  // 1. 排除META-INF 目录下的文件
175
176
  // 2. 生产环境排除 .map 文件
176
177
  const mapReg = /\.map$/;
177
- let result = FileUtil_1.default.readAlldirSync(dist);
178
+ let result = shared_utils_1.FileUtil.readAlldirSync(dist);
178
179
  result = result
179
180
  .filter((item) => {
180
181
  return !(item.startsWith(UxCompileUtil_1.default.DIGEST_ZIP_DIR) ||
181
182
  (param.mode === CompileMode_1.default.PRODUCTION && mapReg.test(item)));
182
183
  })
183
- .map((item) => path_1.default.relative(dist, item));
184
+ .map((item) => path_1.default.relative(dist, item).split(path_1.default.sep).join(path_1.default.posix.sep));
184
185
  result.sort((a, b) => {
185
186
  const indexA = getFileIndex(a);
186
187
  const indexB = getFileIndex(b);
@@ -210,7 +211,7 @@ class ZipUtil {
210
211
  ...entrySkFiles,
211
212
  new RegExp(`^${entry}/$`),
212
213
  new RegExp(`^${entry}/.+`),
213
- /^common\//i,
214
+ /^common\//i, // 静态资源
214
215
  /.+\.js/,
215
216
  'META-INF/build.txt'
216
217
  ];
@@ -231,27 +232,31 @@ class ZipUtil {
231
232
  };
232
233
  return obj;
233
234
  }
234
- static buildProjectAndOutput(fullPackage, signConfig) {
235
+ /**
236
+ * 生成rpk的最终的Buffer
237
+ *
238
+ * @description 使用证书对原始rpk包的 buffer 签名. 签名失败,返回原始包; 签名成功,返回新包
239
+ * @param fullPackage 原始包 buffer
240
+ * @param signConfig 证书信息
241
+ * @returns
242
+ */
243
+ static buildProjectAndOutput(target, signConfig) {
235
244
  return __awaiter(this, void 0, void 0, function* () {
236
- // 1. 默认携带META,如果禁用流失打包,需要删除META
237
- // 2. 是否需要增加签名内容
245
+ let result;
238
246
  if (signConfig) {
239
247
  const { privatekey, certificate } = signConfig;
240
- // fullPackageBuffer
241
- const fullPackageBuffer = yield SignUtil_1.default.signZipBufferForPackage(fullPackage, privatekey, certificate);
248
+ const fullPackageBuffer = yield SignUtil_1.default.signPackage(target, privatekey, certificate);
242
249
  if (fullPackageBuffer === false) {
243
- ColorConsole_1.default.throw('Fullpackage signature failed');
250
+ shared_utils_1.ColorConsole.throw('Fullpackage signature failed');
244
251
  }
245
252
  else {
246
- fullPackage = fullPackageBuffer;
253
+ result = fullPackageBuffer;
247
254
  }
248
255
  }
249
- // 3. 校验体积等
250
- // 4. 生成rpks:不需要META和签名
251
- // 5. 返回
252
- return {
253
- rpkBuffer: fullPackage
254
- };
256
+ if (!result) {
257
+ result = yield this.packageToZipBuffer(target);
258
+ }
259
+ return result;
255
260
  });
256
261
  }
257
262
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  /**
3
2
  * Base64
4
3
  */
@@ -1,29 +1,45 @@
1
- /// <reference types="node" />
2
- import ICompileParam from '../../../../interface/ICompileParam';
3
1
  import IJavascriptCompileOption from '../../../interface/IJavascriptCompileOption';
2
+ import Package from '../../model/Package';
4
3
  /**
5
4
  * SignUtil
6
5
  */
7
6
  declare class SignUtil {
8
7
  /**
9
8
  * 获取签名相关的配置内容
10
- * 1. ICompileParam参数中获取编译模式是否为release
11
- * 2. IJavascriptCompileOption参数中获取签名目录等内容
12
- * @param param
9
+ * @param param IJavascriptCompileOption参数中获取签名目录等内容
10
+ * @returns
13
11
  */
14
- static getProjectSignConfig(param: ICompileParam & IJavascriptCompileOption): {
12
+ static getProjectSignConfig(param: IJavascriptCompileOption): {
15
13
  privatekey: Buffer;
16
14
  certificate: Buffer;
17
15
  };
18
- static signZipBufferForPackage(zipBuffer: Buffer, privatekey: Buffer, certificate: Buffer): Promise<false | Buffer>;
16
+ /**
17
+ * 对二进制zipBuffer签名
18
+ *
19
+ * 1. 对`META-INF/CERT`做签名,并生成新的`META-INF/CERT` buffer
20
+ * 2. "新`META-INF/CERT` + 其它文件"生成新的 zipBuffer
21
+ * 3. 对“新zipBuffer”,做整体签名
22
+ * @param zipBuffer
23
+ * @param privatekey
24
+ * @param certificate
25
+ * @returns
26
+ */
27
+ static signPackage(target: Package, privatekey: Buffer, certificate: Buffer): Promise<false | Buffer>;
19
28
  /**
20
29
  * 根据ZIP流获取文件实例
30
+ *
31
+ * 1. zipbuffer转换为JSZip对象
32
+ * 2. 提取文件列表,并生成每个文件的 buffer
33
+ * 3. 创建获取文件buffer的函数
34
+ *
21
35
  * @param zipBuffer
22
36
  * @returns
23
37
  */
24
38
  private static createFileListFromZipBuffer;
25
39
  /**
26
40
  * 为 zip buffer 签名,返回签名后的buffer
41
+ *
42
+ * @description 根据zipBuffer + zip的文件列表 + 私钥 + 证书,对 zipbuffer 签名
27
43
  * @param fileBuffer
28
44
  * @param files
29
45
  * @param privatekey
@@ -12,9 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
16
- const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
17
- const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
15
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
18
16
  const crypto_1 = __importDefault(require("crypto"));
19
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
20
18
  const jsrsasign_1 = __importDefault(require("jsrsasign"));
@@ -31,64 +29,104 @@ const Signer_1 = __importDefault(require("./Signer"));
31
29
  class SignUtil {
32
30
  /**
33
31
  * 获取签名相关的配置内容
34
- * 1. ICompileParam参数中获取编译模式是否为release
35
- * 2. IJavascriptCompileOption参数中获取签名目录等内容
36
- * @param param
32
+ * @param param IJavascriptCompileOption参数中获取签名目录等内容
33
+ * @returns
37
34
  */
38
35
  static getProjectSignConfig(param) {
39
36
  const { mode, projectPath, signRoot } = param;
37
+ const signPathFolder = path_1.default.join(projectPath, signRoot || 'sign');
38
+ const signPathConfig = {
39
+ debug: {
40
+ privatekey: path_1.default.join(signPathFolder, 'debug', 'private.pem'),
41
+ certificate: path_1.default.join(signPathFolder, 'debug', 'certificate.pem')
42
+ },
43
+ sign: {
44
+ privatekey: path_1.default.join(signPathFolder, 'private.pem'),
45
+ certificate: path_1.default.join(signPathFolder, 'certificate.pem')
46
+ },
47
+ defaultDevelopment: {
48
+ privatekey: path_1.default.join(__dirname, 'pem', 'private.pem'),
49
+ certificate: path_1.default.join(__dirname, 'pem', 'certificate.pem')
50
+ },
51
+ oldRelease: {
52
+ privatekey: path_1.default.join(signPathFolder, 'release', 'private.pem'),
53
+ certificate: path_1.default.join(signPathFolder, 'release', 'certificate.pem')
54
+ }
55
+ };
56
+ // build模式 优先sign/debug/证书 其次sign/证书 最后toolkit中默认的证书
57
+ const developmentSignConfig = [
58
+ signPathConfig.debug,
59
+ signPathConfig.sign,
60
+ signPathConfig.defaultDevelopment
61
+ ];
62
+ // release模式 优先sign/release/证书 其次sign/证书
63
+ const releaseSignConfig = [signPathConfig.oldRelease, signPathConfig.sign];
64
+ let modeSignConfig = [];
40
65
  let signConfig;
41
- let privatekeyPath;
42
- let certificatePath;
43
66
  switch (mode) {
44
67
  case CompileMode_1.default.DEVELOPMENT:
45
- privatekeyPath = path_1.default.join(__dirname, 'pem', 'private.pem');
46
- certificatePath = path_1.default.join(__dirname, 'pem', 'certificate.pem');
47
- ColorConsole_1.default.info(`User debug signature is enabled by project build`);
68
+ modeSignConfig = developmentSignConfig;
48
69
  break;
49
70
  case CompileMode_1.default.PRODUCTION:
50
- privatekeyPath = path_1.default.join(projectPath, signRoot, 'private.pem');
51
- certificatePath = path_1.default.join(projectPath, signRoot, 'certificate.pem');
52
- ColorConsole_1.default.info(`release signature is enabled by project build`);
71
+ modeSignConfig = releaseSignConfig;
53
72
  break;
54
73
  default:
55
74
  // 打印信息, 模式未定义
56
- ColorConsole_1.default.error(`Error: mode ${mode} undefined`);
75
+ shared_utils_1.ColorConsole.error(`Error: mode ${mode} undefined`);
57
76
  break;
58
77
  }
59
- // 检查路径是否真实存在
60
- if (privatekeyPath &&
61
- certificatePath &&
62
- FileUtil_1.default.checkFilePath([privatekeyPath, certificatePath])) {
78
+ // 寻找有效的证书路径
79
+ const findPath = modeSignConfig.find(({ privatekey, certificate }) => shared_utils_1.FileUtil.checkFilePath([privatekey, certificate]));
80
+ if (findPath) {
81
+ let { privatekey: privatekeyPath, certificate: certificatePath } = findPath;
82
+ shared_utils_1.ColorConsole.info('privatekeyPath is ', {
83
+ word: privatekeyPath
84
+ }, `\ncertificatePath is `, {
85
+ word: certificatePath
86
+ });
87
+ // 读取证书内容
63
88
  signConfig = {
64
89
  privatekey: fs_extra_1.default.readFileSync(privatekeyPath),
65
90
  certificate: fs_extra_1.default.readFileSync(certificatePath)
66
91
  };
67
92
  }
68
93
  else {
69
- // 结束程序
70
- process.exit();
94
+ // 抛出错误,在指定模式下未找到证书
95
+ throw new Error(`The current mode is ${mode}, and there is a problem with the certification path`);
71
96
  }
72
97
  return signConfig;
73
98
  }
74
- static signZipBufferForPackage(zipBuffer, privatekey, certificate) {
99
+ /**
100
+ * 对二进制zipBuffer签名
101
+ *
102
+ * 1. 对`META-INF/CERT`做签名,并生成新的`META-INF/CERT` buffer
103
+ * 2. "新`META-INF/CERT` + 其它文件"生成新的 zipBuffer
104
+ * 3. 对“新zipBuffer”,做整体签名
105
+ * @param zipBuffer
106
+ * @param privatekey
107
+ * @param certificate
108
+ * @returns
109
+ */
110
+ static signPackage(target, privatekey, certificate) {
75
111
  return __awaiter(this, void 0, void 0, function* () {
76
- // 1. 解压得到文件列表
77
- const zipInstWrap = yield SignUtil.createFileListFromZipBuffer(zipBuffer);
78
- // 摘要map
112
+ var _a;
113
+ const getFileBuffer = (path) => {
114
+ return target.getResource(path);
115
+ };
116
+ // 摘要 和 文件列表
79
117
  const fileDigestHash = [];
80
118
  const fileList = [];
81
- // 2. 如果包含META-INF/CERT,则对其解压,增加签名
82
- const metaBuffer = zipInstWrap.getFileBuffer(ZipUtil_1.default.CERT_PATH);
119
+ // 1
120
+ const metaBuffer = (_a = getFileBuffer(ZipUtil_1.default.CERT_PATH)) === null || _a === void 0 ? void 0 : _a.fileContentBuffer;
83
121
  if (metaBuffer) {
84
122
  const metaHash = {
85
123
  name: ZipUtil_1.default.DIGEST_HASH_JSON,
86
- hash: CommonUtil_1.default.calcDataDigest(metaBuffer)
124
+ hash: shared_utils_1.CommonUtil.calcDataDigest(metaBuffer)
87
125
  };
88
126
  const signedMetaBuffer = SignUtil.doSign(metaBuffer, [metaHash], privatekey, certificate);
89
127
  if (signedMetaBuffer === false) {
90
128
  // META-INF/CERT签名失败
91
- ColorConsole_1.default.throw('META-INF/CERT signature failed');
129
+ shared_utils_1.ColorConsole.throw('META-INF/CERT signature failed');
92
130
  }
93
131
  else {
94
132
  fileList.push({
@@ -97,32 +135,45 @@ class SignUtil {
97
135
  });
98
136
  fileDigestHash.push({
99
137
  name: ZipUtil_1.default.CERT_PATH,
100
- hash: CommonUtil_1.default.calcDataDigest(signedMetaBuffer)
138
+ hash: shared_utils_1.CommonUtil.calcDataDigest(signedMetaBuffer)
101
139
  });
102
140
  }
103
141
  }
104
- // 3. 对整个zip做签名
105
- const files = zipInstWrap.fileList;
106
- files.filter(SignUtil.fileFilter).map((item) => {
142
+ // 2
143
+ const files = target.resourceList;
144
+ files
145
+ .map((item) => {
146
+ return {
147
+ path: item.fileBuildPath,
148
+ content: item.fileContentBuffer
149
+ };
150
+ })
151
+ .filter(SignUtil.fileFilter)
152
+ .map((item) => {
107
153
  fileList.push(item);
108
154
  fileDigestHash.push({
109
155
  name: item.path,
110
- hash: CommonUtil_1.default.calcDataDigest(item.content)
156
+ hash: shared_utils_1.CommonUtil.calcDataDigest(item.content)
111
157
  });
112
158
  });
113
159
  // 因为META变化,重新创建ZIP流
114
- const newZipBuffer = yield ZipUtil_1.default.createZipBufferFromFileList(fileList, zipInstWrap.comment);
115
- // 对新ZIP流重新签名
160
+ const newZipBuffer = yield ZipUtil_1.default.createZipBufferFromFileList(fileList, target.comment);
161
+ // 3
116
162
  const signedZipBuffer = SignUtil.doSign(newZipBuffer, fileDigestHash, privatekey, certificate);
117
163
  if (signedZipBuffer === false) {
118
164
  // 签名失败
119
- ColorConsole_1.default.throw('package signature failed');
165
+ shared_utils_1.ColorConsole.throw('package signature failed');
120
166
  }
121
167
  return signedZipBuffer;
122
168
  });
123
169
  }
124
170
  /**
125
171
  * 根据ZIP流获取文件实例
172
+ *
173
+ * 1. zipbuffer转换为JSZip对象
174
+ * 2. 提取文件列表,并生成每个文件的 buffer
175
+ * 3. 创建获取文件buffer的函数
176
+ *
126
177
  * @param zipBuffer
127
178
  * @returns
128
179
  */
@@ -144,17 +195,15 @@ class SignUtil {
144
195
  comment: zipInst.comment,
145
196
  getFileBuffer(path) {
146
197
  const buffer = fileList.find((item) => item.path === path);
147
- let content;
148
- if (buffer) {
149
- content = buffer.content;
150
- }
151
- return content;
198
+ return buffer === null || buffer === void 0 ? void 0 : buffer.content;
152
199
  }
153
200
  };
154
201
  });
155
202
  }
156
203
  /**
157
204
  * 为 zip buffer 签名,返回签名后的buffer
205
+ *
206
+ * @description 根据zipBuffer + zip的文件列表 + 私钥 + 证书,对 zipbuffer 签名
158
207
  * @param fileBuffer
159
208
  * @param files
160
209
  * @param privatekey
@@ -180,13 +229,13 @@ class SignUtil {
180
229
  static unZipFiles(fileBuffer, files) {
181
230
  // 1. 读取zip文件
182
231
  if (!fileBuffer || fileBuffer.length <= 4) {
183
- ColorConsole_1.default.error('Zip file open failed');
232
+ shared_utils_1.ColorConsole.error('Zip file open failed');
184
233
  return false;
185
234
  }
186
235
  // 2. 检查文件格式是否正确
187
236
  const fileMagic = fileBuffer.readInt32LE(0);
188
237
  if (fileMagic !== 0x4034b50) {
189
- ColorConsole_1.default.error('Zip file format is wrong');
238
+ shared_utils_1.ColorConsole.error('Zip file format is wrong');
190
239
  return false;
191
240
  }
192
241
  // 3. 解析数据块
@@ -386,7 +435,7 @@ class SignUtil {
386
435
  const cert = Buffer.from(Base64_1.default.unarmor(certificate));
387
436
  const c = new jsrsasign_1.default.X509();
388
437
  c.readCertPEM(certificate.toString());
389
- const pubKey = jsrsasign_1.default.KEYUTIL.getPEM(c.subjectPublicKeyRSA);
438
+ const pubKey = jsrsasign_1.default.KEYUTIL.getPEM(c.getPublicKey());
390
439
  // 摘要块
391
440
  const digestBuf = Buffer.alloc(sign.length + 12);
392
441
  digestBuf.writeInt32LE(sign.length + 8, 0);
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  /**
3
2
  * Signer
4
3
  */
@@ -0,0 +1,3 @@
1
+ import { LoaderContext } from '@rspack/core';
2
+ declare function addColSourceMap(this: LoaderContext<any>, source: string, map: any): Promise<void>;
3
+ export default addColSourceMap;
@@ -0,0 +1,56 @@
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 parser_1 = require("@aiot-toolkit/parser");
13
+ function addColSourceMap(source, map) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const callback = this.async();
16
+ if (!map) {
17
+ callback(null, source, map);
18
+ }
19
+ let { consumer, tempGenerator } = yield parser_1.SourceMapUtil.createConsumerAndGenerator(JSON.stringify(map));
20
+ let recordLine = -1;
21
+ consumer.eachMapping((mapping) => {
22
+ if (mapping.source === consumer.sources[consumer.sources.length - 1]) {
23
+ if (recordLine < mapping.generatedLine &&
24
+ (mapping.generatedColumn !== 0 || mapping.originalColumn !== 0)) {
25
+ tempGenerator.addMapping({
26
+ generated: {
27
+ line: mapping.generatedLine,
28
+ column: 0
29
+ },
30
+ original: {
31
+ line: mapping.originalLine,
32
+ column: 0
33
+ },
34
+ source: mapping.source,
35
+ name: ''
36
+ });
37
+ }
38
+ recordLine = mapping.generatedLine;
39
+ }
40
+ tempGenerator.addMapping({
41
+ generated: {
42
+ line: mapping.generatedLine,
43
+ column: mapping.generatedColumn
44
+ },
45
+ original: {
46
+ line: mapping.originalLine,
47
+ column: mapping.originalColumn
48
+ },
49
+ source: mapping.source,
50
+ name: mapping.name
51
+ });
52
+ });
53
+ callback(null, source, JSON.parse(tempGenerator.toString()));
54
+ });
55
+ }
56
+ exports.default = addColSourceMap;
@@ -0,0 +1,3 @@
1
+ import { LoaderContext } from '@rspack/core';
2
+ declare function extractMapData(this: LoaderContext<any>, source: string, map: any): void;
3
+ export default extractMapData;
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const fs_1 = __importDefault(require("fs"));
7
7
  const path_1 = __importDefault(require("path"));
8
- function splitMap(source, map) {
8
+ function extractMapData(source, map) {
9
9
  const enterFilePath = this.resourcePath;
10
10
  // 获取当前文件夹和文件名
11
11
  const dirName = path_1.default.dirname(enterFilePath);
@@ -17,4 +17,4 @@ function splitMap(source, map) {
17
17
  }
18
18
  this.callback(null, source, map && JSON.parse(map));
19
19
  }
20
- exports.default = splitMap;
20
+ exports.default = extractMapData;
@@ -1,14 +1,41 @@
1
1
  import { IFileLaneConfig } from 'file-lane';
2
2
  import IJavascriptCompileOption from '../compiler/javascript/interface/IJavascriptCompileOption';
3
- import AppUxLoader from '../loader/ux/AppUxLoader';
4
3
  import JsLoader from '../loader/ux/JsLoader';
5
- import UxLoader from '../loader/ux/UxLoader';
4
+ import PngLoader from '../loader/ux/PngLoader';
5
+ import AppUxLoader from '../loader/ux/vela/AppUxLoader';
6
+ import HmlLoader from '../loader/ux/vela/HmlLoader';
7
+ import UxLoader from '../loader/ux/vela/UxLoader';
8
+ import UxBeforeWorks from '../beforeWorks/ux/UxBeforeWorks';
9
+ import UxAfterWorks from '../afterWorks/ux/UxAfterWorks';
10
+ import { IChangedFile } from 'file-lane/lib/interface/IChangedFile';
6
11
  declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
7
12
  readonly projectPath: string;
8
13
  constructor(projectPath: string);
9
- exclude: RegExp[];
14
+ /**
15
+ * 1. 取项目中所有的真实文件
16
+ * 1.1 无entryFileList时
17
+ * 1.2 有entryFileList且文件列表中有 与其他文件相关 的文件时
18
+ * 1.3 有entryFileList且文件列表中有文件为 删除 操作时
19
+ * 2. 返回符合条件的文件列表
20
+ * 2.1 有entryFileList且文件列表中 只有 不影响其他文件 的文件时
21
+ * @param entryFileList
22
+ * @returns
23
+ */
24
+ collectFile: (entryFileList?: IChangedFile[]) => string[];
25
+ exclude: (string | ((filePath: string) => boolean))[];
10
26
  get output(): string;
11
- module: {
27
+ beforeWorks: (typeof UxBeforeWorks.cleanOutput)[];
28
+ beforeCompile: import("file-lane").PreWork<IJavascriptCompileOption>[];
29
+ afterCompile: {
30
+ worker: import("file-lane").FollowWork<IJavascriptCompileOption>;
31
+ workerDescribe: string;
32
+ }[];
33
+ afterWorks: (typeof UxAfterWorks.cleanOutput)[];
34
+ watchIgnores: RegExp[];
35
+ /**
36
+ * 通过项目类型,返回模块配置
37
+ */
38
+ get module(): {
12
39
  rules: ({
13
40
  test: string[];
14
41
  loader: (typeof AppUxLoader)[];
@@ -17,14 +44,25 @@ declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
17
44
  test: RegExp[];
18
45
  exclude: RegExp[];
19
46
  loader: (typeof UxLoader)[];
47
+ } | {
48
+ test: RegExp[];
49
+ loader: (typeof HmlLoader | typeof UxLoader)[];
50
+ exclude?: undefined;
20
51
  } | {
21
52
  test: RegExp[];
22
53
  loader: (typeof JsLoader)[];
23
54
  exclude?: undefined;
55
+ } | {
56
+ test: RegExp[];
57
+ loader: (typeof PngLoader)[];
58
+ exclude?: undefined;
24
59
  })[];
25
60
  };
26
- preWorks: import("file-lane/lib/interface/IFileLaneConfig").PreWork<IJavascriptCompileOption>[];
27
- followWorks: import("file-lane/lib/interface/IFileLaneConfig").FollowWork<IJavascriptCompileOption>[];
28
- watchIgnores: RegExp[];
61
+ /**
62
+ * 判断项目类型
63
+ *
64
+ * 目前的办法是通过 manifest.json 的 deviceTypeList 是否有 watch 判断
65
+ */
66
+ private getProjectType;
29
67
  }
30
68
  export default UxConfig;