@aiot-toolkit/emulator 2.0.3-beta.1 → 2.0.3-beta.11
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/README.md +133 -8
- package/lib/emulatorutil/EmulatorLog.js +22 -18
- package/lib/emulatorutil/constants.d.ts +18 -5
- package/lib/emulatorutil/constants.js +94 -53
- package/lib/emulatorutil/index.d.ts +3 -2
- package/lib/emulatorutil/index.js +38 -8
- package/lib/emulatorutil/running.d.ts +24 -0
- package/lib/emulatorutil/running.js +108 -0
- package/lib/emulatorutil/skinLayoutParser.d.ts +14 -0
- package/lib/emulatorutil/skinLayoutParser.js +111 -0
- package/lib/index.d.ts +5 -5
- package/lib/index.js +76 -26
- package/lib/instance/common.d.ts +39 -39
- package/lib/instance/common.js +151 -221
- package/lib/instance/dev.d.ts +7 -42
- package/lib/instance/dev.js +53 -235
- package/lib/instance/index.d.ts +6 -5
- package/lib/instance/index.js +51 -35
- package/lib/instance/miwear.d.ts +14 -75
- package/lib/instance/miwear.js +92 -370
- package/lib/instance/pre.d.ts +11 -3
- package/lib/instance/pre.js +54 -93
- package/lib/instance/pre5.d.ts +11 -0
- package/lib/instance/pre5.js +37 -0
- package/lib/static/avdConfigIni.json +5 -5
- package/lib/typing/Instance.d.ts +32 -15
- package/lib/typing/Instance.js +13 -6
- package/lib/typing/Vvd.d.ts +105 -0
- package/lib/typing/Vvd.js +31 -0
- package/lib/utils/file.d.ts +0 -0
- package/lib/utils/file.js +1 -0
- package/lib/utils/index.js +86 -100
- package/lib/vvd/index.d.ts +107 -0
- package/lib/vvd/index.js +715 -0
- package/lib/vvd/logcat.d.ts +16 -0
- package/lib/vvd/logcat.js +67 -0
- package/package.json +9 -8
- package/lib/avd/index.d.ts +0 -28
- package/lib/avd/index.js +0 -173
- package/lib/emulatorutil/EmulatorCmd.d.ts +0 -9
- package/lib/emulatorutil/EmulatorCmd.js +0 -226
- package/lib/instance/preDev.d.ts +0 -53
- package/lib/instance/preDev.js +0 -249
- package/lib/typing/Avd.d.ts +0 -23
- package/lib/typing/Avd.js +0 -8
package/lib/instance/preDev.js
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
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 ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
39
|
-
const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
|
|
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 readline_1 = __importDefault(require("readline"));
|
|
48
|
-
const Instance_1 = require("../typing/Instance");
|
|
49
|
-
const emulatorutil_1 = require("../emulatorutil");
|
|
50
|
-
const common_1 = __importDefault(require("./common"));
|
|
51
|
-
/**
|
|
52
|
-
* OldGoldfishInstance
|
|
53
|
-
* 针对 Vela开发版(dev, 0.0.2)的镜像
|
|
54
|
-
*/
|
|
55
|
-
class OldGoldfishInstance extends common_1.default {
|
|
56
|
-
constructor(params) {
|
|
57
|
-
super(params);
|
|
58
|
-
this.host9pPort = 7878;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* 1. 启动9p server
|
|
62
|
-
* 2. 将打包好的rpk推到host的挂载目录
|
|
63
|
-
* 3. 启动模拟器
|
|
64
|
-
* 4. 模拟器启动成功后,adb连接模拟器
|
|
65
|
-
* 5. 连接成功后,在模拟器中启动快应用
|
|
66
|
-
*/
|
|
67
|
-
start(options) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
this.startOptions = options;
|
|
70
|
-
this.sn = `127.0.0.1:${this.startOptions.adbPort}`;
|
|
71
|
-
// host启动9p server
|
|
72
|
-
yield this.ensure9pServerRunnning();
|
|
73
|
-
// 将rpk推到host的./export/qa/app目录
|
|
74
|
-
const buildedFilesPath = this.isRpk
|
|
75
|
-
? this.projectPath
|
|
76
|
-
: path_1.default.resolve(this.projectPath, './build');
|
|
77
|
-
this.pushRpk(buildedFilesPath);
|
|
78
|
-
// 启动模拟器
|
|
79
|
-
yield this.startGoldfish(options);
|
|
80
|
-
// adb连接快应用
|
|
81
|
-
const connected = yield this.connectGoldfish();
|
|
82
|
-
if (connected) {
|
|
83
|
-
ColorConsole_1.default.log('### Emulator ### Goldfish emulator connected successfully');
|
|
84
|
-
// 如果是首次启动,创建server端监听事件
|
|
85
|
-
if (this.isFirstStart && this.startOptions.serverPort) {
|
|
86
|
-
yield this.createWebsockeServer();
|
|
87
|
-
}
|
|
88
|
-
// 在模拟器中启动快应用
|
|
89
|
-
this.startupQuickApp(options);
|
|
90
|
-
this.isFirstStart = false;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
ColorConsole_1.default.throw('### Emulator ### Failed to connect emulator, please check whether the adb is normal');
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* 在模拟器中启动快应用(快应用都在模拟器的/data/app目录下)
|
|
99
|
-
* 1. 是否为调试模式
|
|
100
|
-
* 若是,在模拟器终端执行vapp app/${packageName} &
|
|
101
|
-
* 若否,在模拟器终端执行vapp --jsdebugger=10.0.2.15:101 app/${packageName} &
|
|
102
|
-
*/
|
|
103
|
-
startupQuickApp(options) {
|
|
104
|
-
try {
|
|
105
|
-
const { package: packageName } = this.projectInfo;
|
|
106
|
-
const appMountDir = path_1.default.resolve(this.sdkHome, 'qa');
|
|
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`;
|
|
108
|
-
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${mountCmd}`);
|
|
109
|
-
adbMiwt.execAdbCmdSync(mountCmd);
|
|
110
|
-
let vappCmd = `adb -s 127.0.0.1:${options.adbPort} shell vapp app/${packageName} &`;
|
|
111
|
-
// 调试情况下,需要加--jsdebugger=10.0.2.15:101
|
|
112
|
-
if (options.devtool) {
|
|
113
|
-
vappCmd = `adb -s 127.0.0.1:${options.adbPort} shell vapp --jsdebugger=10.0.2.15:101 app/${packageName} &`;
|
|
114
|
-
}
|
|
115
|
-
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${vappCmd}`);
|
|
116
|
-
// vapp进程会一直pending,不会退出。这里必须加stdio: 'ignore',否则快应用无法运行成功
|
|
117
|
-
adbMiwt.execAdbCmdAsync(vappCmd, { stdio: 'ignore', encoding: 'utf-8' });
|
|
118
|
-
}
|
|
119
|
-
catch (e) {
|
|
120
|
-
ColorConsole_1.default.error(`### Emulator ### Failed to startup quickapp: ${e.message}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/** host启动9pServer
|
|
124
|
-
* 作用是将本地的quickappMountDir目录挂载到模拟器的/data目录
|
|
125
|
-
*/
|
|
126
|
-
ensure9pServerRunnning() {
|
|
127
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
var _a;
|
|
129
|
-
const yaFileName = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
|
|
130
|
-
const pidList = yield (0, find_process_1.default)('name', yaFileName);
|
|
131
|
-
if (pidList.length > 0) {
|
|
132
|
-
ColorConsole_1.default.log('### Emulator ### 9p server started in host');
|
|
133
|
-
return resolve();
|
|
134
|
-
}
|
|
135
|
-
ColorConsole_1.default.log('### Emulator ### Starting 9p server in host');
|
|
136
|
-
const quickappMountDir = path_1.default.resolve(this.sdkHome, 'qa');
|
|
137
|
-
const toolsHome = path_1.default.resolve(this.sdkHome, 'tools');
|
|
138
|
-
const serverBinPath = path_1.default.resolve(toolsHome, yaFileName);
|
|
139
|
-
fs_1.default.chmodSync(serverBinPath, 0o777);
|
|
140
|
-
this.host9pPort = yield portfinder_1.default.getPortPromise({ port: 7878 });
|
|
141
|
-
const address = `127.0.0.1:${this.host9pPort}`;
|
|
142
|
-
this.v9fsProcess = (0, child_process_1.spawn)(serverBinPath, [
|
|
143
|
-
'--mount-point',
|
|
144
|
-
quickappMountDir,
|
|
145
|
-
'--network-address',
|
|
146
|
-
address,
|
|
147
|
-
'--debug'
|
|
148
|
-
]);
|
|
149
|
-
// 监听stderr,判断9p server是否启动成功了
|
|
150
|
-
(_a = this.v9fsProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
151
|
-
const output = data.toString();
|
|
152
|
-
if (emulatorutil_1.EmulatorLog.preDevIsStart(output)) {
|
|
153
|
-
ColorConsole_1.default.log('### Emulator ### 9p server starts successfully');
|
|
154
|
-
return resolve();
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
// 监听exit事件,判断9p server是否退出了
|
|
158
|
-
this.v9fsProcess.on('exit', (code) => {
|
|
159
|
-
ColorConsole_1.default.error(`### Emulator ### ya-vm-file-server exited with code ${code}`);
|
|
160
|
-
return reject();
|
|
161
|
-
});
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* 启动模拟器
|
|
166
|
-
* 1. 通过options生成模拟器的启动命令
|
|
167
|
-
* 2. 执行启动命令
|
|
168
|
-
* 3. 判断模拟器是否启动成功
|
|
169
|
-
* 3.1 若disableNSH=true,输出流中匹配到/quickapp_rpk_installer_init|rpk installer init done/,认为模拟器启动成功了
|
|
170
|
-
* 3.2 若disableNSH=false,认为8s过后模拟器启动成功了
|
|
171
|
-
* @param options
|
|
172
|
-
* @returns
|
|
173
|
-
*/
|
|
174
|
-
startGoldfish(options) {
|
|
175
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
-
const { origin = Instance_1.IStartOrigin.Terminal } = options;
|
|
177
|
-
// 启动goldfish的命令和参数
|
|
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(' ')}`);
|
|
183
|
-
return new Promise((resolve) => {
|
|
184
|
-
var _a, _b, _c;
|
|
185
|
-
this.goldfishProcess = (0, child_process_1.spawn)(spawnBin, spawnArgs, { stdio: 'pipe', shell: true });
|
|
186
|
-
// 监听错误流
|
|
187
|
-
(_a = this.goldfishProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
188
|
-
const stderrCb = options.stderrCallback || console.log;
|
|
189
|
-
stderrCb(data.toString());
|
|
190
|
-
});
|
|
191
|
-
if (origin === Instance_1.IStartOrigin.Terminal) {
|
|
192
|
-
process.stdout.pipe(this.goldfishProcess.stdin);
|
|
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
|
-
});
|
|
201
|
-
// 监听模拟器的退出事件
|
|
202
|
-
this.goldfishProcess.on('exit', (code) => {
|
|
203
|
-
ColorConsole_1.default.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
|
|
204
|
-
if (options.exitCallback) {
|
|
205
|
-
options.exitCallback(code);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
// 监听输出流。输出了'(NSH)'标识后则认为模拟器启动成功
|
|
209
|
-
(_c = (_b = this.goldfishProcess) === null || _b === void 0 ? void 0 : _b.stdout) === null || _c === void 0 ? void 0 : _c.on('data', (data) => {
|
|
210
|
-
const msg = data.toString();
|
|
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`);
|
|
215
|
-
resolve();
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* 推送文件到本地的${sdkHome}/qa/app/${packageName}目录
|
|
223
|
-
* @param sourceRoot 源目录
|
|
224
|
-
*/
|
|
225
|
-
pushRpk(sourceRoot) {
|
|
226
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
-
const { package: appPackageName } = this.projectInfo;
|
|
228
|
-
const appRunDir = path_1.default.resolve(this.sdkHome, 'qa/app', appPackageName);
|
|
229
|
-
ColorConsole_1.default.log(`### Emulator ### Pushing ${appPackageName} to ${appRunDir}`);
|
|
230
|
-
fs_1.default.rmSync(appRunDir, { recursive: true, force: true });
|
|
231
|
-
FileUtil_1.default.copyFiles(sourceRoot, appRunDir);
|
|
232
|
-
ColorConsole_1.default.log(`### Emulator ### Push ${appPackageName} to ${appRunDir} successfully`);
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
/** 停止模拟器并释放相关资源 */
|
|
236
|
-
stop() {
|
|
237
|
-
const _super = Object.create(null, {
|
|
238
|
-
stop: { get: () => super.stop }
|
|
239
|
-
});
|
|
240
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
_super.stop.call(this);
|
|
242
|
-
if (this.v9fsProcess) {
|
|
243
|
-
this.killProcess(this.v9fsProcess);
|
|
244
|
-
this.v9fsProcess = undefined;
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
exports.default = OldGoldfishInstance;
|
package/lib/typing/Avd.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export interface IAvdResourcePaths {
|
|
2
|
-
avdHome?: string;
|
|
3
|
-
sdkHome?: string;
|
|
4
|
-
imageHome?: string;
|
|
5
|
-
}
|
|
6
|
-
export declare enum IAvdArchType {
|
|
7
|
-
arm = "arm",
|
|
8
|
-
arm64 = "arm64"
|
|
9
|
-
}
|
|
10
|
-
export interface IAvdParams {
|
|
11
|
-
avdName: string;
|
|
12
|
-
avdArch: IAvdArchType;
|
|
13
|
-
avdWidth: string;
|
|
14
|
-
avdHeight: string;
|
|
15
|
-
avdSkin?: string;
|
|
16
|
-
avdImagePath?: string;
|
|
17
|
-
customImagePath?: string;
|
|
18
|
-
}
|
|
19
|
-
export interface ISkinInfo {
|
|
20
|
-
skinName: string;
|
|
21
|
-
skinPath: string;
|
|
22
|
-
skinBackBase64: string;
|
|
23
|
-
}
|
package/lib/typing/Avd.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IAvdArchType = void 0;
|
|
4
|
-
var IAvdArchType;
|
|
5
|
-
(function (IAvdArchType) {
|
|
6
|
-
IAvdArchType["arm"] = "arm";
|
|
7
|
-
IAvdArchType["arm64"] = "arm64";
|
|
8
|
-
})(IAvdArchType || (exports.IAvdArchType = IAvdArchType = {}));
|