@aiot-toolkit/emulator 2.0.2-beta.12 → 2.0.2-beta.14
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.
- package/lib/avd/index.js +3 -3
- package/lib/emulatorutil/EmulatorCmd.d.ts +9 -0
- package/lib/emulatorutil/EmulatorCmd.js +226 -0
- package/lib/emulatorutil/EmulatorLog.d.ts +11 -0
- package/lib/emulatorutil/EmulatorLog.js +21 -0
- package/lib/{static → emulatorutil}/constants.js +2 -2
- package/lib/emulatorutil/index.d.ts +3 -0
- package/lib/emulatorutil/index.js +10 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/instance/common.js +17 -15
- package/lib/instance/dev.d.ts +10 -3
- package/lib/instance/dev.js +63 -128
- package/lib/instance/index.js +2 -2
- package/lib/instance/miwear.d.ts +10 -4
- package/lib/instance/miwear.js +59 -89
- package/lib/instance/pre.d.ts +4 -1
- package/lib/instance/pre.js +82 -1
- package/lib/instance/preDev.d.ts +4 -0
- package/lib/instance/preDev.js +39 -74
- package/lib/static/avdConfigIni.json +1 -1
- package/lib/typing/Instance.d.ts +5 -1
- package/lib/typing/Instance.js +6 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +7 -7
- package/package.json +9 -5
- /package/lib/{static → emulatorutil}/constants.d.ts +0 -0
package/lib/avd/index.js
CHANGED
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
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
10
|
const ini_1 = require("ini");
|
|
11
|
-
const constants_1 = require("../
|
|
11
|
+
const constants_1 = require("../emulatorutil/constants");
|
|
12
12
|
const Avd_1 = require("../typing/Avd");
|
|
13
13
|
const EAvdParamsToIni = {
|
|
14
14
|
arm: {
|
|
@@ -104,7 +104,7 @@ class VelaAvdCls {
|
|
|
104
104
|
return avdInfo;
|
|
105
105
|
}
|
|
106
106
|
catch (err) {
|
|
107
|
-
|
|
107
|
+
ColorConsole_1.default.log(`getVelaAvdInfo: ${err.message}`);
|
|
108
108
|
return avdInfo;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IStartOptions } from '../typing/Instance';
|
|
2
|
+
declare class EmulatorCmd {
|
|
3
|
+
static startOptions: IStartOptions | undefined;
|
|
4
|
+
static createMiwerCmd(options: IStartOptions, sdkHome: string, avdHome: string): string | undefined;
|
|
5
|
+
static createDevCmd(options: IStartOptions, sdkHome: string, avdHome: string): string | undefined;
|
|
6
|
+
static createPreCmd(options: IStartOptions, sdkHome: string, avdHome: string): string[] | undefined;
|
|
7
|
+
static getEmulatorBinPath(sdkHome: string): string;
|
|
8
|
+
}
|
|
9
|
+
export default EmulatorCmd;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const avd_1 = __importDefault(require("../avd"));
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
const os_1 = __importDefault(require("os"));
|
|
12
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
class EmulatorCmd {
|
|
15
|
+
static createMiwerCmd(options, sdkHome, avdHome) {
|
|
16
|
+
var _a;
|
|
17
|
+
this.startOptions = options;
|
|
18
|
+
const { avdName, devtool } = options;
|
|
19
|
+
// 获取emulator bin的绝对路径
|
|
20
|
+
const emulatorBin = this.getEmulatorBinPath(sdkHome);
|
|
21
|
+
ColorConsole_1.default.log(`### Emulator ### emulator path: ${emulatorBin}`);
|
|
22
|
+
// 获取vela镜像的绝对路径
|
|
23
|
+
const velaAvdCls = new avd_1.default({
|
|
24
|
+
sdkHome: sdkHome,
|
|
25
|
+
avdHome: avdHome
|
|
26
|
+
});
|
|
27
|
+
const avdInfo = velaAvdCls.getVelaAvdInfo(avdName);
|
|
28
|
+
const { avdArch, avdImagePath, customImagePath } = avdInfo;
|
|
29
|
+
ColorConsole_1.default.log(`### Emulator ### adb port: ${options.adbPort}`);
|
|
30
|
+
if (!avdImagePath) {
|
|
31
|
+
ColorConsole_1.default.throw(`### Emulator ### Unable to find vela image via avd`);
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const nuttxBinPath = path_1.default.resolve(customImagePath || avdImagePath, 'nuttx');
|
|
35
|
+
ColorConsole_1.default.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
|
|
36
|
+
// 端口映射
|
|
37
|
+
let portMappingStr = ``;
|
|
38
|
+
if (devtool) {
|
|
39
|
+
portMappingStr += `-network-user-mode-options hostfwd=tcp:127.0.0.1:${options.debugPort}-10.0.2.15:101`;
|
|
40
|
+
}
|
|
41
|
+
// 设备挂载节点
|
|
42
|
+
const systemImageBin = path_1.default.resolve(avdImagePath, 'vela_resource.bin'); // 只读
|
|
43
|
+
const dataImageBin = path_1.default.resolve(avdImagePath, 'vela_data.bin'); // 可读可写
|
|
44
|
+
const coreBin = path_1.default.resolve(avdImagePath, 'coredump.core'); // 只读
|
|
45
|
+
// 复制可写文件到AVD目录下(多模拟器实例时需要)
|
|
46
|
+
const dataImageBinInAvd = path_1.default.join(avdHome, `${avdName}.avd`, 'vela_data.bin');
|
|
47
|
+
if (!fs_extra_1.default.existsSync(dataImageBinInAvd)) {
|
|
48
|
+
// vela_data.bin不存在时直接copy
|
|
49
|
+
fs_extra_1.default.copyFileSync(dataImageBin, dataImageBinInAvd);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// vela_data.bin存在时,如果.export里的时间晚于avd里的时候,说明更新了镜像,需要重新copy
|
|
53
|
+
const statsInAvd = fs_extra_1.default.statSync(dataImageBinInAvd);
|
|
54
|
+
const stats = fs_extra_1.default.statSync(dataImageBin);
|
|
55
|
+
if ((0, dayjs_1.default)(stats.mtime).isAfter(statsInAvd.mtime)) {
|
|
56
|
+
fs_extra_1.default.copyFileSync(dataImageBin, dataImageBinInAvd);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// 挂载节点配置,只读文件加入read-only标识
|
|
60
|
+
const imageMountStr = `-drive index=0,id=system,if=none,format=raw,file=${systemImageBin},read-only \
|
|
61
|
+
-device virtio-blk-device,bus=virtio-mmio-bus.0,drive=system \
|
|
62
|
+
-drive index=1,id=userdata,if=none,format=raw,file=${dataImageBinInAvd} \
|
|
63
|
+
-device virtio-blk-device,bus=virtio-mmio-bus.1,drive=userdata \
|
|
64
|
+
-drive index=2,id=vendor,if=none,format=raw,file=${coreBin},read-only \
|
|
65
|
+
-device virtio-blk-device,bus=virtio-mmio-bus.4,drive=vendor \
|
|
66
|
+
-device virtio-snd,bus=virtio-mmio-bus.2 -allow-host-audio -semihosting`;
|
|
67
|
+
// grpc配置
|
|
68
|
+
let windowStr = '';
|
|
69
|
+
let grpcStr = '';
|
|
70
|
+
if ((_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.grpcPort) {
|
|
71
|
+
windowStr = '-qt-hide-window';
|
|
72
|
+
grpcStr = ` -idle-grpc-timeout 300 -grpc ${this.startOptions.grpcPort}`;
|
|
73
|
+
}
|
|
74
|
+
// 启动模拟器的命令和参数
|
|
75
|
+
const cmd = `${emulatorBin} -nuttx -avd ${avdName} -port ${options.adbPort} -avd-arch ${avdArch} -show-kernel -kernel ${nuttxBinPath} ${portMappingStr} ${windowStr} ${grpcStr} -qemu ${imageMountStr}`;
|
|
76
|
+
return cmd;
|
|
77
|
+
}
|
|
78
|
+
static createDevCmd(options, sdkHome, avdHome) {
|
|
79
|
+
var _a;
|
|
80
|
+
this.startOptions = options;
|
|
81
|
+
const { avdName, devtool } = options;
|
|
82
|
+
const emulatorBin = this.getEmulatorBinPath(sdkHome);
|
|
83
|
+
ColorConsole_1.default.log(`### Emulator ### emulator path: ${emulatorBin}`);
|
|
84
|
+
const velaAvdCls = new avd_1.default({
|
|
85
|
+
sdkHome: sdkHome,
|
|
86
|
+
avdHome: avdHome
|
|
87
|
+
});
|
|
88
|
+
const avdInfo = velaAvdCls.getVelaAvdInfo(avdName);
|
|
89
|
+
const { avdArch, avdImagePath, customImagePath } = avdInfo;
|
|
90
|
+
ColorConsole_1.default.log(`### Emulator ### adb port: ${options.adbPort}`);
|
|
91
|
+
if (!avdImagePath) {
|
|
92
|
+
ColorConsole_1.default.throw(`### Emulator ### Unable to find vela image via avd`);
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const nuttxBinPath = path_1.default.resolve(customImagePath || avdImagePath, 'nuttx');
|
|
96
|
+
ColorConsole_1.default.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
|
|
97
|
+
// 端口映射
|
|
98
|
+
let portMappingStr = ``;
|
|
99
|
+
if (devtool) {
|
|
100
|
+
portMappingStr += `-network-user-mode-options hostfwd=tcp:127.0.0.1:${options.debugPort}-10.0.2.15:101`;
|
|
101
|
+
}
|
|
102
|
+
// 文件系统配置,第一次使用fatfs镜像挂载,后续使用adb push更新应用
|
|
103
|
+
const systemImageBin = path_1.default.join(avdImagePath, 'system.img');
|
|
104
|
+
const dataImageBin = path_1.default.join(avdImagePath, 'data.img');
|
|
105
|
+
// 复制可写文件到AVD目录下(多模拟器实例时需要)
|
|
106
|
+
const dataImageBinInAvd = path_1.default.join(avdHome, `${avdName}.avd`, 'data.img');
|
|
107
|
+
if (!fs_extra_1.default.existsSync(dataImageBinInAvd)) {
|
|
108
|
+
// data.img不存在时直接copy
|
|
109
|
+
fs_extra_1.default.copyFileSync(dataImageBin, dataImageBinInAvd);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// data.img存在时,如果.export里的时间晚于avd里的时候,说明更新了镜像,需要重新copy
|
|
113
|
+
const statsInAvd = fs_extra_1.default.statSync(dataImageBinInAvd);
|
|
114
|
+
const stats = fs_extra_1.default.statSync(dataImageBin);
|
|
115
|
+
if ((0, dayjs_1.default)(stats.mtime).isAfter(statsInAvd.mtime)) {
|
|
116
|
+
fs_extra_1.default.copyFileSync(dataImageBin, dataImageBinInAvd);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// 复制可写文件到AVD目录下(多模拟器实例时需要)
|
|
120
|
+
const systemImageBinInAvd = path_1.default.join(avdHome, `${avdName}.avd`, 'system.img');
|
|
121
|
+
if (!fs_extra_1.default.existsSync(systemImageBinInAvd)) {
|
|
122
|
+
// data.img不存在时直接copy
|
|
123
|
+
fs_extra_1.default.copyFileSync(systemImageBin, systemImageBinInAvd);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
// data.img存在时,如果.export里的时间晚于avd里的时候,说明更新了镜像,需要重新copy
|
|
127
|
+
const statsInAvd = fs_extra_1.default.statSync(systemImageBinInAvd);
|
|
128
|
+
const stats = fs_extra_1.default.statSync(systemImageBin);
|
|
129
|
+
if ((0, dayjs_1.default)(stats.mtime).isAfter(statsInAvd.mtime)) {
|
|
130
|
+
fs_extra_1.default.copyFileSync(systemImageBin, systemImageBinInAvd);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// 复制可写文件到AVD目录下(多模拟器实例时需要)
|
|
134
|
+
// const nuttxBinInAvd = path.join(this.avdHome, `${avdName}.avd`, 'nuttx')
|
|
135
|
+
// if (!fs.existsSync(nuttxBinInAvd)) {
|
|
136
|
+
// // data.img不存在时直接copy
|
|
137
|
+
// fs.copyFileSync(nuttxBinPath, nuttxBinInAvd)
|
|
138
|
+
// } else {
|
|
139
|
+
// // data.img存在时,如果.export里的时间晚于avd里的时候,说明更新了镜像,需要重新copy
|
|
140
|
+
// const statsInAvd = fs.statSync(nuttxBinInAvd)
|
|
141
|
+
// const stats = fs.statSync(nuttxBinPath)
|
|
142
|
+
// if (dayjs(stats.mtime).isAfter(statsInAvd.mtime)) {
|
|
143
|
+
// fs.copyFileSync(nuttxBinPath, nuttxBinInAvd)
|
|
144
|
+
// }
|
|
145
|
+
// }
|
|
146
|
+
const imageMountStr = `-drive index=0,id=system,if=none,format=raw,file=${systemImageBinInAvd} \
|
|
147
|
+
-device virtio-blk-device,bus=virtio-mmio-bus.0,drive=system \
|
|
148
|
+
-drive index=1,id=userdata,if=none,format=raw,file=${dataImageBinInAvd} \
|
|
149
|
+
-device virtio-blk-device,bus=virtio-mmio-bus.1,drive=userdata \
|
|
150
|
+
-device virtio-snd,bus=virtio-mmio-bus.2 -allow-host-audio -semihosting`;
|
|
151
|
+
// grpc配置
|
|
152
|
+
let windowStr = '';
|
|
153
|
+
let grpcStr = '';
|
|
154
|
+
if ((_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.grpcPort) {
|
|
155
|
+
windowStr = '-qt-hide-window';
|
|
156
|
+
grpcStr = ` -idle-grpc-timeout 300 -grpc ${this.startOptions.grpcPort}`;
|
|
157
|
+
}
|
|
158
|
+
// 启动模拟器的命令和参数
|
|
159
|
+
const cmd = `${emulatorBin} -nuttx -avd ${avdName} -port ${options.adbPort} -avd-arch ${avdArch} -show-kernel -kernel ${nuttxBinPath} ${portMappingStr} ${windowStr} ${grpcStr} -qemu ${imageMountStr}`;
|
|
160
|
+
return cmd;
|
|
161
|
+
}
|
|
162
|
+
static createPreCmd(options, sdkHome, avdHome) {
|
|
163
|
+
this.startOptions = options;
|
|
164
|
+
const { avdName, devtool } = options;
|
|
165
|
+
// 获取emulator bin的绝对路径
|
|
166
|
+
const emulatorBin = this.getEmulatorBinPath(sdkHome);
|
|
167
|
+
ColorConsole_1.default.log(`### Emulator ### emulator path: ${emulatorBin}`);
|
|
168
|
+
// 获取vela镜像的绝对路径
|
|
169
|
+
const velaAvdCls = new avd_1.default({
|
|
170
|
+
sdkHome: sdkHome,
|
|
171
|
+
avdHome: avdHome
|
|
172
|
+
});
|
|
173
|
+
const avdInfo = velaAvdCls.getVelaAvdInfo(avdName);
|
|
174
|
+
const { avdArch, avdImagePath, customImagePath } = avdInfo;
|
|
175
|
+
ColorConsole_1.default.log(`### Emulator ### adb port: ${options.adbPort}`);
|
|
176
|
+
if (!avdImagePath) {
|
|
177
|
+
ColorConsole_1.default.throw(`### Emulator ### Unable to find vela image via avd`);
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
const nuttxBinPath = path_1.default.resolve(customImagePath || avdImagePath, 'nuttx');
|
|
181
|
+
ColorConsole_1.default.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
|
|
182
|
+
// 端口映射,adb端口和debug端口
|
|
183
|
+
let portMappingStr = `user,id=u1,hostfwd=tcp:127.0.0.1:${options.adbPort}-10.0.2.15:5555`;
|
|
184
|
+
if (devtool) {
|
|
185
|
+
ColorConsole_1.default.log(`### Emulator ### debug port: ${options.debugPort}`);
|
|
186
|
+
portMappingStr += `,hostfwd=tcp:127.0.0.1:${options.debugPort}-10.0.2.15:101`;
|
|
187
|
+
}
|
|
188
|
+
ColorConsole_1.default.log(`### Emulator ### Start qemu with TCP: ${portMappingStr}`);
|
|
189
|
+
// vnc配置
|
|
190
|
+
let noWindow = false;
|
|
191
|
+
let vncStr = '';
|
|
192
|
+
if (options.grpcPort) {
|
|
193
|
+
noWindow = true;
|
|
194
|
+
const portSuffix = options.grpcPort - constants_1.defaultVncPort;
|
|
195
|
+
vncStr = `-vnc :${portSuffix}`;
|
|
196
|
+
}
|
|
197
|
+
// 启动goldfish的命令和参数
|
|
198
|
+
const spawnArgs = [
|
|
199
|
+
emulatorBin,
|
|
200
|
+
'-nuttx',
|
|
201
|
+
'-avd',
|
|
202
|
+
avdName,
|
|
203
|
+
'-avd-arch',
|
|
204
|
+
avdArch,
|
|
205
|
+
'-show-kernel',
|
|
206
|
+
'-kernel',
|
|
207
|
+
nuttxBinPath,
|
|
208
|
+
noWindow ? '-no-window' : '',
|
|
209
|
+
'-qemu',
|
|
210
|
+
vncStr,
|
|
211
|
+
'-netdev',
|
|
212
|
+
portMappingStr,
|
|
213
|
+
'-device',
|
|
214
|
+
'virtio-net-device,netdev=u1,bus=virtio-mmio-bus.3'
|
|
215
|
+
];
|
|
216
|
+
return spawnArgs;
|
|
217
|
+
}
|
|
218
|
+
static getEmulatorBinPath(sdkHome) {
|
|
219
|
+
const osPlatform = os_1.default.platform();
|
|
220
|
+
const arch = (0, utils_1.getSystemArch)();
|
|
221
|
+
const platform = osPlatform === 'win32' ? 'windows' : osPlatform;
|
|
222
|
+
const emulatorHome = path_1.default.resolve(sdkHome, 'emulator');
|
|
223
|
+
return path_1.default.resolve(emulatorHome, `${platform}-${arch}`, 'emulator');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.default = EmulatorCmd;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare class EmulatorLog {
|
|
2
|
+
static emulatorStartedFlag: RegExp;
|
|
3
|
+
static installFlag: RegExp;
|
|
4
|
+
static devStartFlag: string;
|
|
5
|
+
static preDevStartFlag: RegExp;
|
|
6
|
+
static inStallIsFinshe(msg: string): RegExpMatchArray | null;
|
|
7
|
+
static rpkIsStart(msg: string): RegExpMatchArray | null;
|
|
8
|
+
static devIsStart(msg: string): boolean;
|
|
9
|
+
static preDevIsStart(msg: string): RegExpMatchArray | null;
|
|
10
|
+
}
|
|
11
|
+
export default EmulatorLog;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class EmulatorLog {
|
|
4
|
+
static inStallIsFinshe(msg) {
|
|
5
|
+
return msg.match(EmulatorLog.installFlag);
|
|
6
|
+
}
|
|
7
|
+
static rpkIsStart(msg) {
|
|
8
|
+
return msg.match(EmulatorLog.emulatorStartedFlag);
|
|
9
|
+
}
|
|
10
|
+
static devIsStart(msg) {
|
|
11
|
+
return msg.includes(EmulatorLog.devStartFlag);
|
|
12
|
+
}
|
|
13
|
+
static preDevIsStart(msg) {
|
|
14
|
+
return msg.match(EmulatorLog.preDevStartFlag);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
EmulatorLog.emulatorStartedFlag = /quickapp_rpk_installer_init|rpk installer init done/;
|
|
18
|
+
EmulatorLog.installFlag = /InstallState_Finished|install finished/;
|
|
19
|
+
EmulatorLog.devStartFlag = '(NSH)';
|
|
20
|
+
EmulatorLog.preDevStartFlag = /Server started, listening on: 127.0.0.1:(\d+)/;
|
|
21
|
+
exports.default = EmulatorLog;
|
|
@@ -27,14 +27,14 @@ exports.VelaImageVersionList = [
|
|
|
27
27
|
{
|
|
28
28
|
label: 'vela-4.0-正式版',
|
|
29
29
|
value: 'vela-release-4.0',
|
|
30
|
-
time: '2024-
|
|
30
|
+
time: '2024-08-12T06:48:00',
|
|
31
31
|
hide: false,
|
|
32
32
|
icon: null
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
label: 'vela-4.0-测试版',
|
|
36
36
|
value: 'vela-pre-4.0',
|
|
37
|
-
time: '2024-
|
|
37
|
+
time: '2024-08-12T06:48:00',
|
|
38
38
|
hide: false,
|
|
39
39
|
icon: null
|
|
40
40
|
},
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EmulatorCmd = exports.EmulatorLog = void 0;
|
|
7
|
+
const EmulatorLog_1 = __importDefault(require("./EmulatorLog"));
|
|
8
|
+
exports.EmulatorLog = EmulatorLog_1.default;
|
|
9
|
+
const EmulatorCmd_1 = __importDefault(require("./EmulatorCmd"));
|
|
10
|
+
exports.EmulatorCmd = EmulatorCmd_1.default;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -25,4 +25,4 @@ Object.defineProperty(exports, "getSystemArch", { enumerable: true, get: functio
|
|
|
25
25
|
__exportStar(require("./instance"), exports);
|
|
26
26
|
__exportStar(require("./typing/Avd"), exports);
|
|
27
27
|
__exportStar(require("./typing/Instance"), exports);
|
|
28
|
-
__exportStar(require("./
|
|
28
|
+
__exportStar(require("./emulatorutil/constants"), exports);
|
package/lib/instance/common.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const UxFileUtils_1 = __importDefault(require("@aiot-toolkit/aiotpack/lib/utils/ux/UxFileUtils"));
|
|
39
|
-
const
|
|
39
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
40
40
|
const adbMiwt = __importStar(require("@miwt/adb"));
|
|
41
41
|
const child_process_1 = require("child_process");
|
|
42
42
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -44,14 +44,14 @@ const os_1 = __importDefault(require("os"));
|
|
|
44
44
|
const path_1 = __importDefault(require("path"));
|
|
45
45
|
const ws_1 = require("ws");
|
|
46
46
|
const avd_1 = __importDefault(require("../avd"));
|
|
47
|
-
const constants_1 = require("../
|
|
47
|
+
const constants_1 = require("../emulatorutil/constants");
|
|
48
48
|
const utils_1 = require("../utils");
|
|
49
49
|
/**
|
|
50
50
|
* CommonInstance
|
|
51
51
|
*/
|
|
52
52
|
class CommonInstance {
|
|
53
53
|
constructor(params) {
|
|
54
|
-
this.quickappStartedFlag = /
|
|
54
|
+
this.quickappStartedFlag = /Start App loop/;
|
|
55
55
|
this.isFirstStart = true;
|
|
56
56
|
this.isDistributedApp = false;
|
|
57
57
|
this.projectPath = params.projectPath;
|
|
@@ -80,7 +80,9 @@ class CommonInstance {
|
|
|
80
80
|
}
|
|
81
81
|
/** 在goldfish模拟器中运行快应用 */
|
|
82
82
|
start(options) {
|
|
83
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
throw new Error(`start method not implemented, ${options}`);
|
|
85
|
+
});
|
|
84
86
|
}
|
|
85
87
|
/**
|
|
86
88
|
* 判断模拟器是否 ready
|
|
@@ -89,7 +91,7 @@ class CommonInstance {
|
|
|
89
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
92
|
return (0, utils_1.tryRun)(() => __awaiter(this, void 0, void 0, function* () {
|
|
91
93
|
const devices = yield adbMiwt.getAdbDevices();
|
|
92
|
-
|
|
94
|
+
ColorConsole_1.default.log(`### Emulator ### adb devices: ${JSON.stringify(devices)}`);
|
|
93
95
|
const curDev = devices.find((t) => t.sn === this.sn);
|
|
94
96
|
return (curDev === null || curDev === void 0 ? void 0 : curDev.status) === 'device';
|
|
95
97
|
}), 10, 500);
|
|
@@ -109,14 +111,14 @@ class CommonInstance {
|
|
|
109
111
|
while (enableLoop && !adbConnected) {
|
|
110
112
|
if (needKill) {
|
|
111
113
|
const adbKillCmd = `adb kill-server`;
|
|
112
|
-
|
|
114
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${adbKillCmd}`);
|
|
113
115
|
yield adbMiwt.execAdbCmdAsync(adbKillCmd);
|
|
114
116
|
}
|
|
115
117
|
const str = yield this.connectDevice();
|
|
116
|
-
|
|
118
|
+
ColorConsole_1.default.log(`### Emulator ### ${str}`);
|
|
117
119
|
// 查询模拟器的状态是否为“device”
|
|
118
120
|
const devices = yield adbMiwt.getAdbDevices();
|
|
119
|
-
|
|
121
|
+
ColorConsole_1.default.log(`### Emulator ### adb devices: ${JSON.stringify(devices)}`);
|
|
120
122
|
const curDev = devices.find((t) => t.sn === this.sn);
|
|
121
123
|
if ((curDev === null || curDev === void 0 ? void 0 : curDev.status) === 'offline')
|
|
122
124
|
needKill = true;
|
|
@@ -155,7 +157,7 @@ class CommonInstance {
|
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
catch (err) {
|
|
158
|
-
|
|
160
|
+
ColorConsole_1.default.log(`### Emulator ### kill process get error :\n${err.stack}`);
|
|
159
161
|
}
|
|
160
162
|
}
|
|
161
163
|
}
|
|
@@ -193,13 +195,13 @@ class CommonInstance {
|
|
|
193
195
|
port: (_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.serverPort
|
|
194
196
|
});
|
|
195
197
|
wsServer.on('connection', (socket) => {
|
|
196
|
-
|
|
198
|
+
ColorConsole_1.default.success(`### App Socket server ### Websocket connects to websocket server`);
|
|
197
199
|
socket.on('error', (err) => {
|
|
198
|
-
|
|
200
|
+
ColorConsole_1.default.error(`### App Socket server ### Websocket server error: ${err.message}`);
|
|
199
201
|
});
|
|
200
202
|
socket.on('message', (data) => {
|
|
201
203
|
const message = JSON.parse(data.toString());
|
|
202
|
-
|
|
204
|
+
ColorConsole_1.default.log(`### App Socket server ### Websocket server get data: ${data}`);
|
|
203
205
|
if (message.type === 'restart') {
|
|
204
206
|
this.restart();
|
|
205
207
|
}
|
|
@@ -213,17 +215,17 @@ class CommonInstance {
|
|
|
213
215
|
connectDevice() {
|
|
214
216
|
return __awaiter(this, void 0, void 0, function* () {
|
|
215
217
|
const adbConnectCmd = `adb connect ${this.sn}`;
|
|
216
|
-
|
|
218
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${adbConnectCmd}`);
|
|
217
219
|
let pending = true;
|
|
218
220
|
const p1 = adbMiwt.execAdbCmdAsync(adbConnectCmd);
|
|
219
221
|
let timer;
|
|
220
222
|
// 超过一定时间还没有连接成功,则 kill-server 后再试
|
|
221
223
|
// 用于处理 adb connect 一直 pending 的情况
|
|
222
|
-
const p2 = new Promise((resolve
|
|
224
|
+
const p2 = new Promise((resolve) => {
|
|
223
225
|
timer = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
224
226
|
if (pending) {
|
|
225
227
|
const adbKillCmd = `adb kill-server`;
|
|
226
|
-
|
|
228
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${adbKillCmd}`);
|
|
227
229
|
yield adbMiwt.execAdbCmdAsync(adbKillCmd);
|
|
228
230
|
}
|
|
229
231
|
resolve();
|
package/lib/instance/dev.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import readline from 'readline';
|
|
1
3
|
import { INewGoldfishInstanceParams, IStartOptions } from '../typing/Instance';
|
|
2
4
|
import CommonInstance from './common';
|
|
3
5
|
declare class GoldfishInstance extends CommonInstance {
|
|
4
|
-
|
|
6
|
+
appDir: string;
|
|
5
7
|
emulatorStartedFlag: string;
|
|
8
|
+
stdoutReadline: readline.Interface;
|
|
9
|
+
stderrReadline: readline.Interface;
|
|
6
10
|
constructor(params: INewGoldfishInstanceParams);
|
|
7
11
|
/**
|
|
8
12
|
* 1. 启动模拟器
|
|
@@ -29,9 +33,12 @@ declare class GoldfishInstance extends CommonInstance {
|
|
|
29
33
|
startGoldfish(options: IStartOptions): Promise<void>;
|
|
30
34
|
/**
|
|
31
35
|
* 将目录通过adb push到模拟器中
|
|
32
|
-
* @param sourceRoot
|
|
33
36
|
*/
|
|
34
|
-
|
|
37
|
+
pushAndInstall(rpkPath?: string): Promise<void>;
|
|
38
|
+
/** 通过命令行启动时,在watich模式下监听websocket消息,
|
|
39
|
+
* 在文件发生变动时,重新启动应用
|
|
40
|
+
*/
|
|
41
|
+
restart(): Promise<void>;
|
|
35
42
|
/**
|
|
36
43
|
* 重新推送,然后重启应用
|
|
37
44
|
*/
|