@aiot-toolkit/emulator 2.0.3-beta.9 → 2.0.4-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/lib/emulatorutil/constants.d.ts +2 -2
- package/lib/emulatorutil/constants.js +14 -14
- package/lib/emulatorutil/index.d.ts +0 -2
- package/lib/emulatorutil/index.js +1 -14
- package/lib/emulatorutil/running.js +1 -1
- package/lib/instance/common.d.ts +8 -2
- package/lib/instance/common.js +44 -12
- package/lib/instance/dev.d.ts +2 -2
- package/lib/instance/dev.js +7 -8
- package/lib/instance/index.d.ts +3 -2
- package/lib/instance/index.js +12 -7
- package/lib/instance/miwear.d.ts +1 -0
- package/lib/instance/miwear.js +12 -13
- package/lib/instance/pre.js +4 -5
- package/lib/instance/pre5.js +2 -3
- package/lib/typing/Instance.d.ts +2 -0
- package/lib/typing/Vvd.d.ts +1 -1
- package/lib/typing/Vvd.js +8 -8
- package/lib/vvd/index.d.ts +5 -5
- package/lib/vvd/index.js +41 -23
- package/package.json +3 -3
- package/lib/emulatorutil/EmulatorLog.d.ts +0 -11
- package/lib/emulatorutil/EmulatorLog.js +0 -25
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SDKParts, VelaImageType } from '../typing/Vvd';
|
|
2
2
|
export declare const defaultSDKHome: string;
|
|
3
3
|
export declare const defaultVvdHome: string;
|
|
4
4
|
export declare const defaultImageHome: string;
|
|
@@ -40,5 +40,5 @@ export declare function getImageDownloadUrl(): Record<VelaImageType, string>;
|
|
|
40
40
|
* 镜像地址默认返回 REL 版本的地址,如果需要获取其他版本,请使用
|
|
41
41
|
* {@link getImageDownloadUrl}
|
|
42
42
|
*/
|
|
43
|
-
export declare function
|
|
43
|
+
export declare function getSDKPartDownloadUrl(type: SDKParts): string;
|
|
44
44
|
export declare function getDefaultImage(): VelaImageType;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.emulatorBaseUrl = exports.defaultVvdHome = exports.defaultVncPort = exports.defaultToolsHome = exports.defaultSkinHome = exports.defaultSDKHome = exports.defaultQuickappHome = exports.defaultImageHome = exports.defaultEmulatorHome = exports.defaultDebugPort = exports.defaultAdbPort = exports.baseUrl = exports.VelaImageVersionList = exports.EmulatorEnvVersion = void 0;
|
|
7
7
|
exports.getDefaultImage = getDefaultImage;
|
|
8
8
|
exports.getImageDownloadUrl = getImageDownloadUrl;
|
|
9
|
-
exports.
|
|
9
|
+
exports.getSDKPartDownloadUrl = getSDKPartDownloadUrl;
|
|
10
10
|
exports.versionUrl = exports.systemImageBaseUrl = void 0;
|
|
11
11
|
var _os = _interopRequireDefault(require("os"));
|
|
12
12
|
var _path = _interopRequireDefault(require("path"));
|
|
@@ -38,13 +38,13 @@ const systemImageBaseUrl = exports.systemImageBaseUrl = 'https://vela-ide.cnbj3-
|
|
|
38
38
|
const VelaImageVersionList = exports.VelaImageVersionList = [{
|
|
39
39
|
label: 'vela-4.0-正式版',
|
|
40
40
|
value: _Vvd.VelaImageType.REL,
|
|
41
|
-
time: '
|
|
41
|
+
time: '20241205',
|
|
42
42
|
hide: false,
|
|
43
43
|
icon: ''
|
|
44
44
|
}, {
|
|
45
45
|
label: 'vela-4.0-测试版',
|
|
46
46
|
value: _Vvd.VelaImageType.PRE,
|
|
47
|
-
time: '
|
|
47
|
+
time: '20241205',
|
|
48
48
|
hide: false,
|
|
49
49
|
icon: ''
|
|
50
50
|
}, {
|
|
@@ -64,11 +64,11 @@ const VelaImageVersionList = exports.VelaImageVersionList = [{
|
|
|
64
64
|
];
|
|
65
65
|
const EmulatorEnvVersion = exports.EmulatorEnvVersion = {
|
|
66
66
|
name: '模拟器资源版本管理',
|
|
67
|
-
[_Vvd.
|
|
68
|
-
[_Vvd.
|
|
69
|
-
[_Vvd.
|
|
70
|
-
[_Vvd.
|
|
71
|
-
[_Vvd.
|
|
67
|
+
[_Vvd.SDKParts.EMULATOR]: '0.0.9',
|
|
68
|
+
[_Vvd.SDKParts.QA]: '0.0.1',
|
|
69
|
+
[_Vvd.SDKParts.SKINS]: '0.0.9',
|
|
70
|
+
[_Vvd.SDKParts.SYSTEM_IMAGES]: VelaImageVersionList[0].time,
|
|
71
|
+
[_Vvd.SDKParts.MODEM_SIMULATOR]: '0.0.3'
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
/** 获取镜像下载地址 */
|
|
@@ -84,18 +84,18 @@ function getImageDownloadUrl() {
|
|
|
84
84
|
* 镜像地址默认返回 REL 版本的地址,如果需要获取其他版本,请使用
|
|
85
85
|
* {@link getImageDownloadUrl}
|
|
86
86
|
*/
|
|
87
|
-
function
|
|
87
|
+
function getSDKPartDownloadUrl(type) {
|
|
88
88
|
switch (type) {
|
|
89
|
-
case _Vvd.
|
|
89
|
+
case _Vvd.SDKParts.EMULATOR:
|
|
90
90
|
const systemOs = _os.default.platform();
|
|
91
91
|
const hostArch = (0, _utils.getSystemArch)();
|
|
92
92
|
let hostOs = systemOs === 'win32' ? 'windows' : systemOs;
|
|
93
93
|
return `${emulatorBaseUrl}/v${EmulatorEnvVersion.emulator}/${hostOs}-${hostArch}.zip`;
|
|
94
|
-
case _Vvd.
|
|
94
|
+
case _Vvd.SDKParts.SYSTEM_IMAGES:
|
|
95
95
|
return getImageDownloadUrl()[_Vvd.VelaImageType.REL];
|
|
96
|
-
case _Vvd.
|
|
97
|
-
case _Vvd.
|
|
98
|
-
case _Vvd.
|
|
96
|
+
case _Vvd.SDKParts.QA:
|
|
97
|
+
case _Vvd.SDKParts.MODEM_SIMULATOR:
|
|
98
|
+
case _Vvd.SDKParts.SKINS:
|
|
99
99
|
return `${baseUrl}/${type}/v${EmulatorEnvVersion[type]}/${type}.zip`;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -3,20 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
EmulatorLog: true
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "EmulatorLog", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () {
|
|
12
|
-
return _EmulatorLog.default;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
var _EmulatorLog = _interopRequireDefault(require("./EmulatorLog"));
|
|
16
6
|
var _running = require("./running");
|
|
17
7
|
Object.keys(_running).forEach(function (key) {
|
|
18
8
|
if (key === "default" || key === "__esModule") return;
|
|
19
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
20
9
|
if (key in exports && exports[key] === _running[key]) return;
|
|
21
10
|
Object.defineProperty(exports, key, {
|
|
22
11
|
enumerable: true,
|
|
@@ -28,7 +17,6 @@ Object.keys(_running).forEach(function (key) {
|
|
|
28
17
|
var _constants = require("./constants");
|
|
29
18
|
Object.keys(_constants).forEach(function (key) {
|
|
30
19
|
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
32
20
|
if (key in exports && exports[key] === _constants[key]) return;
|
|
33
21
|
Object.defineProperty(exports, key, {
|
|
34
22
|
enumerable: true,
|
|
@@ -36,5 +24,4 @@ Object.keys(_constants).forEach(function (key) {
|
|
|
36
24
|
return _constants[key];
|
|
37
25
|
}
|
|
38
26
|
});
|
|
39
|
-
});
|
|
40
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
27
|
+
});
|
|
@@ -95,7 +95,7 @@ async function getRunningVvds() {
|
|
|
95
95
|
const config = getRunningAvdConfig();
|
|
96
96
|
// running 文件中的数据可能会因为上次模拟器未正常退出而残留,所以需要过滤一下
|
|
97
97
|
const adbDevices = await (0, _adb.getAdbDevices)();
|
|
98
|
-
return config.filter(c => adbDevices.some(e => e.sn === `emulator-${c['port.serial']}`));
|
|
98
|
+
return config.filter(c => adbDevices.some(e => e.sn === `emulator-${c['port.serial']}` && e.status === 'device'));
|
|
99
99
|
}
|
|
100
100
|
function getRunningAvdConfigByName(name) {
|
|
101
101
|
const config = getRunningAvdConfig();
|
package/lib/instance/common.d.ts
CHANGED
|
@@ -5,7 +5,11 @@ import { ChildProcessWithoutNullStreams } from 'child_process';
|
|
|
5
5
|
declare class CommonEmulatorInstance {
|
|
6
6
|
imageType: VelaImageType;
|
|
7
7
|
appDir: string;
|
|
8
|
-
|
|
8
|
+
static emulatorStartedFlag: RegExp;
|
|
9
|
+
static appInstalledFlag: RegExp;
|
|
10
|
+
static appStartedFlag: RegExp;
|
|
11
|
+
static isAppInstalled(log: string): boolean;
|
|
12
|
+
static isEmulatorStarted(log: string): boolean;
|
|
9
13
|
sn: string;
|
|
10
14
|
vvdName: string;
|
|
11
15
|
debugPort?: number | string;
|
|
@@ -15,6 +19,7 @@ declare class CommonEmulatorInstance {
|
|
|
15
19
|
onStdout: (msg: string) => void;
|
|
16
20
|
onErrout: (msg: string) => void;
|
|
17
21
|
logcatProcess: ChildProcessWithoutNullStreams;
|
|
22
|
+
logger: (log: string) => void;
|
|
18
23
|
constructor(params: IEmulatorInstanceParams);
|
|
19
24
|
/** 推送指定文件 */
|
|
20
25
|
push(sourcePath: string, targetPath: string): Promise<string>;
|
|
@@ -26,7 +31,7 @@ declare class CommonEmulatorInstance {
|
|
|
26
31
|
*/
|
|
27
32
|
isConnected(): Promise<boolean>;
|
|
28
33
|
/** 安装应用,留给子类实现 */
|
|
29
|
-
install(rpkPath: string, packageName
|
|
34
|
+
install(rpkPath: string, packageName: string): Promise<void>;
|
|
30
35
|
/** 卸载应用,留给子类实现 */
|
|
31
36
|
uninstall(packageName: string): Promise<void>;
|
|
32
37
|
/** 启动应用,留给子类实现 */
|
|
@@ -39,6 +44,7 @@ declare class CommonEmulatorInstance {
|
|
|
39
44
|
/** 关闭模拟器 */
|
|
40
45
|
poweroff(timeout?: number): Promise<void>;
|
|
41
46
|
systemed(): Promise<string>;
|
|
47
|
+
getApplist(): Promise<string[]>;
|
|
42
48
|
/** 重启模拟器 */
|
|
43
49
|
reboot(): Promise<void>;
|
|
44
50
|
}
|
package/lib/instance/common.js
CHANGED
|
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _ColorConsole = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
8
|
-
var
|
|
8
|
+
var _ILog = require("@aiot-toolkit/shared-utils/lib/interface/ILog");
|
|
9
|
+
var _adb = _interopRequireWildcard(require("@miwt/adb"));
|
|
10
|
+
var adbMiwt = _adb;
|
|
9
11
|
var _utils = require("../utils");
|
|
10
12
|
var _logcat = require("../vvd/logcat");
|
|
11
13
|
var _emulatorutil = require("../emulatorutil");
|
|
@@ -14,13 +16,32 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
14
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
17
|
class CommonEmulatorInstance {
|
|
16
18
|
appDir = '/data/quickapp/app';
|
|
17
|
-
|
|
19
|
+
static emulatorStartedFlag = /quickapp_rpk_installer_init|rpk installer init done|booting completed/;
|
|
20
|
+
static appInstalledFlag = /InstallState_Finished|install finished/;
|
|
21
|
+
static appStartedFlag = /Start App loop/;
|
|
22
|
+
static isAppInstalled(log) {
|
|
23
|
+
return this.appInstalledFlag.test(log);
|
|
24
|
+
}
|
|
25
|
+
static isEmulatorStarted(log) {
|
|
26
|
+
return this.emulatorStartedFlag.test(log);
|
|
27
|
+
}
|
|
18
28
|
constructor(params) {
|
|
19
29
|
this.sn = `emulator-${params.serialPort}`;
|
|
20
30
|
this.vvdName = params.vvdName;
|
|
21
31
|
this.onStdout = params.onStdout || console.log;
|
|
22
32
|
this.onErrout = params.onErrout || console.error;
|
|
23
33
|
this.debugPort = params.debugPort || (0, _emulatorutil.getRunningVvdDebugPort)(this.vvdName);
|
|
34
|
+
if (params.customLogger) {
|
|
35
|
+
this.logger = msg => {
|
|
36
|
+
const prefix = _ColorConsole.default.createDefaultPrefix({
|
|
37
|
+
level: _ILog.Loglevel.INFO,
|
|
38
|
+
message: msg
|
|
39
|
+
});
|
|
40
|
+
params.customLogger(`${prefix[1]} ${msg?.trim()}`);
|
|
41
|
+
};
|
|
42
|
+
} else {
|
|
43
|
+
this.logger = _ColorConsole.default.info;
|
|
44
|
+
}
|
|
24
45
|
if (params.logcatProcess) {
|
|
25
46
|
this.logcatProcess = params.logcatProcess;
|
|
26
47
|
if (!params.stdoutReadline || !params.stderrReadline) {
|
|
@@ -45,16 +66,16 @@ class CommonEmulatorInstance {
|
|
|
45
66
|
async push(sourcePath, targetPath) {
|
|
46
67
|
// 1. adb push应用的rpk
|
|
47
68
|
const pushCmd = `adb -s ${this.sn} push "${sourcePath}" ${targetPath}`;
|
|
48
|
-
|
|
69
|
+
this.logger(`Excuting: ${pushCmd}`);
|
|
49
70
|
const res = await adbMiwt.execAdbCmdAsync(pushCmd);
|
|
50
|
-
|
|
71
|
+
this.logger(`Push result: ${res}`);
|
|
51
72
|
return targetPath;
|
|
52
73
|
}
|
|
53
74
|
async unzip(zipPath, targetPath) {
|
|
54
75
|
const unzipCmd = `adb -s ${this.sn} shell unzip -o ${zipPath} -d ${targetPath}`;
|
|
55
|
-
|
|
76
|
+
this.logger(`Excuting: ${unzipCmd}`);
|
|
56
77
|
const res = await adbMiwt.execAdbCmdAsync(unzipCmd);
|
|
57
|
-
|
|
78
|
+
this.logger(`Unzip result: ${res}`);
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
/** 推送指定 rpk */
|
|
@@ -62,9 +83,9 @@ class CommonEmulatorInstance {
|
|
|
62
83
|
// 1. adb push应用的rpk
|
|
63
84
|
const targetPath = `${this.appDir}/${appPackageName}.rpk`;
|
|
64
85
|
const pushCmd = `adb -s ${this.sn} push "${rpkPath}" ${targetPath}`;
|
|
65
|
-
|
|
86
|
+
this.logger(`Excuting: ${pushCmd}`);
|
|
66
87
|
const res = await adbMiwt.execAdbCmdAsync(pushCmd);
|
|
67
|
-
|
|
88
|
+
this.logger(`Push ${this.vvdName} rpk result: ${res}`);
|
|
68
89
|
return targetPath;
|
|
69
90
|
}
|
|
70
91
|
|
|
@@ -74,7 +95,7 @@ class CommonEmulatorInstance {
|
|
|
74
95
|
async isConnected() {
|
|
75
96
|
return (0, _utils.tryRun)(async () => {
|
|
76
97
|
const devices = await adbMiwt.getAdbDevices();
|
|
77
|
-
_ColorConsole.default.log(
|
|
98
|
+
_ColorConsole.default.log(`adb devices: ${JSON.stringify(devices)}`);
|
|
78
99
|
const curDev = devices.find(t => t.sn === this.sn);
|
|
79
100
|
return curDev?.status === 'device';
|
|
80
101
|
}, 10, 500);
|
|
@@ -109,7 +130,7 @@ class CommonEmulatorInstance {
|
|
|
109
130
|
return new Promise((resolve, reject) => {
|
|
110
131
|
const t = setTimeout(() => {
|
|
111
132
|
(0, _utils.killProcessByCmd)(this.vvdName).then(resolve).catch(e => {
|
|
112
|
-
reject(`poweroff failed ${e}`);
|
|
133
|
+
reject(`poweroff ${this.vvdName} failed ${e}`);
|
|
113
134
|
});
|
|
114
135
|
}, timeout);
|
|
115
136
|
adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} shell poweroff`).then(() => {
|
|
@@ -120,7 +141,7 @@ class CommonEmulatorInstance {
|
|
|
120
141
|
clearTimeout(t);
|
|
121
142
|
resolve();
|
|
122
143
|
}).catch(e => {
|
|
123
|
-
reject(`poweroff failed ${e}`);
|
|
144
|
+
reject(`poweroff ${this.vvdName} failed ${e}`);
|
|
124
145
|
});
|
|
125
146
|
});
|
|
126
147
|
});
|
|
@@ -128,11 +149,22 @@ class CommonEmulatorInstance {
|
|
|
128
149
|
systemed() {
|
|
129
150
|
return adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} shell systemd &`);
|
|
130
151
|
}
|
|
152
|
+
async getApplist() {
|
|
153
|
+
const cmd = `adb -s ${this.sn} shell ls ${this.appDir}`;
|
|
154
|
+
const dataStr = await (0, _adb.execAdbCmdAsync)(cmd);
|
|
155
|
+
if (dataStr) {
|
|
156
|
+
// 使用换行符分割字符串,得到数组
|
|
157
|
+
const appsArray = dataStr.replace(/\r\n/g, '\n').split('\n');
|
|
158
|
+
const cleanedAppsArray = appsArray.filter(item => item.endsWith('/')).map(item => item.trim().slice(0, -1));
|
|
159
|
+
return cleanedAppsArray;
|
|
160
|
+
}
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
131
163
|
|
|
132
164
|
/** 重启模拟器 */
|
|
133
165
|
async reboot() {
|
|
134
166
|
const rebootCmd = `adb -s ${this.sn} shell reboot`;
|
|
135
|
-
_ColorConsole.default.log(
|
|
167
|
+
_ColorConsole.default.log(`Excuting: ${rebootCmd}`);
|
|
136
168
|
await adbMiwt.execAdbCmdAsync(rebootCmd);
|
|
137
169
|
await this.isConnected();
|
|
138
170
|
if (!this.logcatProcess.exitCode !== undefined) {
|
package/lib/instance/dev.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import CommonEmulatorInstance from './common';
|
|
|
2
2
|
import { VelaImageType } from '../typing/Vvd';
|
|
3
3
|
declare class GoldfishInstance extends CommonEmulatorInstance {
|
|
4
4
|
imageType: VelaImageType;
|
|
5
|
-
appDir: string;
|
|
6
|
-
emulatorStartedFlag:
|
|
5
|
+
static appDir: string;
|
|
6
|
+
static emulatorStartedFlag: RegExp;
|
|
7
7
|
install(rpkPath: string, appPackageName?: string): Promise<void>;
|
|
8
8
|
/**
|
|
9
9
|
* 在模拟器中启动快应用
|
package/lib/instance/dev.js
CHANGED
|
@@ -4,26 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _ColorConsole = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
8
7
|
var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
|
|
9
8
|
var _common = _interopRequireDefault(require("./common"));
|
|
10
9
|
var _Vvd = require("../typing/Vvd");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
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
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
13
|
class GoldfishInstance extends _common.default {
|
|
15
14
|
imageType = (() => _Vvd.VelaImageType.DEV)();
|
|
16
|
-
appDir = '/data/app';
|
|
17
|
-
emulatorStartedFlag =
|
|
15
|
+
static appDir = '/data/app';
|
|
16
|
+
static emulatorStartedFlag = /(NSH)/;
|
|
18
17
|
async install(rpkPath, appPackageName) {
|
|
19
18
|
// 基于 vapp 启动的应用只需要将 rpk 解压到指定的目录下
|
|
20
19
|
rpkPath = rpkPath || `${this.appDir}/${appPackageName}.rpk`;
|
|
21
20
|
const targetPath = `${this.appDir}/${appPackageName}`;
|
|
22
21
|
const mkdirCmd = `adb -s ${this.sn} shell mkdir ${targetPath}`;
|
|
23
|
-
|
|
22
|
+
this.logger(`Excuting: ${mkdirCmd}`);
|
|
24
23
|
await adbMiwt.execAdbCmdAsync(mkdirCmd);
|
|
25
24
|
const unzipCmd = `adb -s ${this.sn} shell unzip -o ${rpkPath} -d ${targetPath}`;
|
|
26
|
-
|
|
25
|
+
this.logger(`Excuting: ${unzipCmd}`);
|
|
27
26
|
await adbMiwt.execAdbCmdAsync(unzipCmd);
|
|
28
27
|
}
|
|
29
28
|
|
|
@@ -39,13 +38,13 @@ class GoldfishInstance extends _common.default {
|
|
|
39
38
|
if (debug) {
|
|
40
39
|
vappCmd = `adb -s ${this.sn} shell vapp --jsdebugger=10.0.2.15:101 app/${packageName} &`;
|
|
41
40
|
}
|
|
42
|
-
|
|
41
|
+
this.logger(`Excuting: ${vappCmd}`);
|
|
43
42
|
adbMiwt.execAdbCmd(vappCmd, {
|
|
44
43
|
stdio: 'ignore',
|
|
45
44
|
encoding: 'utf-8'
|
|
46
45
|
});
|
|
47
46
|
} catch (e) {
|
|
48
|
-
|
|
47
|
+
this.logger(`Failed to startup quickapp: ${e.message}`);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
async reloadApp(appName) {
|
package/lib/instance/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import PreInstance from './pre';
|
|
|
5
5
|
import { VelaImageType } from '../typing/Vvd';
|
|
6
6
|
import { IEmulatorInstanceParams } from '../typing/Instance';
|
|
7
7
|
import { VelaPre5Instance } from './pre5';
|
|
8
|
+
declare function getInstanceClass(imageType: VelaImageType): typeof GoldfishInstance | typeof MiwearInstance | typeof PreInstance | typeof VelaPre5Instance;
|
|
8
9
|
/**
|
|
9
10
|
* 根据镜像决定使用哪个instance
|
|
10
11
|
* Vela正式版(4.0) -> MiwearInstance
|
|
@@ -12,5 +13,5 @@ import { VelaPre5Instance } from './pre5';
|
|
|
12
13
|
* Vela开发版(dev, 0.0.2) -> OldGoldfishInstance
|
|
13
14
|
* Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
|
|
14
15
|
*/
|
|
15
|
-
declare function findInstance(imageType: VelaImageType, params: IEmulatorInstanceParams):
|
|
16
|
-
export { CommonEmulatorInstance as CommonInstance, GoldfishInstance, MiwearInstance, VelaPre5Instance, PreInstance, findInstance };
|
|
16
|
+
declare function findInstance(imageType: VelaImageType, params: IEmulatorInstanceParams): CommonEmulatorInstance;
|
|
17
|
+
export { CommonEmulatorInstance as CommonInstance, GoldfishInstance, MiwearInstance, VelaPre5Instance, PreInstance, findInstance, getInstanceClass };
|
package/lib/instance/index.js
CHANGED
|
@@ -34,6 +34,7 @@ Object.defineProperty(exports, "VelaPre5Instance", {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
exports.findInstance = findInstance;
|
|
37
|
+
exports.getInstanceClass = getInstanceClass;
|
|
37
38
|
var _common = _interopRequireDefault(require("./common"));
|
|
38
39
|
var _dev = _interopRequireDefault(require("./dev"));
|
|
39
40
|
var _miwear = _interopRequireDefault(require("./miwear"));
|
|
@@ -41,6 +42,16 @@ var _pre = _interopRequireDefault(require("./pre"));
|
|
|
41
42
|
var _Vvd = require("../typing/Vvd");
|
|
42
43
|
var _pre2 = require("./pre5");
|
|
43
44
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
45
|
+
function getInstanceClass(imageType) {
|
|
46
|
+
const map = {
|
|
47
|
+
[_Vvd.VelaImageType.PRE]: _pre.default,
|
|
48
|
+
[_Vvd.VelaImageType.REL]: _miwear.default,
|
|
49
|
+
[_Vvd.VelaImageType.DEV]: _dev.default,
|
|
50
|
+
[_Vvd.VelaImageType.VELA_PRE_5]: _pre2.VelaPre5Instance
|
|
51
|
+
};
|
|
52
|
+
return map[imageType] || _dev.default;
|
|
53
|
+
}
|
|
54
|
+
|
|
44
55
|
/**
|
|
45
56
|
* 根据镜像决定使用哪个instance
|
|
46
57
|
* Vela正式版(4.0) -> MiwearInstance
|
|
@@ -49,12 +60,6 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
49
60
|
* Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
|
|
50
61
|
*/
|
|
51
62
|
function findInstance(imageType, params) {
|
|
52
|
-
const
|
|
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;
|
|
63
|
+
const Instance = getInstanceClass(imageType);
|
|
59
64
|
return new Instance(params);
|
|
60
65
|
}
|
package/lib/instance/miwear.d.ts
CHANGED
package/lib/instance/miwear.js
CHANGED
|
@@ -4,21 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _ColorConsole = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
8
7
|
var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
|
|
9
8
|
var _path = _interopRequireDefault(require("path"));
|
|
10
9
|
var _utils = require("../utils");
|
|
11
10
|
var _common = _interopRequireDefault(require("./common"));
|
|
12
|
-
var _emulatorutil = require("../emulatorutil");
|
|
13
11
|
var _Vvd = require("../typing/Vvd");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
13
|
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); }
|
|
15
14
|
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; }
|
|
16
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
15
|
/**
|
|
18
16
|
* MiwearInstance
|
|
19
17
|
* 针对 Vela正式版(4.0)的镜像
|
|
20
18
|
*/
|
|
21
19
|
class MiwearInstance extends _common.default {
|
|
20
|
+
static appInstalledFlag = /InstallState_Finished|install finished/;
|
|
22
21
|
imageType = (() => _Vvd.VelaImageType.REL)();
|
|
23
22
|
appDir = '/data/quickapp/app';
|
|
24
23
|
|
|
@@ -30,15 +29,15 @@ class MiwearInstance extends _common.default {
|
|
|
30
29
|
adbMiwt.execAdbCmd(`adb -s ${this.sn} shell pm install ${targeRpk}`);
|
|
31
30
|
return new Promise((resolve, reject) => {
|
|
32
31
|
const func = msg => {
|
|
33
|
-
if (
|
|
32
|
+
if (MiwearInstance.isAppInstalled(msg)) {
|
|
34
33
|
clearTimeout(timer);
|
|
35
|
-
|
|
34
|
+
this.logger(`Install to ${this.vvdName} ${targeRpk} successfully`);
|
|
36
35
|
resolve();
|
|
37
36
|
}
|
|
38
37
|
};
|
|
39
38
|
let timer = setTimeout(() => {
|
|
40
39
|
this.stdoutReadline.off('line', func);
|
|
41
|
-
|
|
40
|
+
this.logger(`Install to ${this.vvdName} ${targeRpk} timeout`);
|
|
42
41
|
reject('Install timeout');
|
|
43
42
|
}, 2 * 60 * 1000);
|
|
44
43
|
this.stdoutReadline.on('line', func);
|
|
@@ -56,27 +55,27 @@ class MiwearInstance extends _common.default {
|
|
|
56
55
|
await adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} shell rm /data/debugger_ip.cfg`);
|
|
57
56
|
}
|
|
58
57
|
const startCmd = `adb -s ${this.sn} shell am start ${packageName}`;
|
|
59
|
-
|
|
58
|
+
this.logger(`Excuting: ${startCmd}`);
|
|
60
59
|
await adbMiwt.execAdbCmdAsync(startCmd);
|
|
61
60
|
}
|
|
62
61
|
async closeApp(appName) {
|
|
63
62
|
const stopCmd = `adb -s ${this.sn} shell am stop ${appName}`;
|
|
64
63
|
await adbMiwt.execAdbCmdAsync(stopCmd);
|
|
65
|
-
|
|
64
|
+
this.logger(`Stop ${this.vvdName} ${appName} successfully`);
|
|
66
65
|
// 这里是为了等am stop命令清除资源等
|
|
67
66
|
}
|
|
68
67
|
async reboot() {
|
|
69
68
|
await super.reboot();
|
|
70
69
|
return new Promise((resolve, reject) => {
|
|
71
70
|
const func = msg => {
|
|
72
|
-
if (
|
|
71
|
+
if (MiwearInstance.isEmulatorStarted(msg)) {
|
|
73
72
|
clearTimeout(timer);
|
|
74
73
|
resolve();
|
|
75
74
|
}
|
|
76
75
|
};
|
|
77
76
|
let timer = setTimeout(() => {
|
|
78
77
|
this.stdoutReadline.off('line', func);
|
|
79
|
-
|
|
78
|
+
this.logger(`Reboot ${this.vvdName} timeout`);
|
|
80
79
|
reject('reboot timeout');
|
|
81
80
|
}, 2 * 60 * 1000);
|
|
82
81
|
this.stdoutReadline.on('line', func);
|
|
@@ -88,14 +87,14 @@ class MiwearInstance extends _common.default {
|
|
|
88
87
|
// 2. 执行am stop和am start命令
|
|
89
88
|
const stopCmd = `adb -s ${this.sn} shell am stop ${appPackageName}`;
|
|
90
89
|
await adbMiwt.execAdbCmdAsync(stopCmd);
|
|
91
|
-
|
|
90
|
+
this.logger(`Stop ${this.vvdName} ${appPackageName} successfully`);
|
|
92
91
|
// 这里是为了等am stop命令清除资源等
|
|
93
92
|
await (0, _utils.sleep)(500);
|
|
94
93
|
const startCmd = `adb -s ${this.sn} shell am start ${appPackageName}`;
|
|
95
94
|
await adbMiwt.execAdbCmdAsync(startCmd);
|
|
96
|
-
|
|
95
|
+
this.logger(`Start ${this.vvdName} ${appPackageName} successfully`);
|
|
97
96
|
} catch (e) {
|
|
98
|
-
|
|
97
|
+
this.logger(`${e}`);
|
|
99
98
|
}
|
|
100
99
|
}
|
|
101
100
|
}
|
package/lib/instance/pre.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _dev = _interopRequireDefault(require("./dev"));
|
|
8
|
-
var _ColorConsole = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
9
8
|
var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
|
|
10
9
|
var _Vvd = require("../typing/Vvd");
|
|
11
10
|
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); }
|
|
@@ -22,10 +21,10 @@ class PreInstance extends _dev.default {
|
|
|
22
21
|
rpkPath = rpkPath || `${this.appDir}/${appPackageName}.rpk`;
|
|
23
22
|
const targetPath = `${this.appDir}/${appPackageName}`;
|
|
24
23
|
const mkdirCmd = `adb -s ${this.sn} shell mkdir ${targetPath}`;
|
|
25
|
-
|
|
24
|
+
this.logger(`Excuting: ${mkdirCmd}`);
|
|
26
25
|
await adbMiwt.execAdbCmdAsync(mkdirCmd);
|
|
27
26
|
const unzipCmd = `adb -s ${this.sn} shell unzip -o ${rpkPath} -d ${targetPath}`;
|
|
28
|
-
|
|
27
|
+
this.logger(`Excuting: ${unzipCmd}`);
|
|
29
28
|
await adbMiwt.execAdbCmdAsync(unzipCmd);
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -41,13 +40,13 @@ class PreInstance extends _dev.default {
|
|
|
41
40
|
if (debug) {
|
|
42
41
|
vappCmd = `adb -s ${this.sn} shell vapp --jsdebugger=10.0.2.15:101 app/${packageName} &`;
|
|
43
42
|
}
|
|
44
|
-
|
|
43
|
+
this.logger(`Excuting: ${vappCmd}`);
|
|
45
44
|
adbMiwt.execAdbCmd(vappCmd, {
|
|
46
45
|
stdio: 'ignore',
|
|
47
46
|
encoding: 'utf-8'
|
|
48
47
|
});
|
|
49
48
|
} catch (e) {
|
|
50
|
-
|
|
49
|
+
this.logger(`Failed to startup app for ${this.vvdName}: ${e.message}`);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
async closeApp(_appName) {
|
package/lib/instance/pre5.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.VelaPre5Instance = void 0;
|
|
7
|
-
var _ColorConsole = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
8
7
|
var _Vvd = require("../typing/Vvd");
|
|
9
8
|
var _miwear = _interopRequireDefault(require("./miwear"));
|
|
10
9
|
var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
|
|
@@ -22,10 +21,10 @@ class VelaPre5Instance extends _miwear.default {
|
|
|
22
21
|
*/
|
|
23
22
|
async install(targeRpk) {
|
|
24
23
|
const installCmd = `adb -s ${this.sn} shell pm install ${targeRpk}`;
|
|
25
|
-
|
|
24
|
+
this.logger(`Excuting: ${installCmd}`);
|
|
26
25
|
const res = await adbMiwt.execAdbCmdAsync(installCmd);
|
|
27
26
|
await (0, _util.promisify)(process.nextTick)();
|
|
28
|
-
|
|
27
|
+
this.logger(`Install result: ${res}`);
|
|
29
28
|
// vela 5 安装成功的日志为:
|
|
30
29
|
// onInstallResult: com.application.watch.demo(success 0)
|
|
31
30
|
if (res.includes('(success 0)')) {
|
package/lib/typing/Instance.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface IEmulatorInstanceParams extends Partial<EmulatorReadlines> {
|
|
|
13
13
|
onErrout?: (msg: string) => void;
|
|
14
14
|
/** 模拟器日志输出进程 */
|
|
15
15
|
logcatProcess?: ChildProcessWithoutNullStreams;
|
|
16
|
+
customLogger?: (log: string) => void;
|
|
16
17
|
}
|
|
17
18
|
export interface IStartOptions {
|
|
18
19
|
vvdName: string;
|
|
@@ -29,6 +30,7 @@ export interface IStartOptions {
|
|
|
29
30
|
stdoutCallback?: (buffer: string) => void;
|
|
30
31
|
stderrCallback?: (buffer: string) => void;
|
|
31
32
|
exitCallback?: (code: number | null) => void;
|
|
33
|
+
customLogger?: (log: string) => void;
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
36
|
* 如果指定了 serialPort 则必须同时指定 grpcPort
|
package/lib/typing/Vvd.d.ts
CHANGED
package/lib/typing/Vvd.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.VelaImageType = exports.VELAHOME = exports.
|
|
6
|
+
exports.VelaImageType = exports.VELAHOME = exports.SDKParts = exports.IVvdArchType = void 0;
|
|
7
7
|
let IVvdArchType = exports.IVvdArchType = /*#__PURE__*/function (IVvdArchType) {
|
|
8
8
|
IVvdArchType["arm"] = "arm";
|
|
9
9
|
IVvdArchType["arm64"] = "arm64";
|
|
@@ -16,13 +16,13 @@ let VelaImageType = exports.VelaImageType = /*#__PURE__*/function (VelaImageType
|
|
|
16
16
|
VelaImageType["DEV"] = "vela-dev-0.0.4";
|
|
17
17
|
return VelaImageType;
|
|
18
18
|
}({});
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return
|
|
19
|
+
let SDKParts = exports.SDKParts = /*#__PURE__*/function (SDKParts) {
|
|
20
|
+
SDKParts["EMULATOR"] = "emulator";
|
|
21
|
+
SDKParts["QA"] = "qa";
|
|
22
|
+
SDKParts["SKINS"] = "skins";
|
|
23
|
+
SDKParts["SYSTEM_IMAGES"] = "system-images";
|
|
24
|
+
SDKParts["MODEM_SIMULATOR"] = "modem_simulator";
|
|
25
|
+
return SDKParts;
|
|
26
26
|
}({});
|
|
27
27
|
let VELAHOME = exports.VELAHOME = /*#__PURE__*/function (VELAHOME) {
|
|
28
28
|
VELAHOME["SDK"] = ".export";
|
package/lib/vvd/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IVvdParams, IVvdResourcePaths,
|
|
1
|
+
import { IVvdParams, IVvdResourcePaths, SDKParts, SDKDownloadOpt, SkinInfo, VelaImageType } from '../typing/Vvd';
|
|
2
2
|
import { IStartOptions, IStartWithSerialPort } from '../typing/Instance';
|
|
3
3
|
import { findInstance } from '../instance';
|
|
4
4
|
import type { DownloadFileOptions } from 'ipull';
|
|
@@ -23,7 +23,7 @@ export declare class VvdManager {
|
|
|
23
23
|
/** 获取已经创建的模拟器列表 */
|
|
24
24
|
getVvdList(): IVvdParams[];
|
|
25
25
|
/** 获取 SDK 子目录 */
|
|
26
|
-
|
|
26
|
+
getSDKPart(name: SDKParts): string;
|
|
27
27
|
getSkinInfo(skinName: string, skinPath: string): {
|
|
28
28
|
name: string;
|
|
29
29
|
path: string;
|
|
@@ -58,7 +58,7 @@ export declare class VvdManager {
|
|
|
58
58
|
getLocalImageBuildTime(imagePath: string): Promise<Date | undefined>;
|
|
59
59
|
getSDKVersionPath(): string;
|
|
60
60
|
/** 获取本地 SDK 的版本信息 */
|
|
61
|
-
getSDKVersion(): Promise<Record<
|
|
61
|
+
getSDKVersion(): Promise<Record<SDKParts, string>>;
|
|
62
62
|
/** 获取本地已经下载的镜像 */
|
|
63
63
|
getLocalSystemImage(): Promise<{
|
|
64
64
|
value: string;
|
|
@@ -68,9 +68,9 @@ export declare class VvdManager {
|
|
|
68
68
|
hasLocaleImage(imageId: VelaImageType): boolean;
|
|
69
69
|
/** 判断本地的某个 vela 镜像是否需要更新 */
|
|
70
70
|
isLocalImageNeedUpdate(imageId: VelaImageType): Promise<boolean>;
|
|
71
|
-
getNotInstalledSDKPart(): Promise<
|
|
71
|
+
getNotInstalledSDKPart(): Promise<SDKParts[]>;
|
|
72
72
|
/** 检查 SDK 有哪些部分需要更新 */
|
|
73
|
-
|
|
73
|
+
hasSDKPartUpdate(): Promise<SDKParts[]>;
|
|
74
74
|
/**
|
|
75
75
|
* 下载 SDK,默认只下载需要更新的部分
|
|
76
76
|
* @param opt.force 强制下载所有部分
|
package/lib/vvd/index.js
CHANGED
|
@@ -24,6 +24,7 @@ var _admZip = _interopRequireDefault(require("adm-zip"));
|
|
|
24
24
|
var _instance = require("../instance");
|
|
25
25
|
var _logcat = require("./logcat");
|
|
26
26
|
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
27
|
+
var _ILog = require("@aiot-toolkit/shared-utils/lib/interface/ILog");
|
|
27
28
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
28
29
|
// TODO: 升级构建工具支持 esm @xujunjie
|
|
29
30
|
const getPort = (async () => {
|
|
@@ -125,7 +126,7 @@ class VvdManager {
|
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
// 拷贝 MODEM_SIMULATOR
|
|
128
|
-
const modemPath = this.
|
|
129
|
+
const modemPath = this.getSDKPart(_Vvd.SDKParts.MODEM_SIMULATOR);
|
|
129
130
|
if (_fs.default.existsSync(modemPath)) {
|
|
130
131
|
_sharedUtils.FileUtil.copyFiles(modemPath, _path.default.join(vvdDir, 'modem_simulator'));
|
|
131
132
|
}
|
|
@@ -148,6 +149,7 @@ class VvdManager {
|
|
|
148
149
|
const vvdInfo = {
|
|
149
150
|
name: vvdName,
|
|
150
151
|
arch: _Vvd.IVvdArchType.arm,
|
|
152
|
+
shape: '',
|
|
151
153
|
height: '',
|
|
152
154
|
width: '',
|
|
153
155
|
skin: '',
|
|
@@ -163,6 +165,7 @@ class VvdManager {
|
|
|
163
165
|
vvdInfo.arch = config['hw.cpu.arch'];
|
|
164
166
|
vvdInfo.height = config['hw.lcd.height'];
|
|
165
167
|
vvdInfo.width = config['hw.lcd.width'];
|
|
168
|
+
vvdInfo.shape = config['hw.lcd.shape'];
|
|
166
169
|
vvdInfo.skin = config['skin.name'];
|
|
167
170
|
vvdInfo.imageDir = config['image.sysdir.2'];
|
|
168
171
|
vvdInfo.customImagePath = config['image.sysdir.1'];
|
|
@@ -217,7 +220,7 @@ class VvdManager {
|
|
|
217
220
|
}
|
|
218
221
|
|
|
219
222
|
/** 获取 SDK 子目录 */
|
|
220
|
-
|
|
223
|
+
getSDKPart(name) {
|
|
221
224
|
return _path.default.resolve(this.sdkHome, name);
|
|
222
225
|
}
|
|
223
226
|
getSkinInfo(skinName, skinPath) {
|
|
@@ -248,7 +251,7 @@ class VvdManager {
|
|
|
248
251
|
async getVelaSkinList() {
|
|
249
252
|
try {
|
|
250
253
|
const skinList = [];
|
|
251
|
-
const skinHome = this.
|
|
254
|
+
const skinHome = this.getSDKPart(_Vvd.SDKParts.SKINS);
|
|
252
255
|
const builinDir = _path.default.join(skinHome, 'builtin');
|
|
253
256
|
const userDir = _path.default.join(skinHome, 'user');
|
|
254
257
|
const builtinFiles = await _fs.default.promises.readdir(builinDir).catch(() => []);
|
|
@@ -364,13 +367,25 @@ class VvdManager {
|
|
|
364
367
|
}
|
|
365
368
|
|
|
366
369
|
// 拷贝 MODEM_SIMULATOR
|
|
367
|
-
const modemPath = this.
|
|
370
|
+
const modemPath = this.getSDKPart(_Vvd.SDKParts.MODEM_SIMULATOR);
|
|
368
371
|
if (_fs.default.existsSync(modemPath) && !_fs.default.existsSync(_path.default.join(vvdDir, 'modem_simulator', 'modem_nvram.json'))) {
|
|
369
372
|
_sharedUtils.FileUtil.copyFiles(modemPath, _path.default.join(vvdDir, 'modem_simulator'));
|
|
370
373
|
}
|
|
371
374
|
return cmd;
|
|
372
375
|
}
|
|
373
376
|
async startVvd(options) {
|
|
377
|
+
let logger;
|
|
378
|
+
if (options.customLogger) {
|
|
379
|
+
logger = msg => {
|
|
380
|
+
const prefix = _ColorConsole.default.createDefaultPrefix({
|
|
381
|
+
level: _ILog.Loglevel.INFO,
|
|
382
|
+
message: msg
|
|
383
|
+
});
|
|
384
|
+
options.customLogger(`${prefix[1]} ${msg?.trim()}`);
|
|
385
|
+
};
|
|
386
|
+
} else {
|
|
387
|
+
logger = _ColorConsole.default.info;
|
|
388
|
+
}
|
|
374
389
|
const runningVvds = await (0, _emulatorutil.getRunningVvds)();
|
|
375
390
|
const vvdName = options.vvdName;
|
|
376
391
|
const onStdout = options.stdoutCallback || console.log;
|
|
@@ -388,7 +403,8 @@ class VvdManager {
|
|
|
388
403
|
vvdName: vvdName,
|
|
389
404
|
onStdout,
|
|
390
405
|
onErrout,
|
|
391
|
-
debugPort
|
|
406
|
+
debugPort,
|
|
407
|
+
customLogger: options.customLogger
|
|
392
408
|
});
|
|
393
409
|
return {
|
|
394
410
|
coldBoot: false,
|
|
@@ -400,8 +416,9 @@ class VvdManager {
|
|
|
400
416
|
const cmd = await this.getVvdStartCmd(options);
|
|
401
417
|
const spawnArgs = cmd.split(' ');
|
|
402
418
|
const spawnBin = spawnArgs.shift();
|
|
403
|
-
|
|
404
|
-
const
|
|
419
|
+
logger(`Start CMD: ${cmd}`);
|
|
420
|
+
const InstanceCalss = (0, _instance.getInstanceClass)(vvdInfo.imageType);
|
|
421
|
+
const func = InstanceCalss.isEmulatorStarted.bind(InstanceCalss);
|
|
405
422
|
return new Promise((resolve, reject) => {
|
|
406
423
|
const emulatorProcess = (0, _child_process.spawn)(spawnBin, spawnArgs, {
|
|
407
424
|
stdio: 'pipe',
|
|
@@ -425,9 +442,10 @@ class VvdManager {
|
|
|
425
442
|
...readlines,
|
|
426
443
|
onStdout,
|
|
427
444
|
onErrout,
|
|
428
|
-
debugPort: options.debugPort
|
|
445
|
+
debugPort: options.debugPort,
|
|
446
|
+
customLogger: options.customLogger
|
|
429
447
|
});
|
|
430
|
-
|
|
448
|
+
logger(`${options.vvdName} started successfully`);
|
|
431
449
|
resolve({
|
|
432
450
|
coldBoot: true,
|
|
433
451
|
emulatorInstance
|
|
@@ -441,7 +459,7 @@ class VvdManager {
|
|
|
441
459
|
|
|
442
460
|
// 监听模拟器的退出事件
|
|
443
461
|
emulatorProcess.on('exit', code => {
|
|
444
|
-
|
|
462
|
+
logger(`${options.vvdName} emulator exited with code ${code}`);
|
|
445
463
|
if (options.exitCallback) {
|
|
446
464
|
options.exitCallback(code);
|
|
447
465
|
}
|
|
@@ -517,7 +535,7 @@ class VvdManager {
|
|
|
517
535
|
|
|
518
536
|
/** 获取本地已经下载的镜像 */
|
|
519
537
|
async getLocalSystemImage() {
|
|
520
|
-
const home = this.
|
|
538
|
+
const home = this.getSDKPart(_Vvd.SDKParts.SYSTEM_IMAGES);
|
|
521
539
|
const res = [];
|
|
522
540
|
if (_fs.default.existsSync(home)) {
|
|
523
541
|
const files = _fs.default.readdirSync(home);
|
|
@@ -535,7 +553,7 @@ class VvdManager {
|
|
|
535
553
|
return res;
|
|
536
554
|
}
|
|
537
555
|
getLocalSystemPath(imageId) {
|
|
538
|
-
const home = this.
|
|
556
|
+
const home = this.getSDKPart(_Vvd.SDKParts.SYSTEM_IMAGES);
|
|
539
557
|
return _path.default.resolve(home, imageId, 'nuttx');
|
|
540
558
|
}
|
|
541
559
|
hasLocaleImage(imageId) {
|
|
@@ -553,8 +571,7 @@ class VvdManager {
|
|
|
553
571
|
return false;
|
|
554
572
|
}
|
|
555
573
|
async getNotInstalledSDKPart() {
|
|
556
|
-
const allResouce = Object.values(_Vvd.
|
|
557
|
-
const res = [];
|
|
574
|
+
const allResouce = Object.values(_Vvd.SDKParts);
|
|
558
575
|
try {
|
|
559
576
|
const res = [];
|
|
560
577
|
for (const resouces of allResouce) {
|
|
@@ -572,8 +589,8 @@ class VvdManager {
|
|
|
572
589
|
}
|
|
573
590
|
|
|
574
591
|
/** 检查 SDK 有哪些部分需要更新 */
|
|
575
|
-
async
|
|
576
|
-
const allResouce = Object.values(_Vvd.
|
|
592
|
+
async hasSDKPartUpdate() {
|
|
593
|
+
const allResouce = Object.values(_Vvd.SDKParts);
|
|
577
594
|
try {
|
|
578
595
|
const res = [];
|
|
579
596
|
const localVersion = await this.getSDKVersion();
|
|
@@ -583,7 +600,7 @@ class VvdManager {
|
|
|
583
600
|
res.push(resouces);
|
|
584
601
|
continue;
|
|
585
602
|
}
|
|
586
|
-
if (resouces === _Vvd.
|
|
603
|
+
if (resouces === _Vvd.SDKParts.SYSTEM_IMAGES) {
|
|
587
604
|
if (await this.isLocalImageNeedUpdate((0, _constants.getDefaultImage)())) res.push(resouces);
|
|
588
605
|
continue;
|
|
589
606
|
}
|
|
@@ -625,10 +642,10 @@ class VvdManager {
|
|
|
625
642
|
* }
|
|
626
643
|
*/
|
|
627
644
|
async downloadSDK(opt) {
|
|
628
|
-
const updateList = opt.force ? Object.values(_Vvd.
|
|
645
|
+
const updateList = opt.force ? Object.values(_Vvd.SDKParts) : await this.hasSDKPartUpdate();
|
|
629
646
|
const urls = updateList.map(t => ({
|
|
630
647
|
name: t,
|
|
631
|
-
url: (0, _constants.
|
|
648
|
+
url: (0, _constants.getSDKPartDownloadUrl)(t)
|
|
632
649
|
}));
|
|
633
650
|
const downloads = urls.map(async u => {
|
|
634
651
|
const d = await (await ipull).downloadFile({
|
|
@@ -646,10 +663,11 @@ class VvdManager {
|
|
|
646
663
|
if (downloader.downloadStatues.some(status => status.downloadStatus !== 'Finished')) {
|
|
647
664
|
return;
|
|
648
665
|
}
|
|
666
|
+
_ColorConsole.default.warn('All file resources have been successfully downloaded and are being decompressed.');
|
|
649
667
|
for (const u of urls) {
|
|
650
668
|
// 解压
|
|
651
669
|
const targetDirName = u.name;
|
|
652
|
-
const targetDir = u.name === _Vvd.
|
|
670
|
+
const targetDir = u.name === _Vvd.SDKParts.SYSTEM_IMAGES ? _path.default.resolve(this.sdkHome, targetDirName, _path.default.basename(u.url).replace('.zip', '')) : _path.default.resolve(this.sdkHome, targetDirName);
|
|
653
671
|
const targetDirExist = _fs.default.existsSync(targetDir);
|
|
654
672
|
if (!targetDirExist) await _fs.default.promises.mkdir(targetDir, {
|
|
655
673
|
recursive: true
|
|
@@ -675,7 +693,7 @@ class VvdManager {
|
|
|
675
693
|
const u = downloadUrls[imageId];
|
|
676
694
|
const downloader = await (await ipull).downloadFile({
|
|
677
695
|
url: u,
|
|
678
|
-
directory: this.
|
|
696
|
+
directory: this.getSDKPart(_Vvd.SDKParts.SYSTEM_IMAGES),
|
|
679
697
|
skipExisting: false,
|
|
680
698
|
...opt
|
|
681
699
|
});
|
|
@@ -683,9 +701,9 @@ class VvdManager {
|
|
|
683
701
|
const p2 = p.then(async () => {
|
|
684
702
|
//如果下载被取消或者出错,就不再执行后续操作
|
|
685
703
|
if (downloader.status.downloadStatus !== 'Finished') return;
|
|
686
|
-
const zipFile = _path.default.resolve(this.sdkHome, _Vvd.
|
|
704
|
+
const zipFile = _path.default.resolve(this.sdkHome, _Vvd.SDKParts.SYSTEM_IMAGES, _path.default.basename(u));
|
|
687
705
|
const zip = new _admZip.default(zipFile);
|
|
688
|
-
zip.extractAllTo(_path.default.resolve(this.sdkHome, _Vvd.
|
|
706
|
+
zip.extractAllTo(_path.default.resolve(this.sdkHome, _Vvd.SDKParts.SYSTEM_IMAGES, imageId), true, true);
|
|
689
707
|
await _fs.default.promises.rm(zipFile, {
|
|
690
708
|
force: true
|
|
691
709
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/emulator",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4-beta.1",
|
|
4
4
|
"description": "vela emulator tool.",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"emulator"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@aiot-toolkit/shared-utils": "2.0.
|
|
39
|
+
"@aiot-toolkit/shared-utils": "2.0.4-beta.1",
|
|
40
40
|
"@miwt/adb": "^0.9.0",
|
|
41
41
|
"adm-zip": "^0.5.16",
|
|
42
42
|
"dayjs": "^1.11.12",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"@types/adm-zip": "^0.5.5",
|
|
52
52
|
"@types/ini": "^4.1.1"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "85c4287c7b9468c83d468cfc39b147f4975f8285"
|
|
55
55
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
declare class EmulatorLog {
|
|
2
|
-
static emulatorStartedFlag: RegExp;
|
|
3
|
-
static installFlag: RegExp;
|
|
4
|
-
static devStartFlag: string;
|
|
5
|
-
static preDevStartFlag: RegExp;
|
|
6
|
-
static inStallIsFinshe(msg: string): RegExpMatchArray | null;
|
|
7
|
-
static rpkIsStart(msg: string): RegExpMatchArray | null;
|
|
8
|
-
static devIsStart(msg: string): boolean;
|
|
9
|
-
static preDevIsStart(msg: string): RegExpMatchArray | null;
|
|
10
|
-
}
|
|
11
|
-
export default EmulatorLog;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
class EmulatorLog {
|
|
8
|
-
static emulatorStartedFlag = /quickapp_rpk_installer_init|rpk installer init done/;
|
|
9
|
-
static installFlag = /InstallState_Finished|install finished/;
|
|
10
|
-
static devStartFlag = '(NSH)';
|
|
11
|
-
static preDevStartFlag = /Server started, listening on: 127.0.0.1:(\d+)/;
|
|
12
|
-
static inStallIsFinshe(msg) {
|
|
13
|
-
return msg.match(EmulatorLog.installFlag);
|
|
14
|
-
}
|
|
15
|
-
static rpkIsStart(msg) {
|
|
16
|
-
return msg.match(EmulatorLog.emulatorStartedFlag);
|
|
17
|
-
}
|
|
18
|
-
static devIsStart(msg) {
|
|
19
|
-
return msg.includes(EmulatorLog.devStartFlag);
|
|
20
|
-
}
|
|
21
|
-
static preDevIsStart(msg) {
|
|
22
|
-
return msg.match(EmulatorLog.preDevStartFlag);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
var _default = exports.default = EmulatorLog;
|