@aiot-toolkit/emulator 2.0.2-beta.11 → 2.0.2-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.
@@ -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 = ``;
@@ -241,7 +241,8 @@ class GoldfishInstance extends common_1.default {
241
241
  const basename = path_1.default.basename(sourceRoot);
242
242
  if (os_1.default.platform() === 'win32' || this.projectPath.indexOf(' ') > 0) {
243
243
  // windows系统或者项目路径有空格:1. adb push目录;2. 在模拟器中使用mv命令重命名
244
- yield adbMiwt.execAdbCmdAsync(`adb -s ${sn} push ${sourceRoot} ${this.appRunDir}`);
244
+ // 注意 sourceRoot 中可能会有空格
245
+ yield adbMiwt.execAdbCmdAsync(`adb -s ${sn} push "${sourceRoot}" ${this.appRunDir}`);
245
246
  yield adbMiwt.execAdbCmdAsync(`adb -s ${sn} shell mv ${this.appRunDir}/${basename} ${this.appRunDir}/${appPackageName}`);
246
247
  }
247
248
  else {
@@ -11,6 +11,7 @@ declare class MiwearInstance extends CommonInstance {
11
11
  private debugSocket?;
12
12
  private reconnectCount;
13
13
  emulatorStartedFlag: RegExp;
14
+ installBol: boolean;
14
15
  constructor(params: INewGoldfishInstanceParams);
15
16
  /**
16
17
  * 1. 启动模拟器
@@ -49,6 +50,10 @@ declare class MiwearInstance extends CommonInstance {
49
50
  installRpkToAppList(rpkPath: string, targetDir: string): Promise<void>;
50
51
  /** 使用am start启动快应用 */
51
52
  launchQuickapp(): Promise<void>;
53
+ /** 命令行模式下添加重复调用防止app无法拉起
54
+ * 主要用将子进程的流输出到主进程后,由于流写入的过多可能会影响事件循环
55
+ */
56
+ pmInstallApp(maxRepeats: number, count?: number): void;
52
57
  /** 连接模拟器中的调试服务,创建debugSocket
53
58
  * 主要用于热更新时,通过debugSocket通知调试服务更新页面
54
59
  * 设置了重连机制,会重复连接8次
@@ -58,6 +58,7 @@ class MiwearInstance extends common_1.default {
58
58
  this.appPathInEmulator = '/data/quickapp/app';
59
59
  this.reconnectCount = 0;
60
60
  this.emulatorStartedFlag = /quickapp_rpk_installer_init|rpk installer init done/;
61
+ this.installBol = false;
61
62
  }
62
63
  /**
63
64
  * 1. 启动模拟器
@@ -108,12 +109,12 @@ class MiwearInstance extends common_1.default {
108
109
  shared_utils_1.ColorConsole.log(`### Emulator ### emulator path: ${emulatorBin}`);
109
110
  // 获取vela镜像的绝对路径
110
111
  const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName);
111
- const { avdArch, avdImagePath } = avdInfo;
112
+ const { avdArch, avdImagePath, customImagePath } = avdInfo;
112
113
  shared_utils_1.ColorConsole.log(`### Emulator ### adb port: ${options.adbPort}`);
113
114
  if (!avdImagePath) {
114
115
  return shared_utils_1.ColorConsole.throw(`### Emulator ### Unable to find vela image via avd`);
115
116
  }
116
- const nuttxBinPath = path_1.default.resolve(avdImagePath, 'nuttx');
117
+ const nuttxBinPath = path_1.default.resolve(customImagePath || avdImagePath, 'nuttx');
117
118
  shared_utils_1.ColorConsole.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
118
119
  // 端口映射
119
120
  let portMappingStr = ``;
@@ -165,6 +166,26 @@ class MiwearInstance extends common_1.default {
165
166
  shell: true,
166
167
  cwd: this.sdkHome
167
168
  });
169
+ // 处理origin为terminal
170
+ if (origin === 'terminal') {
171
+ process.stdout.pipe(this.goldfishProcess.stdin);
172
+ //setTimeout是为了解决window环境报错
173
+ const stdoutPipe = () => {
174
+ var _a, _b, _c, _d;
175
+ (_b = (_a = this.goldfishProcess) === null || _a === void 0 ? void 0 : _a.stdout) === null || _b === void 0 ? void 0 : _b.pipe(process.stdout);
176
+ (_d = (_c = this.goldfishProcess) === null || _c === void 0 ? void 0 : _c.stderr) === null || _d === void 0 ? void 0 : _d.pipe(process.stderr);
177
+ };
178
+ if (this.goldfishProcess.connected) {
179
+ stdoutPipe();
180
+ }
181
+ else {
182
+ setTimeout(stdoutPipe, 0);
183
+ }
184
+ //setTimeout加一层保险防止app无法拉起
185
+ setTimeout(() => {
186
+ this.pmInstallApp && this.pmInstallApp(10);
187
+ }, 10000);
188
+ }
168
189
  // 监听模拟器的退出事件
169
190
  this.goldfishProcess.on('exit', (code) => {
170
191
  shared_utils_1.ColorConsole.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
@@ -180,10 +201,14 @@ class MiwearInstance extends common_1.default {
180
201
  // 监听输出流
181
202
  (_c = (_b = this.goldfishProcess) === null || _b === void 0 ? void 0 : _b.stdout) === null || _c === void 0 ? void 0 : _c.on('data', (data) => {
182
203
  const msg = data.toString();
183
- const stdoutCb = options.stdoutCallback || console.log;
184
- stdoutCb(msg);
204
+ if (origin === 'ide') {
205
+ const stdoutCb = options.stdoutCallback || console.log;
206
+ stdoutCb(msg);
207
+ }
185
208
  // 应用安装成功,则启动它
186
209
  if (msg.match(/InstallState_Finished|install finished/)) {
210
+ if (origin === 'terminal')
211
+ this.installBol = true;
187
212
  shared_utils_1.ColorConsole.info(`### Emulator ### Install quickapp successfully`);
188
213
  this.launchQuickapp();
189
214
  }
@@ -259,6 +284,33 @@ class MiwearInstance extends common_1.default {
259
284
  adbMiwt.execAdbCmdAsync(startCmd);
260
285
  });
261
286
  }
287
+ /** 命令行模式下添加重复调用防止app无法拉起
288
+ * 主要用将子进程的流输出到主进程后,由于流写入的过多可能会影响事件循环
289
+ */
290
+ pmInstallApp(maxRepeats, count = 0) {
291
+ var _a;
292
+ const releaseDir = this.isRpk
293
+ ? path_1.default.resolve(this.projectPath, '../')
294
+ : path_1.default.resolve(this.projectPath, ((_a = this.params.compilerOption) === null || _a === void 0 ? void 0 : _a.releasePath) || 'dist');
295
+ const { package: packageName } = this.projectInfo;
296
+ const files = fs_extra_1.default
297
+ .readdirSync(releaseDir)
298
+ .filter((item) => item.includes(packageName) && item.endsWith('.rpk'));
299
+ const targetDir = path_1.default.resolve(releaseDir, files[0]);
300
+ const targetPath = `${targetDir}/${packageName}.rpk`;
301
+ const installCmd = `adb -s ${this.sn} shell pm install ${targetPath}`;
302
+ if (count < maxRepeats - 1 && !this.installBol) {
303
+ count++;
304
+ shared_utils_1.ColorConsole.info(`### Emulator ### Excuting cmd: terminalr ${installCmd}`);
305
+ adbMiwt.execAdbCmdAsync(installCmd);
306
+ setTimeout(() => {
307
+ this.pmInstallApp(maxRepeats, count);
308
+ }, 6000);
309
+ }
310
+ else {
311
+ return;
312
+ }
313
+ }
262
314
  /** 连接模拟器中的调试服务,创建debugSocket
263
315
  * 主要用于热更新时,通过debugSocket通知调试服务更新页面
264
316
  * 设置了重连机制,会重复连接8次
@@ -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,14 +10,14 @@
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",
18
18
  "hw.gps": "yes",
19
19
  "hw.gpu.enabled": "no",
20
- "hw.gpu.mode ": "off",
20
+ "hw.gpu.mode": "off",
21
21
  "hw.initialOrientation": "Portrait",
22
22
  "hw.keyboard": "yes",
23
23
  "hw.lcd.density": 420,
@@ -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-15T07: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.13",
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.13",
39
+ "@aiot-toolkit/shared-utils": "2.0.2-beta.13",
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": "30bf14ae958b66937da1b79dcfcd7c436e08af50"
48
50
  }