@aiot-toolkit/emulator 2.0.1-alpha.8 → 2.0.2-dev.1
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 +0 -2
- package/lib/index.js +0 -2
- package/lib/instance/goldfish.d.ts +6 -0
- package/lib/instance/goldfish.js +121 -86
- package/lib/instance/goldfish1.d.ts +41 -0
- package/lib/instance/goldfish1.js +332 -0
- package/lib/static/constants.d.ts +1 -0
- package/lib/static/constants.js +2 -3
- package/lib/typing/Avd.js +0 -2
- package/lib/typing/Instance.d.ts +2 -0
- package/lib/typing/Instance.js +0 -2
- package/lib/utils/index.d.ts +5 -0
- package/lib/utils/index.js +39 -0
- package/package.json +4 -4
- package/lib/avd/index.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/instance/goldfish.js.map +0 -1
- package/lib/static/constants.js.map +0 -1
- package/lib/typing/Avd.js.map +0 -1
- package/lib/typing/Instance.js.map +0 -1
package/lib/avd/index.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -24,5 +24,3 @@ const goldfish_1 = __importDefault(require("./instance/goldfish"));
|
|
|
24
24
|
Object.defineProperty(exports, "GoldfishInstance", { enumerable: true, get: function () { return goldfish_1.default; } });
|
|
25
25
|
__exportStar(require("./typing/Avd"), exports);
|
|
26
26
|
__exportStar(require("./typing/Instance"), exports);
|
|
27
|
-
|
|
28
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -12,6 +12,8 @@ declare class GoldfishInstance {
|
|
|
12
12
|
private packageName;
|
|
13
13
|
goldfishProcess: ChildProcess | undefined;
|
|
14
14
|
v9fsProcess: ChildProcess | undefined;
|
|
15
|
+
isFirstStart: boolean;
|
|
16
|
+
private startOptions;
|
|
15
17
|
constructor(params: INewGoldfishInstanceParams);
|
|
16
18
|
/** 获取模拟器二进制文件所在位置 */
|
|
17
19
|
getEmulatorBinPath(): string;
|
|
@@ -31,5 +33,9 @@ declare class GoldfishInstance {
|
|
|
31
33
|
killProcess(currProcess?: ChildProcess): void;
|
|
32
34
|
/** 停止模拟器并释放相关资源 */
|
|
33
35
|
stop(): void;
|
|
36
|
+
/** 重启模拟器 */
|
|
37
|
+
restart(): void;
|
|
38
|
+
/** 创建server */
|
|
39
|
+
createWebsockeServer(): Promise<void>;
|
|
34
40
|
}
|
|
35
41
|
export default GoldfishInstance;
|
package/lib/instance/goldfish.js
CHANGED
|
@@ -36,7 +36,6 @@ 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 shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
40
39
|
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
41
40
|
const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
|
|
42
41
|
const adbMiwt = __importStar(require("@miwt/adb"));
|
|
@@ -46,13 +45,16 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
46
45
|
const os_1 = __importDefault(require("os"));
|
|
47
46
|
const path_1 = __importDefault(require("path"));
|
|
48
47
|
const portfinder_1 = __importDefault(require("portfinder"));
|
|
48
|
+
const ws_1 = require("ws");
|
|
49
49
|
const avd_1 = __importDefault(require("../avd"));
|
|
50
50
|
const constants_1 = require("../static/constants");
|
|
51
|
+
const utils_1 = require("../utils");
|
|
51
52
|
class GoldfishInstance {
|
|
52
53
|
constructor(params) {
|
|
53
54
|
this.adbPort = 15555;
|
|
54
55
|
this.debugPort = 10055;
|
|
55
56
|
this.host9pPort = 7878;
|
|
57
|
+
this.isFirstStart = true;
|
|
56
58
|
this.projectPath = params.projectPath;
|
|
57
59
|
this.sdkHome = params.sdkHome || constants_1.defaultSDKHome;
|
|
58
60
|
this.avdHome = params.avdHome || constants_1.defaultAvdHome;
|
|
@@ -66,34 +68,33 @@ class GoldfishInstance {
|
|
|
66
68
|
/** 获取模拟器二进制文件所在位置 */
|
|
67
69
|
getEmulatorBinPath() {
|
|
68
70
|
const osPlatform = os_1.default.platform();
|
|
69
|
-
const
|
|
71
|
+
const arch = (0, utils_1.getSystemArch)();
|
|
70
72
|
const platform = osPlatform === 'win32' ? 'windows' : osPlatform;
|
|
71
|
-
const
|
|
72
|
-
return path_1.default.resolve(
|
|
73
|
+
const emulatorHome = path_1.default.resolve(this.sdkHome, 'emulator');
|
|
74
|
+
return path_1.default.resolve(emulatorHome, `${platform}-${arch}`, 'emulator');
|
|
73
75
|
}
|
|
74
76
|
/** 在goldfish模拟器中运行快应用 */
|
|
75
77
|
start(options) {
|
|
76
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
79
|
// host启动9p server
|
|
78
80
|
yield this.ensure9pServerRunnning();
|
|
79
|
-
|
|
80
|
-
// 将rpk推到host的
|
|
81
|
+
this.startOptions = options;
|
|
82
|
+
// 将rpk推到host的QuickappHome目录
|
|
81
83
|
this.pushRpk();
|
|
82
84
|
// 启动模拟器
|
|
83
85
|
yield this.startGoldfish(options);
|
|
84
86
|
const connected = yield this.connectGoldfish();
|
|
85
87
|
if (connected) {
|
|
86
|
-
ColorConsole_1.default.log(
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
ColorConsole_1.default.log('### Emulator ### Goldfish emulator connected successfully');
|
|
89
|
+
if (this.isFirstStart && this.startOptions.serverPort) {
|
|
90
|
+
yield this.createWebsockeServer();
|
|
91
|
+
}
|
|
89
92
|
// 在模拟器中启动快应用
|
|
90
93
|
this.startupQuickApp(options);
|
|
94
|
+
this.isFirstStart = false;
|
|
91
95
|
}
|
|
92
96
|
else {
|
|
93
|
-
ColorConsole_1.default.
|
|
94
|
-
level: shared_utils_1.LOG_LEVEL.Error,
|
|
95
|
-
message: '### Emulator ### Failed to connect emulator, please check whether the adb is normal'
|
|
96
|
-
});
|
|
97
|
+
ColorConsole_1.default.throw('### Emulator ### Failed to connect emulator, please check whether the adb is normal');
|
|
97
98
|
}
|
|
98
99
|
});
|
|
99
100
|
}
|
|
@@ -102,22 +103,18 @@ class GoldfishInstance {
|
|
|
102
103
|
try {
|
|
103
104
|
const appMountDir = path_1.default.resolve(this.sdkHome, 'qa');
|
|
104
105
|
const mountCmd = `adb -s 127.0.0.1:${this.adbPort} shell mount -t v9fs -o tag=10.0.2.2,port=${this.host9pPort},aname=${appMountDir} /data`;
|
|
105
|
-
ColorConsole_1.default.log(
|
|
106
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${mountCmd}`);
|
|
106
107
|
adbMiwt.execAdbCmdSync(mountCmd);
|
|
107
108
|
let vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp app/${this.packageName} &`;
|
|
108
109
|
if (options.devtool) {
|
|
109
110
|
vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp --jsdebugger=10.0.2.15:101 app/${this.packageName} &`;
|
|
110
111
|
}
|
|
111
|
-
ColorConsole_1.default.log(
|
|
112
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${vappCmd}`);
|
|
112
113
|
// vapp进程会一直pending,不会退出。这里必须加stdio: 'ignore',否则快应用无法运行成功
|
|
113
114
|
adbMiwt.execAdbCmdAsync(vappCmd, { stdio: 'ignore', encoding: 'utf-8' });
|
|
114
115
|
}
|
|
115
116
|
catch (e) {
|
|
116
|
-
ColorConsole_1.default.
|
|
117
|
-
level: shared_utils_1.LOG_LEVEL.Error,
|
|
118
|
-
message: `### Emulator ### Failed to startup quickapp: ${e.message}`,
|
|
119
|
-
isOnlyPrintError: true
|
|
120
|
-
});
|
|
117
|
+
ColorConsole_1.default.error(`### Emulator ### Failed to startup quickapp: ${e.message}`);
|
|
121
118
|
}
|
|
122
119
|
}
|
|
123
120
|
/** host启动9pServer */
|
|
@@ -127,12 +124,13 @@ class GoldfishInstance {
|
|
|
127
124
|
const yaFileName = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
|
|
128
125
|
const pidList = yield (0, find_process_1.default)('name', yaFileName);
|
|
129
126
|
if (pidList.length > 0) {
|
|
130
|
-
ColorConsole_1.default.log(
|
|
127
|
+
ColorConsole_1.default.log('### Emulator ### 9p server started in host');
|
|
131
128
|
return resolve();
|
|
132
129
|
}
|
|
133
|
-
ColorConsole_1.default.log(
|
|
130
|
+
ColorConsole_1.default.log('### Emulator ### Starting 9p server in host');
|
|
134
131
|
const quickappMountDir = path_1.default.resolve(this.sdkHome, 'qa');
|
|
135
|
-
const
|
|
132
|
+
const toolsHome = path_1.default.resolve(this.sdkHome, 'tools');
|
|
133
|
+
const serverBinPath = path_1.default.resolve(toolsHome, yaFileName);
|
|
136
134
|
fs_1.default.chmodSync(serverBinPath, 0o777);
|
|
137
135
|
this.host9pPort = yield portfinder_1.default.getPortPromise({ port: 7878 });
|
|
138
136
|
const address = `127.0.0.1:${this.host9pPort}`;
|
|
@@ -146,90 +144,93 @@ class GoldfishInstance {
|
|
|
146
144
|
(_a = this.v9fsProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
147
145
|
const output = data.toString();
|
|
148
146
|
if (output.match(/Server started, listening on: 127.0.0.1:(\d+)/)) {
|
|
149
|
-
ColorConsole_1.default.log(
|
|
150
|
-
ColorConsole_1.default.log(
|
|
147
|
+
ColorConsole_1.default.log(output);
|
|
148
|
+
ColorConsole_1.default.log('### Emulator ### 9p server starts successfully');
|
|
151
149
|
return resolve();
|
|
152
150
|
}
|
|
153
151
|
});
|
|
154
152
|
this.v9fsProcess.on('exit', (code) => {
|
|
155
|
-
ColorConsole_1.default.
|
|
156
|
-
level: shared_utils_1.LOG_LEVEL.Error,
|
|
157
|
-
message: `### Emulator ### ya-vm-file-server exited with code ${code}`,
|
|
158
|
-
isOnlyPrintError: true
|
|
159
|
-
});
|
|
153
|
+
ColorConsole_1.default.error(`### Emulator ### ya-vm-file-server exited with code ${code}`);
|
|
160
154
|
return reject();
|
|
161
155
|
});
|
|
162
156
|
}));
|
|
163
157
|
}
|
|
164
158
|
/** 启动goldfish模拟器 */
|
|
165
159
|
startGoldfish(options) {
|
|
160
|
+
var _a;
|
|
166
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
162
|
const { avdName, devtool } = options;
|
|
168
163
|
const emulatorBin = this.getEmulatorBinPath();
|
|
169
|
-
ColorConsole_1.default.log(
|
|
164
|
+
ColorConsole_1.default.log(`### Emulator ### emulator path: ${emulatorBin}`);
|
|
170
165
|
const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName);
|
|
171
166
|
const { avdArch, avdImagePath } = avdInfo;
|
|
172
167
|
this.adbPort = yield portfinder_1.default.getPortPromise({ port: this.adbPort });
|
|
173
|
-
ColorConsole_1.default.log(
|
|
168
|
+
ColorConsole_1.default.log(`### Emulator ### adb port: ${this.adbPort}`);
|
|
174
169
|
if (!avdImagePath) {
|
|
175
|
-
ColorConsole_1.default.
|
|
176
|
-
level: shared_utils_1.LOG_LEVEL.Error,
|
|
177
|
-
message: `### Emulator ### Unable to find vela image via avd`
|
|
178
|
-
});
|
|
179
|
-
process.exit();
|
|
170
|
+
return ColorConsole_1.default.throw(`### Emulator ### Unable to find vela image via avd`);
|
|
180
171
|
}
|
|
181
172
|
const nuttxBinPath = path_1.default.resolve(avdImagePath, 'nuttx');
|
|
182
|
-
ColorConsole_1.default.log(
|
|
173
|
+
ColorConsole_1.default.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
|
|
183
174
|
let portMappingStr = `user,id=u1,hostfwd=tcp:127.0.0.1:${this.adbPort}-10.0.2.15:5555`;
|
|
184
175
|
if (devtool) {
|
|
185
176
|
this.debugPort = yield portfinder_1.default.getPortPromise({ port: this.debugPort });
|
|
186
|
-
ColorConsole_1.default.log(
|
|
177
|
+
ColorConsole_1.default.log(`### Emulator ### debug port: ${this.debugPort}`);
|
|
187
178
|
portMappingStr += `,hostfwd=tcp:127.0.0.1:${this.debugPort}-10.0.2.15:101`;
|
|
188
179
|
}
|
|
189
|
-
ColorConsole_1.default.log(
|
|
180
|
+
ColorConsole_1.default.log(`### Emulator ### Start qemu with TCP: ${portMappingStr}`);
|
|
190
181
|
const stdioType = options.disableNSH ? 'pipe' : 'inherit';
|
|
182
|
+
// vnc配置
|
|
183
|
+
let noWindow = false;
|
|
184
|
+
let vncStr = '';
|
|
185
|
+
if ((_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.vncPort) {
|
|
186
|
+
noWindow = true;
|
|
187
|
+
const portSuffix = this.startOptions.vncPort - constants_1.defaultVncPort;
|
|
188
|
+
vncStr = `-vnc :${portSuffix}`;
|
|
189
|
+
}
|
|
190
|
+
// 启动goldfish的命令和参数
|
|
191
|
+
const spawnBin = emulatorBin;
|
|
192
|
+
const spawnArgs = [
|
|
193
|
+
'-nuttx',
|
|
194
|
+
'-avd',
|
|
195
|
+
avdName,
|
|
196
|
+
'-avd-arch',
|
|
197
|
+
avdArch,
|
|
198
|
+
'-show-kernel',
|
|
199
|
+
'-kernel',
|
|
200
|
+
nuttxBinPath,
|
|
201
|
+
noWindow ? '-no-window' : '',
|
|
202
|
+
'-qemu',
|
|
203
|
+
vncStr,
|
|
204
|
+
'-netdev',
|
|
205
|
+
portMappingStr,
|
|
206
|
+
'-device',
|
|
207
|
+
'virtio-net-device,netdev=u1,bus=virtio-mmio-bus.3'
|
|
208
|
+
];
|
|
209
|
+
ColorConsole_1.default.log(`### Emulator ### Start CMD: ${spawnBin} ${spawnArgs.join(' ')}`);
|
|
191
210
|
return new Promise((resolve) => {
|
|
192
|
-
var _a
|
|
193
|
-
this.goldfishProcess = (0, child_process_1.spawn)(
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
'
|
|
203
|
-
'-netdev',
|
|
204
|
-
portMappingStr,
|
|
205
|
-
'-device',
|
|
206
|
-
'virtio-net-device,netdev=u1,bus=virtio-mmio-bus.3'
|
|
207
|
-
], { stdio: stdioType });
|
|
208
|
-
if (options.disableNSH) {
|
|
209
|
-
(_a = this.goldfishProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
211
|
+
var _a;
|
|
212
|
+
this.goldfishProcess = (0, child_process_1.spawn)(spawnBin, spawnArgs, { stdio: stdioType, shell: true });
|
|
213
|
+
(_a = this.goldfishProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
214
|
+
console.log(data.toString());
|
|
215
|
+
});
|
|
216
|
+
this.goldfishProcess.on('exit', (code) => {
|
|
217
|
+
ColorConsole_1.default.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
|
|
218
|
+
});
|
|
219
|
+
const p1 = new Promise((resolve) => {
|
|
220
|
+
var _a, _b;
|
|
221
|
+
(_b = (_a = this.goldfishProcess) === null || _a === void 0 ? void 0 : _a.stdout) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
210
222
|
console.log(data.toString());
|
|
211
223
|
if (data.toString().includes('(NSH)')) {
|
|
212
|
-
ColorConsole_1.default.log(
|
|
224
|
+
ColorConsole_1.default.log(`### Emulator ### Goldfish emulator starts successfully`);
|
|
213
225
|
resolve();
|
|
214
226
|
}
|
|
215
227
|
});
|
|
216
|
-
(_b = this.goldfishProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
217
|
-
console.log(data.toString());
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
setTimeout(() => {
|
|
222
|
-
ColorConsole_1.default.log({ message: `### Emulator ### Goldfish emulator starts successfully` });
|
|
223
|
-
resolve();
|
|
224
|
-
}, 2000);
|
|
225
|
-
}
|
|
226
|
-
this.goldfishProcess.on('exit', (code) => {
|
|
227
|
-
ColorConsole_1.default.log({
|
|
228
|
-
level: shared_utils_1.LOG_LEVEL.Error,
|
|
229
|
-
message: `### Emulator ### Goldfish emulator exited with code ${code}`,
|
|
230
|
-
isOnlyPrintError: true
|
|
231
|
-
});
|
|
232
228
|
});
|
|
229
|
+
const p2 = setTimeout(() => {
|
|
230
|
+
ColorConsole_1.default.log(`### Emulator ### Goldfish emulator starts successfully`);
|
|
231
|
+
resolve();
|
|
232
|
+
}, 2000);
|
|
233
|
+
return Promise.race([p1, p2]);
|
|
233
234
|
});
|
|
234
235
|
});
|
|
235
236
|
}
|
|
@@ -241,14 +242,14 @@ class GoldfishInstance {
|
|
|
241
242
|
const sn = `127.0.0.1:${this.adbPort}`;
|
|
242
243
|
while (!adbConnected) {
|
|
243
244
|
const adbKillCmd = `adb kill-server`;
|
|
244
|
-
ColorConsole_1.default.log(
|
|
245
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${adbKillCmd}`);
|
|
245
246
|
adbMiwt.execAdbCmdSync(adbKillCmd);
|
|
246
247
|
const adbConnectCmd = `adb connect ${sn}`;
|
|
247
|
-
ColorConsole_1.default.log(
|
|
248
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${adbConnectCmd}`);
|
|
248
249
|
const str = adbMiwt.execAdbCmdSync(adbConnectCmd);
|
|
249
|
-
ColorConsole_1.default.log(
|
|
250
|
+
ColorConsole_1.default.log(`### Emulator ### ${str}`);
|
|
250
251
|
const devices = yield adbMiwt.getAdbDevices();
|
|
251
|
-
ColorConsole_1.default.log(
|
|
252
|
+
ColorConsole_1.default.log(`### Emulator ### adb devices: ${JSON.stringify(devices)}`);
|
|
252
253
|
adbConnected =
|
|
253
254
|
devices.filter((item) => item.sn === sn && item.status === 'device').length > 0;
|
|
254
255
|
}
|
|
@@ -268,12 +269,10 @@ class GoldfishInstance {
|
|
|
268
269
|
const buildDir = path_1.default.resolve(this.projectPath, 'build');
|
|
269
270
|
const { package: appPackageName } = UxFileUtils_1.default.getMainfestInfo(this.projectPath);
|
|
270
271
|
const appRunDir = path_1.default.resolve(this.sdkHome, 'qa/app', appPackageName);
|
|
271
|
-
ColorConsole_1.default.log(
|
|
272
|
+
ColorConsole_1.default.log(`### Emulator ### Pushing ${appPackageName} to ${appRunDir}`);
|
|
272
273
|
fs_1.default.rmSync(appRunDir, { recursive: true, force: true });
|
|
273
274
|
FileUtil_1.default.copyFiles(buildDir, appRunDir);
|
|
274
|
-
ColorConsole_1.default.log({
|
|
275
|
-
message: `### Emulator ### Push ${appPackageName} to ${appRunDir} successfully`
|
|
276
|
-
});
|
|
275
|
+
ColorConsole_1.default.log(`### Emulator ### Push ${appPackageName} to ${appRunDir} successfully`);
|
|
277
276
|
}
|
|
278
277
|
/** 杀死进程 */
|
|
279
278
|
killProcess(currProcess) {
|
|
@@ -291,13 +290,18 @@ class GoldfishInstance {
|
|
|
291
290
|
}
|
|
292
291
|
}
|
|
293
292
|
catch (err) {
|
|
294
|
-
ColorConsole_1.default.log(
|
|
293
|
+
ColorConsole_1.default.log(`### Emulator ### kill process get error :\n${err.stack}`);
|
|
295
294
|
}
|
|
296
295
|
}
|
|
297
296
|
}
|
|
298
297
|
/** 停止模拟器并释放相关资源 */
|
|
299
298
|
stop() {
|
|
300
299
|
if (this.goldfishProcess) {
|
|
300
|
+
// Linux删除goldfishProcess后,子进程仍存在,导致模拟器窗口未关闭
|
|
301
|
+
// 这里的作用是手动删除创建出来的子进程
|
|
302
|
+
if (os_1.default.platform() === 'linux' && this.goldfishProcess.pid) {
|
|
303
|
+
process.kill(this.goldfishProcess.pid + 1);
|
|
304
|
+
}
|
|
301
305
|
this.killProcess(this.goldfishProcess);
|
|
302
306
|
this.goldfishProcess = undefined;
|
|
303
307
|
}
|
|
@@ -306,7 +310,38 @@ class GoldfishInstance {
|
|
|
306
310
|
this.v9fsProcess = undefined;
|
|
307
311
|
}
|
|
308
312
|
}
|
|
313
|
+
/** 重启模拟器 */
|
|
314
|
+
restart() {
|
|
315
|
+
if (this.goldfishProcess) {
|
|
316
|
+
this.killProcess(this.goldfishProcess);
|
|
317
|
+
this.goldfishProcess = undefined;
|
|
318
|
+
}
|
|
319
|
+
this.start(this.startOptions);
|
|
320
|
+
}
|
|
321
|
+
/** 创建server */
|
|
322
|
+
createWebsockeServer() {
|
|
323
|
+
var _a;
|
|
324
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
325
|
+
const wsServer = new ws_1.WebSocketServer({
|
|
326
|
+
port: (_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.serverPort,
|
|
327
|
+
});
|
|
328
|
+
wsServer.on('connection', socket => {
|
|
329
|
+
ColorConsole_1.default.success(`### App Socket server ### Websocket connects to websocket server`);
|
|
330
|
+
socket.on('error', err => {
|
|
331
|
+
ColorConsole_1.default.error(`### App Socket server ### Websocket server error: ${err.message}`);
|
|
332
|
+
});
|
|
333
|
+
socket.on('message', data => {
|
|
334
|
+
const message = JSON.parse(data.toString());
|
|
335
|
+
ColorConsole_1.default.log(`### App Socket server ### Websocket server get data: ${data}`);
|
|
336
|
+
if (message.type === 'restart') {
|
|
337
|
+
this.restart();
|
|
338
|
+
}
|
|
339
|
+
else if (message.type === 'stop') {
|
|
340
|
+
this.stop();
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
}
|
|
309
346
|
}
|
|
310
347
|
exports.default = GoldfishInstance;
|
|
311
|
-
|
|
312
|
-
//# sourceMappingURL=goldfish.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ChildProcess } from 'child_process';
|
|
3
|
+
import { INewGoldfishInstanceParams, IStartOptions } from '../typing/Instance';
|
|
4
|
+
declare class GoldfishInstance {
|
|
5
|
+
private projectPath;
|
|
6
|
+
private sdkHome;
|
|
7
|
+
private avdHome;
|
|
8
|
+
private adbPort;
|
|
9
|
+
debugPort: number;
|
|
10
|
+
private host9pPort;
|
|
11
|
+
private velaAvdCls;
|
|
12
|
+
private packageName;
|
|
13
|
+
goldfishProcess: ChildProcess | undefined;
|
|
14
|
+
v9fsProcess: ChildProcess | undefined;
|
|
15
|
+
isFirstStart: boolean;
|
|
16
|
+
private startOptions;
|
|
17
|
+
constructor(params: INewGoldfishInstanceParams);
|
|
18
|
+
/** 获取模拟器二进制文件所在位置 */
|
|
19
|
+
getEmulatorBinPath(): string;
|
|
20
|
+
/** 在goldfish模拟器中运行快应用 */
|
|
21
|
+
start(options: IStartOptions): Promise<void>;
|
|
22
|
+
/** 在goldfish中启动快应用 */
|
|
23
|
+
startupQuickApp(options: IStartOptions): void;
|
|
24
|
+
/** host启动9pServer */
|
|
25
|
+
ensure9pServerRunnning(): Promise<void>;
|
|
26
|
+
/** 启动goldfish模拟器 */
|
|
27
|
+
startGoldfish(options: IStartOptions): Promise<void>;
|
|
28
|
+
/** 通过adb连接模拟器 */
|
|
29
|
+
connectGoldfish(): Promise<boolean>;
|
|
30
|
+
/** 将打包后的文件推到挂载的快应用目录 */
|
|
31
|
+
pushRpk(): void;
|
|
32
|
+
/** 杀死进程 */
|
|
33
|
+
killProcess(currProcess?: ChildProcess): void;
|
|
34
|
+
/** 停止模拟器并释放相关资源 */
|
|
35
|
+
stop(): void;
|
|
36
|
+
/** 重启模拟器 */
|
|
37
|
+
restart(): void;
|
|
38
|
+
/** 创建server */
|
|
39
|
+
createWebsockeServer(): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export default GoldfishInstance;
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const UxFileUtils_1 = __importDefault(require("@aiot-toolkit/aiotpack/lib/utils/ux/UxFileUtils"));
|
|
39
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
40
|
+
const adbMiwt = __importStar(require("@miwt/adb"));
|
|
41
|
+
const child_process_1 = require("child_process");
|
|
42
|
+
const find_process_1 = __importDefault(require("find-process"));
|
|
43
|
+
const fs_1 = __importDefault(require("fs"));
|
|
44
|
+
const os_1 = __importDefault(require("os"));
|
|
45
|
+
const path_1 = __importDefault(require("path"));
|
|
46
|
+
const portfinder_1 = __importDefault(require("portfinder"));
|
|
47
|
+
const ws_1 = require("ws");
|
|
48
|
+
const avd_1 = __importDefault(require("../avd"));
|
|
49
|
+
const constants_1 = require("../static/constants");
|
|
50
|
+
const utils_1 = require("../utils");
|
|
51
|
+
class GoldfishInstance {
|
|
52
|
+
constructor(params) {
|
|
53
|
+
this.adbPort = 5555;
|
|
54
|
+
this.debugPort = 10055;
|
|
55
|
+
this.host9pPort = 7878;
|
|
56
|
+
this.isFirstStart = true;
|
|
57
|
+
this.projectPath = params.projectPath;
|
|
58
|
+
this.sdkHome = params.sdkHome || constants_1.defaultSDKHome;
|
|
59
|
+
this.avdHome = params.avdHome || constants_1.defaultAvdHome;
|
|
60
|
+
this.velaAvdCls = new avd_1.default({
|
|
61
|
+
sdkHome: this.sdkHome,
|
|
62
|
+
avdHome: this.avdHome
|
|
63
|
+
});
|
|
64
|
+
const { package: appPackageName } = UxFileUtils_1.default.getMainfestInfo(this.projectPath, params.sourceRoot);
|
|
65
|
+
this.packageName = appPackageName;
|
|
66
|
+
}
|
|
67
|
+
/** 获取模拟器二进制文件所在位置 */
|
|
68
|
+
getEmulatorBinPath() {
|
|
69
|
+
const osPlatform = os_1.default.platform();
|
|
70
|
+
const arch = (0, utils_1.getSystemArch)();
|
|
71
|
+
const platform = osPlatform === 'win32' ? 'windows' : osPlatform;
|
|
72
|
+
const emulatorHome = path_1.default.resolve(this.sdkHome, 'emulator');
|
|
73
|
+
return path_1.default.resolve(emulatorHome, `${platform}-${arch}`, 'emulator');
|
|
74
|
+
}
|
|
75
|
+
/** 在goldfish模拟器中运行快应用 */
|
|
76
|
+
start(options) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
this.startOptions = options;
|
|
79
|
+
// 启动模拟器
|
|
80
|
+
yield this.startGoldfish(options);
|
|
81
|
+
const connected = yield this.connectGoldfish();
|
|
82
|
+
if (connected) {
|
|
83
|
+
ColorConsole_1.default.log('### Emulator ### Goldfish emulator connected successfully');
|
|
84
|
+
if (this.isFirstStart && this.startOptions.serverPort) {
|
|
85
|
+
yield this.createWebsockeServer();
|
|
86
|
+
}
|
|
87
|
+
// adb push快应用到模拟器的/data/app目录
|
|
88
|
+
this.pushRpk();
|
|
89
|
+
// 在模拟器中启动快应用
|
|
90
|
+
this.startupQuickApp(options);
|
|
91
|
+
this.isFirstStart = false;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
ColorConsole_1.default.throw('### Emulator ### Failed to connect emulator, please check whether the adb is normal');
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** 在goldfish中启动快应用 */
|
|
99
|
+
startupQuickApp(options) {
|
|
100
|
+
try {
|
|
101
|
+
let vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp app/${this.packageName} &`;
|
|
102
|
+
if (options.devtool) {
|
|
103
|
+
vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp --jsdebugger=10.0.2.15:101 app/${this.packageName} &`;
|
|
104
|
+
}
|
|
105
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${vappCmd}`);
|
|
106
|
+
// vapp进程会一直pending,不会退出。这里必须加stdio: 'ignore',否则快应用无法运行成功
|
|
107
|
+
adbMiwt.execAdbCmdAsync(vappCmd, { stdio: 'ignore', encoding: 'utf-8' });
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
ColorConsole_1.default.error(`### Emulator ### Failed to startup quickapp: ${e.message}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** host启动9pServer */
|
|
114
|
+
ensure9pServerRunnning() {
|
|
115
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
var _a;
|
|
117
|
+
const yaFileName = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
|
|
118
|
+
const pidList = yield (0, find_process_1.default)('name', yaFileName);
|
|
119
|
+
if (pidList.length > 0) {
|
|
120
|
+
ColorConsole_1.default.log('### Emulator ### 9p server started in host');
|
|
121
|
+
return resolve();
|
|
122
|
+
}
|
|
123
|
+
ColorConsole_1.default.log('### Emulator ### Starting 9p server in host');
|
|
124
|
+
const quickappMountDir = path_1.default.resolve(this.sdkHome, 'qa');
|
|
125
|
+
const toolsHome = path_1.default.resolve(this.sdkHome, 'tools');
|
|
126
|
+
const serverBinPath = path_1.default.resolve(toolsHome, yaFileName);
|
|
127
|
+
fs_1.default.chmodSync(serverBinPath, 0o777);
|
|
128
|
+
this.host9pPort = yield portfinder_1.default.getPortPromise({ port: 7878 });
|
|
129
|
+
const address = `127.0.0.1:${this.host9pPort}`;
|
|
130
|
+
this.v9fsProcess = (0, child_process_1.spawn)(serverBinPath, [
|
|
131
|
+
'--mount-point',
|
|
132
|
+
quickappMountDir,
|
|
133
|
+
'--network-address',
|
|
134
|
+
address,
|
|
135
|
+
'--debug'
|
|
136
|
+
]);
|
|
137
|
+
(_a = this.v9fsProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
138
|
+
const output = data.toString();
|
|
139
|
+
if (output.match(/Server started, listening on: 127.0.0.1:(\d+)/)) {
|
|
140
|
+
ColorConsole_1.default.log(output);
|
|
141
|
+
ColorConsole_1.default.log('### Emulator ### 9p server starts successfully');
|
|
142
|
+
return resolve();
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
this.v9fsProcess.on('exit', (code) => {
|
|
146
|
+
ColorConsole_1.default.error(`### Emulator ### ya-vm-file-server exited with code ${code}`);
|
|
147
|
+
return reject();
|
|
148
|
+
});
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
/** 启动goldfish模拟器 */
|
|
152
|
+
startGoldfish(options) {
|
|
153
|
+
var _a;
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const { avdName, devtool } = options;
|
|
156
|
+
const emulatorBin = this.getEmulatorBinPath();
|
|
157
|
+
ColorConsole_1.default.log(`### Emulator ### emulator path: ${emulatorBin}`);
|
|
158
|
+
const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName);
|
|
159
|
+
const { avdArch, avdImagePath } = avdInfo;
|
|
160
|
+
this.adbPort = yield portfinder_1.default.getPortPromise({ port: this.adbPort });
|
|
161
|
+
ColorConsole_1.default.log(`### Emulator ### adb port: ${this.adbPort}`);
|
|
162
|
+
if (!avdImagePath) {
|
|
163
|
+
return ColorConsole_1.default.throw(`### Emulator ### Unable to find vela image via avd`);
|
|
164
|
+
}
|
|
165
|
+
const nuttxBinPath = path_1.default.resolve(avdImagePath, 'nuttx');
|
|
166
|
+
ColorConsole_1.default.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
|
|
167
|
+
// 端口映射
|
|
168
|
+
const adbPortMappingStr = `-network-user-mode-options hostfwd=tcp:127.0.0.1:${this.adbPort}-10.0.2.15:5555`;
|
|
169
|
+
let debugPortMappingStr = '';
|
|
170
|
+
if (devtool) {
|
|
171
|
+
debugPortMappingStr = `-network-user-mode-options hostfwd=tcp:127.0.0.1:${this.debugPort}-10.0.2.15:101`;
|
|
172
|
+
}
|
|
173
|
+
// 文件系统配置,第一次使用fatfs镜像挂载,后续使用adb push更新应用
|
|
174
|
+
const systemImageBin = path_1.default.resolve(this.sdkHome, 'tools/image/system.img');
|
|
175
|
+
const dataImageBin = path_1.default.resolve(this.sdkHome, 'tools/image/data.img');
|
|
176
|
+
const imageMountStr = `-drive index=0,id=system,if=none,format=raw,file=${systemImageBin} \
|
|
177
|
+
-device virtio-blk-device,bus=virtio-mmio-bus.0,drive=system \
|
|
178
|
+
-drive index=1,id=userdata,if=none,format=raw,file=${dataImageBin} \
|
|
179
|
+
-device virtio-blk-device,bus=virtio-mmio-bus.1,drive=userdata \
|
|
180
|
+
-device virtio-snd,bus=virtio-mmio-bus.2 -allow-host-audio -semihosting`;
|
|
181
|
+
// vnc配置
|
|
182
|
+
let windowStr = '';
|
|
183
|
+
let vncStr = '';
|
|
184
|
+
if ((_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.vncPort) {
|
|
185
|
+
windowStr = '-no-window';
|
|
186
|
+
const portSuffix = this.startOptions.vncPort - constants_1.defaultVncPort;
|
|
187
|
+
vncStr = `-vnc :${portSuffix}`;
|
|
188
|
+
}
|
|
189
|
+
const stdioType = options.disableNSH ? 'pipe' : 'inherit';
|
|
190
|
+
// 启动goldfish的命令和参数
|
|
191
|
+
const cmd = `${emulatorBin} -nuttx -avd ${avdName} -avd-arch ${avdArch} -show-kernel -kernel ${nuttxBinPath} ${adbPortMappingStr} ${debugPortMappingStr} -qemu ${windowStr} ${vncStr} ${imageMountStr}`;
|
|
192
|
+
const spawnArgs = cmd.split(' ');
|
|
193
|
+
const spawnBin = spawnArgs.shift();
|
|
194
|
+
ColorConsole_1.default.log(`### Emulator ### Start CMD: ${cmd}`);
|
|
195
|
+
return new Promise((resolve) => {
|
|
196
|
+
var _a, _b;
|
|
197
|
+
this.goldfishProcess = (0, child_process_1.spawn)(spawnBin, spawnArgs, { stdio: stdioType, shell: true });
|
|
198
|
+
if (options.disableNSH) {
|
|
199
|
+
(_a = this.goldfishProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
200
|
+
console.log(data.toString());
|
|
201
|
+
if (data.toString().includes('(NSH)')) {
|
|
202
|
+
ColorConsole_1.default.log(`### Emulator ### Goldfish emulator starts successfully`);
|
|
203
|
+
resolve();
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
(_b = this.goldfishProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
207
|
+
console.log(data.toString());
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
setTimeout(() => {
|
|
212
|
+
ColorConsole_1.default.log(`### Emulator ### Goldfish emulator starts successfully`);
|
|
213
|
+
resolve();
|
|
214
|
+
}, 2000);
|
|
215
|
+
}
|
|
216
|
+
this.goldfishProcess.on('exit', (code) => {
|
|
217
|
+
ColorConsole_1.default.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
/** 通过adb连接模拟器 */
|
|
223
|
+
connectGoldfish() {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
let adbConnected = false;
|
|
226
|
+
const connectFn = () => __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
const sn = `127.0.0.1:${this.adbPort}`;
|
|
228
|
+
while (!adbConnected) {
|
|
229
|
+
const adbKillCmd = `adb kill-server`;
|
|
230
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${adbKillCmd}`);
|
|
231
|
+
adbMiwt.execAdbCmdSync(adbKillCmd);
|
|
232
|
+
const adbConnectCmd = `adb connect ${sn}`;
|
|
233
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${adbConnectCmd}`);
|
|
234
|
+
const str = adbMiwt.execAdbCmdSync(adbConnectCmd);
|
|
235
|
+
ColorConsole_1.default.log(`### Emulator ### ${str}`);
|
|
236
|
+
const devices = yield adbMiwt.getAdbDevices();
|
|
237
|
+
ColorConsole_1.default.log(`### Emulator ### adb devices: ${JSON.stringify(devices)}`);
|
|
238
|
+
adbConnected =
|
|
239
|
+
devices.filter((item) => item.sn === sn && item.status === 'device').length > 0;
|
|
240
|
+
}
|
|
241
|
+
Promise.resolve(adbConnected);
|
|
242
|
+
});
|
|
243
|
+
yield Promise.race([
|
|
244
|
+
connectFn(),
|
|
245
|
+
new Promise((resolve) => {
|
|
246
|
+
setTimeout(() => resolve(false), 600 * 1000);
|
|
247
|
+
})
|
|
248
|
+
]);
|
|
249
|
+
return adbConnected;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
/** 将打包后的文件推到挂载的快应用目录 */
|
|
253
|
+
pushRpk() {
|
|
254
|
+
const sn = `127.0.0.1:${this.adbPort}`;
|
|
255
|
+
const { package: appPackageName } = UxFileUtils_1.default.getMainfestInfo(this.projectPath);
|
|
256
|
+
const appRunDir = '/data/app';
|
|
257
|
+
ColorConsole_1.default.log(`### Emulator ### Pushing ${appPackageName} to ${appRunDir}`);
|
|
258
|
+
(0, child_process_1.execSync)(`adb -s ${sn} shell mkdir /data/app/${appPackageName}`, { stdio: 'ignore' });
|
|
259
|
+
(0, child_process_1.execSync)(`adb -s ${sn} push ./build/* /data/app/${appPackageName}`, { cwd: this.projectPath, stdio: 'ignore' });
|
|
260
|
+
ColorConsole_1.default.log(`### Emulator ### Push ${appPackageName} to ${appRunDir} successfully`);
|
|
261
|
+
}
|
|
262
|
+
/** 杀死进程 */
|
|
263
|
+
killProcess(currProcess) {
|
|
264
|
+
if (currProcess && currProcess.pid && currProcess.exitCode === null) {
|
|
265
|
+
console.log('process pid:', currProcess.pid);
|
|
266
|
+
try {
|
|
267
|
+
if (os_1.default.platform() === 'win32') {
|
|
268
|
+
(0, child_process_1.execSync)(`taskkill /pid ${currProcess.pid} /T /F`);
|
|
269
|
+
}
|
|
270
|
+
else if (os_1.default.platform() === 'darwin') {
|
|
271
|
+
process.kill(currProcess.pid);
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
currProcess.kill();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
catch (err) {
|
|
278
|
+
ColorConsole_1.default.log(`### Emulator ### kill process get error :\n${err.stack}`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/** 停止模拟器并释放相关资源 */
|
|
283
|
+
stop() {
|
|
284
|
+
if (this.goldfishProcess) {
|
|
285
|
+
// Linux删除goldfishProcess后,子进程仍存在,导致模拟器窗口未关闭
|
|
286
|
+
// 这里的作用是手动删除创建出来的子进程
|
|
287
|
+
if (os_1.default.platform() === 'linux' && this.goldfishProcess.pid) {
|
|
288
|
+
process.kill(this.goldfishProcess.pid + 1);
|
|
289
|
+
}
|
|
290
|
+
this.killProcess(this.goldfishProcess);
|
|
291
|
+
this.goldfishProcess = undefined;
|
|
292
|
+
}
|
|
293
|
+
if (this.v9fsProcess) {
|
|
294
|
+
this.killProcess(this.v9fsProcess);
|
|
295
|
+
this.v9fsProcess = undefined;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/** 重启模拟器 */
|
|
299
|
+
restart() {
|
|
300
|
+
if (this.goldfishProcess) {
|
|
301
|
+
this.killProcess(this.goldfishProcess);
|
|
302
|
+
this.goldfishProcess = undefined;
|
|
303
|
+
}
|
|
304
|
+
this.start(this.startOptions);
|
|
305
|
+
}
|
|
306
|
+
/** 创建server */
|
|
307
|
+
createWebsockeServer() {
|
|
308
|
+
var _a;
|
|
309
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
+
const wsServer = new ws_1.WebSocketServer({
|
|
311
|
+
port: (_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.serverPort,
|
|
312
|
+
});
|
|
313
|
+
wsServer.on('connection', socket => {
|
|
314
|
+
ColorConsole_1.default.success(`### App Socket server ### Websocket connects to websocket server`);
|
|
315
|
+
socket.on('error', err => {
|
|
316
|
+
ColorConsole_1.default.error(`### App Socket server ### Websocket server error: ${err.message}`);
|
|
317
|
+
});
|
|
318
|
+
socket.on('message', data => {
|
|
319
|
+
const message = JSON.parse(data.toString());
|
|
320
|
+
ColorConsole_1.default.log(`### App Socket server ### Websocket server get data: ${data}`);
|
|
321
|
+
if (message.type === 'restart') {
|
|
322
|
+
this.restart();
|
|
323
|
+
}
|
|
324
|
+
else if (message.type === 'stop') {
|
|
325
|
+
this.stop();
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
exports.default = GoldfishInstance;
|
package/lib/static/constants.js
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
-
exports.defaultToolsHome = exports.defaultQuickappHome = exports.defaultSkinHome = exports.defaultEmulatorHome = exports.defaultImageHome = exports.defaultAvdHome = exports.defaultSDKHome = void 0;
|
|
6
|
+
exports.defaultVncPort = exports.defaultToolsHome = exports.defaultQuickappHome = exports.defaultSkinHome = exports.defaultEmulatorHome = exports.defaultImageHome = exports.defaultAvdHome = exports.defaultSDKHome = void 0;
|
|
7
7
|
const os_1 = __importDefault(require("os"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
exports.defaultSDKHome = path_1.default.resolve(os_1.default.homedir(), '.export');
|
|
@@ -13,5 +13,4 @@ exports.defaultEmulatorHome = path_1.default.resolve(exports.defaultSDKHome, 'em
|
|
|
13
13
|
exports.defaultSkinHome = path_1.default.resolve(exports.defaultSDKHome, 'skins');
|
|
14
14
|
exports.defaultQuickappHome = path_1.default.resolve(exports.defaultSDKHome, 'qa');
|
|
15
15
|
exports.defaultToolsHome = path_1.default.resolve(exports.defaultSDKHome, 'tools');
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=constants.js.map
|
|
16
|
+
exports.defaultVncPort = 5900;
|
package/lib/typing/Avd.js
CHANGED
package/lib/typing/Instance.d.ts
CHANGED
package/lib/typing/Instance.js
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
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.getSystemArch = void 0;
|
|
7
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const os_1 = __importDefault(require("os"));
|
|
10
|
+
const semver_1 = __importDefault(require("semver"));
|
|
11
|
+
const cpuArch = {
|
|
12
|
+
arm64: 'aarch64',
|
|
13
|
+
aarch64: 'aarch64',
|
|
14
|
+
x64: 'x86_64',
|
|
15
|
+
x86_64: 'x86_64',
|
|
16
|
+
};
|
|
17
|
+
/** 获取mac电脑的CPU架构
|
|
18
|
+
* node 15.0.0之后,m1芯片的mac的os.arch()才是arm64,在这之前都是x86
|
|
19
|
+
* 所以15.0.0之前无法通过os.arch()区分,也无法通过execSync('uname -m')区分
|
|
20
|
+
*/
|
|
21
|
+
function getSystemArch() {
|
|
22
|
+
const platform = os_1.default.platform();
|
|
23
|
+
let osArch = os_1.default.arch();
|
|
24
|
+
const nodeVersion = process.version;
|
|
25
|
+
if (semver_1.default.lt(nodeVersion, '15.0.0') && platform === 'darwin') {
|
|
26
|
+
try {
|
|
27
|
+
(0, child_process_1.execSync)('sysctl -n sysctl.proc_translated');
|
|
28
|
+
osArch = 'arm64';
|
|
29
|
+
}
|
|
30
|
+
catch (_a) {
|
|
31
|
+
osArch = 'x64';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (osArch !== 'arm64' && osArch !== 'x64') {
|
|
35
|
+
return ColorConsole_1.default.throw(`unsupport system`);
|
|
36
|
+
}
|
|
37
|
+
return cpuArch[osArch];
|
|
38
|
+
}
|
|
39
|
+
exports.getSystemArch = getSystemArch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/emulator",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-dev.1",
|
|
4
4
|
"description": "vela emulator tool.",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"emulator"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@aiot-toolkit/aiotpack": "2.0.
|
|
39
|
-
"@aiot-toolkit/shared-utils": "2.0.
|
|
38
|
+
"@aiot-toolkit/aiotpack": "2.0.2-dev.1",
|
|
39
|
+
"@aiot-toolkit/shared-utils": "2.0.2-dev.1",
|
|
40
40
|
"find-process": "^1.4.7",
|
|
41
41
|
"portfinder": "^1.0.32"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "0beecc786c41b73ab2dabeaad06fb4ad19115f4b"
|
|
44
44
|
}
|
package/lib/avd/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["avd/index.ts"],"names":[],"mappings":";;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,mDAAsF;AACtF,uCAA2E;AAE3E,MAAM,eAAe,GAAG;IACpB,KAAK,EAAE;QACH,OAAO,EAAE,aAAa;KACzB;IACD,OAAO,EAAE;QACL,OAAO,EAAE,WAAW;KACvB;CACJ,CAAA;AAED,MAAM,UAAU;IAIZ,YAAY,gBAAmC;QAC3C,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAA;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,0BAAc,CAAA;QACxC,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,0BAAc,CAAA;IAC5C,CAAC;IAED,aAAa,CAAC,SAAqB;QAC/B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,4BAAgB,EAAE,GAAG,SAAS,CAAA;QACrG,MAAM,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,MAAM,CAAC,CAAA;QAC3D,MAAM,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,MAAM,CAAC,CAAA;Q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SACd;QAAC,OAAO,CAAC,EAAE;YACR,OAAO,KAAK,CAAA;SACf;IACL,CAAC;IAED,cAAc;QACV,IAAI;YACA,MAAM,OAAO,GAAiB,EAAE,CAAC;YACjC,MAAM,KAAK,GAAG,YAAE,CAAC,WAAW,CAAC,0BAAc,CAAC,CAAC;YAC7C,MAAM,KAAK,GAAG,sBAAsB,CAAC;YACrC,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE;gBAC1B,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACtC,IAAI,OAAO,EAAE;oBACT,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;oBAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;oBAC7C,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;iBACzB;aACJ;YACD,OAAO,OAAO,CAAC;SAClB;QAAC,OAAO,GAAG,EAAE;YACV,OAAO,EAAE,CAAC;SACb;IACL,CAAC;IAED,eAAe;QACX,IAAI;YACA,MAAM,QAAQ,GAAG,EAAE,CAAA;YACnB,MAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YACpD,IAAI,KAAK,GAAG,YAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;YACpC,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE;gBAC1B,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;aACvD;YACD,OAAO,QAAQ,CAAA;SAClB;QAAC,OAAO,CAAC,EAAE;YACR,OAAO,EAAE,CAAA;SACZ;IACL,CAAC;CACJ;AAED,kBAAe,UAAU,CAAA","file":"index.js","sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport { defaultAvdHome, defaultImageHome, defaultSDKHome } from '../static/constants'\nimport { IAvdArchType, IAvdParams, IAvdResourcePaths } from '../typing/Avd'\n\nconst EAvdParamsToIni = {\n 'arm': {\n abiType: 'armeabi-v7a',\n },\n 'arm64': {\n abiType: 'arm64-v8a',\n }\n}\n\nclass VelaAvdCls {\n private avdHome: string\n private sdkHome: string\n\n constructor(avdResourcePaths: IAvdResourcePaths) {\n const { avdHome, sdkHome } = avdResourcePaths\n this.avdHome = avdHome || defaultAvdHome\n this.sdkHome = sdkHome || defaultSDKHome\n }\n\n createVelaAvd(avdParams: IAvdParams) {\n const { avdName, avdArch, avdWidth, avdHeight, avdSkin, avdImagePath = defaultImageHome } = avdParams\n const avdDir = path.resolve(this.avdHome, `${avdName}.avd`)\n const avdIni = path.resolve(this.avdHome, `${avdName}.ini`)\n const avdConfigIni = path.resolve(avdDir, 'config.ini')\n const nuttxAvdIniContent = `path=${avdDir}\\npath.rel=avd${path.sep}${avdName}.avd`\n const abiType = EAvdParamsToIni[avdArch]['abiType']\n const configIniJson: any = JSON.parse(fs.readFileSync(path.join(__dirname, '../static/avdConfigIni.json'), 'utf-8'))\n configIniJson['AvdId'] = avdName\n configIniJson['abi.type'] = abiType\n configIniJson['avd.ini.displayname'] = avdName\n configIniJson['hw.cpu.arch'] = avdArch\n if (avdSkin) {\n delete configIniJson['hw.lcd.height']\n delete configIniJson['hw.lcd.width']\n configIniJson['skin.dynamic'] = 'yes'\n configIniJson['skin.name'] = avdSkin\n configIniJson['skin.path'] = path.resolve(this.sdkHome, 'skins', avdSkin)\n } else {\n configIniJson['hw.lcd.height'] = avdHeight\n configIniJson['hw.lcd.width'] = avdWidth\n configIniJson['skin.dynamic'] = 'no'\n delete configIniJson['skin.name']\n delete configIniJson['skin.path']\n }\n configIniJson['image.sysdir.1'] = avdImagePath\n try {\n fs.mkdirSync(avdDir, { recursive: true })\n // 写入Vela_Virtual_Device.ini文件\n fs.writeFileSync(avdIni, nuttxAvdIniContent)\n // 写入Vela_Virtual_Device.avd/config.ini文件\n const fWrite = fs.createWriteStream(avdConfigIni)\n for (const item in configIniJson) {\n const line = `${item} = ${configIniJson[item]}\\n`\n fWrite.write(line);\n }\n fWrite.close();\n return true\n } catch (e) {\n return false\n }\n }\n\n getVelaAvdInfo(avdName: string) {\n const avdInfo: IAvdParams = {\n avdName,\n avdArch: IAvdArchType.arm,\n avdHeight: '',\n avdWidth: '',\n avdSkin: '',\n avdImagePath: ''\n }\n const currAvdDir = path.resolve(this.avdHome, `${avdName}.avd`)\n const configIni = path.resolve(currAvdDir, 'config.ini')\n const contents = fs.readFileSync(configIni, 'utf-8')\n // 这里需要使用惰性匹配\n const archRegex = /hw.cpu.arch = ([\\d\\D]+?)\\n/\n const archMatcher = contents.match(archRegex)\n const heightRegex = /hw.lcd.height = ([\\d\\D]+?)\\n/\n const heightMatcher = contents.match(heightRegex)\n const widthRegex = /hw.lcd.width = ([\\d\\D]+?)\\n/\n const widthMatcher = contents.match(widthRegex)\n const skinRegex = /skin.name = ([\\d\\D]+?)\\n/\n const skinMatcher = contents.match(skinRegex)\n const imagePathRegex = /image.sysdir.1 = ([\\d\\D]+?)\\n/\n const imagePathMather = contents.match(imagePathRegex)\n archMatcher && (avdInfo.avdArch = (archMatcher[1] as IAvdArchType))\n heightMatcher && (avdInfo.avdHeight = heightMatcher[1])\n widthMatcher && (avdInfo.avdWidth = widthMatcher[1])\n skinMatcher && (avdInfo.avdSkin = skinMatcher[1])\n imagePathMather && (avdInfo.avdImagePath = imagePathMather[1])\n return avdInfo\n }\n\n deleteVelaAvd(avdName: string) {\n const avdDir = path.resolve(this.avdHome, `${avdName}.avd`)\n const avdIni = path.resolve(this.avdHome, `${avdName}.ini`);\n try {\n fs.rmSync(avdDir, { recursive: true, force: true });\n fs.rmSync(avdIni, { force: true })\n return true\n } catch (e) {\n return false\n }\n }\n\n getVelaAvdList() {\n try {\n const avdList: IAvdParams[] = [];\n const files = fs.readdirSync(defaultAvdHome);\n const regex = /^(Vela[\\d\\D]*)\\.avd$/;\n for (const fileName of files) {\n const matcher = fileName.match(regex);\n if (matcher) {\n const avdName = matcher[1];\n const avdInfo = this.getVelaAvdInfo(avdName);\n avdList.push(avdInfo);\n }\n }\n return avdList;\n } catch (err) {\n return [];\n }\n }\n\n getVelaSkinList() {\n try {\n const skinList = []\n const skinHome = path.resolve(this.sdkHome, 'skins')\n let files = fs.readdirSync(skinHome)\n for (const fileName of files) {\n !fileName.startsWith('.') && skinList.push(fileName)\n }\n return skinList\n } catch (e) {\n return []\n }\n }\n}\n\nexport default VelaAvdCls\n"],"sourceRoot":"../../src"}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,gDAA8C;AAM1B,2FANA,aAAU,OAMA;AAL9B,mEAAkE;AAKhE,iGALkB,kBAAgB,OAKlB;AAJlB,+CAA6B;AAC7B,oDAAkC","file":"index.js","sourcesContent":["import { default as VelaAvdCls } from './avd';\nimport { default as GoldfishInstance } from './instance/goldfish';\nexport * from './typing/Avd';\nexport * from './typing/Instance';\n\nexport {\n GoldfishInstance, VelaAvdCls\n};\n\n"],"sourceRoot":"../src"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["instance/goldfish.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kGAAyE;AACzE,6DAAsD;AACtD,+FAAsE;AACtE,6FAAoE;AACpE,mDAAoC;AACpC,iDAA6D;AAC7D,gEAAsC;AACtC,4CAAmB;AACnB,4CAAmB;AACnB,gDAAuB;AACvB,4DAAmC;AACnC,iDAA+B;AAC/B,mDAK4B;AAG5B,MAAM,gBAAgB;IAYpB,YAAY,MAAkC;QARtC,YAAO,GAAW,KAAK,CAAA;QACxB,cAAS,GAAW,KAAK,CAAA;QACxB,eAAU,GAAW,IAAI,CAAA;QAO/B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAA;QACrC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I,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;iBAC9B;qBAAM;oBACL,WAAW,CAAC,IAAI,EAAE,CAAA;iBACnB;aACF;YAAC,OAAO,GAAG,EAAE;gBACZ,sBAAY,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,6BAA8B,GAAa,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;aACnF;SACF;IACH,CAAC;IAED,mBAAmB;IACnB,IAAI;QACF,IAAI,IAAI,CAAC,eAAe,EAAE;YACxB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;YACtC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAA;SACjC;QACD,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YAClC,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;SAC7B;IACH,CAAC;CACF;AAED,kBAAe,gBAAgB,CAAA","file":"goldfish.js","sourcesContent":["import UxFileUtils from '@aiot-toolkit/aiotpack/lib/utils/ux/UxFileUtils'\nimport { LOG_LEVEL } from '@aiot-toolkit/shared-utils'\nimport ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport FileUtil from '@aiot-toolkit/shared-utils/lib/utils/FileUtil'\nimport * as adbMiwt from '@miwt/adb'\nimport { ChildProcess, execSync, spawn } from 'child_process'\nimport findProcess from 'find-process'\nimport fs from 'fs'\nimport os from 'os'\nimport path from 'path'\nimport portfinder from 'portfinder'\nimport VelaAvdCls from '../avd'\nimport {\n defaultAvdHome,\n defaultEmulatorHome,\n defaultSDKHome,\n defaultToolsHome\n} from '../static/constants'\nimport { INewGoldfishInstanceParams, IStartOptions } from '../typing/Instance'\n\nclass GoldfishInstance {\n private projectPath: string\n private sdkHome: string\n private avdHome: string\n private adbPort: number = 15555\n public debugPort: number = 10055\n private host9pPort: number = 7878\n private velaAvdCls: VelaAvdCls\n private packageName: string\n public goldfishProcess: ChildProcess | undefined\n public v9fsProcess: ChildProcess | undefined\n\n constructor(params: INewGoldfishInstanceParams) {\n this.projectPath = params.projectPath\n this.sdkHome = params.sdkHome || defaultSDKHome\n this.avdHome = params.avdHome || defaultAvdHome\n this.velaAvdCls = new VelaAvdCls({\n sdkHome: this.sdkHome,\n avdHome: this.avdHome\n })\n const { package: appPackageName } = UxFileUtils.getMainfestInfo(\n this.projectPath,\n params.sourceRoot\n )\n this.packageName = appPackageName\n }\n\n /** 获取模拟器二进制文件所在位置 */\n getEmulatorBinPath() {\n const osPlatform = os.platform()\n const osArch = os.arch()\n const platform = osPlatform === 'win32' ? 'windows' : osPlatform\n const arch = (osArch === 'arm64' || osArch === 'aarch64') ? 'aarch64' : 'x86_64'\n return path.resolve(defaultEmulatorHome, `${platform}-${arch}`, 'emulator')\n }\n\n /** 在goldfish模拟器中运行快应用 */\n async start(options: IStartOptions) {\n // host启动9p server\n await this.ensure9pServerRunnning()\n // TODO: 打包快应用\n // 将rpk推到host的defaultQuickappHome目录\n this.pushRpk()\n // 启动模拟器\n await this.startGoldfish(options)\n const connected = await this.connectGoldfish()\n if (connected) {\n ColorConsole.log({\n message: '### Emulator ### Goldfish emulator connected successfully'\n })\n // 在模拟器中启动快应用\n this.startupQuickApp(options)\n } else {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message:\n '### Emulator ### Failed to connect emulator, please check whether the adb is normal'\n })\n }\n }\n\n /** 在goldfish中启动快应用 */\n startupQuickApp(options: IStartOptions) {\n try {\n const appMountDir = path.resolve(this.sdkHome, 'qa')\n const mountCmd = `adb -s 127.0.0.1:${this.adbPort} shell mount -t v9fs -o tag=10.0.2.2,port=${this.host9pPort},aname=${appMountDir} /data`\n ColorConsole.log({ message: `### Emulator ### Excuting adb cmd: ${mountCmd}` })\n adbMiwt.execAdbCmdSync(mountCmd)\n let vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp app/${this.packageName} &`\n if (options.devtool) {\n vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp --jsdebugger=10.0.2.15:101 app/${this.packageName} &`\n }\n ColorConsole.log({ message: `### Emulator ### Excuting adb cmd: ${vappCmd}` })\n // vapp进程会一直pending,不会退出。这里必须加stdio: 'ignore',否则快应用无法运行成功\n adbMiwt.execAdbCmdAsync(vappCmd, { stdio: 'ignore', encoding: 'utf-8' })\n } catch (e: any) {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `### Emulator ### Failed to startup quickapp: ${e.message}`,\n isOnlyPrintError: true\n })\n }\n }\n /** host启动9pServer */\n ensure9pServerRunnning(): Promise<void> {\n return new Promise(async (resolve, reject) => {\n const yaFileName = os.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server'\n const pidList = await findProcess('name', yaFileName)\n if (pidList.length > 0) {\n ColorConsole.log({ message: '### Emulator ### 9p server started in host' })\n return resolve()\n }\n ColorConsole.log({ message: '### Emulator ### Starting 9p server in host' })\n const quickappMountDir = path.resolve(this.sdkHome, 'qa')\n const serverBinPath = path.resolve(defaultToolsHome, yaFileName)\n fs.chmodSync(serverBinPath, 0o777)\n this.host9pPort = await portfinder.getPortPromise({ port: 7878 })\n const address = `127.0.0.1:${this.host9pPort}`\n this.v9fsProcess = spawn(serverBinPath, [\n '--mount-point',\n quickappMountDir,\n '--network-address',\n address,\n '--debug'\n ])\n\n this.v9fsProcess.stderr?.on('data', (data) => {\n const output = data.toString()\n if (output.match(/Server started, listening on: 127.0.0.1:(\\d+)/)) {\n ColorConsole.log({ message: output })\n ColorConsole.log({ message: '### Emulator ### 9p server starts successfully' })\n return resolve()\n }\n })\n\n this.v9fsProcess.on('exit', (code) => {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `### Emulator ### ya-vm-file-server exited with code ${code}`,\n isOnlyPrintError: true\n })\n return reject()\n })\n })\n }\n\n /** 启动goldfish模拟器 */\n async startGoldfish(options: IStartOptions) {\n const { avdName, devtool } = options\n const emulatorBin = this.getEmulatorBinPath()\n ColorConsole.log({ message: `### Emulator ### emulator path: ${emulatorBin}` })\n const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName)\n const { avdArch, avdImagePath } = avdInfo\n this.adbPort = await portfinder.getPortPromise({ port: this.adbPort })\n ColorConsole.log({ message: `### Emulator ### adb port: ${this.adbPort}` })\n if (!avdImagePath) {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `### Emulator ### Unable to find vela image via avd`\n })\n process.exit()\n }\n const nuttxBinPath = path.resolve(avdImagePath, 'nuttx')\n ColorConsole.log({ message: `### Emulator ### nuttx path: ${nuttxBinPath}` })\n let portMappingStr = `user,id=u1,hostfwd=tcp:127.0.0.1:${this.adbPort}-10.0.2.15:5555`\n if (devtool) {\n this.debugPort = await portfinder.getPortPromise({ port: this.debugPort })\n ColorConsole.log({ message: `### Emulator ### debug port: ${this.debugPort}` })\n portMappingStr += `,hostfwd=tcp:127.0.0.1:${this.debugPort}-10.0.2.15:101`\n }\n ColorConsole.log({ message: `### Emulator ### Start qemu with TCP: ${portMappingStr}` })\n const stdioType = options.disableNSH ? 'pipe' : 'inherit'\n\n return new Promise<void>((resolve) => {\n this.goldfishProcess = spawn(\n emulatorBin,\n [\n '-nuttx',\n '-avd',\n avdName,\n '-avd-arch',\n avdArch,\n '-show-kernel',\n '-kernel',\n nuttxBinPath,\n '-qemu',\n '-netdev',\n portMappingStr,\n '-device',\n 'virtio-net-device,netdev=u1,bus=virtio-mmio-bus.3'\n ],\n { stdio: stdioType }\n )\n if (options.disableNSH) {\n this.goldfishProcess.stdout?.on('data', (data: Buffer) => {\n console.log(data.toString())\n if (data.toString().includes('(NSH)')) {\n ColorConsole.log({ message: `### Emulator ### Goldfish emulator starts successfully` })\n resolve()\n }\n })\n this.goldfishProcess.stderr?.on('data', (data) => {\n console.log(data.toString())\n })\n } else {\n setTimeout(() => {\n ColorConsole.log({ message: `### Emulator ### Goldfish emulator starts successfully` })\n resolve()\n }, 2000)\n }\n this.goldfishProcess.on('exit', (code) => {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `### Emulator ### Goldfish emulator exited with code ${code}`,\n isOnlyPrintError: true\n })\n })\n })\n }\n\n /** 通过adb连接模拟器 */\n async connectGoldfish() {\n let adbConnected = false\n const connectFn = async () => {\n const sn = `127.0.0.1:${this.adbPort}`\n while (!adbConnected) {\n const adbKillCmd = `adb kill-server`\n ColorConsole.log({ message: `### Emulator ### Excuting adb cmd: ${adbKillCmd}` })\n adbMiwt.execAdbCmdSync(adbKillCmd)\n const adbConnectCmd = `adb connect ${sn}`\n ColorConsole.log({ message: `### Emulator ### Excuting adb cmd: ${adbConnectCmd}` })\n const str = adbMiwt.execAdbCmdSync(adbConnectCmd)\n ColorConsole.log({ message: `### Emulator ### ${str}` })\n const devices = await adbMiwt.getAdbDevices()\n ColorConsole.log({ message: `### Emulator ### adb devices: ${JSON.stringify(devices)}` })\n adbConnected =\n devices.filter((item) => item.sn === sn && item.status === 'device').length > 0\n }\n Promise.resolve(adbConnected)\n }\n await Promise.race([\n connectFn(),\n new Promise((resolve) => {\n setTimeout(() => resolve(false), 600 * 1000)\n })\n ])\n return adbConnected\n }\n\n /** 将打包后的文件推到挂载的快应用目录 */\n pushRpk() {\n const buildDir = path.resolve(this.projectPath, 'build')\n const { package: appPackageName } = UxFileUtils.getMainfestInfo(this.projectPath)\n const appRunDir = path.resolve(this.sdkHome, 'qa/app', appPackageName)\n ColorConsole.log({ message: `### Emulator ### Pushing ${appPackageName} to ${appRunDir}` })\n fs.rmSync(appRunDir, { recursive: true, force: true })\n FileUtil.copyFiles(buildDir, appRunDir)\n ColorConsole.log({\n message: `### Emulator ### Push ${appPackageName} to ${appRunDir} successfully`\n })\n }\n\n /** 杀死进程 */\n killProcess(currProcess?: ChildProcess) {\n if (currProcess && currProcess.pid && currProcess.exitCode === null) {\n console.log('process pid:', currProcess.pid)\n try {\n if (os.platform() === 'win32') {\n execSync(`taskkill /pid ${currProcess.pid} /T /F`)\n } else if (os.platform() === 'darwin') {\n process.kill(currProcess.pid)\n } else {\n currProcess.kill()\n }\n } catch (err) {\n ColorConsole.log({ message: `kill process get error :\\n${(err as Error).stack}` })\n }\n }\n }\n\n /** 停止模拟器并释放相关资源 */\n stop() {\n if (this.goldfishProcess) {\n this.killProcess(this.goldfishProcess)\n this.goldfishProcess = undefined\n }\n if (this.v9fsProcess) {\n this.killProcess(this.v9fsProcess)\n this.v9fsProcess = undefined\n }\n }\n}\n\nexport default GoldfishInstance\n"],"sourceRoot":"../../src"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["static/constants.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AAEV,QAAA,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAA;AACtD,QAAA,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC,CAAA;AAC9D,QAAA,gBAAgB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,mBAAmB,CAAC,CAAA;AACpE,QAAA,mBAAmB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,UAAU,CAAC,CAAA;AAC9D,QAAA,eAAe,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,OAAO,CAAC,CAAA;AACvD,QAAA,mBAAmB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,IAAI,CAAC,CAAA;AACxD,QAAA,gBAAgB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,OAAO,CAAC,CAAA","file":"constants.js","sourcesContent":["import os from 'os'\nimport path from 'path'\n\nexport const defaultSDKHome = path.resolve(os.homedir(), '.export')\nexport const defaultAvdHome = path.resolve(os.homedir(), '.android', 'avd')\nexport const defaultImageHome = path.resolve(defaultSDKHome, 'system-images/arm')\nexport const defaultEmulatorHome = path.resolve(defaultSDKHome, 'emulator')\nexport const defaultSkinHome = path.resolve(defaultSDKHome, 'skins')\nexport const defaultQuickappHome = path.resolve(defaultSDKHome, 'qa')\nexport const defaultToolsHome = path.resolve(defaultSDKHome, 'tools')"],"sourceRoot":"../../src"}
|
package/lib/typing/Avd.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["typing/Avd.ts"],"names":[],"mappings":";;;AAMA,IAAY,YAA4C;AAAxD,WAAY,YAAY;IAAG,2BAAW,CAAA;IAAE,+BAAe,CAAA;AAAA,CAAC,EAA5C,YAAY,4BAAZ,YAAY,QAAgC","file":"Avd.js","sourcesContent":["export interface IAvdResourcePaths {\n avdHome?: string\n sdkHome?: string\n imageHome?: string\n}\n\nexport enum IAvdArchType { arm = 'arm', arm64 = 'arm64'}\n\nexport interface IAvdParams {\n avdName: string\n avdArch: IAvdArchType\n avdWidth: string\n avdHeight: string\n avdSkin?: string\n avdImagePath?: string\n}\n\nexport interface ISkinInfo {\n skinName: string\n skinPath: string\n skinBackBase64: string // 背景图的base64\n}"],"sourceRoot":"../../src"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["typing/Instance.ts"],"names":[],"mappings":"","file":"Instance.js","sourcesContent":["import { IAvdResourcePaths } from \"./Avd\";\n\nexport interface INewGoldfishInstanceParams extends IAvdResourcePaths {\n projectPath: string\n sourceRoot?: string\n}\n\nexport interface IStartOptions {\n avdName: string;\n devtool?: string;\n disableNSH?: boolean;\n}"],"sourceRoot":"../../src"}
|