@aiot-toolkit/aiotpack 2.0.2 → 2.0.3-beta.10

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 (63) hide show
  1. package/lib/afterCompile/ux/UxAfterCompile.d.ts +1 -1
  2. package/lib/afterCompile/ux/UxAfterCompile.js +295 -243
  3. package/lib/afterCompile/xts/entryTemplate.js +111 -113
  4. package/lib/afterCompile/xts/generateRpk.js +25 -54
  5. package/lib/afterCompile/xts/ts2wasm.js +62 -63
  6. package/lib/afterWorks/ux/UxAfterWorks.js +12 -19
  7. package/lib/beforeCompile/ux/UxBeforeCompile.js +26 -28
  8. package/lib/beforeCompile/xts/preInstall.js +50 -55
  9. package/lib/beforeWorks/ux/UxBeforeWorks.js +12 -19
  10. package/lib/compiler/enum/CompileMode.js +16 -23
  11. package/lib/compiler/interface/ICompileParam.js +1 -2
  12. package/lib/compiler/interface/ICompiler.js +1 -2
  13. package/lib/compiler/interface/ISignConfig.js +1 -2
  14. package/lib/compiler/javascript/JavascriptCompiler.js +147 -154
  15. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +20 -16
  16. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +13 -11
  17. package/lib/compiler/javascript/android/plugin/WrapPlugin.js +53 -49
  18. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +1 -2
  19. package/lib/compiler/javascript/interface/IWebpackConfigurator.js +4 -1
  20. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +78 -75
  21. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +30 -41
  22. package/lib/compiler/javascript/vela/enum/EntryType.js +15 -29
  23. package/lib/compiler/javascript/vela/interface/IChunk.js +4 -1
  24. package/lib/compiler/javascript/vela/interface/IManifest.js +1 -2
  25. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js +1 -2
  26. package/lib/compiler/javascript/vela/model/Package.js +80 -51
  27. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +31 -27
  28. package/lib/compiler/javascript/vela/utils/Jsc.js +30 -33
  29. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +152 -130
  30. package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +10 -2
  31. package/lib/compiler/javascript/vela/utils/ZipUtil.js +282 -267
  32. package/lib/compiler/javascript/vela/utils/signature/Base64.js +65 -67
  33. package/lib/compiler/javascript/vela/utils/signature/CRC32.js +37 -35
  34. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +755 -731
  35. package/lib/compiler/javascript/vela/utils/signature/Signer.js +24 -22
  36. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +47 -52
  37. package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.js +21 -17
  38. package/lib/config/UxConfig.js +145 -173
  39. package/lib/config/XtsConfig.d.ts +2 -0
  40. package/lib/config/XtsConfig.js +30 -39
  41. package/lib/index.js +88 -41
  42. package/lib/interface/ICompileOptions.js +5 -2
  43. package/lib/interface/IDeviceList.js +1 -2
  44. package/lib/loader/ux/JsLoader.js +32 -30
  45. package/lib/loader/ux/PngLoader.js +47 -53
  46. package/lib/loader/ux/android/UxLoader.d.ts +2 -0
  47. package/lib/loader/ux/android/UxLoader.js +30 -32
  48. package/lib/loader/ux/vela/AppUxLoader.d.ts +2 -0
  49. package/lib/loader/ux/vela/AppUxLoader.js +23 -25
  50. package/lib/loader/ux/vela/HmlLoader.js +59 -55
  51. package/lib/loader/ux/vela/UxLoader.d.ts +2 -0
  52. package/lib/loader/ux/vela/UxLoader.js +29 -37
  53. package/lib/loader/xts/XtsLoader.js +55 -41
  54. package/lib/utils/BeforeCompileUtils.js +100 -95
  55. package/lib/utils/PngUtils.js +42 -36
  56. package/lib/utils/ux/ManifestSchema.js +198 -194
  57. package/lib/utils/ux/UxFileUtils.d.ts +3 -3
  58. package/lib/utils/ux/UxFileUtils.js +130 -125
  59. package/lib/utils/ux/UxLoaderUtils.js +292 -307
  60. package/lib/utils/ux/android/AndroidUx.js +88 -90
  61. package/lib/utils/xts/XtsFileLaneUtils.js +58 -65
  62. package/lib/utils/xts/XtsFollowWorks.js +122 -129
  63. package/package.json +6 -6
@@ -1,98 +1,96 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const parser_1 = require("@aiot-toolkit/parser");
16
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
17
- const UxToTypescript_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/android/UxToTypescript"));
18
- const generator_1 = require("@aiot-toolkit/generator");
19
- const path_1 = __importDefault(require("path"));
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _parser = require("@aiot-toolkit/parser");
8
+ var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
+ var _UxToTypescript = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/translate/android/UxToTypescript"));
10
+ var _generator = require("@aiot-toolkit/generator");
11
+ var _path = _interopRequireDefault(require("path"));
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
13
  /**
21
14
  * AndroidUx
22
15
  */
23
16
  class AndroidUx {
24
- /**
25
- *
26
- * 编译 ux 文件
27
- * 1. 获取文件类型:app page 普通ux
28
- * 2. 使用`UxParse`解析
29
- * 3. 使用`UxToTypeScript`转换
30
- * 4. 使用`TypeScriptGenerator`生成
31
- * @param params
32
- */
33
- compileUx(params) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const { context, file, compilerOption } = params;
36
- const { path: filePath, content } = file;
37
- const { projectPath } = context;
38
- const fileType = this.getFileType(filePath, context);
39
- // 无内容的文件,添加空内容警告
40
- if (!content) {
41
- return {
42
- files: [],
43
- logs: [
44
- {
45
- level: shared_utils_1.Loglevel.WARN,
46
- message: `${filePath} is empty`,
47
- filePath
48
- }
49
- ]
50
- };
51
- }
52
- const logs = [];
53
- const option = {
54
- filePath,
55
- projectPath,
56
- projectType: shared_utils_1.ProjectType.ANDDROID_UX,
57
- fileType,
58
- onLog: function (log) {
59
- logs.push(log);
60
- },
61
- content: content.toString()
62
- };
63
- const uxAst = yield new parser_1.UxParser(option, compilerOption, {}, (path) => path).parser();
64
- const tsAst = yield new UxToTypescript_1.default(option, compilerOption, context).translate(uxAst.ast, uxAst.offsetList || []);
65
- const filePathParse = path_1.default.parse(filePath);
66
- const code = new generator_1.TypescriptGenerator().generate({
67
- sourceFilePath: filePathParse.base,
68
- targetFilePath: `${filePathParse.name}.js`,
69
- ast: tsAst.targetTree,
70
- mapList: tsAst.mapList
71
- });
72
- return {
73
- files: [
74
- {
75
- path: filePath,
76
- content: code.code
77
- },
78
- {
79
- path: `${filePathParse.dir}/${filePathParse.base}.map`,
80
- content: code.sourcemap
81
- }
82
- // resource todo
83
- ],
84
- logs
85
- };
86
- });
17
+ /**
18
+ *
19
+ * 编译 ux 文件
20
+ * 1. 获取文件类型:app page 普通ux
21
+ * 2. 使用`UxParse`解析
22
+ * 3. 使用`UxToTypeScript`转换
23
+ * 4. 使用`TypeScriptGenerator`生成
24
+ * @param params
25
+ */
26
+ async compileUx(params) {
27
+ const {
28
+ context,
29
+ file,
30
+ compilerOption
31
+ } = params;
32
+ const {
33
+ path: filePath,
34
+ content
35
+ } = file;
36
+ const {
37
+ projectPath
38
+ } = context;
39
+ const fileType = this.getFileType(filePath, context);
40
+
41
+ // 无内容的文件,添加空内容警告
42
+ if (!content) {
43
+ return {
44
+ files: [],
45
+ logs: [{
46
+ level: _sharedUtils.Loglevel.WARN,
47
+ message: `${filePath} is empty`,
48
+ filePath
49
+ }]
50
+ };
87
51
  }
88
- getFileType(filePath, context) {
89
- const { entries } = context;
90
- if (path_1.default.basename(filePath) === 'app.ux') {
91
- return 'app';
92
- }
93
- else if (entries.includes(filePath)) {
94
- return 'page';
95
- }
52
+ const logs = [];
53
+ const option = {
54
+ filePath,
55
+ projectPath,
56
+ projectType: _sharedUtils.ProjectType.ANDDROID_UX,
57
+ fileType,
58
+ onLog: function (log) {
59
+ logs.push(log);
60
+ },
61
+ content: content.toString()
62
+ };
63
+ const uxAst = await new _parser.UxParser(option, compilerOption, {}, path => path).parser();
64
+ const tsAst = await new _UxToTypescript.default(option, compilerOption, context).translate(uxAst.ast, uxAst.offsetList || []);
65
+ const filePathParse = _path.default.parse(filePath);
66
+ const code = new _generator.TypescriptGenerator().generate({
67
+ sourceFilePath: filePathParse.base,
68
+ targetFilePath: `${filePathParse.name}.js`,
69
+ ast: tsAst.targetTree,
70
+ mapList: tsAst.mapList
71
+ });
72
+ return {
73
+ files: [{
74
+ path: filePath,
75
+ content: code.code
76
+ }, {
77
+ path: `${filePathParse.dir}/${filePathParse.base}.map`,
78
+ content: code.sourcemap
79
+ }
80
+ // resource todo
81
+ ],
82
+ logs
83
+ };
84
+ }
85
+ getFileType(filePath, context) {
86
+ const {
87
+ entries
88
+ } = context;
89
+ if (_path.default.basename(filePath) === 'app.ux') {
90
+ return 'app';
91
+ } else if (entries.includes(filePath)) {
92
+ return 'page';
96
93
  }
94
+ }
97
95
  }
98
- exports.default = AndroidUx;
96
+ var _default = exports.default = AndroidUx;
@@ -1,68 +1,61 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
- const archiver_1 = __importDefault(require("archiver"));
17
- const fs_extra_1 = __importDefault(require("fs-extra"));
18
- const path_1 = __importDefault(require("path"));
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 }; }
19
12
  class XtsFileLaneUtils {
20
- /**
21
- * 将buildPath文件夹的内容压缩成zip包,放置于targetPath路径下
22
- * @param buildPath
23
- * @param targetPath
24
- * @param zipRootDirNames 可自定义压缩包内最外层目录的名称
25
- */
26
- static zipProject(buildPath, targetFile, zipRootDirNames) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- return new Promise((resolve, reject) => {
29
- const output = fs_extra_1.default.createWriteStream(targetFile);
30
- const archive = archiver_1.default.create('zip', {
31
- zlib: { level: 9 }
32
- });
33
- // 监听错误
34
- archive.on('error', (err) => {
35
- shared_utils_1.ColorConsole.throw(`${err.message}`);
36
- output.close();
37
- reject();
38
- });
39
- // 监听写入流打开的事件
40
- output.on('open', () => {
41
- shared_utils_1.ColorConsole.info(`Write stream is open`);
42
- });
43
- output.on('close', () => {
44
- shared_utils_1.ColorConsole.info(`Write stream is closed`);
45
- resolve();
46
- });
47
- // 将压缩文件导入到输出流中
48
- archive.pipe(output);
49
- // 指定压缩目录
50
- buildPath.forEach((folder, index) => {
51
- const folderName = path_1.default.basename(folder); // 获取文件夹名
52
- if (zipRootDirNames && zipRootDirNames[index]) {
53
- archive.directory(folder, zipRootDirNames[index]);
54
- }
55
- else {
56
- archive.directory(folder, folderName);
57
- }
58
- });
59
- archive.on('finish', () => {
60
- shared_utils_1.ColorConsole.info('finish');
61
- });
62
- // 完成压缩,关闭输出流
63
- archive.finalize();
64
- });
65
- });
66
- }
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
+ }
67
60
  }
68
- exports.default = XtsFileLaneUtils;
61
+ var _default = exports.default = XtsFileLaneUtils;
@@ -1,141 +1,134 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
- const fs_extra_1 = __importDefault(require("fs-extra"));
17
- const path_1 = __importDefault(require("path"));
18
- const UxFileUtils_1 = __importDefault(require("./../ux/UxFileUtils"));
19
- const XtsFileLaneUtils_1 = __importDefault(require("../../utils/xts/XtsFileLaneUtils"));
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 }; }
20
13
  /**
21
14
  * XtsFollowWorks
22
15
  */
23
16
  class XtsFollowWorks {
24
- /**
25
- * 将项目中build文件夹的内容压缩成zip包,并将压缩产物放到dist文件夹下
26
- * @param context
27
- */
28
- static defaultZipProject(context, options) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- const { projectPath } = context;
31
- const output = options.tarDir || context.output;
32
- const buildPath = path_1.default.join(projectPath, output);
33
- const zipPath = path_1.default.join(projectPath, 'dist');
34
- // buildPath必须是真实文件夹路径
35
- if (!fs_extra_1.default.existsSync(buildPath)) {
36
- shared_utils_1.ColorConsole.throw(`buildPath: '${buildPath}' not exist`);
37
- }
38
- try {
39
- // 确认文件夹是否存在,不存在则创建
40
- fs_extra_1.default.ensureDirSync(zipPath);
41
- // 清空dist文件夹
42
- fs_extra_1.default.emptyDirSync(zipPath);
43
- const filePath = XtsFollowWorks.getFilePath(projectPath, 'dist', options.packageName, 'rpk');
44
- yield XtsFileLaneUtils_1.default.zipProject([buildPath], filePath, [options.packageName]);
45
- }
46
- catch (err) {
47
- shared_utils_1.ColorConsole.throw(`${err.message}`);
48
- }
49
- });
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`);
50
31
  }
51
- /**
52
- * 将分布式项目按照manifest.json中的配置打包,思路如下:
53
- * 1. 获取manifest中aspect的路由配置
54
- * 2. 对aspects中的所有路由信息进行遍历
55
- * 3. 按照设备(设备+rule)对aspect分类
56
- * 4. 按照设备列表分别进行打包
57
- * @param context
58
- */
59
- static zipDistributedQuickApp(context) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- var _a, _b;
62
- const deviceList = [
63
- {
64
- device: 'phone',
65
- aspectList: []
66
- }
67
- ];
68
- const { projectPath, output } = context;
69
- const manifestPath = UxFileUtils_1.default.getManifestFilePath(projectPath, 'app');
70
- if (fs_extra_1.default.existsSync(manifestPath)) {
71
- //获取manifest.json内容
72
- const aspectsRule = (_b = (_a = fs_extra_1.default.readJSONSync(manifestPath)) === null || _a === void 0 ? void 0 : _a.router) === null || _b === void 0 ? void 0 : _b.aspects;
73
- if (aspectsRule) {
74
- Object.keys(aspectsRule).forEach((aspectRule) => {
75
- // 分别处理每个aspectRule数组
76
- for (let item of aspectsRule[aspectRule]) {
77
- const { devices, rule, path } = item;
78
- // 如果存在设备列表
79
- if (devices && Array.isArray(devices) && devices.length > 0) {
80
- for (let device of devices) {
81
- // 设备名与rule组合为一个设备
82
- if (rule) {
83
- device = `${device}.${rule}`;
84
- }
85
- // 查找设备是否已存在于设备列表中
86
- const index = device === 'phone' ? 0 : deviceList.findIndex((item) => item.device === device);
87
- if (index === -1) {
88
- // 新设备
89
- deviceList.push({
90
- device,
91
- aspectList: [path]
92
- });
93
- }
94
- else {
95
- // 已存在的设备信息时,仅需添加aspect路由
96
- deviceList[index].aspectList.push(path);
97
- }
98
- }
99
- }
100
- else {
101
- // 设备值默认值为phone
102
- deviceList[0].aspectList.push(path);
103
- }
104
- }
105
- });
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}`;
106
79
  }
107
- const zipPath = path_1.default.join(projectPath, 'dist');
108
- fs_extra_1.default.ensureDirSync(zipPath);
109
- fs_extra_1.default.emptyDirSync(zipPath);
110
- // 根据deviceList进行打包
111
- for (const item of deviceList) {
112
- // 所有zip包都需要app信息
113
- item.aspectList.push('app');
114
- // 将路由转为真实路径
115
- const buildPaths = item.aspectList.map((name) => path_1.default.join(projectPath, output, name));
116
- const filePath = XtsFollowWorks.getFilePath(projectPath, 'dist', item.device);
117
- try {
118
- yield XtsFileLaneUtils_1.default.zipProject(buildPaths, filePath);
119
- }
120
- catch (error) { }
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);
121
91
  }
92
+ }
93
+ } else {
94
+ // 设备值默认值为phone
95
+ deviceList[0].aspectList.push(path);
122
96
  }
123
- else {
124
- shared_utils_1.ColorConsole.throw('not find manifest.json');
125
- }
97
+ }
126
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');
127
116
  }
128
- /**
129
- * 根据项目路径,打包文件夹名和传入的压缩包名,生成压缩文件zip路径
130
- * @param projectPath
131
- * @param outputDir
132
- * @param zipName
133
- * @returns
134
- */
135
- static getFilePath(projectPath, outputDir = 'dist', zipName, ext = 'zip') {
136
- zipName = zipName ? `${zipName}.${ext}` : `${path_1.default.basename(projectPath)}.${ext}`;
137
- const zipPath = path_1.default.join(projectPath, outputDir);
138
- return path_1.default.join(zipPath, zipName);
139
- }
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
+ }
140
133
  }
141
- exports.default = XtsFollowWorks;
134
+ var _default = exports.default = XtsFollowWorks;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.2",
3
+ "version": "2.0.3-beta.10",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,16 +19,16 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.2",
23
- "@aiot-toolkit/parser": "2.0.2",
24
- "@aiot-toolkit/shared-utils": "2.0.2",
22
+ "@aiot-toolkit/generator": "2.0.3-beta.10",
23
+ "@aiot-toolkit/parser": "2.0.3-beta.10",
24
+ "@aiot-toolkit/shared-utils": "2.0.3-beta.10",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
26
  "@rspack/core": "^1.0.0",
27
27
  "aiot-parse5": "^1.0.0",
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.2",
31
+ "file-lane": "2.0.3-beta.10",
32
32
  "file-loader": "^6.2.0",
33
33
  "fs-extra": "^11.2.0",
34
34
  "jsrsasign": "^11.1.0",
@@ -45,5 +45,5 @@
45
45
  "@types/jsrsasign": "^10.5.12",
46
46
  "@types/webpack-sources": "^3.2.3"
47
47
  },
48
- "gitHead": "8ca4bf2ed7bcf11911e5c514696951bdba4fc12d"
48
+ "gitHead": "e591934b19bc474453ce11b63f0c8bb0d8eb8bd9"
49
49
  }