@aiot-toolkit/emulator 2.0.2-beta.11 → 2.0.2-beta.12

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.
@@ -20,5 +20,9 @@ declare class VelaAvdCls {
20
20
  getVelaAvdList(): IAvdParams[];
21
21
  /** 获取模拟器皮肤列表 */
22
22
  getVelaSkinList(): string[];
23
+ /** 自定义模拟器的镜像目录 */
24
+ customImageDir(avdName: string, target: string): void;
25
+ /** 重置自定义的镜像目录 */
26
+ resetImageDir(avdName: string): void;
23
27
  }
24
28
  export default VelaAvdCls;
package/lib/avd/index.js CHANGED
@@ -7,6 +7,7 @@ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const path_1 = __importDefault(require("path"));
10
+ const ini_1 = require("ini");
10
11
  const constants_1 = require("../static/constants");
11
12
  const Avd_1 = require("../typing/Avd");
12
13
  const EAvdParamsToIni = {
@@ -72,12 +73,7 @@ class VelaAvdCls {
72
73
  // 写入Vela_Virtual_Device.ini文件
73
74
  fs_1.default.writeFileSync(avdIni, nuttxAvdIniContent);
74
75
  // 写入Vela_Virtual_Device.avd/config.ini文件
75
- const fWrite = fs_1.default.createWriteStream(avdConfigIni);
76
- for (const item in configIniJson) {
77
- const line = `${item} = ${configIniJson[item]}\n`;
78
- fWrite.write(line);
79
- }
80
- fWrite.close();
76
+ fs_1.default.writeFileSync(avdConfigIni, (0, ini_1.stringify)(configIniJson));
81
77
  return true;
82
78
  }
83
79
  catch (e) {
@@ -98,22 +94,13 @@ class VelaAvdCls {
98
94
  const configIni = path_1.default.resolve(currAvdDir, 'config.ini');
99
95
  try {
100
96
  const contents = fs_1.default.readFileSync(configIni, 'utf-8');
101
- // 这里需要使用惰性匹配
102
- const archRegex = /hw.cpu.arch = ([\d\D]+?)\n/;
103
- const archMatcher = contents.match(archRegex);
104
- const heightRegex = /hw.lcd.height = ([\d\D]+?)\n/;
105
- const heightMatcher = contents.match(heightRegex);
106
- const widthRegex = /hw.lcd.width = ([\d\D]+?)\n/;
107
- const widthMatcher = contents.match(widthRegex);
108
- const skinRegex = /skin.name = ([\d\D]+?)\n/;
109
- const skinMatcher = contents.match(skinRegex);
110
- const imagePathRegex = /image.sysdir.1 = ([\d\D]+?)\n/;
111
- const imagePathMather = contents.match(imagePathRegex);
112
- archMatcher && (avdInfo.avdArch = archMatcher[1]);
113
- heightMatcher && (avdInfo.avdHeight = heightMatcher[1]);
114
- widthMatcher && (avdInfo.avdWidth = widthMatcher[1]);
115
- skinMatcher && (avdInfo.avdSkin = skinMatcher[1]);
116
- imagePathMather && (avdInfo.avdImagePath = imagePathMather[1]);
97
+ const config = (0, ini_1.parse)(contents);
98
+ avdInfo.avdArch = config['hw.cpu.arch'];
99
+ avdInfo.avdHeight = config['hw.lcd.height'];
100
+ avdInfo.avdWidth = config['hw.lcd.width'];
101
+ avdInfo.avdSkin = config['skin.name'];
102
+ avdInfo.avdImagePath = config['image.sysdir.1'];
103
+ avdInfo.customImagePath = config['image.sysdir.2'];
117
104
  return avdInfo;
118
105
  }
119
106
  catch (err) {
@@ -164,5 +151,23 @@ class VelaAvdCls {
164
151
  return [];
165
152
  }
166
153
  }
154
+ /** 自定义模拟器的镜像目录 */
155
+ customImageDir(avdName, target) {
156
+ const currAvdDir = path_1.default.resolve(this.avdHome, `${avdName}.avd`);
157
+ const configIni = path_1.default.resolve(currAvdDir, 'config.ini');
158
+ const contents = fs_1.default.readFileSync(configIni, 'utf-8');
159
+ const config = (0, ini_1.parse)(contents);
160
+ config['image.sysdir.2'] = target;
161
+ fs_1.default.writeFileSync(configIni, (0, ini_1.stringify)(config));
162
+ }
163
+ /** 重置自定义的镜像目录 */
164
+ resetImageDir(avdName) {
165
+ const currAvdDir = path_1.default.resolve(this.avdHome, `${avdName}.avd`);
166
+ const configIni = path_1.default.resolve(currAvdDir, 'config.ini');
167
+ const contents = fs_1.default.readFileSync(configIni, 'utf-8');
168
+ const config = (0, ini_1.parse)(contents);
169
+ delete config['image.sysdir.2'];
170
+ fs_1.default.writeFileSync(configIni, (0, ini_1.stringify)(config));
171
+ }
167
172
  }
168
173
  exports.default = VelaAvdCls;
@@ -125,12 +125,12 @@ class GoldfishInstance extends common_1.default {
125
125
  const emulatorBin = this.getEmulatorBinPath();
126
126
  shared_utils_1.ColorConsole.log(`### Emulator ### emulator path: ${emulatorBin}`);
127
127
  const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName);
128
- const { avdArch, avdImagePath } = avdInfo;
128
+ const { avdArch, avdImagePath, customImagePath } = avdInfo;
129
129
  shared_utils_1.ColorConsole.log(`### Emulator ### adb port: ${options.adbPort}`);
130
130
  if (!avdImagePath) {
131
131
  return shared_utils_1.ColorConsole.throw(`### Emulator ### Unable to find vela image via avd`);
132
132
  }
133
- const nuttxBinPath = path_1.default.resolve(avdImagePath, 'nuttx');
133
+ const nuttxBinPath = path_1.default.resolve(customImagePath || avdImagePath, 'nuttx');
134
134
  shared_utils_1.ColorConsole.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
135
135
  // 端口映射
136
136
  let portMappingStr = ``;
@@ -108,12 +108,12 @@ class MiwearInstance extends common_1.default {
108
108
  shared_utils_1.ColorConsole.log(`### Emulator ### emulator path: ${emulatorBin}`);
109
109
  // 获取vela镜像的绝对路径
110
110
  const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName);
111
- const { avdArch, avdImagePath } = avdInfo;
111
+ const { avdArch, avdImagePath, customImagePath } = avdInfo;
112
112
  shared_utils_1.ColorConsole.log(`### Emulator ### adb port: ${options.adbPort}`);
113
113
  if (!avdImagePath) {
114
114
  return shared_utils_1.ColorConsole.throw(`### Emulator ### Unable to find vela image via avd`);
115
115
  }
116
- const nuttxBinPath = path_1.default.resolve(avdImagePath, 'nuttx');
116
+ const nuttxBinPath = path_1.default.resolve(customImagePath || avdImagePath, 'nuttx');
117
117
  shared_utils_1.ColorConsole.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
118
118
  // 端口映射
119
119
  let portMappingStr = ``;
@@ -177,12 +177,12 @@ class OldGoldfishInstance extends common_1.default {
177
177
  shared_utils_1.ColorConsole.log(`### Emulator ### emulator path: ${emulatorBin}`);
178
178
  // 获取vela镜像的绝对路径
179
179
  const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName);
180
- const { avdArch, avdImagePath } = avdInfo;
180
+ const { avdArch, avdImagePath, customImagePath } = avdInfo;
181
181
  shared_utils_1.ColorConsole.log(`### Emulator ### adb port: ${options.adbPort}`);
182
182
  if (!avdImagePath) {
183
183
  return shared_utils_1.ColorConsole.throw(`### Emulator ### Unable to find vela image via avd`);
184
184
  }
185
- const nuttxBinPath = path_1.default.resolve(avdImagePath, 'nuttx');
185
+ const nuttxBinPath = path_1.default.resolve(customImagePath || avdImagePath, 'nuttx');
186
186
  shared_utils_1.ColorConsole.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
187
187
  // 端口映射,adb端口和debug端口
188
188
  let portMappingStr = `user,id=u1,hostfwd=tcp:127.0.0.1:${options.adbPort}-10.0.2.15:5555`;
@@ -10,8 +10,8 @@
10
10
  "hw.arc": false,
11
11
  "hw.audioInput": "yes",
12
12
  "hw.battery": "yes",
13
- "hw.camera.back": "virtualscene",
14
- "hw.camera.front": "emulated",
13
+ "hw.camera.back": "None",
14
+ "hw.camera.front": "None",
15
15
  "hw.cpu.arch": "arm",
16
16
  "hw.cpu.ncore": 4,
17
17
  "hw.dPad": "no",
@@ -36,4 +36,4 @@
36
36
  "skin.dynamic": "no",
37
37
  "skin.name": "",
38
38
  "skin.path": ""
39
- }
39
+ }
@@ -8,10 +8,17 @@ export declare const defaultToolsHome: string;
8
8
  export declare const defaultVncPort = 5900;
9
9
  export declare const defaultAdbPort = 5555;
10
10
  export declare const defaultDebugPort = 10055;
11
+ /**
12
+ * vela-release-4.0 : vela 4.0 带 miwear
13
+ * vela-pre-4.0 : vela 4.0 不带 miwear
14
+ * vela-dev-0.0.4 : vela 4.0 dev 分支
15
+ */
11
16
  export declare const VelaImageVersionList: {
12
17
  label: string;
13
18
  value: string;
14
19
  time: string;
20
+ hide: boolean;
21
+ icon: null;
15
22
  }[];
16
23
  export declare const EmulatorEnvVersion: {
17
24
  name: string;
@@ -16,21 +16,45 @@ exports.defaultToolsHome = path_1.default.resolve(exports.defaultSDKHome, 'tools
16
16
  exports.defaultVncPort = 5900;
17
17
  exports.defaultAdbPort = 5555;
18
18
  exports.defaultDebugPort = 10055;
19
+ // 不确定vela镜像的发布策略,暂时需要手动更新此列表
20
+ // 0.0.2和0.0.3版本比较特殊,线上是一个nuttx文件。其他版本都是一个zip包,包含nuttx data.img和vela_source.img
21
+ /**
22
+ * vela-release-4.0 : vela 4.0 带 miwear
23
+ * vela-pre-4.0 : vela 4.0 不带 miwear
24
+ * vela-dev-0.0.4 : vela 4.0 dev 分支
25
+ */
19
26
  exports.VelaImageVersionList = [
20
27
  {
21
- label: 'vela正式版(4.0',
28
+ label: 'vela-4.0-正式版',
22
29
  value: 'vela-release-4.0',
23
- time: '2024-04-10T04:10:00'
30
+ time: '2024-07-15T15:57:00',
31
+ hide: false,
32
+ icon: null
24
33
  },
25
34
  {
26
- label: 'vela开发版(dev, 0.0.2)',
27
- value: 'vela-dev-0.0.2',
28
- time: '2023-12-04T16:31:00'
35
+ label: 'vela-4.0-测试版',
36
+ value: 'vela-pre-4.0',
37
+ time: '2024-07-151T07:07:00',
38
+ hide: false,
39
+ icon: null
40
+ },
41
+ // 废弃 0.0.2 版本
42
+ // {
43
+ // label: 'vela开发版(dev, 0.0.2)',
44
+ // value: 'vela-dev-0.0.2',
45
+ // time: '2023-12-04T16:31:00',
46
+ // },
47
+ {
48
+ label: 'vela-dev-开发版',
49
+ value: 'vela-dev-0.0.4',
50
+ time: '2024-07-12T11:12:00',
51
+ hide: true,
52
+ icon: null
29
53
  }
30
54
  ];
31
55
  exports.EmulatorEnvVersion = {
32
56
  name: '模拟器资源版本管理',
33
- emulator: '0.0.3',
57
+ emulator: '0.0.4',
34
58
  qa: '0.0.1',
35
59
  skins: '0.0.1',
36
60
  'system-images': exports.VelaImageVersionList[0].value,
@@ -14,6 +14,7 @@ export interface IAvdParams {
14
14
  avdHeight: string;
15
15
  avdSkin?: string;
16
16
  avdImagePath?: string;
17
+ customImagePath?: string;
17
18
  }
18
19
  export interface ISkinInfo {
19
20
  skinName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/emulator",
3
- "version": "2.0.2-beta.11",
3
+ "version": "2.0.2-beta.12",
4
4
  "description": "vela emulator tool.",
5
5
  "homepage": "",
6
6
  "license": "ISC",
@@ -35,14 +35,16 @@
35
35
  "emulator"
36
36
  ],
37
37
  "dependencies": {
38
- "@aiot-toolkit/aiotpack": "2.0.2-beta.11",
39
- "@aiot-toolkit/shared-utils": "2.0.2-beta.11",
38
+ "@aiot-toolkit/aiotpack": "2.0.2-beta.12",
39
+ "@aiot-toolkit/shared-utils": "2.0.2-beta.12",
40
40
  "find-process": "^1.4.7",
41
+ "fs-extra": "^11.2.0",
42
+ "ini": "^4.1.3",
41
43
  "portfinder": "^1.0.32"
42
44
  },
43
45
  "devDependencies": {
44
46
  "@types/fs-extra": "^11.0.4",
45
- "fs-extra": "^11.2.0"
47
+ "@types/ini": "^4.1.1"
46
48
  },
47
- "gitHead": "07c38dd12ba0d932c6dc1fd16fe25aaf15ab9fbb"
49
+ "gitHead": "3d2f9f8f48bb88492013d867f6eff27cb33365a0"
48
50
  }