@aiot-toolkit/emulator 2.0.1-alpha.8 → 2.0.2-batchmanifest-beta.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/README.md +14 -1
- package/lib/avd/index.d.ts +12 -0
- package/lib/avd/index.js +58 -36
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -5
- package/lib/instance/common.d.ts +42 -0
- package/lib/instance/common.js +227 -0
- package/lib/instance/dev.d.ts +35 -0
- package/lib/instance/dev.js +258 -0
- package/lib/instance/index.d.ts +13 -0
- package/lib/instance/index.js +38 -0
- package/lib/instance/miwear.d.ts +74 -0
- package/lib/instance/miwear.js +437 -0
- package/lib/instance/preDev.d.ts +51 -0
- package/lib/instance/preDev.js +285 -0
- package/lib/static/advancedFeatures.ini +1 -0
- package/lib/static/constants.d.ts +17 -0
- package/lib/static/constants.js +25 -3
- package/lib/static/debugger_ip.cfg +1 -0
- package/lib/typing/Avd.js +0 -2
- package/lib/typing/Instance.d.ts +17 -1
- package/lib/typing/Instance.js +0 -2
- package/lib/utils/index.d.ts +13 -0
- package/lib/utils/index.js +88 -0
- package/package.json +8 -4
- package/lib/avd/index.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/instance/goldfish.d.ts +0 -35
- package/lib/instance/goldfish.js +0 -312
- 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
|
@@ -0,0 +1,258 @@
|
|
|
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 adbMiwt = __importStar(require("@miwt/adb"));
|
|
40
|
+
const child_process_1 = require("child_process");
|
|
41
|
+
const path_1 = require("path");
|
|
42
|
+
const constants_1 = require("../static/constants");
|
|
43
|
+
const common_1 = __importDefault(require("./common"));
|
|
44
|
+
const os_1 = __importDefault(require("os"));
|
|
45
|
+
const fs_1 = __importDefault(require("fs"));
|
|
46
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
47
|
+
class GoldfishInstance extends common_1.default {
|
|
48
|
+
constructor(params) {
|
|
49
|
+
super(params);
|
|
50
|
+
this.appRunDir = '/data/app';
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 1. 启动模拟器
|
|
54
|
+
* 2. 启动成功后,adb连接模拟器
|
|
55
|
+
* 3. 连接成功后,在模拟器中启动快应用
|
|
56
|
+
*/
|
|
57
|
+
start(options) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
this.startOptions = options;
|
|
60
|
+
this.sn = `127.0.0.1:${this.startOptions.adbPort}`;
|
|
61
|
+
// 启动模拟器
|
|
62
|
+
yield this.startGoldfish(options);
|
|
63
|
+
const connected = yield this.connectGoldfish(120);
|
|
64
|
+
if (connected) {
|
|
65
|
+
ColorConsole_1.default.log('### Emulator ### Goldfish emulator connected successfully');
|
|
66
|
+
if (this.isFirstStart && this.startOptions.serverPort) {
|
|
67
|
+
yield this.createWebsockeServer();
|
|
68
|
+
}
|
|
69
|
+
// adb push快应用到模拟器的/data/app目录
|
|
70
|
+
// aspect应用后续要考虑各种形状表盘的推包
|
|
71
|
+
const buildedFilesPath = this.isRpk
|
|
72
|
+
? this.projectPath
|
|
73
|
+
: this.isDistributedApp
|
|
74
|
+
? options.dist ||
|
|
75
|
+
path_1.posix.resolve(this.projectPath, './build', `${this.projectInfo.package}.watch`)
|
|
76
|
+
: path_1.posix.resolve(this.projectPath, './build');
|
|
77
|
+
yield this.pushRpk(buildedFilesPath);
|
|
78
|
+
// 在模拟器中启动快应用
|
|
79
|
+
this.startupQuickApp(options);
|
|
80
|
+
this.isFirstStart = false;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const msg = '### Emulator ### Failed to connect emulator, please check whether the adb is normal';
|
|
84
|
+
ColorConsole_1.default.throw(msg);
|
|
85
|
+
throw new Error(msg);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 在模拟器中启动快应用
|
|
91
|
+
* 通过vapp命令启动,调试时需额外配置--jsdebugger参数
|
|
92
|
+
* @param options
|
|
93
|
+
*/
|
|
94
|
+
startupQuickApp(options) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
try {
|
|
97
|
+
const { package: packageName } = this.projectInfo;
|
|
98
|
+
let vappCmd = `adb -s 127.0.0.1:${options.adbPort} shell vapp app/${packageName} &`;
|
|
99
|
+
if (options.devtool) {
|
|
100
|
+
vappCmd = `adb -s 127.0.0.1:${options.adbPort} shell vapp --jsdebugger=10.0.2.15:101 app/${packageName} &`;
|
|
101
|
+
}
|
|
102
|
+
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${vappCmd}`);
|
|
103
|
+
// vapp进程会一直pending,不会退出。这里必须加stdio: 'ignore',否则快应用无法运行成功
|
|
104
|
+
adbMiwt.execAdbCmdAsync(vappCmd, { stdio: 'ignore', encoding: 'utf-8' });
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
ColorConsole_1.default.error(`### Emulator ### Failed to startup quickapp: ${e.message}`);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 启动模拟器
|
|
113
|
+
* 1. 通过options生成模拟器的启动命令
|
|
114
|
+
* 2. 执行启动命令
|
|
115
|
+
* 3. 判断模拟器是否启动成功
|
|
116
|
+
* 3.1 若disableNSH=true,输出流中匹配到(NSH),认为模拟器启动成功了
|
|
117
|
+
* 3.2 若disableNSH=false,认为2s过后模拟器启动成功了
|
|
118
|
+
* @param options
|
|
119
|
+
* @returns
|
|
120
|
+
*/
|
|
121
|
+
startGoldfish(options) {
|
|
122
|
+
var _a;
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const { avdName, devtool, origin = 'terminal' } = options;
|
|
125
|
+
const emulatorBin = this.getEmulatorBinPath();
|
|
126
|
+
ColorConsole_1.default.log(`### Emulator ### emulator path: ${emulatorBin}`);
|
|
127
|
+
const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName);
|
|
128
|
+
const { avdArch, avdImagePath } = avdInfo;
|
|
129
|
+
ColorConsole_1.default.log(`### Emulator ### adb port: ${options.adbPort}`);
|
|
130
|
+
if (!avdImagePath) {
|
|
131
|
+
return ColorConsole_1.default.throw(`### Emulator ### Unable to find vela image via avd`);
|
|
132
|
+
}
|
|
133
|
+
const nuttxBinPath = path_1.posix.resolve(avdImagePath, 'nuttx');
|
|
134
|
+
ColorConsole_1.default.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
|
|
135
|
+
// 端口映射
|
|
136
|
+
let portMappingStr = `-network-user-mode-options hostfwd=tcp:127.0.0.1:${options.adbPort}-10.0.2.15:5555`;
|
|
137
|
+
if (devtool) {
|
|
138
|
+
portMappingStr += `,hostfwd=tcp:127.0.0.1:${options.debugPort}-10.0.2.15:101`;
|
|
139
|
+
}
|
|
140
|
+
// 文件系统配置,第一次使用fatfs镜像挂载,后续使用adb push更新应用
|
|
141
|
+
const systemImageBin = path_1.posix.resolve(avdImagePath, 'system.img');
|
|
142
|
+
const dataImageBin = path_1.posix.resolve(avdImagePath, 'data.img');
|
|
143
|
+
// 复制可写文件到AVD目录下(多模拟器实例时需要)
|
|
144
|
+
const dataImageBinInAvd = path_1.posix.join(this.avdHome, `${avdName}.avd`, 'data.img');
|
|
145
|
+
if (!fs_1.default.existsSync(dataImageBinInAvd)) {
|
|
146
|
+
// data.img不存在时直接copy
|
|
147
|
+
fs_1.default.copyFileSync(dataImageBin, dataImageBinInAvd);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
// data.img存在时,如果.export里的时间晚于avd里的时候,说明更新了镜像,需要重新copy
|
|
151
|
+
const statsInAvd = fs_1.default.statSync(dataImageBinInAvd);
|
|
152
|
+
const stats = fs_1.default.statSync(dataImageBin);
|
|
153
|
+
if ((0, dayjs_1.default)(stats.mtime).isAfter(statsInAvd.mtime)) {
|
|
154
|
+
fs_1.default.copyFileSync(dataImageBin, dataImageBinInAvd);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// 复制可写文件到AVD目录下(多模拟器实例时需要)
|
|
158
|
+
const systemImageBinInAvd = path_1.posix.join(this.avdHome, `${avdName}.avd`, 'system.img');
|
|
159
|
+
if (!fs_1.default.existsSync(systemImageBinInAvd)) {
|
|
160
|
+
// data.img不存在时直接copy
|
|
161
|
+
fs_1.default.copyFileSync(systemImageBin, systemImageBinInAvd);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// data.img存在时,如果.export里的时间晚于avd里的时候,说明更新了镜像,需要重新copy
|
|
165
|
+
const statsInAvd = fs_1.default.statSync(systemImageBinInAvd);
|
|
166
|
+
const stats = fs_1.default.statSync(systemImageBin);
|
|
167
|
+
if ((0, dayjs_1.default)(stats.mtime).isAfter(statsInAvd.mtime)) {
|
|
168
|
+
fs_1.default.copyFileSync(systemImageBin, systemImageBinInAvd);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// 复制可写文件到AVD目录下(多模拟器实例时需要)
|
|
172
|
+
// const nuttxBinInAvd = path.join(this.avdHome, `${avdName}.avd`, 'nuttx')
|
|
173
|
+
// if (!fs.existsSync(nuttxBinInAvd)) {
|
|
174
|
+
// // data.img不存在时直接copy
|
|
175
|
+
// fs.copyFileSync(nuttxBinPath, nuttxBinInAvd)
|
|
176
|
+
// } else {
|
|
177
|
+
// // data.img存在时,如果.export里的时间晚于avd里的时候,说明更新了镜像,需要重新copy
|
|
178
|
+
// const statsInAvd = fs.statSync(nuttxBinInAvd)
|
|
179
|
+
// const stats = fs.statSync(nuttxBinPath)
|
|
180
|
+
// if (dayjs(stats.mtime).isAfter(statsInAvd.mtime)) {
|
|
181
|
+
// fs.copyFileSync(nuttxBinPath, nuttxBinInAvd)
|
|
182
|
+
// }
|
|
183
|
+
// }
|
|
184
|
+
const imageMountStr = `-drive index=0,id=system,if=none,format=raw,file=${systemImageBinInAvd} \
|
|
185
|
+
-device virtio-blk-device,bus=virtio-mmio-bus.0,drive=system \
|
|
186
|
+
-drive index=1,id=userdata,if=none,format=raw,file=${dataImageBinInAvd} \
|
|
187
|
+
-device virtio-blk-device,bus=virtio-mmio-bus.1,drive=userdata \
|
|
188
|
+
-device virtio-snd,bus=virtio-mmio-bus.2 -allow-host-audio -semihosting`;
|
|
189
|
+
// vnc配置
|
|
190
|
+
let windowStr = '';
|
|
191
|
+
let vncStr = '';
|
|
192
|
+
if ((_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.vncPort) {
|
|
193
|
+
windowStr = '-no-window';
|
|
194
|
+
const portSuffix = this.startOptions.vncPort - constants_1.defaultVncPort;
|
|
195
|
+
vncStr = `-vnc :${portSuffix}`;
|
|
196
|
+
}
|
|
197
|
+
// 启动goldfish的命令和参数
|
|
198
|
+
const cmd = `${emulatorBin} -nuttx -avd ${avdName} -avd-arch ${avdArch} -show-kernel -kernel ${nuttxBinPath} ${portMappingStr} ${windowStr} -qemu ${vncStr} ${imageMountStr}`;
|
|
199
|
+
const spawnArgs = cmd.split(' ');
|
|
200
|
+
const spawnBin = spawnArgs.shift();
|
|
201
|
+
ColorConsole_1.default.log(`### Emulator ### Start CMD: ${cmd}`);
|
|
202
|
+
return new Promise((resolve) => {
|
|
203
|
+
var _a, _b, _c;
|
|
204
|
+
this.goldfishProcess = (0, child_process_1.spawn)(spawnBin, spawnArgs, { stdio: 'pipe', shell: true });
|
|
205
|
+
(_a = this.goldfishProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
206
|
+
const stderrCb = options.stderrCallback || console.log;
|
|
207
|
+
stderrCb(data.toString());
|
|
208
|
+
});
|
|
209
|
+
if (origin === 'terminal') {
|
|
210
|
+
process.stdout.pipe(this.goldfishProcess.stdin);
|
|
211
|
+
(_b = this.goldfishProcess.stdout) === null || _b === void 0 ? void 0 : _b.pipe(process.stdout);
|
|
212
|
+
}
|
|
213
|
+
this.goldfishProcess.on('exit', (code) => {
|
|
214
|
+
ColorConsole_1.default.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
|
|
215
|
+
if (options.exitCallback) {
|
|
216
|
+
options.exitCallback(code);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
(_c = this.goldfishProcess.stdout) === null || _c === void 0 ? void 0 : _c.on('data', (data) => {
|
|
220
|
+
const msg = data.toString();
|
|
221
|
+
if (origin === 'ide') {
|
|
222
|
+
const stdoutCb = options.stdoutCallback || console.log;
|
|
223
|
+
stdoutCb(msg);
|
|
224
|
+
}
|
|
225
|
+
if (msg.includes('(NSH)')) {
|
|
226
|
+
ColorConsole_1.default.log(`### Emulator ### Goldfish emulator starts successfully`);
|
|
227
|
+
resolve();
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* 将目录通过adb push到模拟器中
|
|
235
|
+
* @param sourceRoot
|
|
236
|
+
*/
|
|
237
|
+
pushRpk(sourceRoot) {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
const sn = `127.0.0.1:${this.startOptions.adbPort}`;
|
|
240
|
+
const { package: appPackageName } = this.projectInfo;
|
|
241
|
+
// 获取最后一层目录,比如build
|
|
242
|
+
const basename = path_1.posix.basename(sourceRoot);
|
|
243
|
+
if (os_1.default.platform() === 'win32' || this.projectPath.indexOf(' ') > 0) {
|
|
244
|
+
// windows系统或者项目路径有空格:1. adb push目录;2. 在模拟器中使用mv命令重命名
|
|
245
|
+
yield adbMiwt.execAdbCmdAsync(`adb -s ${sn} push ${sourceRoot} ${this.appRunDir}`);
|
|
246
|
+
yield adbMiwt.execAdbCmdAsync(`adb -s ${sn} shell mv ${this.appRunDir}/${basename} ${this.appRunDir}/${appPackageName}`);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
// 支持通配符处理: 1. 模拟器中mkdir创建目录 2. adb push ./XXXXX/* /XXX
|
|
250
|
+
const sourcePath = path_1.posix.resolve(sourceRoot, './*');
|
|
251
|
+
yield adbMiwt.execAdbCmdAsync(`adb -s ${sn} shell mkdir ${this.appRunDir}/${appPackageName}`);
|
|
252
|
+
yield adbMiwt.execAdbCmdAsync(`adb -s ${sn} push ${sourcePath} ${this.appRunDir}/${appPackageName}`);
|
|
253
|
+
}
|
|
254
|
+
ColorConsole_1.default.info(`### Emulator push to ${this.appRunDir}/${appPackageName} successfully`);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.default = GoldfishInstance;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { INewGoldfishInstanceParams } from '../typing/Instance';
|
|
2
|
+
import CommonInstance from './common';
|
|
3
|
+
import GoldfishInstance from './dev';
|
|
4
|
+
import MiwearInstance from "./miwear";
|
|
5
|
+
import OldGoldfishInstance from './preDev';
|
|
6
|
+
/**
|
|
7
|
+
* 根据镜像决定使用哪个instance
|
|
8
|
+
* Vela正式版(4.0) -> MiwearInstance
|
|
9
|
+
* Vela开发版(dev, 0.0.2) -> OldGoldfishInstance
|
|
10
|
+
* Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
|
|
11
|
+
*/
|
|
12
|
+
declare function findInstance(avdName: string, params: INewGoldfishInstanceParams): GoldfishInstance | MiwearInstance | OldGoldfishInstance | undefined;
|
|
13
|
+
export { CommonInstance, GoldfishInstance, MiwearInstance, OldGoldfishInstance, findInstance };
|
|
@@ -0,0 +1,38 @@
|
|
|
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.findInstance = exports.OldGoldfishInstance = exports.MiwearInstance = exports.GoldfishInstance = exports.CommonInstance = void 0;
|
|
7
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
8
|
+
const avd_1 = __importDefault(require("../avd"));
|
|
9
|
+
const common_1 = __importDefault(require("./common"));
|
|
10
|
+
exports.CommonInstance = common_1.default;
|
|
11
|
+
const dev_1 = __importDefault(require("./dev"));
|
|
12
|
+
exports.GoldfishInstance = dev_1.default;
|
|
13
|
+
const miwear_1 = __importDefault(require("./miwear"));
|
|
14
|
+
exports.MiwearInstance = miwear_1.default;
|
|
15
|
+
const preDev_1 = __importDefault(require("./preDev"));
|
|
16
|
+
exports.OldGoldfishInstance = preDev_1.default;
|
|
17
|
+
/**
|
|
18
|
+
* 根据镜像决定使用哪个instance
|
|
19
|
+
* Vela正式版(4.0) -> MiwearInstance
|
|
20
|
+
* Vela开发版(dev, 0.0.2) -> OldGoldfishInstance
|
|
21
|
+
* Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
|
|
22
|
+
*/
|
|
23
|
+
function findInstance(avdName, params) {
|
|
24
|
+
const { sdkHome, avdHome } = params;
|
|
25
|
+
const { avdImagePath } = new avd_1.default({ sdkHome, avdHome }).getVelaAvdInfo(avdName);
|
|
26
|
+
if (!avdImagePath) {
|
|
27
|
+
ColorConsole_1.default.throw(`### Emulator ### Unable to find vela image via avd`);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (avdImagePath.includes('release')) {
|
|
31
|
+
return new miwear_1.default(params);
|
|
32
|
+
}
|
|
33
|
+
else if (avdImagePath.match(/0\.0\.2|0\.0\.1/)) {
|
|
34
|
+
return new preDev_1.default(params);
|
|
35
|
+
}
|
|
36
|
+
return new dev_1.default(params);
|
|
37
|
+
}
|
|
38
|
+
exports.findInstance = findInstance;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { INewGoldfishInstanceParams, IStartOptions } from '../typing/Instance';
|
|
2
|
+
import CommonInstance from './common';
|
|
3
|
+
/**
|
|
4
|
+
* MiwearInstance
|
|
5
|
+
* 针对 Vela正式版(4.0)的镜像
|
|
6
|
+
*/
|
|
7
|
+
declare class MiwearInstance extends CommonInstance {
|
|
8
|
+
private params;
|
|
9
|
+
private appPathInEmulator;
|
|
10
|
+
private debugSocket?;
|
|
11
|
+
private reconnectCount;
|
|
12
|
+
constructor(params: INewGoldfishInstanceParams);
|
|
13
|
+
/**
|
|
14
|
+
* 1. 启动模拟器
|
|
15
|
+
* 2. 启动成功后,adb连接模拟器
|
|
16
|
+
* 3. 连接成功后,在模拟器中启动快应用
|
|
17
|
+
*/
|
|
18
|
+
start(options: IStartOptions): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* 启动模拟器
|
|
21
|
+
* 1. 通过options生成模拟器的启动命令
|
|
22
|
+
* 2. 执行启动命令
|
|
23
|
+
* 3. 判断模拟器是否启动成功
|
|
24
|
+
* 3.1 若disableNSH=true,输出流中匹配到/quickapp_rpk_installer_init|rpk installer init done/,认为模拟器启动成功了
|
|
25
|
+
* 3.2 若disableNSH=false,认为8s过后模拟器启动成功了
|
|
26
|
+
* @param options
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
startGoldfish(options: IStartOptions): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* 在模拟器中启动快应用
|
|
32
|
+
* 1. 检查release目录是否有打包好的rpk
|
|
33
|
+
* 2. 检查当前是否为调试模式.
|
|
34
|
+
* 若是,将debugger_ip.cfg推到模拟器的/data/目录下
|
|
35
|
+
* 若否,则要删除模拟器中已有的data/debugger_ip.cfg
|
|
36
|
+
* 3. 调用installRpkToAppList将当前快应用安装到模拟器的应用列表中
|
|
37
|
+
* @param options
|
|
38
|
+
*/
|
|
39
|
+
startupQuickApp(options: IStartOptions): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* 将快应用安装到模拟器的应用列表
|
|
42
|
+
* 1. 使用adb push将打包好的rpk推到模拟器的/data/quickapp/app/
|
|
43
|
+
* 2. nsh中调用pm install命令安装应用
|
|
44
|
+
* @param rpkPath rpk的绝对目录
|
|
45
|
+
* @param targetDir 要将rpk放到模拟器的哪个目录下
|
|
46
|
+
*/
|
|
47
|
+
installRpkToAppList(rpkPath: string, targetDir: string): Promise<void>;
|
|
48
|
+
/** 使用am start启动快应用 */
|
|
49
|
+
launchQuickapp(): Promise<void>;
|
|
50
|
+
/** 连接模拟器中的调试服务,创建debugSocket
|
|
51
|
+
* 主要用于热更新时,通过debugSocket通知调试服务更新页面
|
|
52
|
+
* 设置了重连机制,会重复连接8次
|
|
53
|
+
*/
|
|
54
|
+
initDebugSocket(): Promise<void>;
|
|
55
|
+
/** 通知模拟器更新
|
|
56
|
+
* 1. 确保已经成功连接模拟器中的调试服务
|
|
57
|
+
* 2. 使用adb push将build文件下的内容推到/data/quickapp/app/${packageName}
|
|
58
|
+
* 3. 发送Page.reload命令给调试服务,通知更新
|
|
59
|
+
*/
|
|
60
|
+
handleUpdate(): Promise<void>;
|
|
61
|
+
/** 热更新时push目录 */
|
|
62
|
+
pushBuild(): Promise<void>;
|
|
63
|
+
/** 在模拟器中重启快应用(基于am命令,需要保证镜像中已经有am功能)
|
|
64
|
+
* 1. 使用adb push将build文件下的内容推到/data/quickapp/app/${packageName}
|
|
65
|
+
* 2. nsh中执行am stop命令退出快应用
|
|
66
|
+
* 3. nsh中执行am start命令启动快应用
|
|
67
|
+
*/
|
|
68
|
+
reloadApp(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* 创建server端,监听打包过程中client端发来的消息
|
|
71
|
+
*/
|
|
72
|
+
createWebsockeServer(): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
export default MiwearInstance;
|