@aiot-toolkit/emulator 2.0.2-beta.13 → 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 +62 -128
- package/lib/instance/index.js +2 -2
- package/lib/instance/miwear.d.ts +10 -9
- package/lib/instance/miwear.js +60 -142
- 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/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/instance/preDev.js
CHANGED
|
@@ -35,7 +35,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const
|
|
38
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
39
|
+
const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
|
|
39
40
|
const adbMiwt = __importStar(require("@miwt/adb"));
|
|
40
41
|
const child_process_1 = require("child_process");
|
|
41
42
|
const find_process_1 = __importDefault(require("find-process"));
|
|
@@ -43,7 +44,9 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
43
44
|
const os_1 = __importDefault(require("os"));
|
|
44
45
|
const path_1 = __importDefault(require("path"));
|
|
45
46
|
const portfinder_1 = __importDefault(require("portfinder"));
|
|
46
|
-
const
|
|
47
|
+
const readline_1 = __importDefault(require("readline"));
|
|
48
|
+
const Instance_1 = require("../typing/Instance");
|
|
49
|
+
const emulatorutil_1 = require("../emulatorutil");
|
|
47
50
|
const common_1 = __importDefault(require("./common"));
|
|
48
51
|
/**
|
|
49
52
|
* OldGoldfishInstance
|
|
@@ -77,7 +80,7 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
77
80
|
// adb连接快应用
|
|
78
81
|
const connected = yield this.connectGoldfish();
|
|
79
82
|
if (connected) {
|
|
80
|
-
|
|
83
|
+
ColorConsole_1.default.log('### Emulator ### Goldfish emulator connected successfully');
|
|
81
84
|
// 如果是首次启动,创建server端监听事件
|
|
82
85
|
if (this.isFirstStart && this.startOptions.serverPort) {
|
|
83
86
|
yield this.createWebsockeServer();
|
|
@@ -87,7 +90,7 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
87
90
|
this.isFirstStart = false;
|
|
88
91
|
}
|
|
89
92
|
else {
|
|
90
|
-
|
|
93
|
+
ColorConsole_1.default.throw('### Emulator ### Failed to connect emulator, please check whether the adb is normal');
|
|
91
94
|
}
|
|
92
95
|
});
|
|
93
96
|
}
|
|
@@ -102,19 +105,19 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
102
105
|
const { package: packageName } = this.projectInfo;
|
|
103
106
|
const appMountDir = path_1.default.resolve(this.sdkHome, 'qa');
|
|
104
107
|
const mountCmd = `adb -s 127.0.0.1:${options.adbPort} shell mount -t v9fs -o tag=10.0.2.2,port=${this.host9pPort},aname=${appMountDir} /data`;
|
|
105
|
-
|
|
108
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${mountCmd}`);
|
|
106
109
|
adbMiwt.execAdbCmdSync(mountCmd);
|
|
107
110
|
let vappCmd = `adb -s 127.0.0.1:${options.adbPort} shell vapp app/${packageName} &`;
|
|
108
111
|
// 调试情况下,需要加--jsdebugger=10.0.2.15:101
|
|
109
112
|
if (options.devtool) {
|
|
110
113
|
vappCmd = `adb -s 127.0.0.1:${options.adbPort} shell vapp --jsdebugger=10.0.2.15:101 app/${packageName} &`;
|
|
111
114
|
}
|
|
112
|
-
|
|
115
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${vappCmd}`);
|
|
113
116
|
// vapp进程会一直pending,不会退出。这里必须加stdio: 'ignore',否则快应用无法运行成功
|
|
114
117
|
adbMiwt.execAdbCmdAsync(vappCmd, { stdio: 'ignore', encoding: 'utf-8' });
|
|
115
118
|
}
|
|
116
119
|
catch (e) {
|
|
117
|
-
|
|
120
|
+
ColorConsole_1.default.error(`### Emulator ### Failed to startup quickapp: ${e.message}`);
|
|
118
121
|
}
|
|
119
122
|
}
|
|
120
123
|
/** host启动9pServer
|
|
@@ -126,10 +129,10 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
126
129
|
const yaFileName = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
|
|
127
130
|
const pidList = yield (0, find_process_1.default)('name', yaFileName);
|
|
128
131
|
if (pidList.length > 0) {
|
|
129
|
-
|
|
132
|
+
ColorConsole_1.default.log('### Emulator ### 9p server started in host');
|
|
130
133
|
return resolve();
|
|
131
134
|
}
|
|
132
|
-
|
|
135
|
+
ColorConsole_1.default.log('### Emulator ### Starting 9p server in host');
|
|
133
136
|
const quickappMountDir = path_1.default.resolve(this.sdkHome, 'qa');
|
|
134
137
|
const toolsHome = path_1.default.resolve(this.sdkHome, 'tools');
|
|
135
138
|
const serverBinPath = path_1.default.resolve(toolsHome, yaFileName);
|
|
@@ -146,15 +149,14 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
146
149
|
// 监听stderr,判断9p server是否启动成功了
|
|
147
150
|
(_a = this.v9fsProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
148
151
|
const output = data.toString();
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
shared_utils_1.ColorConsole.log('### Emulator ### 9p server starts successfully');
|
|
152
|
+
if (emulatorutil_1.EmulatorLog.preDevIsStart(output)) {
|
|
153
|
+
ColorConsole_1.default.log('### Emulator ### 9p server starts successfully');
|
|
152
154
|
return resolve();
|
|
153
155
|
}
|
|
154
156
|
});
|
|
155
157
|
// 监听exit事件,判断9p server是否退出了
|
|
156
158
|
this.v9fsProcess.on('exit', (code) => {
|
|
157
|
-
|
|
159
|
+
ColorConsole_1.default.error(`### Emulator ### ya-vm-file-server exited with code ${code}`);
|
|
158
160
|
return reject();
|
|
159
161
|
});
|
|
160
162
|
}));
|
|
@@ -171,82 +173,45 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
171
173
|
*/
|
|
172
174
|
startGoldfish(options) {
|
|
173
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
-
const {
|
|
175
|
-
// 获取emulator bin的绝对路径
|
|
176
|
-
const emulatorBin = this.getEmulatorBinPath();
|
|
177
|
-
shared_utils_1.ColorConsole.log(`### Emulator ### emulator path: ${emulatorBin}`);
|
|
178
|
-
// 获取vela镜像的绝对路径
|
|
179
|
-
const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName);
|
|
180
|
-
const { avdArch, avdImagePath, customImagePath } = avdInfo;
|
|
181
|
-
shared_utils_1.ColorConsole.log(`### Emulator ### adb port: ${options.adbPort}`);
|
|
182
|
-
if (!avdImagePath) {
|
|
183
|
-
return shared_utils_1.ColorConsole.throw(`### Emulator ### Unable to find vela image via avd`);
|
|
184
|
-
}
|
|
185
|
-
const nuttxBinPath = path_1.default.resolve(customImagePath || avdImagePath, 'nuttx');
|
|
186
|
-
shared_utils_1.ColorConsole.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
|
|
187
|
-
// 端口映射,adb端口和debug端口
|
|
188
|
-
let portMappingStr = `user,id=u1,hostfwd=tcp:127.0.0.1:${options.adbPort}-10.0.2.15:5555`;
|
|
189
|
-
if (devtool) {
|
|
190
|
-
shared_utils_1.ColorConsole.log(`### Emulator ### debug port: ${options.debugPort}`);
|
|
191
|
-
portMappingStr += `,hostfwd=tcp:127.0.0.1:${options.debugPort}-10.0.2.15:101`;
|
|
192
|
-
}
|
|
193
|
-
shared_utils_1.ColorConsole.log(`### Emulator ### Start qemu with TCP: ${portMappingStr}`);
|
|
194
|
-
// vnc配置
|
|
195
|
-
let noWindow = false;
|
|
196
|
-
let vncStr = '';
|
|
197
|
-
if (options.grpcPort) {
|
|
198
|
-
noWindow = true;
|
|
199
|
-
const portSuffix = options.grpcPort - constants_1.defaultVncPort;
|
|
200
|
-
vncStr = `-vnc :${portSuffix}`;
|
|
201
|
-
}
|
|
176
|
+
const { origin = Instance_1.IStartOrigin.Terminal } = options;
|
|
202
177
|
// 启动goldfish的命令和参数
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
'-avd-arch',
|
|
209
|
-
avdArch,
|
|
210
|
-
'-show-kernel',
|
|
211
|
-
'-kernel',
|
|
212
|
-
nuttxBinPath,
|
|
213
|
-
noWindow ? '-no-window' : '',
|
|
214
|
-
'-qemu',
|
|
215
|
-
vncStr,
|
|
216
|
-
'-netdev',
|
|
217
|
-
portMappingStr,
|
|
218
|
-
'-device',
|
|
219
|
-
'virtio-net-device,netdev=u1,bus=virtio-mmio-bus.3'
|
|
220
|
-
];
|
|
221
|
-
shared_utils_1.ColorConsole.log(`### Emulator ### Start CMD: ${spawnBin} ${spawnArgs.join(' ')}`);
|
|
178
|
+
const spawnArgs = emulatorutil_1.EmulatorCmd.createPreCmd(options, this.sdkHome, this.avdHome);
|
|
179
|
+
const spawnBin = spawnArgs && spawnArgs.shift();
|
|
180
|
+
if (!spawnArgs || !spawnBin)
|
|
181
|
+
return;
|
|
182
|
+
ColorConsole_1.default.log(`### Emulator ### Start CMD preDev: ${spawnBin} ${spawnArgs.join(' ')}`);
|
|
222
183
|
return new Promise((resolve) => {
|
|
223
|
-
var _a, _b, _c
|
|
184
|
+
var _a, _b, _c;
|
|
224
185
|
this.goldfishProcess = (0, child_process_1.spawn)(spawnBin, spawnArgs, { stdio: 'pipe', shell: true });
|
|
225
186
|
// 监听错误流
|
|
226
187
|
(_a = this.goldfishProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
227
188
|
const stderrCb = options.stderrCallback || console.log;
|
|
228
189
|
stderrCb(data.toString());
|
|
229
190
|
});
|
|
230
|
-
if (origin ===
|
|
191
|
+
if (origin === Instance_1.IStartOrigin.Terminal) {
|
|
231
192
|
process.stdout.pipe(this.goldfishProcess.stdin);
|
|
232
|
-
(_b = this.goldfishProcess.stdout) === null || _b === void 0 ? void 0 : _b.pipe(process.stdout);
|
|
233
193
|
}
|
|
194
|
+
// 利用 readline 接口可解决子进程日志换行的问题
|
|
195
|
+
this.stdoutReadline = readline_1.default.createInterface({
|
|
196
|
+
input: this.goldfishProcess.stdout
|
|
197
|
+
});
|
|
198
|
+
this.stderrReadline = readline_1.default.createInterface({
|
|
199
|
+
input: this.goldfishProcess.stderr
|
|
200
|
+
});
|
|
234
201
|
// 监听模拟器的退出事件
|
|
235
202
|
this.goldfishProcess.on('exit', (code) => {
|
|
236
|
-
|
|
203
|
+
ColorConsole_1.default.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
|
|
237
204
|
if (options.exitCallback) {
|
|
238
205
|
options.exitCallback(code);
|
|
239
206
|
}
|
|
240
207
|
});
|
|
241
208
|
// 监听输出流。输出了'(NSH)'标识后则认为模拟器启动成功
|
|
242
|
-
(
|
|
209
|
+
(_c = (_b = this.goldfishProcess) === null || _b === void 0 ? void 0 : _b.stdout) === null || _c === void 0 ? void 0 : _c.on('data', (data) => {
|
|
243
210
|
const msg = data.toString();
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (msg.includes('(NSH)')) {
|
|
249
|
-
shared_utils_1.ColorConsole.log(`### Emulator ### Goldfish emulator starts successfully`);
|
|
211
|
+
const stdoutCb = options.stdoutCallback || console.log;
|
|
212
|
+
stdoutCb(msg);
|
|
213
|
+
if (emulatorutil_1.EmulatorLog.devIsStart(msg)) {
|
|
214
|
+
ColorConsole_1.default.log(`### Emulator ### Goldfish emulator starts successfully`);
|
|
250
215
|
resolve();
|
|
251
216
|
}
|
|
252
217
|
});
|
|
@@ -261,10 +226,10 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
261
226
|
return __awaiter(this, void 0, void 0, function* () {
|
|
262
227
|
const { package: appPackageName } = this.projectInfo;
|
|
263
228
|
const appRunDir = path_1.default.resolve(this.sdkHome, 'qa/app', appPackageName);
|
|
264
|
-
|
|
229
|
+
ColorConsole_1.default.log(`### Emulator ### Pushing ${appPackageName} to ${appRunDir}`);
|
|
265
230
|
fs_1.default.rmSync(appRunDir, { recursive: true, force: true });
|
|
266
|
-
|
|
267
|
-
|
|
231
|
+
FileUtil_1.default.copyFiles(sourceRoot, appRunDir);
|
|
232
|
+
ColorConsole_1.default.log(`### Emulator ### Push ${appPackageName} to ${appRunDir} successfully`);
|
|
268
233
|
});
|
|
269
234
|
}
|
|
270
235
|
/** 停止模拟器并释放相关资源 */
|
package/lib/typing/Instance.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface IStartOptions {
|
|
|
11
11
|
devtool?: string;
|
|
12
12
|
/** @deprecated */
|
|
13
13
|
disableNSH?: boolean;
|
|
14
|
-
origin?:
|
|
14
|
+
origin?: IStartOrigin;
|
|
15
15
|
serverPort?: number;
|
|
16
16
|
grpcPort?: number;
|
|
17
17
|
adbPort: number;
|
|
@@ -24,3 +24,7 @@ export interface IStartOptions {
|
|
|
24
24
|
/** 要推送到的目的路径 */
|
|
25
25
|
tar?: string;
|
|
26
26
|
}
|
|
27
|
+
export declare enum IStartOrigin {
|
|
28
|
+
Terminal = "terminal",
|
|
29
|
+
Ide = "ide"
|
|
30
|
+
}
|
package/lib/typing/Instance.js
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IStartOrigin = void 0;
|
|
4
|
+
var IStartOrigin;
|
|
5
|
+
(function (IStartOrigin) {
|
|
6
|
+
IStartOrigin["Terminal"] = "terminal";
|
|
7
|
+
IStartOrigin["Ide"] = "ide";
|
|
8
|
+
})(IStartOrigin || (exports.IStartOrigin = IStartOrigin = {}));
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -30,4 +30,4 @@ export declare function delayRun<T = any>(task: (...args: any[]) => Promise<T> |
|
|
|
30
30
|
* 端口号必须是偶数且在5555和5585之间
|
|
31
31
|
* @returns {number}
|
|
32
32
|
*/
|
|
33
|
-
export declare function getEvenPort(): Promise<number | false
|
|
33
|
+
export declare function getEvenPort(): Promise<number | false>;
|
package/lib/utils/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.getEvenPort = exports.delayRun = exports.tryRun = exports.sleep = exports.killProcessByCmd = exports.killProcessByPid = exports.getSystemArch = void 0;
|
|
16
|
-
const
|
|
16
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
17
17
|
const child_process_1 = require("child_process");
|
|
18
18
|
const find_process_1 = __importDefault(require("find-process"));
|
|
19
19
|
const os_1 = __importDefault(require("os"));
|
|
@@ -43,7 +43,7 @@ function getSystemArch() {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
if (osArch !== 'arm64' && osArch !== 'x64') {
|
|
46
|
-
return
|
|
46
|
+
return ColorConsole_1.default.throw(`unsupport system`);
|
|
47
47
|
}
|
|
48
48
|
return cpuArch[osArch];
|
|
49
49
|
}
|
|
@@ -123,23 +123,23 @@ exports.delayRun = delayRun;
|
|
|
123
123
|
*/
|
|
124
124
|
function getEvenPort() {
|
|
125
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
const startPort =
|
|
127
|
-
const stopPort =
|
|
126
|
+
const startPort = 5556;
|
|
127
|
+
const stopPort = 5584;
|
|
128
128
|
let index = 1;
|
|
129
129
|
let port = yield portfinder_1.default.getPortPromise({
|
|
130
130
|
port: startPort,
|
|
131
131
|
stopPort
|
|
132
132
|
});
|
|
133
133
|
while (port % 2 !== 0) {
|
|
134
|
-
if (index >
|
|
134
|
+
if (index > 13)
|
|
135
135
|
return false;
|
|
136
136
|
port = yield portfinder_1.default.getPortPromise({
|
|
137
|
-
port: startPort +
|
|
137
|
+
port: startPort + 2,
|
|
138
138
|
stopPort
|
|
139
139
|
});
|
|
140
140
|
index++;
|
|
141
|
-
return port;
|
|
142
141
|
}
|
|
142
|
+
return port;
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
exports.getEvenPort = getEvenPort;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/emulator",
|
|
3
|
-
"version": "2.0.2-beta.
|
|
3
|
+
"version": "2.0.2-beta.14",
|
|
4
4
|
"description": "vela emulator tool.",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -35,16 +35,20 @@
|
|
|
35
35
|
"emulator"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@aiot-toolkit/aiotpack": "2.0.2-beta.
|
|
39
|
-
"@aiot-toolkit/shared-utils": "2.0.2-beta.
|
|
38
|
+
"@aiot-toolkit/aiotpack": "2.0.2-beta.14",
|
|
39
|
+
"@aiot-toolkit/shared-utils": "2.0.2-beta.14",
|
|
40
|
+
"@miwt/adb": "^0.9.0",
|
|
41
|
+
"dayjs": "^1.11.12",
|
|
40
42
|
"find-process": "^1.4.7",
|
|
41
43
|
"fs-extra": "^11.2.0",
|
|
42
44
|
"ini": "^4.1.3",
|
|
43
|
-
"portfinder": "^1.0.32"
|
|
45
|
+
"portfinder": "^1.0.32",
|
|
46
|
+
"semver": "^7.6.3",
|
|
47
|
+
"ws": "^8.18.0"
|
|
44
48
|
},
|
|
45
49
|
"devDependencies": {
|
|
46
50
|
"@types/fs-extra": "^11.0.4",
|
|
47
51
|
"@types/ini": "^4.1.1"
|
|
48
52
|
},
|
|
49
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "c6093733d0267d2d1359fec0af8f7a253955e3e3"
|
|
50
54
|
}
|
|
File without changes
|