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

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.
@@ -39,5 +39,21 @@ declare class UxAfterCompile {
39
39
  * @param compilerOption
40
40
  */
41
41
  static symlinkNodeModule: FollowWork<IJavascriptCompileOption>;
42
+ /**
43
+ * 编译轻卡ux
44
+ * 1. 使用hap-toolkit编译项目,编译结果存储在build文件夹
45
+ * 1.1 重写stdout以捕获hap-toolkit中的正常日志,错误日志正常输出
46
+ * 1.2 使用hap-toolkit编译项目
47
+ * 1.3 还原stdout
48
+ * 2. 取widgets中配置的轻卡内容,将build文件夹中对应的产物复制到临时文件夹
49
+ * @param params
50
+ */
51
+ static compileLiteCard: FollowWork<IJavascriptCompileOption>;
52
+ /**
53
+ * 检查资源文件
54
+ * 1. 检查文件体积是否过大, 如果超出,则提示到真机验证
55
+ * @param params
56
+ */
57
+ static resourceCheck: FollowWork<IJavascriptCompileOption>;
42
58
  }
43
59
  export default UxAfterCompile;
@@ -16,8 +16,10 @@ 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");
19
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
21
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
22
+ const HapToolkit = require('hap-toolkit');
21
23
 
22
24
  /**
23
25
  * UxAfterCompile
@@ -361,5 +363,104 @@ class UxAfterCompile {
361
363
  throw new Error(`${error?.toString() || 'unknown error'}. Please check whether the file system of the current disk supports the creation of soft links.`);
362
364
  }
363
365
  };
366
+ /**
367
+ * 编译轻卡ux
368
+ * 1. 使用hap-toolkit编译项目,编译结果存储在build文件夹
369
+ * 1.1 重写stdout以捕获hap-toolkit中的正常日志,错误日志正常输出
370
+ * 1.2 使用hap-toolkit编译项目
371
+ * 1.3 还原stdout
372
+ * 2. 取widgets中配置的轻卡内容,将build文件夹中对应的产物复制到临时文件夹
373
+ * @param params
374
+ */
375
+ static compileLiteCard = async params => {
376
+ const {
377
+ config,
378
+ compilerOption,
379
+ context
380
+ } = params;
381
+ try {
382
+ if (context?.liteCards?.length > 0 && compilerOption) {
383
+ const {
384
+ projectPath,
385
+ outputPath
386
+ } = compilerOption;
387
+ const LITE_OUTPUT_PATH = outputPath;
388
+ // 1.1
389
+ const originalStdout = _process.stdout.write;
390
+ _process.stdout.write = function () {
391
+ return true;
392
+ };
393
+ // 1.2
394
+ await HapToolkit.compile('native', 'dev', false, {
395
+ cwd: config.projectPath,
396
+ signMode: 'BUILD',
397
+ enableCustomComponent: true
398
+ });
399
+ // 1.3
400
+ _process.stdout.write = originalStdout;
401
+ // 2.
402
+ context.liteCards.forEach(card => {
403
+ // hap-toolkit的产物在项目的build文件夹下
404
+ const fromPath = _path.default.join(config.projectPath, LITE_OUTPUT_PATH, card);
405
+ // aiot-toolkit的产物在临时项目的build文件夹下
406
+ const toPath = _path.default.join(projectPath, LITE_OUTPUT_PATH, card);
407
+ //确定目标目录存在,若不存在则创建到父目录
408
+ _fsExtra.default.ensureDirSync(_path.default.dirname(toPath));
409
+ // 复制文件
410
+ _fsExtra.default.moveSync(fromPath + '.template.json', toPath + '.template.json', {
411
+ overwrite: true
412
+ });
413
+ _fsExtra.default.moveSync(fromPath + '.css.json', toPath + '.css.json', {
414
+ overwrite: true
415
+ });
416
+ });
417
+ }
418
+ } catch (error) {
419
+ throw new Error(`compile lite card error, ${error?.toString() || 'unknown error'}.`);
420
+ }
421
+ };
422
+ /**
423
+ * 检查资源文件
424
+ * 1. 检查文件体积是否过大, 如果超出,则提示到真机验证
425
+ * @param params
426
+ */
427
+ static resourceCheck = async params => {
428
+ const {
429
+ context,
430
+ compilerOption,
431
+ onLog
432
+ } = params;
433
+ if (!compilerOption) {
434
+ return;
435
+ }
436
+
437
+ // 最大值,单位KB
438
+ const MAX_SIZE = 1024;
439
+ const {
440
+ projectPath
441
+ } = context;
442
+ const {
443
+ outputPath
444
+ } = compilerOption;
445
+ const fileList = _sharedUtils.FileUtil.readAlldirSync(_path.default.join(projectPath, outputPath));
446
+ const largeFileList = fileList.filter(item => {
447
+ const status = _fsExtra.default.statSync(item);
448
+ return status.size > MAX_SIZE * 1024;
449
+ });
450
+ if (largeFileList.length) {
451
+ const logs = [];
452
+ logs.push({
453
+ level: _sharedUtils.Loglevel.WARN,
454
+ message: [`the following files is large than`, {
455
+ word: `${MAX_SIZE}KB`
456
+ }, `, please check on the`, {
457
+ word: `real device\r\n`
458
+ }, {
459
+ word: largeFileList.map((item, index) => `${index + 1}. ${item}`).join('\r\n ')
460
+ }]
461
+ });
462
+ onLog?.(logs);
463
+ }
464
+ };
364
465
  }
365
466
  var _default = exports.default = UxAfterCompile;
@@ -1,4 +1,13 @@
1
1
  import { Dictionary } from '@aiot-toolkit/shared-utils';
2
+ export declare const LITE_CARD_TYPE = "lite";
3
+ interface IWidget {
4
+ name: string;
5
+ component: string;
6
+ minCardPlatformVersion: Number;
7
+ providerUri: string;
8
+ sizes: string[];
9
+ type?: string;
10
+ }
2
11
  /**
3
12
  * vela manifest文件对应的数据结构
4
13
  */
@@ -16,6 +25,7 @@ export default interface IManifest {
16
25
  designWidth?: string | number;
17
26
  };
18
27
  router: {
28
+ widgets?: Record<string, IWidget>;
19
29
  entry: string;
20
30
  pages: Dictionary<{
21
31
  component?: string;
@@ -28,3 +38,4 @@ export default interface IManifest {
28
38
  export interface IFeatures {
29
39
  name: string;
30
40
  }
41
+ export {};
@@ -1 +1,11 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LITE_CARD_TYPE = void 0;
7
+ const LITE_CARD_TYPE = exports.LITE_CARD_TYPE = 'lite';
8
+
9
+ /**
10
+ * vela manifest文件对应的数据结构
11
+ */
@@ -8,6 +8,7 @@ var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
8
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
9
  var _path = _interopRequireDefault(require("path"));
10
10
  var _EntryType = _interopRequireDefault(require("../enum/EntryType"));
11
+ var _IManifest = require("../interface/IManifest");
11
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
13
  class UxCompileUtil {
13
14
  // 摘要文件夹
@@ -80,6 +81,10 @@ class UxCompileUtil {
80
81
  throw new Error(`Compilation failed: please confirm that '${routePath}' configured by router.pages in manifest.json is the directory name`);
81
82
  }
82
83
  const conf = confs[routePath];
84
+ //轻卡无需打包
85
+ if (conf.type === _IManifest.LITE_CARD_TYPE) {
86
+ return;
87
+ }
83
88
  const entryKey = _path.default.join(routePath, conf.component);
84
89
  const filePath = this.resolveFile(_path.default.join(codeDir, entryKey));
85
90
  if (!filePath) {
@@ -89,6 +89,9 @@ class UxConfig {
89
89
  }, {
90
90
  worker: _UxAfterCompile.default.protobuf,
91
91
  workerDescribe: 'Generate protobuf json'
92
+ }, {
93
+ worker: _UxAfterCompile.default.compileLiteCard,
94
+ workerDescribe: 'compile lite card'
92
95
  }, {
93
96
  worker: _UxAfterCompile.default.toRpk,
94
97
  workerDescribe: 'Package the project into an RPK file'
@@ -98,6 +101,9 @@ class UxConfig {
98
101
  }, {
99
102
  worker: _UxAfterCompile.default.moveBackResult,
100
103
  workerDescribe: 'Migrate temporary project'
104
+ }, {
105
+ worker: _UxAfterCompile.default.resourceCheck,
106
+ workerDescribe: 'Check resource'
101
107
  }])();
102
108
  afterWorks = (() => [_UxAfterWorks.default.cleanOutput])();
103
109
  watchIgnores = [/node_modules/, /build/, /dist/];
@@ -5,11 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _UxLoaderUtils = _interopRequireDefault(require("../../../utils/ux/UxLoaderUtils"));
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _parser = require("@aiot-toolkit/parser");
8
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
11
  class UxLoader {
10
12
  async parser(files) {
11
13
  const resultFiles = [];
14
+ const liteCardList = this.context.liteCards?.map(item => _path.default.join(this.context.projectPath, this.compilerOption.sourceRoot, `${item}${_parser.ExtensionConfig.UX}`)) || [];
12
15
  for (const file of files) {
16
+ // 轻卡ux不转换
17
+ if (liteCardList.includes(file.path)) {
18
+ continue;
19
+ }
13
20
  // 转换每个文件
14
21
  const {
15
22
  files: compiledFiles,
@@ -6,6 +6,8 @@ import IJavascriptCompileOption from '../compiler/javascript/interface/IJavascri
6
6
  declare class BeforeCompileUtils {
7
7
  /**
8
8
  * 获取ux项目的路由入口
9
+ * context.entries中存放ux页面路由
10
+ * context.liteCards中存放轻卡路由
9
11
  * @param context
10
12
  * @param fileList
11
13
  * @returns
@@ -10,6 +10,7 @@ var _fsExtra = _interopRequireDefault(require("fs-extra"));
10
10
  var _path = _interopRequireDefault(require("path"));
11
11
  var _TranslateCache = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/TranslateCache"));
12
12
  var _UxFileUtils = _interopRequireDefault(require("./ux/UxFileUtils"));
13
+ var _IManifest = require("../compiler/javascript/vela/interface/IManifest");
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
15
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
15
16
 
@@ -19,6 +20,8 @@ const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobu
19
20
  class BeforeCompileUtils {
20
21
  /**
21
22
  * 获取ux项目的路由入口
23
+ * context.entries中存放ux页面路由
24
+ * context.liteCards中存放轻卡路由
22
25
  * @param context
23
26
  * @param fileList
24
27
  * @returns
@@ -34,14 +37,17 @@ class BeforeCompileUtils {
34
37
  const srcPath = _path.default.join(projectPath, compilerOption.sourceRoot);
35
38
  // 判断路径是否真实存在
36
39
  const manifestContent = _UxFileUtils.default.getManifestInfo(projectPath);
37
- // 存储entries
40
+ // 存储页面entries
38
41
  let entryList = [];
42
+ // 存储轻卡路由
43
+ let liteCardList = [];
39
44
  const {
40
45
  router
41
46
  } = manifestContent;
42
47
  if (router) {
43
48
  const {
44
- pages
49
+ pages,
50
+ widgets
45
51
  } = router;
46
52
  if (pages) {
47
53
  Object.keys(pages).map(page => {
@@ -60,11 +66,27 @@ class BeforeCompileUtils {
60
66
  // 没有pages配置
61
67
  _sharedUtils.ColorConsole.throw(`### manifest ### No pages configuration`);
62
68
  }
69
+ //获取轻卡路由
70
+ if (widgets) {
71
+ Object.keys(widgets).map(card => {
72
+ const cardContent = widgets[card];
73
+ if (cardContent.type === _IManifest.LITE_CARD_TYPE) {
74
+ const cardPath = _path.default.join(srcPath, card, cardContent.component + _parser.ExtensionConfig.UX);
75
+ if (_fsExtra.default.existsSync(cardPath)) {
76
+ liteCardList.push(card + _path.default.posix.sep + cardContent.component);
77
+ } else {
78
+ // 报错
79
+ _sharedUtils.ColorConsole.throw(`### manifest ### lite card path '${cardPath}' does not exist`);
80
+ }
81
+ }
82
+ });
83
+ }
63
84
  } else {
64
85
  // 没有router配置
65
86
  _sharedUtils.ColorConsole.throw(`### manifest ### No router configuration`);
66
87
  }
67
88
  context['entries'] = entryList;
89
+ context['liteCards'] = liteCardList;
68
90
  return Promise.resolve();
69
91
  };
70
92
  static clean = async params => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.5-beta.10",
3
+ "version": "2.0.5-beta.13",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,18 +19,19 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.5-beta.10",
23
- "@aiot-toolkit/parser": "2.0.5-beta.10",
24
- "@aiot-toolkit/shared-utils": "2.0.5-beta.10",
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",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
26
  "@rspack/core": "^1.1.8",
27
27
  "aiot-parse5": "^1.0.2",
28
28
  "archiver": "^7.0.1",
29
29
  "babel-loader": "^9.1.3",
30
30
  "fast-glob": "^3.3.2",
31
- "file-lane": "2.0.5-beta.10",
31
+ "file-lane": "2.0.5-beta.13",
32
32
  "file-loader": "^6.2.0",
33
33
  "fs-extra": "^11.2.0",
34
+ "hap-toolkit": "^2.0.0",
34
35
  "jsrsasign": "^11.1.0",
35
36
  "jszip": "^3.10.1",
36
37
  "lodash": "^4.17.21",
@@ -46,5 +47,5 @@
46
47
  "@types/jsrsasign": "^10.5.12",
47
48
  "@types/webpack-sources": "^3.2.3"
48
49
  },
49
- "gitHead": "b2403dbd071d5a6ae33b27f49c6f47ba95861477"
50
+ "gitHead": "45bca4420e8a8708733eccea32bf928b4821f4d5"
50
51
  }