@aiot-toolkit/aiotpack 2.0.5-beta.13 → 2.0.5-beta.15

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 (34) hide show
  1. package/lib/afterCompile/ux/UxAfterCompile.d.ts +8 -1
  2. package/lib/afterCompile/ux/UxAfterCompile.js +40 -9
  3. package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +4 -0
  4. package/lib/compiler/tools/icu/ImageIcu.d.ts +37 -0
  5. package/lib/compiler/tools/icu/ImageIcu.js +110 -0
  6. package/lib/compiler/tools/icu/icu_darwin_arm64 +0 -0
  7. package/lib/compiler/tools/icu/icu_darwin_x64 +0 -0
  8. package/lib/compiler/tools/icu/icu_linux_arm64 +0 -0
  9. package/lib/compiler/tools/icu/icu_linux_x64 +0 -0
  10. package/lib/compiler/tools/icu/icu_win32_x64.exe +0 -0
  11. package/lib/config/UxConfig.js +5 -2
  12. package/lib/index.d.ts +1 -3
  13. package/lib/index.js +2 -28
  14. package/lib/utils/ux/UxFileUtils.d.ts +1 -0
  15. package/lib/utils/ux/UxFileUtils.js +18 -7
  16. package/package.json +7 -11
  17. package/lib/afterCompile/xts/entryTemplate.d.ts +0 -21
  18. package/lib/afterCompile/xts/entryTemplate.js +0 -182
  19. package/lib/afterCompile/xts/generateRpk.d.ts +0 -3
  20. package/lib/afterCompile/xts/generateRpk.js +0 -28
  21. package/lib/afterCompile/xts/ts2wasm.d.ts +0 -8
  22. package/lib/afterCompile/xts/ts2wasm.js +0 -69
  23. package/lib/beforeCompile/xts/preInstall.d.ts +0 -3
  24. package/lib/beforeCompile/xts/preInstall.js +0 -54
  25. package/lib/config/XtsConfig.d.ts +0 -22
  26. package/lib/config/XtsConfig.js +0 -36
  27. package/lib/interface/ICompileOptions.d.ts +0 -6
  28. package/lib/interface/ICompileOptions.js +0 -7
  29. package/lib/loader/xts/XtsLoader.d.ts +0 -9
  30. package/lib/loader/xts/XtsLoader.js +0 -62
  31. package/lib/utils/xts/XtsFileLaneUtils.d.ts +0 -10
  32. package/lib/utils/xts/XtsFileLaneUtils.js +0 -61
  33. package/lib/utils/xts/XtsFollowWorks.d.ts +0 -34
  34. package/lib/utils/xts/XtsFollowWorks.js +0 -134
@@ -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
@@ -17,6 +17,7 @@ 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
19
  var _process = require("process");
20
+ var _ImageIcu = _interopRequireDefault(require("../../compiler/tools/icu/ImageIcu"));
20
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
22
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
22
23
  const HapToolkit = require('hap-toolkit');
@@ -25,7 +26,7 @@ const HapToolkit = require('hap-toolkit');
25
26
  * UxAfterCompile
26
27
  */
27
28
  class UxAfterCompile {
28
- static webpack = async params => {
29
+ static compileJavascript = async params => {
29
30
  const {
30
31
  context,
31
32
  compilerOption
@@ -91,12 +92,12 @@ class UxAfterCompile {
91
92
  const {
92
93
  compilerOption,
93
94
  compalition,
94
- config
95
+ context
95
96
  } = params;
96
97
  if (compilerOption) {
97
98
  const fileName = await _ZipUtil.default.createRpk(_path.default.join(compilerOption.projectPath, compilerOption.outputPath), compilerOption);
98
99
  if (compalition && fileName) {
99
- compalition.info.rpk = _path.default.join(config.projectPath, compilerOption.releasePath, fileName);
100
+ compalition.info.rpk = _path.default.join(context.projectPath, compilerOption.releasePath, fileName);
100
101
  }
101
102
  return fileName;
102
103
  }
@@ -146,7 +147,7 @@ class UxAfterCompile {
146
147
  sourceRoot,
147
148
  outputPath
148
149
  } = compilerOption;
149
- const includeList = [/sitemap\.json$/, /i18n(.+)\.json/];
150
+ const includeList = [/sitemap\.json$/, /i18n(.+)\.json/, /web\/*/];
150
151
  const excludeExtList = ['js', 'jsx', 'coffee', 'ts', 'tsx', 'vue', 'css', 'less', 'sass', 'styl', 'html', 'md', 'ux', 'mix', 'DS_Store', 'map'];
151
152
  const excludeReg = `\\.(${excludeExtList.join('|')})$`;
152
153
  _sharedUtils.FileUtil.copyFiles(_path.default.join(projectPath, sourceRoot), _path.default.join(projectPath, outputPath), new RegExp(excludeReg));
@@ -253,6 +254,37 @@ class UxAfterCompile {
253
254
  await genMetaFiles(compilerOption);
254
255
  }
255
256
  };
257
+
258
+ /**
259
+ * 压缩资源文件
260
+ * 1. png8
261
+ * 2. bin
262
+ * @param params
263
+ */
264
+ static compressResource = async params => {
265
+ const {
266
+ compilerOption
267
+ } = params;
268
+ if (compilerOption) {
269
+ const {
270
+ enableImagePng8,
271
+ projectPath,
272
+ outputPath
273
+ } = compilerOption;
274
+ if (enableImagePng8) {
275
+ const format = 'png';
276
+ const files = _sharedUtils.FileUtil.readAlldirSync(_path.default.join(projectPath, outputPath));
277
+ const compressFiles = files.filter(filePath => _ImageIcu.default.canTranslate(filePath, format));
278
+ if (compressFiles.length) {
279
+ const icu = new _ImageIcu.default();
280
+ compressFiles.forEach(item => {
281
+ icu.translate(item, _path.default.dirname(item), format);
282
+ });
283
+ }
284
+ }
285
+ }
286
+ };
287
+
256
288
  /**
257
289
  * 如果是更新触发,则对比临时项目build文件夹 和 项目build文件夹,生成diff.json
258
290
  * @param context
@@ -263,7 +295,7 @@ class UxAfterCompile {
263
295
  const {
264
296
  compilerOption,
265
297
  compalition,
266
- config
298
+ context
267
299
  } = params;
268
300
  if (!compilerOption || !compalition) {
269
301
  return;
@@ -292,7 +324,7 @@ class UxAfterCompile {
292
324
  zipFilePath: item
293
325
  })));
294
326
  compalition.info.diffList = diffList;
295
- compalition.info.diffFile = _path.default.join(config.projectPath, compilerOption.releasePath, diffFileName);
327
+ compalition.info.diffFile = _path.default.join(context.projectPath, compilerOption.releasePath, diffFileName);
296
328
  }
297
329
  };
298
330
 
@@ -374,7 +406,6 @@ class UxAfterCompile {
374
406
  */
375
407
  static compileLiteCard = async params => {
376
408
  const {
377
- config,
378
409
  compilerOption,
379
410
  context
380
411
  } = params;
@@ -392,7 +423,7 @@ class UxAfterCompile {
392
423
  };
393
424
  // 1.2
394
425
  await HapToolkit.compile('native', 'dev', false, {
395
- cwd: config.projectPath,
426
+ cwd: context.projectPath,
396
427
  signMode: 'BUILD',
397
428
  enableCustomComponent: true
398
429
  });
@@ -401,7 +432,7 @@ class UxAfterCompile {
401
432
  // 2.
402
433
  context.liteCards.forEach(card => {
403
434
  // hap-toolkit的产物在项目的build文件夹下
404
- const fromPath = _path.default.join(config.projectPath, LITE_OUTPUT_PATH, card);
435
+ const fromPath = _path.default.join(context.projectPath, LITE_OUTPUT_PATH, card);
405
436
  // aiot-toolkit的产物在临时项目的build文件夹下
406
437
  const toPath = _path.default.join(projectPath, LITE_OUTPUT_PATH, card);
407
438
  //确定目标目录存在,若不存在则创建到父目录
@@ -48,6 +48,10 @@ export default interface IJavascriptCompileOption extends ICompileParam {
48
48
  * 启用应用自动化测试
49
49
  */
50
50
  enableE2e?: boolean;
51
+ /**
52
+ * 启用 png8 压缩
53
+ */
54
+ enableImagePng8?: boolean;
51
55
  /**
52
56
  * 启用代码体积分析,会生成 report.html 文件,可查看打包后各模块占用体积
53
57
  */
@@ -0,0 +1,37 @@
1
+ declare class ImageIcu {
2
+ static EXT: string;
3
+ static INCLUDE_LIST: string[];
4
+ /**
5
+ * @private
6
+ * @returns
7
+ */
8
+ getBinPath(): string;
9
+ /**
10
+ * 文件转换为 bin 格式
11
+ * @param {*} resourcePath 源文件
12
+ * @param {*} folder 产物目录
13
+ * @param {'lvgl'|'png'} format
14
+ * @returns
15
+ */
16
+ translate(resourcePath: string, folder: string, format?: string): string | undefined;
17
+ /**
18
+ * 资源转换为 bin 文件路径
19
+ *
20
+ * 如果是 png, jpg,jpeg, webp, bmp,则转换为 .bin 后缀;其它类型不处理
21
+ *
22
+ * **此方法仅返回转换后的路径, 不会实际转换文件**
23
+ * @param {string} path
24
+ * @example assetsToBinPath('images/test.png') // images/test.bin
25
+ *
26
+ * @return {string} 可转则返回对应的 bin 路径;否则返回''
27
+ */
28
+ static assetsToBinPath(assetsPath: string): string;
29
+ /**
30
+ * 是否可转换
31
+ * @param {string} assetsPath
32
+ * @param {'lvgl'|'png'} format
33
+ * @returns
34
+ */
35
+ static canTranslate(assetsPath: string, format?: string): boolean;
36
+ }
37
+ export default ImageIcu;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ var _os = _interopRequireDefault(require("os"));
9
+ var _fs = _interopRequireDefault(require("fs"));
10
+ var _child_process = require("child_process");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ class ImageIcu {
13
+ static EXT = '.bin';
14
+ static INCLUDE_LIST = ['.png', '.jpg', '.jpeg', '.webp', '.bmp'];
15
+ /**
16
+ * @private
17
+ * @returns
18
+ */
19
+ getBinPath() {
20
+ const platform = _os.default.platform();
21
+ const arch = _os.default.arch();
22
+ let result = _path.default.join(__dirname, `icu_${platform}_${arch}`);
23
+ if (platform === 'win32') {
24
+ result += '.exe';
25
+ }
26
+ return result;
27
+ }
28
+
29
+ /**
30
+ * 文件转换为 bin 格式
31
+ * @param {*} resourcePath 源文件
32
+ * @param {*} folder 产物目录
33
+ * @param {'lvgl'|'png'} format
34
+ * @returns
35
+ */
36
+ translate(resourcePath, folder) {
37
+ let format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'lvgl';
38
+ if (!_fs.default.existsSync(resourcePath) || !ImageIcu.canTranslate(resourcePath)) {
39
+ return;
40
+ }
41
+ const binPath = this.getBinPath();
42
+ if (_fs.default.existsSync(binPath)) {
43
+ const pathParse = _path.default.parse(resourcePath);
44
+
45
+ // 后缀,lvgl格式的后缀为"bin", 其它保持原后缀
46
+ const extDic = {
47
+ lvgl: ImageIcu.EXT,
48
+ png: pathParse.ext
49
+ };
50
+ const ext = extDic[format];
51
+ if (!_fs.default.existsSync(folder)) {
52
+ _fs.default.mkdirSync(folder, {
53
+ recursive: true
54
+ });
55
+ }
56
+ const command = `${binPath} convert ${resourcePath} -O ${folder} -F ${format} -C i8 -r`;
57
+ const message = (0, _child_process.execSync)(command).toString('utf-8');
58
+ if (message) {
59
+ console.log(`convert error: path=${resourcePath} message=${message}`);
60
+ return '';
61
+ }
62
+ const result = _path.default.join(pathParse.dir, `${pathParse.name}${ext}`);
63
+ return result;
64
+ } else {
65
+ return resourcePath;
66
+ }
67
+ }
68
+
69
+ /**
70
+ * 资源转换为 bin 文件路径
71
+ *
72
+ * 如果是 png, jpg,jpeg, webp, bmp,则转换为 .bin 后缀;其它类型不处理
73
+ *
74
+ * **此方法仅返回转换后的路径, 不会实际转换文件**
75
+ * @param {string} path
76
+ * @example assetsToBinPath('images/test.png') // images/test.bin
77
+ *
78
+ * @return {string} 可转则返回对应的 bin 路径;否则返回''
79
+ */
80
+ static assetsToBinPath(assetsPath) {
81
+ if (!assetsPath) {
82
+ return '';
83
+ }
84
+ const pathParse = _path.default.parse(assetsPath);
85
+ if (ImageIcu.canTranslate(assetsPath)) {
86
+ return _path.default.join(pathParse.dir, `${pathParse.name}${ImageIcu.EXT}`);
87
+ }
88
+ return '';
89
+ }
90
+
91
+ /**
92
+ * 是否可转换
93
+ * @param {string} assetsPath
94
+ * @param {'lvgl'|'png'} format
95
+ * @returns
96
+ */
97
+ static canTranslate(assetsPath) {
98
+ let format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'lvgl';
99
+ if (!assetsPath) {
100
+ return false;
101
+ }
102
+ const pathParse = _path.default.parse(assetsPath);
103
+ const ext = pathParse.ext.toLowerCase();
104
+ if (format === 'png') {
105
+ return ext === '.png';
106
+ }
107
+ return ImageIcu.INCLUDE_LIST.includes(ext);
108
+ }
109
+ }
110
+ var _default = exports.default = ImageIcu;
@@ -78,11 +78,14 @@ class UxConfig {
78
78
  worker: _UxAfterCompile.default.symlinkNodeModule,
79
79
  workerDescribe: 'Create a soft link to the node_modules folder'
80
80
  }, {
81
- worker: _UxAfterCompile.default.webpack,
82
- workerDescribe: 'Compile the project using webpack'
81
+ worker: _UxAfterCompile.default.compileJavascript,
82
+ workerDescribe: 'Compile javascript project'
83
83
  }, {
84
84
  worker: _UxAfterCompile.default.copyResource,
85
85
  workerDescribe: 'Copy resource files'
86
+ }, {
87
+ worker: _UxAfterCompile.default.compressResource,
88
+ workerDescribe: 'Compress resource files'
86
89
  }, {
87
90
  worker: _UxAfterCompile.default.jsc,
88
91
  workerDescribe: 'Generate jsc bytecode'
package/lib/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import XtsConfig from './config/XtsConfig';
2
1
  import JavascriptDefaultCompileOption, { setServerPort } from './compiler/javascript/JavascriptDefaultCompileOption';
3
2
  import UxConfig from './config/UxConfig';
4
3
  import CompileMode from './compiler/enum/CompileMode';
@@ -6,5 +5,4 @@ import IJavascriptCompileOption from './compiler/javascript/interface/IJavascrip
6
5
  import IQuickAppConfig from './compiler/javascript/vela/interface/IQuickAppConfig';
7
6
  import UxFileUtils from './utils/ux/UxFileUtils';
8
7
  import IManifest from './compiler/javascript/vela/interface/IManifest';
9
- import { ISkipList, IXtsCompileOptions, skipList } from './interface/ICompileOptions';
10
- export { XtsConfig, UxConfig, JavascriptDefaultCompileOption, CompileMode, IJavascriptCompileOption, IQuickAppConfig, setServerPort, UxFileUtils, IManifest, skipList, IXtsCompileOptions, ISkipList };
8
+ export { UxConfig, JavascriptDefaultCompileOption, CompileMode, IJavascriptCompileOption, IQuickAppConfig, setServerPort, UxFileUtils, IManifest };
package/lib/index.js CHANGED
@@ -27,18 +27,6 @@ Object.defineProperty(exports, "IQuickAppConfig", {
27
27
  return _IQuickAppConfig.default;
28
28
  }
29
29
  });
30
- Object.defineProperty(exports, "ISkipList", {
31
- enumerable: true,
32
- get: function () {
33
- return _ICompileOptions.ISkipList;
34
- }
35
- });
36
- Object.defineProperty(exports, "IXtsCompileOptions", {
37
- enumerable: true,
38
- get: function () {
39
- return _ICompileOptions.IXtsCompileOptions;
40
- }
41
- });
42
30
  Object.defineProperty(exports, "JavascriptDefaultCompileOption", {
43
31
  enumerable: true,
44
32
  get: function () {
@@ -57,25 +45,12 @@ Object.defineProperty(exports, "UxFileUtils", {
57
45
  return _UxFileUtils.default;
58
46
  }
59
47
  });
60
- Object.defineProperty(exports, "XtsConfig", {
61
- enumerable: true,
62
- get: function () {
63
- return _XtsConfig.default;
64
- }
65
- });
66
48
  Object.defineProperty(exports, "setServerPort", {
67
49
  enumerable: true,
68
50
  get: function () {
69
51
  return _JavascriptDefaultCompileOption.setServerPort;
70
52
  }
71
53
  });
72
- Object.defineProperty(exports, "skipList", {
73
- enumerable: true,
74
- get: function () {
75
- return _ICompileOptions.skipList;
76
- }
77
- });
78
- var _XtsConfig = _interopRequireDefault(require("./config/XtsConfig"));
79
54
  var _JavascriptDefaultCompileOption = _interopRequireWildcard(require("./compiler/javascript/JavascriptDefaultCompileOption"));
80
55
  var _UxConfig = _interopRequireDefault(require("./config/UxConfig"));
81
56
  var _CompileMode = _interopRequireDefault(require("./compiler/enum/CompileMode"));
@@ -83,7 +58,6 @@ var _IJavascriptCompileOption = _interopRequireDefault(require("./compiler/javas
83
58
  var _IQuickAppConfig = _interopRequireDefault(require("./compiler/javascript/vela/interface/IQuickAppConfig"));
84
59
  var _UxFileUtils = _interopRequireDefault(require("./utils/ux/UxFileUtils"));
85
60
  var _IManifest = _interopRequireDefault(require("./compiler/javascript/vela/interface/IManifest"));
86
- var _ICompileOptions = require("./interface/ICompileOptions");
61
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
87
62
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
88
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
89
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
63
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -23,6 +23,7 @@ export declare class UxFileUtils {
23
23
  * 1. TypeError: Error
24
24
  * 2. 其它: Warn
25
25
  * 2. 检查 router.entry 是否存在于 router.pages
26
+ * 3. 检查icon是否存在
26
27
  *
27
28
  * @param projectPath 项目路径
28
29
  * @param sourceRoot 源码路径--相对项目根目录
@@ -42,6 +42,7 @@ class UxFileUtils {
42
42
  * 1. TypeError: Error
43
43
  * 2. 其它: Warn
44
44
  * 2. 检查 router.entry 是否存在于 router.pages
45
+ * 3. 检查icon是否存在
45
46
  *
46
47
  * @param projectPath 项目路径
47
48
  * @param sourceRoot 源码路径--相对项目根目录
@@ -60,15 +61,25 @@ class UxFileUtils {
60
61
  const errors = _CommonUtil.default.validateJson(jsonData, schema) || [];
61
62
 
62
63
  // 2
63
- const {
64
- entry,
65
- pages
66
- } = jsonData.router;
67
- if (!pages[entry]) {
68
- errors.push(new TypeError(`router.entry content: ${entry}, is missing in router.pages`));
64
+ if (jsonData.router) {
65
+ const {
66
+ entry,
67
+ pages
68
+ } = jsonData.router;
69
+ if (!pages[entry]) {
70
+ errors.push(new TypeError(`router.entry content: ${entry}, is missing in router.pages`));
71
+ }
72
+ }
73
+
74
+ // 3
75
+ if (jsonData.icon) {
76
+ const iconPath = _path.default.join(projectPath, sourceRoot, jsonData.icon);
77
+ if (!_fsExtra.default.existsSync(iconPath)) {
78
+ errors.push(new Error(`icon: "${jsonData.icon}" is missing in project`));
79
+ }
69
80
  }
70
81
  if (errors?.length) {
71
- const message = `Manifest.json error: ${errors.map((item, index) => {
82
+ const message = `error in ${path}: ${errors.map((item, index) => {
72
83
  return `\r\n${index + 1}. ${item.message}`;
73
84
  })}`;
74
85
  throw new Error(message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.5-beta.13",
3
+ "version": "2.0.5-beta.15",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,16 +19,14 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.5-beta.13",
23
- "@aiot-toolkit/parser": "2.0.5-beta.13",
24
- "@aiot-toolkit/shared-utils": "2.0.5-beta.13",
22
+ "@aiot-toolkit/generator": "2.0.5-beta.15",
23
+ "@aiot-toolkit/parser": "2.0.5-beta.15",
24
+ "@aiot-toolkit/shared-utils": "2.0.5-beta.15",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
- "@rspack/core": "^1.1.8",
26
+ "@rspack/core": "^1.3.9",
27
27
  "aiot-parse5": "^1.0.2",
28
- "archiver": "^7.0.1",
29
28
  "babel-loader": "^9.1.3",
30
- "fast-glob": "^3.3.2",
31
- "file-lane": "2.0.5-beta.13",
29
+ "file-lane": "2.0.5-beta.15",
32
30
  "file-loader": "^6.2.0",
33
31
  "fs-extra": "^11.2.0",
34
32
  "hap-toolkit": "^2.0.0",
@@ -37,15 +35,13 @@
37
35
  "lodash": "^4.17.21",
38
36
  "ts-morph": "^19.0.0",
39
37
  "url-loader": "^4.1.1",
40
- "webpack": "^5.97.1",
41
38
  "webpack-bundle-analyzer": "^4.10.2",
42
39
  "webpack-sources": "^3.2.3"
43
40
  },
44
41
  "devDependencies": {
45
- "@types/archiver": "^6.0.2",
46
42
  "@types/fs-extra": "^11.0.4",
47
43
  "@types/jsrsasign": "^10.5.12",
48
44
  "@types/webpack-sources": "^3.2.3"
49
45
  },
50
- "gitHead": "45bca4420e8a8708733eccea32bf928b4821f4d5"
46
+ "gitHead": "6e39bae7f788a36a777e08545d862b87fab26a9b"
51
47
  }
@@ -1,21 +0,0 @@
1
- import { FollowWork } from 'file-lane';
2
- export interface Aspects {
3
- path: string;
4
- name: string;
5
- routes?: {
6
- importPath: string;
7
- name: string;
8
- route: string;
9
- }[];
10
- }
11
- export interface GenerateEntryParams {
12
- appPath: string;
13
- aspects?: Aspects[];
14
- }
15
- export declare const entryTemplate: (options: GenerateEntryParams) => string;
16
- export declare const XtsEntryFileName = "__entry__.ts";
17
- /**
18
- * 生成 __entry__.ts 文件
19
- * @param context
20
- */
21
- export declare const generateEntryFile: FollowWork;
@@ -1,182 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.generateEntryFile = exports.entryTemplate = exports.XtsEntryFileName = void 0;
7
- var _parser = require("@aiot-toolkit/parser");
8
- var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
10
- var _path = _interopRequireDefault(require("path"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- const entryTemplate = options => {
13
- const {
14
- aspects = []
15
- } = options;
16
- function generatImportAspects() {
17
- if (!aspects) return '';
18
- let imports = '// import aspects\n';
19
- for (let i = 0; i < aspects.length; i++) {
20
- const aspect = aspects[i];
21
- imports += `import AspectClass${i + 1} from './${aspect.path}'\n`;
22
- const {
23
- routes = []
24
- } = aspect;
25
- for (let r = 0; r < routes?.length; r++) {
26
- const route = routes[r];
27
- imports += `import Page${i + 1}_${r + 1}, { ${_parser.HomeState.interface} as ${_parser.HomeState.interface}${i + 1}_${r + 1}_ } from './${route.importPath}'\n`;
28
- }
29
- }
30
- return imports;
31
- }
32
- function generateDefs() {
33
- let res = '// aspects\n';
34
- for (let i = 0; i < aspects.length; i++) {
35
- const aspect = aspects[i];
36
- const {
37
- routes = []
38
- } = aspect;
39
- res += `
40
- const aspectName_${i + 1} = '${aspect.name}'
41
- const pathPages_${i + 1} = new Map()`;
42
- for (let r = 0; r < routes.length; r++) {
43
- const route = routes[r];
44
- res += `
45
- pathPages_${i + 1}.set('${route.route}', function (params?: ${_parser.HomeState.interface}${i + 1}_${r + 1}_): Page {
46
- return new Page${i + 1}_${r + 1}(params)
47
- })
48
- `;
49
- }
50
- res += `
51
- const aspectDef_${i + 1}: AspectDefinition = {
52
- newFn: (): ViewAspect => new AspectClass${i + 1}(),
53
- pathPages: pathPages_${i + 1}
54
- }
55
- aspectDefs.set(aspectName_${i + 1}, aspectDef_${i + 1})
56
- `;
57
- }
58
- return res;
59
- }
60
- return `import {
61
- // class
62
- App,
63
- AppDefinition,
64
- AppContainer,
65
- AspectDefinition,
66
- ViewAspect,
67
- Page,
68
- Route,
69
- RouteInfo,
70
- // framework
71
- context,
72
- getInfoFromRoute,
73
-
74
- // export function
75
- on
76
- } from '../node_modules/${_parser.tsFrameWork.name}/index'
77
-
78
- // import app
79
- import AppClass from './${options.appPath}'
80
- ${generatImportAspects()}
81
- console.log('startApp-start timeEnd:', Date.now())
82
-
83
- function getAspectDefs() {
84
- const aspectDefs = new Map()
85
- ${generateDefs()}
86
- return aspectDefs
87
- }
88
-
89
- function entry(path: string): void {
90
- console.log('~~~~~~~~~entry path', path)
91
- const route: Route = { uri: path }
92
- const routeInfo: RouteInfo = getInfoFromRoute(route)
93
- // app
94
- let appName: string = ''
95
- if (routeInfo?.appName) appName = routeInfo.appName
96
- let app = context.getApp(appName)
97
- if (app === null) {
98
- const appDef: AppDefinition = {
99
- newFn: (): App => new AppClass()
100
- }
101
- const aspectDefs = getAspectDefs()
102
- app = new AppContainer(appDef, aspectDefs)
103
- }
104
- context.openApp(app, routeInfo)
105
- }
106
-
107
- // export api to native
108
- export { entry, on }
109
- `;
110
- };
111
- exports.entryTemplate = entryTemplate;
112
- function getManifest(manifestPath) {
113
- const content = _fsExtra.default.readFileSync(manifestPath, 'utf-8');
114
- const data = JSON.parse(content);
115
- return data;
116
- }
117
- const XtsEntryFileName = exports.XtsEntryFileName = '__entry__.ts';
118
- /**
119
- * 生成 __entry__.ts 文件
120
- * @param context
121
- */
122
- const generateEntryFile = exports.generateEntryFile = async function generateEntryFile(params) {
123
- const {
124
- context,
125
- compilerOption
126
- } = params;
127
- const {
128
- projectPath,
129
- output
130
- } = context;
131
- if (compilerOption?.skip?.includes('xts2ts')) {
132
- _sharedUtils.ColorConsole.info(`### skip generate entry file due to --skip xts2ts}`);
133
- return;
134
- }
135
- _sharedUtils.ColorConsole.info(`Generating entry file`);
136
- const buildDir = _path.default.resolve(projectPath, output);
137
- const appManifestPath = _path.default.join(buildDir, 'app', 'manifest.json');
138
- const appManifest = getManifest(appManifestPath);
139
- if (!appManifest) {
140
- _sharedUtils.ColorConsole.throw('not find app/manifest.json file !');
141
- }
142
- const appTs = _path.default.join(buildDir, 'app', 'app.ts');
143
- if (!_fsExtra.default.existsSync(appTs)) {
144
- _sharedUtils.ColorConsole.throw('not find app/app.ts file !');
145
- }
146
- function relativeDist(tar) {
147
- return _path.default.join('.', _path.default.relative(buildDir, tar)).replace(_path.default.sep, '/');
148
- }
149
- let opt = {
150
- appPath: relativeDist(appTs.replace('.ts', '')),
151
- aspects: []
152
- };
153
- function getAspectRoutes(aspectPath) {
154
- const aspectManifestPath = _path.default.join(aspectPath, 'src', 'manifest.json');
155
- const aspectManifest = getManifest(aspectManifestPath);
156
- if (!aspectManifest?.router?.pages) return [];
157
- return Object.entries(aspectManifest.router.pages).map(_ref => {
158
- let [k, v] = _ref;
159
- return {
160
- importPath: relativeDist(_path.default.resolve(_path.default.dirname(aspectManifestPath), v.path)),
161
- name: k,
162
- route: v.path
163
- };
164
- });
165
- }
166
- if (appManifest?.router?.aspects) {
167
- Object.entries(appManifest.router.aspects).forEach(_ref2 => {
168
- let [name, aspects] = _ref2;
169
- aspects.forEach(aspect => {
170
- const aspectPath = _path.default.join(buildDir, aspect.path);
171
- opt.aspects?.push({
172
- name: name,
173
- path: relativeDist(_path.default.resolve(buildDir, aspect.path, 'src', 'aspect')),
174
- routes: getAspectRoutes(aspectPath)
175
- });
176
- });
177
- });
178
- }
179
- const template = entryTemplate(opt);
180
- _fsExtra.default.writeFileSync(_path.default.join(projectPath, output, XtsEntryFileName), template);
181
- _sharedUtils.ColorConsole.info(`entry file built`);
182
- };
@@ -1,3 +0,0 @@
1
- import { FollowWork } from 'file-lane';
2
- import { IXtsCompileOptions } from '../../interface/ICompileOptions';
3
- export declare const generateRpk: FollowWork<IXtsCompileOptions>;
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.generateRpk = void 0;
7
- var _path = _interopRequireDefault(require("path"));
8
- var _XtsFollowWorks = _interopRequireDefault(require("../../utils/xts/XtsFollowWorks"));
9
- var _sharedUtils = require("@aiot-toolkit/shared-utils");
10
- var _ts2wasm = require("./ts2wasm");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- const generateRpk = async params => {
13
- const {
14
- context,
15
- compilerOption
16
- } = params;
17
- if (compilerOption?.skip?.includes('package')) {
18
- _sharedUtils.ColorConsole.info(`### skip package due to --skip ${compilerOption.skip.join(',')}`);
19
- return;
20
- }
21
- const manifestPath = _path.default.resolve(context.projectPath, 'app', 'manifest.json');
22
- const manifest = await import(manifestPath);
23
- return _XtsFollowWorks.default.defaultZipProject(context, {
24
- tarDir: _ts2wasm.wasmPackageName,
25
- packageName: manifest.package
26
- });
27
- };
28
- exports.generateRpk = generateRpk;
@@ -1,8 +0,0 @@
1
- import { FollowWork } from 'file-lane';
2
- import { IXtsCompileOptions } from '../../interface/ICompileOptions';
3
- export declare const wasmPackageName = "wasmUnpacked";
4
- /**
5
- * 将 __entry__.ts 文件打包成 warm 文件
6
- * @param context
7
- */
8
- export declare const ts2wasm: FollowWork<IXtsCompileOptions>;
@@ -1,69 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.wasmPackageName = exports.ts2wasm = void 0;
7
- var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
- var _child_process = require("child_process");
9
- var _fastGlob = _interopRequireDefault(require("fast-glob"));
10
- var _fs = _interopRequireDefault(require("fs"));
11
- var _path = _interopRequireDefault(require("path"));
12
- var _entryTemplate = require("./entryTemplate");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- const wasmPackageName = exports.wasmPackageName = 'wasmUnpacked';
15
-
16
- /**
17
- * 将 __entry__.ts 文件打包成 warm 文件
18
- * @param context
19
- */
20
- const ts2wasm = async params => {
21
- const {
22
- context,
23
- compilerOption
24
- } = params;
25
- /** 1. 生成 app.wasm 文件 */
26
- const {
27
- projectPath,
28
- output
29
- } = context;
30
- const buildDir = _path.default.resolve(projectPath, output);
31
- const entryFile = _path.default.resolve(buildDir, _entryTemplate.XtsEntryFileName);
32
- const wasmDir = _path.default.resolve(projectPath, wasmPackageName);
33
- _fs.default.mkdirSync(wasmDir, {
34
- recursive: true
35
- });
36
- function compile() {
37
- // TODO: 后续修改为 @mi
38
- const ts2wasmpath = _path.default.resolve(projectPath, 'node_modules', 'mi/wasmnizer-ts');
39
- _sharedUtils.ColorConsole.info('### Waiting for generating app.wasm file.');
40
- const res = (0, _child_process.execSync)(`node ${ts2wasmpath}/build/cli/ts2wasm.js ${entryFile} -o ${wasmDir}/app.wasm`, {
41
- encoding: 'utf-8'
42
- });
43
- _sharedUtils.ColorConsole.info(`### ts2wasm ### ${res.toString()}`);
44
- }
45
- if (compilerOption?.skip?.includes('ts2wasm')) {
46
- _sharedUtils.ColorConsole.info(`### skip compile ts to wasm due to --skip ${compilerOption?.skip.join(',')}`);
47
- } else {
48
- compile();
49
- }
50
-
51
- /** 2. 拷贝静态资源 */
52
- // TODO: ignore 数组待优化
53
- const files = _fastGlob.default.sync(`${_fastGlob.default.convertPathToPattern(projectPath)}/${output}/**/*`, {
54
- absolute: true,
55
- ignore: ['**/*.ts', '**/*.xts', '**/package.json', '**/package-lock.json', '**/*.wasm'],
56
- onlyFiles: true
57
- });
58
- for (const from of files) {
59
- const to = from.replace('/src', '').replace(`/${output}`, `/${wasmPackageName}`);
60
- _fs.default.mkdirSync(_path.default.dirname(to), {
61
- recursive: true
62
- });
63
- _fs.default.copyFileSync(from, to);
64
- }
65
-
66
- /** 3. 特殊处理 app/manifest.json */
67
- _fs.default.copyFileSync(_path.default.resolve(_fastGlob.default.convertPathToPattern(projectPath), output, 'app', 'manifest.json'), _path.default.resolve(_fastGlob.default.convertPathToPattern(projectPath), wasmPackageName, 'manifest.json'));
68
- };
69
- exports.ts2wasm = ts2wasm;
@@ -1,3 +0,0 @@
1
- import { PreWork } from 'file-lane';
2
- import { IXtsCompileOptions } from '../../interface/ICompileOptions';
3
- export declare const preInstall: PreWork<IXtsCompileOptions>;
@@ -1,54 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.preInstall = void 0;
7
- var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
- var _child_process = require("child_process");
9
- var _fs = _interopRequireDefault(require("fs"));
10
- var _path = _interopRequireDefault(require("path"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- const preInstall = async params => {
13
- const {
14
- context,
15
- compilerOption
16
- } = params;
17
- if (compilerOption?.skip?.includes('install')) {
18
- _sharedUtils.ColorConsole.info(`### skip install pre-dependencies due to --skip ${compilerOption?.skip.join(',')}`);
19
- return;
20
- }
21
- const {
22
- projectPath
23
- } = context;
24
- const packagePath = _path.default.resolve(projectPath, 'package.json');
25
- const preContent = {
26
- dependencies: {
27
- '@mi/ts-framework': 'https://pkgs.d.xiaomi.net:443/artifactory/api/npm/mi-npm/@mi/ts-framework/-/@mi/ts-framework-1.0.9.tgz',
28
- '@mi/wasmnizer-ts': 'https://pkgs.d.xiaomi.net:443/artifactory/api/npm/mi-npm/@mi/wasmnizer-ts/-/@mi/wasmnizer-ts-0.0.12.tgz'
29
- }
30
- };
31
- if (!_fs.default.existsSync(packagePath)) {
32
- /** 如果没有 package.json 则创建 */
33
- _fs.default.writeFileSync(packagePath, JSON.stringify(preContent, undefined, 2), {
34
- encoding: 'utf-8'
35
- });
36
- } else {
37
- const pckageContent = require(packagePath);
38
- if (!pckageContent.dependencies['@mi/ts-framework'] || !pckageContent.dependencies['@mi/wasmnizer-ts']) {
39
- Object.assign(pckageContent, preContent);
40
- _fs.default.writeFileSync(packagePath, JSON.stringify(pckageContent), {
41
- encoding: 'utf-8'
42
- });
43
- }
44
- }
45
- _sharedUtils.ColorConsole.info('### Installing pre-dependencies. The initial build may take some time, please be patient...');
46
- (0, _child_process.execSync)('npm install', {
47
- cwd: projectPath
48
- });
49
-
50
- // 目前ts2wasm不支持@符号
51
- _fs.default.renameSync(_path.default.resolve(projectPath, 'node_modules/@mi'), _path.default.resolve(projectPath, 'node_modules/mi'));
52
- _sharedUtils.ColorConsole.info('### Dependencies installation complete.');
53
- };
54
- exports.preInstall = preInstall;
@@ -1,22 +0,0 @@
1
- import { IFileLaneConfig, PreWork } from 'file-lane';
2
- import XtsLoader from '../loader/xts/XtsLoader';
3
- /**
4
- * XtsConfig
5
- */
6
- declare class XtsConfig implements IFileLaneConfig {
7
- projectPath: string;
8
- constructor(projectPath: string);
9
- exclude: string[];
10
- output: string;
11
- module: {
12
- rules: {
13
- test: RegExp[];
14
- loader: (typeof XtsLoader)[];
15
- }[];
16
- };
17
- beforeCompile: PreWork[];
18
- afterCompile: {
19
- worker: import("file-lane").FollowWork<import("..").IXtsCompileOptions>;
20
- }[];
21
- }
22
- export default XtsConfig;
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _entryTemplate = require("../afterCompile/xts/entryTemplate");
8
- var _generateRpk = require("../afterCompile/xts/generateRpk");
9
- var _ts2wasm = require("../afterCompile/xts/ts2wasm");
10
- var _XtsLoader = _interopRequireDefault(require("../loader/xts/XtsLoader"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- /**
13
- * XtsConfig
14
- */
15
- class XtsConfig {
16
- constructor(projectPath) {
17
- this.projectPath = projectPath;
18
- }
19
- exclude = ['**/node_modules{,/**}', '**/dist{,/**}', '**/build{,/**}', '**/.git{,/**}', '**/.wasmUnpacked{,/**}'];
20
- output = 'build';
21
- module = (() => ({
22
- rules: [{
23
- test: [/\.xts$/],
24
- loader: [_XtsLoader.default]
25
- }]
26
- }))();
27
- beforeCompile = [];
28
- afterCompile = (() => [{
29
- worker: _entryTemplate.generateEntryFile
30
- }, {
31
- worker: _ts2wasm.ts2wasm
32
- }, {
33
- worker: _generateRpk.generateRpk
34
- }])();
35
- }
36
- var _default = exports.default = XtsConfig;
@@ -1,6 +0,0 @@
1
- export declare const skipList: readonly ["xts2ts", "install", "ts2wasm", "package"];
2
- export type ISkipList = typeof skipList;
3
- export interface IXtsCompileOptions {
4
- watch?: boolean;
5
- skip?: ISkipList;
6
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.skipList = void 0;
7
- const skipList = exports.skipList = ['xts2ts', 'install', 'ts2wasm', 'package'];
@@ -1,9 +0,0 @@
1
- import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
- /**
3
- * XtsLoader
4
- */
5
- declare class XtsLoader implements ILoader {
6
- context: IFileLaneContext;
7
- parser(files: IFileParam[]): IFileParam[];
8
- }
9
- export default XtsLoader;
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _generator = require("@aiot-toolkit/generator");
8
- var _parser = require("@aiot-toolkit/parser");
9
- var _sharedUtils = require("@aiot-toolkit/shared-utils");
10
- var _path = _interopRequireDefault(require("path"));
11
- var _tsMorph = require("ts-morph");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- /**
14
- * XtsLoader
15
- */
16
- class XtsLoader {
17
- parser(files) {
18
- const project = new _tsMorph.Project();
19
- const resultFiles = [];
20
- for (const file in files) {
21
- const {
22
- path,
23
- content
24
- } = files[file];
25
- const {
26
- name,
27
- ext
28
- } = _path.default.parse(path);
29
- const fullName = `${name}${ext}`;
30
- const newFileName = `${name}.ts`;
31
- //判断文本,空文本则结束该文件处理
32
- if (!content) {
33
- _sharedUtils.ColorConsole.warn(`The file '${fullName}' under the path '${path}' has no content `);
34
- return [];
35
- }
36
- const parserResult = new _parser.XtsParser(project, _sharedUtils.ColorConsole.logger).parser(content.toString(), fullName);
37
- const {
38
- ast,
39
- mapList
40
- } = new _parser.XtsToTypescript(project, _sharedUtils.ColorConsole.logger, this.context, path).translate(parserResult.ast, parserResult.offsetList);
41
- const {
42
- code,
43
- sourcemap
44
- } = new _generator.TypescriptGenerator().generate({
45
- sourceFilePath: fullName,
46
- targetFilePath: newFileName,
47
- ast,
48
- mapList
49
- });
50
- resultFiles.push({
51
- path: _sharedUtils.FileUtil.updateFileName(path, newFileName),
52
- content: code
53
- }, {
54
- path: _sharedUtils.FileUtil.updateFileName(path, `${name}.map.ts`),
55
- content: sourcemap
56
- });
57
- }
58
- // 返回内容
59
- return resultFiles;
60
- }
61
- }
62
- var _default = exports.default = XtsLoader;
@@ -1,10 +0,0 @@
1
- declare class XtsFileLaneUtils {
2
- /**
3
- * 将buildPath文件夹的内容压缩成zip包,放置于targetPath路径下
4
- * @param buildPath
5
- * @param targetPath
6
- * @param zipRootDirNames 可自定义压缩包内最外层目录的名称
7
- */
8
- static zipProject(buildPath: string[], targetFile: string, zipRootDirNames?: string[]): Promise<void>;
9
- }
10
- export default XtsFileLaneUtils;
@@ -1,61 +0,0 @@
1
- "use strict";
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 _archiver = _interopRequireDefault(require("archiver"));
9
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
10
- var _path = _interopRequireDefault(require("path"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- class XtsFileLaneUtils {
13
- /**
14
- * 将buildPath文件夹的内容压缩成zip包,放置于targetPath路径下
15
- * @param buildPath
16
- * @param targetPath
17
- * @param zipRootDirNames 可自定义压缩包内最外层目录的名称
18
- */
19
- static async zipProject(buildPath, targetFile, zipRootDirNames) {
20
- return new Promise((resolve, reject) => {
21
- const output = _fsExtra.default.createWriteStream(targetFile);
22
- const archive = _archiver.default.create('zip', {
23
- zlib: {
24
- level: 9
25
- }
26
- });
27
- // 监听错误
28
- archive.on('error', err => {
29
- _sharedUtils.ColorConsole.throw(`${err.message}`);
30
- output.close();
31
- reject();
32
- });
33
- // 监听写入流打开的事件
34
- output.on('open', () => {
35
- _sharedUtils.ColorConsole.info(`Write stream is open`);
36
- });
37
- output.on('close', () => {
38
- _sharedUtils.ColorConsole.info(`Write stream is closed`);
39
- resolve();
40
- });
41
- // 将压缩文件导入到输出流中
42
- archive.pipe(output);
43
-
44
- // 指定压缩目录
45
- buildPath.forEach((folder, index) => {
46
- const folderName = _path.default.basename(folder); // 获取文件夹名
47
- if (zipRootDirNames && zipRootDirNames[index]) {
48
- archive.directory(folder, zipRootDirNames[index]);
49
- } else {
50
- archive.directory(folder, folderName);
51
- }
52
- });
53
- archive.on('finish', () => {
54
- _sharedUtils.ColorConsole.info('finish');
55
- });
56
- // 完成压缩,关闭输出流
57
- archive.finalize();
58
- });
59
- }
60
- }
61
- var _default = exports.default = XtsFileLaneUtils;
@@ -1,34 +0,0 @@
1
- import { IFileLaneContext } from 'file-lane';
2
- export interface DefaultZipProjectOptions {
3
- tarDir?: string;
4
- ext?: string;
5
- packageName: string;
6
- }
7
- /**
8
- * XtsFollowWorks
9
- */
10
- declare class XtsFollowWorks {
11
- /**
12
- * 将项目中build文件夹的内容压缩成zip包,并将压缩产物放到dist文件夹下
13
- * @param context
14
- */
15
- static defaultZipProject(context: IFileLaneContext, options: DefaultZipProjectOptions): Promise<void>;
16
- /**
17
- * 将分布式项目按照manifest.json中的配置打包,思路如下:
18
- * 1. 获取manifest中aspect的路由配置
19
- * 2. 对aspects中的所有路由信息进行遍历
20
- * 3. 按照设备(设备+rule)对aspect分类
21
- * 4. 按照设备列表分别进行打包
22
- * @param context
23
- */
24
- static zipDistributedQuickApp(context: IFileLaneContext): Promise<void>;
25
- /**
26
- * 根据项目路径,打包文件夹名和传入的压缩包名,生成压缩文件zip路径
27
- * @param projectPath
28
- * @param outputDir
29
- * @param zipName
30
- * @returns
31
- */
32
- static getFilePath(projectPath: string, outputDir?: string, zipName?: string, ext?: string): string;
33
- }
34
- export default XtsFollowWorks;
@@ -1,134 +0,0 @@
1
- "use strict";
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 _path = _interopRequireDefault(require("path"));
10
- var _UxFileUtils = _interopRequireDefault(require("./../ux/UxFileUtils"));
11
- var _XtsFileLaneUtils = _interopRequireDefault(require("../../utils/xts/XtsFileLaneUtils"));
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- /**
14
- * XtsFollowWorks
15
- */
16
- class XtsFollowWorks {
17
- /**
18
- * 将项目中build文件夹的内容压缩成zip包,并将压缩产物放到dist文件夹下
19
- * @param context
20
- */
21
- static async defaultZipProject(context, options) {
22
- const {
23
- projectPath
24
- } = context;
25
- const output = options.tarDir || context.output;
26
- const buildPath = _path.default.join(projectPath, output);
27
- const zipPath = _path.default.join(projectPath, 'dist');
28
- // buildPath必须是真实文件夹路径
29
- if (!_fsExtra.default.existsSync(buildPath)) {
30
- _sharedUtils.ColorConsole.throw(`buildPath: '${buildPath}' not exist`);
31
- }
32
- try {
33
- // 确认文件夹是否存在,不存在则创建
34
- _fsExtra.default.ensureDirSync(zipPath);
35
- // 清空dist文件夹
36
- _fsExtra.default.emptyDirSync(zipPath);
37
- const filePath = XtsFollowWorks.getFilePath(projectPath, 'dist', options.packageName, 'rpk');
38
- await _XtsFileLaneUtils.default.zipProject([buildPath], filePath, [options.packageName]);
39
- } catch (err) {
40
- _sharedUtils.ColorConsole.throw(`${err.message}`);
41
- }
42
- }
43
- /**
44
- * 将分布式项目按照manifest.json中的配置打包,思路如下:
45
- * 1. 获取manifest中aspect的路由配置
46
- * 2. 对aspects中的所有路由信息进行遍历
47
- * 3. 按照设备(设备+rule)对aspect分类
48
- * 4. 按照设备列表分别进行打包
49
- * @param context
50
- */
51
- static async zipDistributedQuickApp(context) {
52
- const deviceList = [{
53
- device: 'phone',
54
- aspectList: []
55
- }];
56
- const {
57
- projectPath,
58
- output
59
- } = context;
60
- const manifestPath = _UxFileUtils.default.getManifestFilePath(projectPath, 'app');
61
- if (_fsExtra.default.existsSync(manifestPath)) {
62
- //获取manifest.json内容
63
- const aspectsRule = _fsExtra.default.readJSONSync(manifestPath)?.router?.aspects;
64
- if (aspectsRule) {
65
- Object.keys(aspectsRule).forEach(aspectRule => {
66
- // 分别处理每个aspectRule数组
67
- for (let item of aspectsRule[aspectRule]) {
68
- const {
69
- devices,
70
- rule,
71
- path
72
- } = item;
73
- // 如果存在设备列表
74
- if (devices && Array.isArray(devices) && devices.length > 0) {
75
- for (let device of devices) {
76
- // 设备名与rule组合为一个设备
77
- if (rule) {
78
- device = `${device}.${rule}`;
79
- }
80
- // 查找设备是否已存在于设备列表中
81
- const index = device === 'phone' ? 0 : deviceList.findIndex(item => item.device === device);
82
- if (index === -1) {
83
- // 新设备
84
- deviceList.push({
85
- device,
86
- aspectList: [path]
87
- });
88
- } else {
89
- // 已存在的设备信息时,仅需添加aspect路由
90
- deviceList[index].aspectList.push(path);
91
- }
92
- }
93
- } else {
94
- // 设备值默认值为phone
95
- deviceList[0].aspectList.push(path);
96
- }
97
- }
98
- });
99
- }
100
- const zipPath = _path.default.join(projectPath, 'dist');
101
- _fsExtra.default.ensureDirSync(zipPath);
102
- _fsExtra.default.emptyDirSync(zipPath);
103
- // 根据deviceList进行打包
104
- for (const item of deviceList) {
105
- // 所有zip包都需要app信息
106
- item.aspectList.push('app');
107
- // 将路由转为真实路径
108
- const buildPaths = item.aspectList.map(name => _path.default.join(projectPath, output, name));
109
- const filePath = XtsFollowWorks.getFilePath(projectPath, 'dist', item.device);
110
- try {
111
- await _XtsFileLaneUtils.default.zipProject(buildPaths, filePath);
112
- } catch (error) {}
113
- }
114
- } else {
115
- _sharedUtils.ColorConsole.throw('not find manifest.json');
116
- }
117
- }
118
- /**
119
- * 根据项目路径,打包文件夹名和传入的压缩包名,生成压缩文件zip路径
120
- * @param projectPath
121
- * @param outputDir
122
- * @param zipName
123
- * @returns
124
- */
125
- static getFilePath(projectPath) {
126
- let outputDir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'dist';
127
- let zipName = arguments.length > 2 ? arguments[2] : undefined;
128
- let ext = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'zip';
129
- zipName = zipName ? `${zipName}.${ext}` : `${_path.default.basename(projectPath)}.${ext}`;
130
- const zipPath = _path.default.join(projectPath, outputDir);
131
- return _path.default.join(zipPath, zipName);
132
- }
133
- }
134
- var _default = exports.default = XtsFollowWorks;