@aiot-toolkit/aiotpack 2.0.5-beta.14 → 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.
@@ -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
@@ -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
@@ -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'
@@ -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.14",
3
+ "version": "2.0.5-beta.15",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,14 +19,14 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.5-beta.14",
23
- "@aiot-toolkit/parser": "2.0.5-beta.14",
24
- "@aiot-toolkit/shared-utils": "2.0.5-beta.14",
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
28
  "babel-loader": "^9.1.3",
29
- "file-lane": "2.0.5-beta.14",
29
+ "file-lane": "2.0.5-beta.15",
30
30
  "file-loader": "^6.2.0",
31
31
  "fs-extra": "^11.2.0",
32
32
  "hap-toolkit": "^2.0.0",
@@ -35,7 +35,6 @@
35
35
  "lodash": "^4.17.21",
36
36
  "ts-morph": "^19.0.0",
37
37
  "url-loader": "^4.1.1",
38
- "webpack": "^5.97.1",
39
38
  "webpack-bundle-analyzer": "^4.10.2",
40
39
  "webpack-sources": "^3.2.3"
41
40
  },
@@ -44,5 +43,5 @@
44
43
  "@types/jsrsasign": "^10.5.12",
45
44
  "@types/webpack-sources": "^3.2.3"
46
45
  },
47
- "gitHead": "63c6564afe9bedd9c034f03e8e457b6cfa6960ae"
46
+ "gitHead": "6e39bae7f788a36a777e08545d862b87fab26a9b"
48
47
  }