@aiot-toolkit/aiotpack 2.0.5-beta.8 → 2.0.5-widget-provider-beta.1

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 (78) hide show
  1. package/README.md +46 -46
  2. package/lib/afterCompile/ux/UxAfterCompile.d.ts +28 -1
  3. package/lib/afterCompile/ux/UxAfterCompile.js +186 -38
  4. package/lib/afterWorks/ux/UxAfterWorks.js +1 -1
  5. package/lib/beforeCompile/ux/UxBeforeCompile.js +2 -2
  6. package/lib/compiler/enum/CompileMode.js +2 -2
  7. package/lib/compiler/javascript/JavascriptCompiler.d.ts +14 -0
  8. package/lib/compiler/javascript/JavascriptCompiler.js +91 -5
  9. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +2 -2
  10. package/lib/compiler/javascript/android/plugin/WrapPlugin.js +7 -7
  11. package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +17 -1
  12. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +5 -1
  13. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +3 -3
  14. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +2 -2
  15. package/lib/compiler/javascript/vela/enum/EntryType.js +2 -2
  16. package/lib/compiler/javascript/vela/interface/IManifest.d.ts +11 -0
  17. package/lib/compiler/javascript/vela/interface/IManifest.js +11 -1
  18. package/lib/compiler/javascript/vela/model/Package.js +28 -28
  19. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +1 -2
  20. package/lib/compiler/javascript/vela/utils/Jsc.js +2 -2
  21. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +31 -17
  22. package/lib/compiler/javascript/vela/utils/ZipUtil.js +62 -62
  23. package/lib/compiler/javascript/vela/utils/signature/Base64.js +2 -2
  24. package/lib/compiler/javascript/vela/utils/signature/CRC32.js +2 -2
  25. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +68 -68
  26. package/lib/compiler/javascript/vela/utils/signature/Signer.js +6 -6
  27. package/lib/compiler/javascript/vela/utils/signature/pem/certificate.pem +26 -26
  28. package/lib/compiler/javascript/vela/utils/signature/pem/private.pem +50 -50
  29. package/lib/compiler/javascript/vela/utils/webpackLoader/IWebpackLoaderOption.d.ts +11 -0
  30. package/lib/compiler/javascript/vela/utils/webpackLoader/IWebpackLoaderOption.js +1 -0
  31. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackJsLoader.d.ts +2 -0
  32. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackJsLoader.js +27 -0
  33. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackUxLoader.d.ts +2 -0
  34. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackUxLoader.js +26 -0
  35. package/lib/compiler/tools/icu/ImageIcu.d.ts +37 -0
  36. package/lib/compiler/tools/icu/ImageIcu.js +110 -0
  37. package/lib/compiler/tools/icu/icu_darwin_arm64 +0 -0
  38. package/lib/compiler/tools/icu/icu_darwin_x64 +0 -0
  39. package/lib/compiler/tools/icu/icu_linux_arm64 +0 -0
  40. package/lib/compiler/tools/icu/icu_linux_x64 +0 -0
  41. package/lib/compiler/tools/icu/icu_win32_x64.exe +0 -0
  42. package/lib/config/UxConfig.d.ts +9 -4
  43. package/lib/config/UxConfig.js +29 -17
  44. package/lib/index.d.ts +1 -3
  45. package/lib/index.js +2 -28
  46. package/lib/loader/ux/JsLoader.js +2 -2
  47. package/lib/loader/ux/PngLoader.js +2 -2
  48. package/lib/loader/ux/android/UxLoader.js +2 -2
  49. package/lib/loader/ux/vela/AppUxLoader.js +3 -3
  50. package/lib/loader/ux/vela/HmlLoader.js +14 -14
  51. package/lib/loader/ux/vela/UxLoader.js +7 -0
  52. package/lib/utils/BeforeCompileUtils.d.ts +2 -0
  53. package/lib/utils/BeforeCompileUtils.js +34 -12
  54. package/lib/utils/PngUtils.js +11 -11
  55. package/lib/utils/ux/ManifestSchema.js +6 -3
  56. package/lib/utils/ux/UxFileUtils.d.ts +1 -0
  57. package/lib/utils/ux/UxFileUtils.js +56 -45
  58. package/lib/utils/ux/UxLoaderUtils.js +35 -35
  59. package/lib/utils/ux/android/AndroidUx.js +10 -10
  60. package/package.json +8 -11
  61. package/lib/afterCompile/xts/entryTemplate.d.ts +0 -21
  62. package/lib/afterCompile/xts/entryTemplate.js +0 -182
  63. package/lib/afterCompile/xts/generateRpk.d.ts +0 -3
  64. package/lib/afterCompile/xts/generateRpk.js +0 -28
  65. package/lib/afterCompile/xts/ts2wasm.d.ts +0 -8
  66. package/lib/afterCompile/xts/ts2wasm.js +0 -69
  67. package/lib/beforeCompile/xts/preInstall.d.ts +0 -3
  68. package/lib/beforeCompile/xts/preInstall.js +0 -54
  69. package/lib/config/XtsConfig.d.ts +0 -22
  70. package/lib/config/XtsConfig.js +0 -36
  71. package/lib/interface/ICompileOptions.d.ts +0 -6
  72. package/lib/interface/ICompileOptions.js +0 -7
  73. package/lib/loader/xts/XtsLoader.d.ts +0 -9
  74. package/lib/loader/xts/XtsLoader.js +0 -62
  75. package/lib/utils/xts/XtsFileLaneUtils.d.ts +0 -10
  76. package/lib/utils/xts/XtsFileLaneUtils.js +0 -61
  77. package/lib/utils/xts/XtsFollowWorks.d.ts +0 -34
  78. package/lib/utils/xts/XtsFollowWorks.js +0 -134
package/README.md CHANGED
@@ -1,46 +1,46 @@
1
- # `aiotpack`
2
-
3
- 最终打包工具,包含各类语言、各类平台的打包配置
4
-
5
- ## 目录结构
6
-
7
- | 目录 | 描述 |
8
- | -------- | ------------------------------------------------------------------------------- |
9
- | config | FileLane 配置,基于此配置,可完成“源码项目-->目标代码项目-->应用程序”的完整流程 |
10
- | compiler | 目标语言-->应用程序编译器 |
11
- | loader | 源码语言-->目标代码语言 |
12
- | utils | 语言、项目无关的辅助工具 |
13
-
14
- ## config
15
-
16
- 通过在 FileLane 中配置各项参数,可完成“**源码项目-->目标代码项目-->应用程序**”的完整流程
17
-
18
- ## compiler
19
-
20
- #### 概述
21
-
22
- 源码已生成目标代码项目,此时需要生成**最终产物--应用程序**。compiler 目录中的代码即为完成此项工作而生。
23
-
24
- #### 子目录
25
-
26
- compiler 下的每个子目录,对应一种目标语言;每种目标语言在不同平台又可能有不同的生成方式。
27
-
28
- 因此结构为:`compiler/目标语言/目标平台`,例如:
29
-
30
- - `compiler/javascript/vela`--javascript 语言在 vela 平台的生成
31
-
32
- #### 添加编译器
33
-
34
- 1. 按上述目录结构,添加目录
35
- 2. 创建编译器`class XCompiler`, 建议实现实现`ICompiler` 接口,以便以后实现统一的用户端接口
36
- 3. 在需要的位置调用
37
-
38
- ```js
39
- new XCompiler().compile({
40
- projectPath: '',
41
- mode: 'development',
42
- platform: 'native'
43
- })
44
- ```
45
-
46
- ## loader--各类语言的转换器
1
+ # `aiotpack`
2
+
3
+ 最终打包工具,包含各类语言、各类平台的打包配置
4
+
5
+ ## 目录结构
6
+
7
+ | 目录 | 描述 |
8
+ | -------- | ------------------------------------------------------------------------------- |
9
+ | config | FileLane 配置,基于此配置,可完成“源码项目-->目标代码项目-->应用程序”的完整流程 |
10
+ | compiler | 目标语言-->应用程序编译器 |
11
+ | loader | 源码语言-->目标代码语言 |
12
+ | utils | 语言、项目无关的辅助工具 |
13
+
14
+ ## config
15
+
16
+ 通过在 FileLane 中配置各项参数,可完成“**源码项目-->目标代码项目-->应用程序**”的完整流程
17
+
18
+ ## compiler
19
+
20
+ #### 概述
21
+
22
+ 源码已生成目标代码项目,此时需要生成**最终产物--应用程序**。compiler 目录中的代码即为完成此项工作而生。
23
+
24
+ #### 子目录
25
+
26
+ compiler 下的每个子目录,对应一种目标语言;每种目标语言在不同平台又可能有不同的生成方式。
27
+
28
+ 因此结构为:`compiler/目标语言/目标平台`,例如:
29
+
30
+ - `compiler/javascript/vela`--javascript 语言在 vela 平台的生成
31
+
32
+ #### 添加编译器
33
+
34
+ 1. 按上述目录结构,添加目录
35
+ 2. 创建编译器`class XCompiler`, 建议实现实现`ICompiler` 接口,以便以后实现统一的用户端接口
36
+ 3. 在需要的位置调用
37
+
38
+ ```js
39
+ new XCompiler().compile({
40
+ projectPath: '',
41
+ mode: 'development',
42
+ platform: 'native'
43
+ })
44
+ ```
45
+
46
+ ## loader--各类语言的转换器
@@ -4,7 +4,7 @@ import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavas
4
4
  * UxAfterCompile
5
5
  */
6
6
  declare class UxAfterCompile {
7
- static webpack: FollowWork<IJavascriptCompileOption>;
7
+ static compileJavascript: FollowWork<IJavascriptCompileOption>;
8
8
  static protobuf: FollowWork<IJavascriptCompileOption>;
9
9
  static jsc: FollowWork<IJavascriptCompileOption>;
10
10
  static toRpk: FollowWork<IJavascriptCompileOption>;
@@ -15,6 +15,13 @@ declare class UxAfterCompile {
15
15
  * @param compilerOption
16
16
  */
17
17
  static copyResource: FollowWork<IJavascriptCompileOption>;
18
+ /**
19
+ * 压缩资源文件
20
+ * 1. png8
21
+ * 2. bin
22
+ * @param params
23
+ */
24
+ static compressResource: FollowWork<IJavascriptCompileOption>;
18
25
  /**
19
26
  * 如果是更新触发,则对比临时项目build文件夹 和 项目build文件夹,生成diff.json
20
27
  * @param context
@@ -39,5 +46,25 @@ declare class UxAfterCompile {
39
46
  * @param compilerOption
40
47
  */
41
48
  static symlinkNodeModule: FollowWork<IJavascriptCompileOption>;
49
+ /**
50
+ * 编译轻卡ux
51
+ * 1. 使用hap-toolkit编译项目,编译结果存储在build文件夹
52
+ * 1.1 重写stdout以捕获hap-toolkit中的正常日志,错误日志正常输出
53
+ * 1.2 使用hap-toolkit编译项目
54
+ * 1.3 还原stdout
55
+ * 2. 取widgets中配置的轻卡内容,将build文件夹中对应的产物复制到临时文件夹
56
+ * @param params
57
+ */
58
+ static compileLiteCard: FollowWork<IJavascriptCompileOption>;
59
+ /**
60
+ * 检查资源文件
61
+ * 1. 检查文件体积是否过大, 如果超出,则提示到真机验证
62
+ * @param params
63
+ */
64
+ static resourceCheck: FollowWork<IJavascriptCompileOption>;
65
+ /**
66
+ * 写入.gitignore文件, 忽略临时目录
67
+ */
68
+ static writeGitIgnore: FollowWork<IJavascriptCompileOption>;
42
69
  }
43
70
  export default UxAfterCompile;
@@ -16,19 +16,23 @@ var _ZipUtil = _interopRequireDefault(require("../../compiler/javascript/vela/ut
16
16
  var _UxFileUtils = _interopRequireDefault(require("../../utils/ux/UxFileUtils"));
17
17
  var _FileLaneTriggerType = _interopRequireDefault(require("file-lane/lib/enum/FileLaneTriggerType"));
18
18
  var _ZipFileUtil = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/utils/ZipFileUtil"));
19
+ var _process = require("process");
20
+ var _ImageIcu = _interopRequireDefault(require("../../compiler/tools/icu/ImageIcu"));
19
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
22
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
23
+ const HapToolkit = require('hap-toolkit');
21
24
 
22
- /**
23
- * UxAfterCompile
25
+ /**
26
+ * UxAfterCompile
24
27
  */
25
28
  class UxAfterCompile {
26
- static webpack = async params => {
29
+ static compileJavascript = async params => {
27
30
  const {
28
31
  context,
29
- compilerOption
32
+ compilerOption,
33
+ onLog
30
34
  } = params;
31
- return new _JavascriptCompiler.default().compile({
35
+ return new _JavascriptCompiler.default(context, onLog).compile({
32
36
  projectPath: _path.default.join(context.projectPath, context.output),
33
37
  mode: _CompileMode.default.DEVELOPMENT,
34
38
  devtool: false,
@@ -89,22 +93,22 @@ class UxAfterCompile {
89
93
  const {
90
94
  compilerOption,
91
95
  compalition,
92
- config
96
+ context
93
97
  } = params;
94
98
  if (compilerOption) {
95
99
  const fileName = await _ZipUtil.default.createRpk(_path.default.join(compilerOption.projectPath, compilerOption.outputPath), compilerOption);
96
100
  if (compalition && fileName) {
97
- compalition.info.rpk = _path.default.join(config.projectPath, compilerOption.releasePath, fileName);
101
+ compalition.info.rpk = _path.default.join(context.projectPath, compilerOption.releasePath, fileName);
98
102
  }
99
103
  return fileName;
100
104
  }
101
105
  };
102
106
 
103
- /**
104
- * 复制各类资源文件,例如图片、视频等
105
- * @param context
106
- * @param config
107
- * @param compilerOption
107
+ /**
108
+ * 复制各类资源文件,例如图片、视频等
109
+ * @param context
110
+ * @param config
111
+ * @param compilerOption
108
112
  */
109
113
  static copyResource = async params => {
110
114
  const {
@@ -144,18 +148,18 @@ class UxAfterCompile {
144
148
  sourceRoot,
145
149
  outputPath
146
150
  } = compilerOption;
147
- const includeList = [/sitemap\.json$/, /i18n(.+)\.json/];
151
+ const includeList = [/sitemap\.json$/, /i18n(.+)\.json/, /web\/*/];
148
152
  const excludeExtList = ['js', 'jsx', 'coffee', 'ts', 'tsx', 'vue', 'css', 'less', 'sass', 'styl', 'html', 'md', 'ux', 'mix', 'DS_Store', 'map'];
149
153
  const excludeReg = `\\.(${excludeExtList.join('|')})$`;
150
154
  _sharedUtils.FileUtil.copyFiles(_path.default.join(projectPath, sourceRoot), _path.default.join(projectPath, outputPath), new RegExp(excludeReg));
151
155
  _sharedUtils.FileUtil.copyFiles(_path.default.join(projectPath, sourceRoot), _path.default.join(projectPath, outputPath), undefined, includeList);
152
156
  };
153
157
 
154
- /**
155
- * 写入 manifest.json 文件
156
- *
157
- * 需要在源码manifest.json基础加一些额外的内容
158
- * @param compilerOption
158
+ /**
159
+ * 写入 manifest.json 文件
160
+ *
161
+ * 需要在源码manifest.json基础加一些额外的内容
162
+ * @param compilerOption
159
163
  */
160
164
  const updateManifest = compilerOption => {
161
165
  const {
@@ -251,17 +255,48 @@ class UxAfterCompile {
251
255
  await genMetaFiles(compilerOption);
252
256
  }
253
257
  };
254
- /**
255
- * 如果是更新触发,则对比临时项目build文件夹 和 项目build文件夹,生成diff.json
256
- * @param context
257
- * @param config
258
- * @param compilerOption
258
+
259
+ /**
260
+ * 压缩资源文件
261
+ * 1. png8
262
+ * 2. bin
263
+ * @param params
264
+ */
265
+ static compressResource = async params => {
266
+ const {
267
+ compilerOption
268
+ } = params;
269
+ if (compilerOption) {
270
+ const {
271
+ enableImagePng8,
272
+ projectPath,
273
+ outputPath
274
+ } = compilerOption;
275
+ if (enableImagePng8) {
276
+ const format = 'png';
277
+ const files = _sharedUtils.FileUtil.readAlldirSync(_path.default.join(projectPath, outputPath));
278
+ const compressFiles = files.filter(filePath => _ImageIcu.default.canTranslate(filePath, format));
279
+ if (compressFiles.length) {
280
+ const icu = new _ImageIcu.default();
281
+ compressFiles.forEach(item => {
282
+ icu.translate(item, _path.default.dirname(item), format);
283
+ });
284
+ }
285
+ }
286
+ }
287
+ };
288
+
289
+ /**
290
+ * 如果是更新触发,则对比临时项目build文件夹 和 项目build文件夹,生成diff.json
291
+ * @param context
292
+ * @param config
293
+ * @param compilerOption
259
294
  */
260
295
  static generateDiff = async params => {
261
296
  const {
262
297
  compilerOption,
263
298
  compalition,
264
- config
299
+ context
265
300
  } = params;
266
301
  if (!compilerOption || !compalition) {
267
302
  return;
@@ -290,18 +325,18 @@ class UxAfterCompile {
290
325
  zipFilePath: item
291
326
  })));
292
327
  compalition.info.diffList = diffList;
293
- compalition.info.diffFile = _path.default.join(config.projectPath, compilerOption.releasePath, diffFileName);
328
+ compalition.info.diffFile = _path.default.join(context.projectPath, compilerOption.releasePath, diffFileName);
294
329
  }
295
330
  };
296
331
 
297
- /**
298
- * 打包结果移回源码项目,并删除中间项目
299
- *
300
- * 1. 把 build和rpk 目录从**中间项目**移回**源码项目**
301
- * 2. 删除中间项目
302
- * @param context
303
- * @param config
304
- * @param compilerOption
332
+ /**
333
+ * 打包结果移回源码项目,并删除中间项目
334
+ *
335
+ * 1. 把 build和rpk 目录从**中间项目**移回**源码项目**
336
+ * 2. 删除中间项目
337
+ * @param context
338
+ * @param config
339
+ * @param compilerOption
305
340
  */
306
341
  static moveBackResult = async params => {
307
342
  const {
@@ -334,11 +369,11 @@ class UxAfterCompile {
334
369
  });
335
370
  };
336
371
 
337
- /**
338
- * 创建 node_module 软链
339
- * @param context
340
- * @param config
341
- * @param compilerOption
372
+ /**
373
+ * 创建 node_module 软链
374
+ * @param context
375
+ * @param config
376
+ * @param compilerOption
342
377
  */
343
378
  static symlinkNodeModule = async params => {
344
379
  const {
@@ -361,5 +396,118 @@ class UxAfterCompile {
361
396
  throw new Error(`${error?.toString() || 'unknown error'}. Please check whether the file system of the current disk supports the creation of soft links.`);
362
397
  }
363
398
  };
399
+ /**
400
+ * 编译轻卡ux
401
+ * 1. 使用hap-toolkit编译项目,编译结果存储在build文件夹
402
+ * 1.1 重写stdout以捕获hap-toolkit中的正常日志,错误日志正常输出
403
+ * 1.2 使用hap-toolkit编译项目
404
+ * 1.3 还原stdout
405
+ * 2. 取widgets中配置的轻卡内容,将build文件夹中对应的产物复制到临时文件夹
406
+ * @param params
407
+ */
408
+ static compileLiteCard = async params => {
409
+ const {
410
+ compilerOption,
411
+ context
412
+ } = params;
413
+ try {
414
+ if (context?.liteCards?.length > 0 && compilerOption) {
415
+ const {
416
+ projectPath,
417
+ outputPath
418
+ } = compilerOption;
419
+ const LITE_OUTPUT_PATH = outputPath;
420
+ // 1.1
421
+ const originalStdout = _process.stdout.write;
422
+ _process.stdout.write = function () {
423
+ return true;
424
+ };
425
+ // 1.2
426
+ await HapToolkit.compile('native', 'dev', false, {
427
+ cwd: context.projectPath,
428
+ signMode: 'BUILD',
429
+ enableCustomComponent: true
430
+ });
431
+ // 1.3
432
+ _process.stdout.write = originalStdout;
433
+ // 2.
434
+ context.liteCards.forEach(card => {
435
+ // hap-toolkit的产物在项目的build文件夹下
436
+ const fromPath = _path.default.join(context.projectPath, LITE_OUTPUT_PATH, card);
437
+ // aiot-toolkit的产物在临时项目的build文件夹下
438
+ const toPath = _path.default.join(projectPath, LITE_OUTPUT_PATH, card);
439
+ //确定目标目录存在,若不存在则创建到父目录
440
+ _fsExtra.default.ensureDirSync(_path.default.dirname(toPath));
441
+ // 复制文件
442
+ _fsExtra.default.moveSync(fromPath + '.template.json', toPath + '.template.json', {
443
+ overwrite: true
444
+ });
445
+ _fsExtra.default.moveSync(fromPath + '.css.json', toPath + '.css.json', {
446
+ overwrite: true
447
+ });
448
+ });
449
+ }
450
+ } catch (error) {
451
+ throw new Error(`compile lite card error, ${error?.toString() || 'unknown error'}.`);
452
+ }
453
+ };
454
+ /**
455
+ * 检查资源文件
456
+ * 1. 检查文件体积是否过大, 如果超出,则提示到真机验证
457
+ * @param params
458
+ */
459
+ static resourceCheck = async params => {
460
+ const {
461
+ context,
462
+ compilerOption,
463
+ onLog
464
+ } = params;
465
+ if (!compilerOption) {
466
+ return;
467
+ }
468
+
469
+ // 最大值,单位KB
470
+ const MAX_SIZE = 1024;
471
+ const {
472
+ projectPath
473
+ } = context;
474
+ const {
475
+ outputPath
476
+ } = compilerOption;
477
+ const fileList = _sharedUtils.FileUtil.readAlldirSync(_path.default.join(projectPath, outputPath));
478
+ const largeFileList = fileList.filter(item => {
479
+ const status = _fsExtra.default.statSync(item);
480
+ return status.size > MAX_SIZE * 1024;
481
+ });
482
+ if (largeFileList.length) {
483
+ const logs = [];
484
+ logs.push({
485
+ level: _sharedUtils.Loglevel.WARN,
486
+ message: [`the following files is large than`, {
487
+ word: `${MAX_SIZE}KB`
488
+ }, `, please check on the`, {
489
+ word: `real device\r\n`
490
+ }, {
491
+ word: largeFileList.map((item, index) => `${index + 1}. ${item}`).join('\r\n ')
492
+ }]
493
+ });
494
+ onLog?.(logs);
495
+ }
496
+ };
497
+
498
+ /**
499
+ * 写入.gitignore文件, 忽略临时目录
500
+ */
501
+ static writeGitIgnore = async params => {
502
+ const {
503
+ context
504
+ } = params;
505
+ const {
506
+ output,
507
+ projectPath
508
+ } = context;
509
+ const gitIgnorePath = _path.default.join(projectPath, output, '.gitignore');
510
+ _fsExtra.default.writeFileSync(gitIgnorePath, '*');
511
+ };
364
512
  }
365
513
  var _default = exports.default = UxAfterCompile;
@@ -9,7 +9,7 @@ var _fileLane = require("file-lane");
9
9
  class UxAfterWorks {
10
10
  static async cleanOutput(context) {
11
11
  const outputPath = _fileLane.FileLaneUtil.getOutputPath(context);
12
- _sharedUtils.FileUtil.del(outputPath);
12
+ await _sharedUtils.FileUtil.del(outputPath);
13
13
  }
14
14
  }
15
15
  var _default = exports.default = UxAfterWorks;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _UxFileUtils = _interopRequireDefault(require("../../utils/ux/UxFileUtils"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- /**
10
- * UxBeforeCompile
9
+ /**
10
+ * UxBeforeCompile
11
11
  */
12
12
  class UxBeforeCompile {
13
13
  static validateManifest = async _ref => {
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- /**
8
- * 编译模式枚举
7
+ /**
8
+ * 编译模式枚举
9
9
  */
10
10
  var CompileMode = /*#__PURE__*/function (CompileMode) {
11
11
  CompileMode["DEVELOPMENT"] = "development";
@@ -1,9 +1,23 @@
1
+ import { ILog } from '@aiot-toolkit/shared-utils';
2
+ import { IFileLaneContext } from 'file-lane';
1
3
  import ICompileParam from '../interface/ICompileParam';
2
4
  import ICompiler from '../interface/ICompiler';
3
5
  import IJavascriptCompileOption from './interface/IJavascriptCompileOption';
4
6
  declare class JavascriptCompiler implements ICompiler {
7
+ private readonly context;
8
+ private readonly onLog?;
5
9
  readonly QUICKAPP_CONFIG = "quickapp.config.js";
10
+ constructor(context: IFileLaneContext, onLog?: ((log: ILog[]) => void) | undefined);
6
11
  compile(param: IJavascriptCompileOption): Promise<void>;
12
+ /**
13
+ * 压缩插件
14
+ *
15
+ * dev模式,只处理console,其它禁用
16
+ * prod模式,其它使用默认值
17
+ * @param mode
18
+ * @returns
19
+ */
20
+ private createMinimizerRspackPlugin;
7
21
  private createWebpackConfig;
8
22
  private getConfigurator;
9
23
  clean(param: ICompileParam & IJavascriptCompileOption): Promise<void>;
@@ -8,12 +8,17 @@ var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
8
  var _core = require("@rspack/core");
9
9
  var _lodash = _interopRequireDefault(require("lodash"));
10
10
  var _path = _interopRequireDefault(require("path"));
11
+ var _CompileMode = _interopRequireDefault(require("../enum/CompileMode"));
11
12
  var _AndroidWebpackConfigurator = _interopRequireDefault(require("./android/AndroidWebpackConfigurator"));
12
13
  var _VelaWebpackConfigurator = _interopRequireDefault(require("./vela/VelaWebpackConfigurator"));
13
14
  var _UxCompileUtil = _interopRequireDefault(require("./vela/utils/UxCompileUtil"));
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
16
  class JavascriptCompiler {
16
17
  QUICKAPP_CONFIG = 'quickapp.config.js';
18
+ constructor(context, onLog) {
19
+ this.context = context;
20
+ this.onLog = onLog;
21
+ }
17
22
  async compile(param) {
18
23
  return new Promise(async (resolve, reject) => {
19
24
  try {
@@ -49,6 +54,65 @@ class JavascriptCompiler {
49
54
  }
50
55
  });
51
56
  }
57
+
58
+ /**
59
+ * 压缩插件
60
+ *
61
+ * dev模式,只处理console,其它禁用
62
+ * prod模式,其它使用默认值
63
+ * @param mode
64
+ * @returns
65
+ */
66
+ createMinimizerRspackPlugin(compileOption) {
67
+ const {
68
+ mode,
69
+ dropConsole
70
+ } = compileOption;
71
+ const translateDropConsole = () => {
72
+ let dropConsoleValue;
73
+ if (dropConsole === undefined) {
74
+ dropConsoleValue = false;
75
+ } else if (dropConsole === 'true') {
76
+ dropConsoleValue = true;
77
+ } else if (dropConsole === 'false') {
78
+ dropConsoleValue = false;
79
+ } else {
80
+ dropConsoleValue = dropConsole;
81
+ }
82
+ return dropConsoleValue;
83
+ };
84
+ const createCompressValue = dropConsoleValue => {
85
+ const result = {};
86
+ if (typeof dropConsoleValue === 'boolean') {
87
+ result.drop_console = dropConsoleValue;
88
+ } else if (typeof dropConsoleValue === 'string') {
89
+ result.pure_funcs = dropConsoleValue.split(',').map(item => item.trim()).filter(Boolean).map(item => `console.${item}`);
90
+ }
91
+ return result;
92
+ };
93
+ if (mode === _CompileMode.default.DEVELOPMENT) {
94
+ return new _core.rspack.SwcJsMinimizerRspackPlugin({
95
+ minimizerOptions: {
96
+ module: true,
97
+ minify: false,
98
+ mangle: false,
99
+ compress: {
100
+ defaults: false,
101
+ ...createCompressValue(translateDropConsole())
102
+ }
103
+ }
104
+ });
105
+ } else {
106
+ return new _core.rspack.SwcJsMinimizerRspackPlugin({
107
+ minimizerOptions: {
108
+ module: true,
109
+ compress: {
110
+ ...createCompressValue(translateDropConsole())
111
+ }
112
+ }
113
+ });
114
+ }
115
+ }
52
116
  createWebpackConfig(param) {
53
117
  const configurator = this.getConfigurator(param);
54
118
  if (!configurator) {
@@ -82,17 +146,39 @@ class JavascriptCompiler {
82
146
  rules: [{
83
147
  test: /\.ux$/,
84
148
  // 匹配以 .ux 结尾的文件
149
+ exclude: /node_modules/,
85
150
  use: [{
86
151
  loader: _path.default.join(__dirname, '../javascript/vela/utils/webpackLoader/extractMapData.js')
87
152
  }]
153
+ },
154
+ // node_modules下的ux文件
155
+ {
156
+ test: /\.ux$/,
157
+ include: /node_modules/,
158
+ use: [{
159
+ loader: _path.default.join(__dirname, '../javascript/vela/utils/webpackLoader/WebpackUxLoader'),
160
+ options: {
161
+ compileParam: param,
162
+ context: this.context,
163
+ onLog: this.onLog
164
+ }
165
+ }]
166
+ }, {
167
+ test: /\.js$/,
168
+ include: /node_modules/,
169
+ use: [{
170
+ loader: _path.default.join(__dirname, '../javascript/vela/utils/webpackLoader/WebpackJsLoader'),
171
+ options: {
172
+ compileParam: param,
173
+ context: this.context,
174
+ onLog: this.onLog
175
+ }
176
+ }]
88
177
  }]
89
178
  },
90
179
  optimization: {
91
- minimizer: [new _core.rspack.SwcJsMinimizerRspackPlugin({
92
- minimizerOptions: {
93
- module: true
94
- }
95
- })]
180
+ minimize: true,
181
+ minimizer: [this.createMinimizerRspackPlugin(param)]
96
182
  },
97
183
  resolve: {
98
184
  extensions: ['.js', '.ts', '.ux']
@@ -7,8 +7,8 @@ exports.default = void 0;
7
7
  var _VelaWebpackConfigurator = _interopRequireDefault(require("../vela/VelaWebpackConfigurator"));
8
8
  var _WrapPlugin = _interopRequireDefault(require("./plugin/WrapPlugin"));
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- /**
11
- * AndroidWebpackConfigurator
10
+ /**
11
+ * AndroidWebpackConfigurator
12
12
  */
13
13
  class AndroidWebpackConfigurator extends _VelaWebpackConfigurator.default {
14
14
  createWrapPlugin() {
@@ -8,8 +8,8 @@ var _core = require("@rspack/core");
8
8
  var _webpackSources = require("webpack-sources");
9
9
  var _UxFileUtils = _interopRequireDefault(require("../../../../utils/ux/UxFileUtils"));
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- /**
12
- * WrapPlugin
11
+ /**
12
+ * WrapPlugin
13
13
  */
14
14
  class WrapPlugin {
15
15
  constructor(param) {
@@ -26,11 +26,11 @@ class WrapPlugin {
26
26
  });
27
27
  }
28
28
 
29
- /**
30
- * 添加包含代码
31
- *
32
- * 1. 仅 page 文件添加
33
- * @param compilation
29
+ /**
30
+ * 添加包含代码
31
+ *
32
+ * 1. 仅 page 文件添加
33
+ * @param compilation
34
34
  */
35
35
  wrap(compilation) {
36
36
  // 获取入口文件