@aiot-toolkit/emulator 2.0.3-beta.7 → 2.0.3-beta.8
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 +38 -39
- package/lib/instance/common.js +141 -223
- package/lib/instance/dev.d.ts +7 -42
- package/lib/instance/dev.js +54 -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 +93 -370
- package/lib/instance/pre.d.ts +11 -3
- package/lib/instance/pre.js +55 -93
- package/lib/instance/pre5.d.ts +11 -0
- package/lib/instance/pre5.js +38 -0
- package/lib/static/avdConfigIni.json +5 -5
- package/lib/typing/Instance.d.ts +30 -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 +698 -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/dev.js
CHANGED
|
@@ -1,238 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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;
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
17
5
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
yield this.createWebsockeServer();
|
|
69
|
-
}
|
|
70
|
-
yield this.pushAndInstall();
|
|
71
|
-
// 在模拟器中启动快应用
|
|
72
|
-
this.startupQuickApp(options);
|
|
73
|
-
this.isFirstStart = false;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
const msg = '### Emulator ### Failed to connect emulator, please check whether the adb is normal';
|
|
77
|
-
ColorConsole_1.default.throw(msg);
|
|
78
|
-
throw new Error(msg);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* 在模拟器中启动快应用
|
|
84
|
-
* 通过vapp命令启动,调试时需额外配置--jsdebugger参数
|
|
85
|
-
* @param options
|
|
86
|
-
*/
|
|
87
|
-
startupQuickApp(options) {
|
|
88
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
try {
|
|
90
|
-
const { package: packageName } = this.projectInfo;
|
|
91
|
-
let vappCmd = `adb -s ${this.sn} shell vapp app/${packageName} &`;
|
|
92
|
-
if (options.devtool) {
|
|
93
|
-
vappCmd = `adb -s ${this.sn} shell vapp --jsdebugger=10.0.2.15:101 app/${packageName} &`;
|
|
94
|
-
}
|
|
95
|
-
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${vappCmd}`);
|
|
96
|
-
// vapp进程会一直pending,不会退出。这里必须加stdio: 'ignore',否则快应用无法运行成功
|
|
97
|
-
adbMiwt.execAdbCmdAsync(vappCmd, { stdio: 'ignore', encoding: 'utf-8' });
|
|
98
|
-
}
|
|
99
|
-
catch (e) {
|
|
100
|
-
ColorConsole_1.default.error(`### Emulator ### Failed to startup quickapp: ${e.message}`);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* 启动模拟器
|
|
106
|
-
* 1. 通过options生成模拟器的启动命令
|
|
107
|
-
* 2. 执行启动命令
|
|
108
|
-
* 3. 判断模拟器是否启动成功
|
|
109
|
-
* 3.1 若disableNSH=true,输出流中匹配到(NSH),认为模拟器启动成功了
|
|
110
|
-
* 3.2 若disableNSH=false,认为2s过后模拟器启动成功了
|
|
111
|
-
* @param options
|
|
112
|
-
* @returns
|
|
113
|
-
*/
|
|
114
|
-
startGoldfish(options) {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
const { origin = Instance_1.IStartOrigin.Terminal } = options;
|
|
117
|
-
// 启动模拟器的命令和参数
|
|
118
|
-
const cmd = emulatorutil_1.EmulatorCmd.createDevCmd(options, this.sdkHome, this.avdHome);
|
|
119
|
-
if (!cmd)
|
|
120
|
-
return;
|
|
121
|
-
const spawnArgs = cmd.split(' ');
|
|
122
|
-
const spawnBin = spawnArgs.shift();
|
|
123
|
-
ColorConsole_1.default.log(`### Emulator ### Start CMD dev: ${cmd}`);
|
|
124
|
-
return new Promise((resolve) => {
|
|
125
|
-
var _a, _b;
|
|
126
|
-
this.goldfishProcess = (0, child_process_1.spawn)(spawnBin, spawnArgs, { stdio: 'pipe', shell: true });
|
|
127
|
-
// 利用 readline 接口可解决子进程日志换行的问题
|
|
128
|
-
this.stdoutReadline = readline_1.default.createInterface({
|
|
129
|
-
input: this.goldfishProcess.stdout
|
|
130
|
-
});
|
|
131
|
-
this.stderrReadline = readline_1.default.createInterface({
|
|
132
|
-
input: this.goldfishProcess.stderr
|
|
133
|
-
});
|
|
134
|
-
(_a = this.stderrReadline) === null || _a === void 0 ? void 0 : _a.on('line', (data) => {
|
|
135
|
-
const stderrCb = options.stderrCallback || console.log;
|
|
136
|
-
stderrCb(data.toString());
|
|
137
|
-
});
|
|
138
|
-
if (origin === Instance_1.IStartOrigin.Terminal) {
|
|
139
|
-
process.stdin.pipe(this.goldfishProcess.stdin);
|
|
140
|
-
}
|
|
141
|
-
this.goldfishProcess.on('exit', (code) => {
|
|
142
|
-
ColorConsole_1.default.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
|
|
143
|
-
if (options.exitCallback) {
|
|
144
|
-
options.exitCallback(code);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
(_b = this.stdoutReadline) === null || _b === void 0 ? void 0 : _b.on('line', (data) => {
|
|
148
|
-
const msg = data.toString();
|
|
149
|
-
const stdoutCb = options.stdoutCallback || console.log;
|
|
150
|
-
stdoutCb(msg);
|
|
151
|
-
if (emulatorutil_1.EmulatorLog.devIsStart(msg)) {
|
|
152
|
-
ColorConsole_1.default.log(`### Emulator ### Goldfish emulator starts successfully`);
|
|
153
|
-
resolve();
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* 将目录通过adb push到模拟器中
|
|
161
|
-
*/
|
|
162
|
-
pushAndInstall(rpkPath) {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
const sn = this.sn;
|
|
165
|
-
const { package: appPackageName } = this.projectInfo;
|
|
166
|
-
const sourceRoot = rpkPath || this.isRpk ? this.projectPath : path_1.default.join(this.projectPath, './build');
|
|
167
|
-
// 获取最后一层目录,比如build
|
|
168
|
-
const basename = path_1.default.basename(sourceRoot);
|
|
169
|
-
if (os_1.default.platform() === 'win32' || this.projectPath.indexOf(' ') > 0) {
|
|
170
|
-
// windows系统或者项目路径有空格:1. adb push目录;2. 在模拟器中使用mv命令重命名
|
|
171
|
-
// 注意 sourceRoot 中可能会有空格
|
|
172
|
-
const pushCmd = `adb -s ${sn} push "${sourceRoot}" ${this.appDir}`;
|
|
173
|
-
ColorConsole_1.default.info(`### Emulator ### push CMD: ${pushCmd}`);
|
|
174
|
-
yield adbMiwt.execAdbCmdAsync(pushCmd);
|
|
175
|
-
// 在 windows 上 mv 命令不能更新原有的文件,需要先删除
|
|
176
|
-
const rmCmd = `adb -s ${sn} shell rm -r ${this.appDir}/${appPackageName}`;
|
|
177
|
-
ColorConsole_1.default.info(`### Emulator ### mv CMD: ${rmCmd}`);
|
|
178
|
-
yield adbMiwt.execAdbCmdAsync(rmCmd);
|
|
179
|
-
const mvCmd = `adb -s ${sn} shell mv ${this.appDir}/${basename} ${this.appDir}/${appPackageName}`;
|
|
180
|
-
ColorConsole_1.default.info(`### Emulator ### mv CMD: ${mvCmd}`);
|
|
181
|
-
yield adbMiwt.execAdbCmdAsync(mvCmd);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
// 支持通配符处理: 1. 模拟器中mkdir创建目录 2. adb push ./XXXXX/* /XXX
|
|
185
|
-
const sourcePath = path_1.default.join(sourceRoot, './*');
|
|
186
|
-
const mkdirCmd = `adb -s ${sn} shell mkdir ${this.appDir}/${appPackageName}`;
|
|
187
|
-
ColorConsole_1.default.log(`### Emulator ### mkdir CMD: ${mkdirCmd}`);
|
|
188
|
-
yield adbMiwt.execAdbCmdAsync(mkdirCmd);
|
|
189
|
-
const pushCmd = `adb -s ${sn} push ${sourcePath} ${this.appDir}/${appPackageName}`;
|
|
190
|
-
ColorConsole_1.default.log(`### Emulator ### pushCmd CMD: ${pushCmd}`);
|
|
191
|
-
yield adbMiwt.execAdbCmdAsync(pushCmd);
|
|
192
|
-
}
|
|
193
|
-
ColorConsole_1.default.info(`### Emulator push to ${this.appDir}/${appPackageName} successfully`);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
/** 通过命令行启动时,在watich模式下监听websocket消息,
|
|
197
|
-
* 在文件发生变动时,重新启动应用
|
|
198
|
-
*/
|
|
199
|
-
restart() {
|
|
200
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
-
this.pushAndReloadApp();
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* 重新推送,然后重启应用
|
|
206
|
-
*/
|
|
207
|
-
pushAndReloadApp() {
|
|
208
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
-
try {
|
|
210
|
-
yield this.pushAndInstall();
|
|
211
|
-
yield this.reboot();
|
|
212
|
-
this.reloadApp();
|
|
213
|
-
}
|
|
214
|
-
catch (e) {
|
|
215
|
-
ColorConsole_1.default.error(`${e}`);
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* 重启应用
|
|
221
|
-
*/
|
|
222
|
-
reloadApp() {
|
|
223
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
-
const { package: appPackageName } = this.projectInfo;
|
|
225
|
-
this.startupQuickApp(this.startOptions);
|
|
226
|
-
ColorConsole_1.default.info(`### Emulator start ${appPackageName} successfully`);
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
reboot() {
|
|
230
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
-
const rebootCmd = `adb -s ${this.sn} shell reboot`;
|
|
232
|
-
ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${rebootCmd}`);
|
|
233
|
-
yield adbMiwt.execAdbCmdAsync(rebootCmd);
|
|
234
|
-
return this.isConnected();
|
|
235
|
-
});
|
|
236
|
-
}
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _ColorConsole = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
8
|
+
var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
|
|
9
|
+
var _common = _interopRequireDefault(require("./common"));
|
|
10
|
+
var _Vvd = require("../typing/Vvd");
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
class GoldfishInstance extends _common.default {
|
|
15
|
+
imageType = (() => _Vvd.VelaImageType.DEV)();
|
|
16
|
+
appDir = '/data/app';
|
|
17
|
+
emulatorStartedFlag = '(NSH)';
|
|
18
|
+
async install(rpkPath, appPackageName) {
|
|
19
|
+
// 基于 vapp 启动的应用只需要将 rpk 解压到指定的目录下
|
|
20
|
+
rpkPath = rpkPath || `${this.appDir}/${appPackageName}.rpk`;
|
|
21
|
+
const targetPath = `${this.appDir}/${appPackageName}`;
|
|
22
|
+
const mkdirCmd = `adb -s ${this.sn} shell mkdir ${targetPath}`;
|
|
23
|
+
_ColorConsole.default.info(`### Emulator mkdir cmd ${mkdirCmd}`);
|
|
24
|
+
await adbMiwt.execAdbCmdAsync(mkdirCmd);
|
|
25
|
+
const unzipCmd = `adb -s ${this.sn} shell unzip -o ${rpkPath} -d ${targetPath}`;
|
|
26
|
+
_ColorConsole.default.info(`### Emulator unzip cmd ${unzipCmd}`);
|
|
27
|
+
await adbMiwt.execAdbCmdAsync(unzipCmd);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 在模拟器中启动快应用
|
|
32
|
+
* 通过vapp命令启动,调试时需额外配置--jsdebugger参数
|
|
33
|
+
* @param options
|
|
34
|
+
*/
|
|
35
|
+
async startApp(packageName) {
|
|
36
|
+
let debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
37
|
+
try {
|
|
38
|
+
let vappCmd = `adb -s ${this.sn} shell vapp app/${packageName} &`;
|
|
39
|
+
if (debug) {
|
|
40
|
+
vappCmd = `adb -s ${this.sn} shell vapp --jsdebugger=10.0.2.15:101 app/${packageName} &`;
|
|
41
|
+
}
|
|
42
|
+
_ColorConsole.default.log(`### Emulator ### Excuting adb cmd: ${vappCmd}`);
|
|
43
|
+
adbMiwt.execAdbCmd(vappCmd, {
|
|
44
|
+
stdio: 'ignore',
|
|
45
|
+
encoding: 'utf-8'
|
|
46
|
+
});
|
|
47
|
+
} catch (e) {
|
|
48
|
+
_ColorConsole.default.error(`### Emulator ### Failed to startup quickapp: ${e.message}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async reloadApp(appName) {
|
|
52
|
+
let debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
53
|
+
await this.reboot();
|
|
54
|
+
await this.startApp(appName, debug);
|
|
55
|
+
}
|
|
237
56
|
}
|
|
238
|
-
exports.default = GoldfishInstance;
|
|
57
|
+
var _default = exports.default = GoldfishInstance;
|
package/lib/instance/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import CommonInstance from './common';
|
|
1
|
+
import CommonEmulatorInstance from './common';
|
|
3
2
|
import GoldfishInstance from './dev';
|
|
4
3
|
import MiwearInstance from './miwear';
|
|
5
|
-
import OldGoldfishInstance from './preDev';
|
|
6
4
|
import PreInstance from './pre';
|
|
5
|
+
import { VelaImageType } from '../typing/Vvd';
|
|
6
|
+
import { IEmulatorInstanceParams } from '../typing/Instance';
|
|
7
|
+
import { VelaPre5Instance } from './pre5';
|
|
7
8
|
/**
|
|
8
9
|
* 根据镜像决定使用哪个instance
|
|
9
10
|
* Vela正式版(4.0) -> MiwearInstance
|
|
@@ -11,5 +12,5 @@ import PreInstance from './pre';
|
|
|
11
12
|
* Vela开发版(dev, 0.0.2) -> OldGoldfishInstance
|
|
12
13
|
* Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
|
|
13
14
|
*/
|
|
14
|
-
declare function findInstance(
|
|
15
|
-
export { CommonInstance, GoldfishInstance, MiwearInstance,
|
|
15
|
+
declare function findInstance(imageType: VelaImageType, params: IEmulatorInstanceParams): GoldfishInstance | MiwearInstance;
|
|
16
|
+
export { CommonEmulatorInstance as CommonInstance, GoldfishInstance, MiwearInstance, VelaPre5Instance, PreInstance, findInstance };
|
package/lib/instance/index.js
CHANGED
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CommonInstance", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _common.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "GoldfishInstance", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _dev.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "MiwearInstance", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _miwear.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "PreInstance", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _pre.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "VelaPre5Instance", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _pre2.VelaPre5Instance;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
7
36
|
exports.findInstance = findInstance;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
exports.MiwearInstance = miwear_1.default;
|
|
16
|
-
const preDev_1 = __importDefault(require("./preDev"));
|
|
17
|
-
exports.OldGoldfishInstance = preDev_1.default;
|
|
18
|
-
const pre_1 = __importDefault(require("./pre"));
|
|
19
|
-
exports.PreInstance = pre_1.default;
|
|
37
|
+
var _common = _interopRequireDefault(require("./common"));
|
|
38
|
+
var _dev = _interopRequireDefault(require("./dev"));
|
|
39
|
+
var _miwear = _interopRequireDefault(require("./miwear"));
|
|
40
|
+
var _pre = _interopRequireDefault(require("./pre"));
|
|
41
|
+
var _Vvd = require("../typing/Vvd");
|
|
42
|
+
var _pre2 = require("./pre5");
|
|
43
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
44
|
/**
|
|
21
45
|
* 根据镜像决定使用哪个instance
|
|
22
46
|
* Vela正式版(4.0) -> MiwearInstance
|
|
@@ -24,21 +48,13 @@ exports.PreInstance = pre_1.default;
|
|
|
24
48
|
* Vela开发版(dev, 0.0.2) -> OldGoldfishInstance
|
|
25
49
|
* Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
|
|
26
50
|
*/
|
|
27
|
-
function findInstance(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (avdImagePath.includes('release')) {
|
|
38
|
-
return new miwear_1.default(params);
|
|
39
|
-
}
|
|
40
|
-
else if (avdImagePath.match(/0\.0\.2|0\.0\.1/)) {
|
|
41
|
-
return new preDev_1.default(params);
|
|
42
|
-
}
|
|
43
|
-
return new dev_1.default(params);
|
|
44
|
-
}
|
|
51
|
+
function findInstance(imageType, params) {
|
|
52
|
+
const map = {
|
|
53
|
+
[_Vvd.VelaImageType.PRE]: _pre.default,
|
|
54
|
+
[_Vvd.VelaImageType.REL]: _miwear.default,
|
|
55
|
+
[_Vvd.VelaImageType.DEV]: _dev.default,
|
|
56
|
+
[_Vvd.VelaImageType.VELA_PRE_5]: _pre2.VelaPre5Instance
|
|
57
|
+
};
|
|
58
|
+
const Instance = map[imageType] || _dev.default;
|
|
59
|
+
return new Instance(params);
|
|
60
|
+
}
|
package/lib/instance/miwear.d.ts
CHANGED
|
@@ -1,82 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import CommonInstance from './common';
|
|
1
|
+
import CommonEmulatorInstance from './common';
|
|
2
|
+
import { VelaImageType } from '../typing/Vvd';
|
|
4
3
|
/**
|
|
5
4
|
* MiwearInstance
|
|
6
5
|
* 针对 Vela正式版(4.0)的镜像
|
|
7
6
|
*/
|
|
8
|
-
declare class MiwearInstance extends
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
private debugSocket?;
|
|
12
|
-
private reconnectCount;
|
|
13
|
-
stdoutReadline: readline.Interface;
|
|
14
|
-
stderrReadline: readline.Interface;
|
|
15
|
-
constructor(params: INewGoldfishInstanceParams);
|
|
7
|
+
declare class MiwearInstance extends CommonEmulatorInstance {
|
|
8
|
+
imageType: VelaImageType;
|
|
9
|
+
appDir: string;
|
|
16
10
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
start
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* 3. 判断模拟器是否启动成功
|
|
27
|
-
* 3.1 若disableNSH=true,输出流中匹配到/quickapp_rpk_installer_init|rpk installer init done/,认为模拟器启动成功了
|
|
28
|
-
* 3.2 若disableNSH=false,认为8s过后模拟器启动成功了
|
|
29
|
-
* @param options
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
startGoldfish(options: IStartOptions): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* 在模拟器中启动快应用
|
|
35
|
-
* 1. 检查release目录是否有打包好的rpk
|
|
36
|
-
* 2. 检查当前是否为调试模式.
|
|
37
|
-
* 若是,将debugger_ip.cfg推到模拟器的/data/目录下
|
|
38
|
-
* 若否,则要删除模拟器中已有的data/debugger_ip.cfg
|
|
39
|
-
* 3. 调用installRpkToAppList将当前快应用安装到模拟器的应用列表中
|
|
40
|
-
* @param options
|
|
41
|
-
*/
|
|
42
|
-
startupQuickApp(options: IStartOptions): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* 将快应用安装到模拟器的应用列表
|
|
45
|
-
* 1. 使用adb push将打包好的rpk推到模拟器的/data/quickapp/app/
|
|
46
|
-
* 2. nsh中调用pm install命令安装应用
|
|
47
|
-
* @param rpkPath rpk的绝对目录
|
|
48
|
-
* @param targetDir 要将rpk放到模拟器的哪个目录下
|
|
49
|
-
*/
|
|
50
|
-
pushAndInstall(rpkPath: string, targetDir: string): Promise<void>;
|
|
51
|
-
/** 使用am start启动快应用 */
|
|
52
|
-
launchQuickapp(): Promise<void>;
|
|
53
|
-
/** 连接模拟器中的调试服务,创建debugSocket
|
|
54
|
-
* 主要用于热更新时,通过debugSocket通知调试服务更新页面
|
|
55
|
-
* 设置了重连机制,会重复连接8次
|
|
56
|
-
*/
|
|
57
|
-
initDebugSocket(): Promise<void>;
|
|
58
|
-
/** 通知模拟器更新
|
|
59
|
-
* 1. 确保已经成功连接模拟器中的调试服务
|
|
60
|
-
* 2. 使用adb push将build文件下的内容推到/data/quickapp/app/${packageName}
|
|
61
|
-
* 3. 发送Page.reload命令给调试服务,通知更新
|
|
62
|
-
*/
|
|
63
|
-
handleUpdate(): Promise<void>;
|
|
64
|
-
/** 热更新时push目录 */
|
|
65
|
-
pushBuild(): Promise<void>;
|
|
66
|
-
/** 通过命令行启动时,在watich模式下监听websocket消息,
|
|
67
|
-
* 在文件发生变动时,重新启动应用
|
|
68
|
-
*/
|
|
69
|
-
restart(): Promise<void>;
|
|
70
|
-
/** 在模拟器中重启快应用(基于am命令,需要保证镜像中已经有am功能)
|
|
71
|
-
* 1. 使用adb push将build文件下的内容推到/data/quickapp/app/${packageName}
|
|
72
|
-
* 2. nsh中执行am stop命令退出快应用
|
|
73
|
-
* 3. nsh中执行am start命令启动快应用
|
|
74
|
-
*/
|
|
75
|
-
pushAndReloadApp(): Promise<void>;
|
|
76
|
-
reloadApp(): Promise<void>;
|
|
77
|
-
/**
|
|
78
|
-
* 创建server端,监听打包过程中client端发来的消息
|
|
79
|
-
*/
|
|
80
|
-
createWebsockeServer(): Promise<void>;
|
|
11
|
+
* 使用 pm 安装快应用
|
|
12
|
+
* @param targeRpk 快应用的rpk文件路径
|
|
13
|
+
*/
|
|
14
|
+
install(targeRpk: string): Promise<void>;
|
|
15
|
+
/** 使用 am start 启动快应用 */
|
|
16
|
+
startApp(packageName: string, debug?: boolean): Promise<void>;
|
|
17
|
+
closeApp(appName: string): Promise<void>;
|
|
18
|
+
reboot(): Promise<void>;
|
|
19
|
+
reloadApp(appPackageName: string, _debug?: boolean): Promise<void>;
|
|
81
20
|
}
|
|
82
21
|
export default MiwearInstance;
|