@aiot-toolkit/emulator 2.0.3-beta.8 → 2.0.3
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/running.js +1 -1
- package/lib/instance/common.d.ts +2 -1
- package/lib/instance/common.js +22 -10
- package/lib/instance/dev.js +5 -6
- package/lib/instance/miwear.js +9 -10
- 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 +39 -22
- package/package.json +3 -3
|
@@ -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
|
}
|
|
@@ -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
|
@@ -15,6 +15,7 @@ declare class CommonEmulatorInstance {
|
|
|
15
15
|
onStdout: (msg: string) => void;
|
|
16
16
|
onErrout: (msg: string) => void;
|
|
17
17
|
logcatProcess: ChildProcessWithoutNullStreams;
|
|
18
|
+
logger: (log: string) => void;
|
|
18
19
|
constructor(params: IEmulatorInstanceParams);
|
|
19
20
|
/** 推送指定文件 */
|
|
20
21
|
push(sourcePath: string, targetPath: string): Promise<string>;
|
|
@@ -26,7 +27,7 @@ declare class CommonEmulatorInstance {
|
|
|
26
27
|
*/
|
|
27
28
|
isConnected(): Promise<boolean>;
|
|
28
29
|
/** 安装应用,留给子类实现 */
|
|
29
|
-
install(rpkPath: string, packageName
|
|
30
|
+
install(rpkPath: string, packageName: string): Promise<void>;
|
|
30
31
|
/** 卸载应用,留给子类实现 */
|
|
31
32
|
uninstall(packageName: string): Promise<void>;
|
|
32
33
|
/** 启动应用,留给子类实现 */
|
package/lib/instance/common.js
CHANGED
|
@@ -5,6 +5,7 @@ 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 _ILog = require("@aiot-toolkit/shared-utils/lib/interface/ILog");
|
|
8
9
|
var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
|
|
9
10
|
var _utils = require("../utils");
|
|
10
11
|
var _logcat = require("../vvd/logcat");
|
|
@@ -21,6 +22,17 @@ class CommonEmulatorInstance {
|
|
|
21
22
|
this.onStdout = params.onStdout || console.log;
|
|
22
23
|
this.onErrout = params.onErrout || console.error;
|
|
23
24
|
this.debugPort = params.debugPort || (0, _emulatorutil.getRunningVvdDebugPort)(this.vvdName);
|
|
25
|
+
if (params.customLogger) {
|
|
26
|
+
this.logger = msg => {
|
|
27
|
+
const prefix = _ColorConsole.default.createDefaultPrefix({
|
|
28
|
+
level: _ILog.Loglevel.INFO,
|
|
29
|
+
message: msg
|
|
30
|
+
});
|
|
31
|
+
params.customLogger(`${prefix[1]} ${msg?.trim()}`);
|
|
32
|
+
};
|
|
33
|
+
} else {
|
|
34
|
+
this.logger = _ColorConsole.default.info;
|
|
35
|
+
}
|
|
24
36
|
if (params.logcatProcess) {
|
|
25
37
|
this.logcatProcess = params.logcatProcess;
|
|
26
38
|
if (!params.stdoutReadline || !params.stderrReadline) {
|
|
@@ -45,16 +57,16 @@ class CommonEmulatorInstance {
|
|
|
45
57
|
async push(sourcePath, targetPath) {
|
|
46
58
|
// 1. adb push应用的rpk
|
|
47
59
|
const pushCmd = `adb -s ${this.sn} push "${sourcePath}" ${targetPath}`;
|
|
48
|
-
|
|
60
|
+
this.logger(`Excuting: ${pushCmd}`);
|
|
49
61
|
const res = await adbMiwt.execAdbCmdAsync(pushCmd);
|
|
50
|
-
|
|
62
|
+
this.logger(`Push result: ${res}`);
|
|
51
63
|
return targetPath;
|
|
52
64
|
}
|
|
53
65
|
async unzip(zipPath, targetPath) {
|
|
54
66
|
const unzipCmd = `adb -s ${this.sn} shell unzip -o ${zipPath} -d ${targetPath}`;
|
|
55
|
-
|
|
67
|
+
this.logger(`Excuting: ${unzipCmd}`);
|
|
56
68
|
const res = await adbMiwt.execAdbCmdAsync(unzipCmd);
|
|
57
|
-
|
|
69
|
+
this.logger(`Unzip result: ${res}`);
|
|
58
70
|
}
|
|
59
71
|
|
|
60
72
|
/** 推送指定 rpk */
|
|
@@ -62,9 +74,9 @@ class CommonEmulatorInstance {
|
|
|
62
74
|
// 1. adb push应用的rpk
|
|
63
75
|
const targetPath = `${this.appDir}/${appPackageName}.rpk`;
|
|
64
76
|
const pushCmd = `adb -s ${this.sn} push "${rpkPath}" ${targetPath}`;
|
|
65
|
-
|
|
77
|
+
this.logger(`Excuting: ${pushCmd}`);
|
|
66
78
|
const res = await adbMiwt.execAdbCmdAsync(pushCmd);
|
|
67
|
-
|
|
79
|
+
this.logger(`Push ${this.vvdName} rpk result: ${res}`);
|
|
68
80
|
return targetPath;
|
|
69
81
|
}
|
|
70
82
|
|
|
@@ -74,7 +86,7 @@ class CommonEmulatorInstance {
|
|
|
74
86
|
async isConnected() {
|
|
75
87
|
return (0, _utils.tryRun)(async () => {
|
|
76
88
|
const devices = await adbMiwt.getAdbDevices();
|
|
77
|
-
_ColorConsole.default.log(
|
|
89
|
+
_ColorConsole.default.log(`adb devices: ${JSON.stringify(devices)}`);
|
|
78
90
|
const curDev = devices.find(t => t.sn === this.sn);
|
|
79
91
|
return curDev?.status === 'device';
|
|
80
92
|
}, 10, 500);
|
|
@@ -109,7 +121,7 @@ class CommonEmulatorInstance {
|
|
|
109
121
|
return new Promise((resolve, reject) => {
|
|
110
122
|
const t = setTimeout(() => {
|
|
111
123
|
(0, _utils.killProcessByCmd)(this.vvdName).then(resolve).catch(e => {
|
|
112
|
-
reject(`poweroff failed ${e}`);
|
|
124
|
+
reject(`poweroff ${this.vvdName} failed ${e}`);
|
|
113
125
|
});
|
|
114
126
|
}, timeout);
|
|
115
127
|
adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} shell poweroff`).then(() => {
|
|
@@ -120,7 +132,7 @@ class CommonEmulatorInstance {
|
|
|
120
132
|
clearTimeout(t);
|
|
121
133
|
resolve();
|
|
122
134
|
}).catch(e => {
|
|
123
|
-
reject(`poweroff failed ${e}`);
|
|
135
|
+
reject(`poweroff ${this.vvdName} failed ${e}`);
|
|
124
136
|
});
|
|
125
137
|
});
|
|
126
138
|
});
|
|
@@ -132,7 +144,7 @@ class CommonEmulatorInstance {
|
|
|
132
144
|
/** 重启模拟器 */
|
|
133
145
|
async reboot() {
|
|
134
146
|
const rebootCmd = `adb -s ${this.sn} shell reboot`;
|
|
135
|
-
_ColorConsole.default.log(
|
|
147
|
+
_ColorConsole.default.log(`Excuting: ${rebootCmd}`);
|
|
136
148
|
await adbMiwt.execAdbCmdAsync(rebootCmd);
|
|
137
149
|
await this.isConnected();
|
|
138
150
|
if (!this.logcatProcess.exitCode !== undefined) {
|
package/lib/instance/dev.js
CHANGED
|
@@ -4,13 +4,12 @@ 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
15
|
appDir = '/data/app';
|
|
@@ -20,10 +19,10 @@ class GoldfishInstance extends _common.default {
|
|
|
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/miwear.js
CHANGED
|
@@ -4,16 +4,15 @@ 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
11
|
var _emulatorutil = require("../emulatorutil");
|
|
13
12
|
var _Vvd = require("../typing/Vvd");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
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
15
|
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
16
|
/**
|
|
18
17
|
* MiwearInstance
|
|
19
18
|
* 针对 Vela正式版(4.0)的镜像
|
|
@@ -32,13 +31,13 @@ class MiwearInstance extends _common.default {
|
|
|
32
31
|
const func = msg => {
|
|
33
32
|
if (_emulatorutil.EmulatorLog.inStallIsFinshe(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,13 +55,13 @@ 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() {
|
|
@@ -76,7 +75,7 @@ class MiwearInstance extends _common.default {
|
|
|
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,7 +416,7 @@ class VvdManager {
|
|
|
400
416
|
const cmd = await this.getVvdStartCmd(options);
|
|
401
417
|
const spawnArgs = cmd.split(' ');
|
|
402
418
|
const spawnBin = spawnArgs.shift();
|
|
403
|
-
|
|
419
|
+
logger(`Start CMD: ${cmd}`);
|
|
404
420
|
const func = vvdInfo.imageType === _Vvd.VelaImageType.REL ? _emulatorutil.EmulatorLog.rpkIsStart : _emulatorutil.EmulatorLog.devIsStart;
|
|
405
421
|
return new Promise((resolve, reject) => {
|
|
406
422
|
const emulatorProcess = (0, _child_process.spawn)(spawnBin, spawnArgs, {
|
|
@@ -425,9 +441,10 @@ class VvdManager {
|
|
|
425
441
|
...readlines,
|
|
426
442
|
onStdout,
|
|
427
443
|
onErrout,
|
|
428
|
-
debugPort: options.debugPort
|
|
444
|
+
debugPort: options.debugPort,
|
|
445
|
+
customLogger: options.customLogger
|
|
429
446
|
});
|
|
430
|
-
|
|
447
|
+
logger(`${options.vvdName} started successfully`);
|
|
431
448
|
resolve({
|
|
432
449
|
coldBoot: true,
|
|
433
450
|
emulatorInstance
|
|
@@ -441,7 +458,7 @@ class VvdManager {
|
|
|
441
458
|
|
|
442
459
|
// 监听模拟器的退出事件
|
|
443
460
|
emulatorProcess.on('exit', code => {
|
|
444
|
-
|
|
461
|
+
logger(`${options.vvdName} emulator exited with code ${code}`);
|
|
445
462
|
if (options.exitCallback) {
|
|
446
463
|
options.exitCallback(code);
|
|
447
464
|
}
|
|
@@ -517,7 +534,7 @@ class VvdManager {
|
|
|
517
534
|
|
|
518
535
|
/** 获取本地已经下载的镜像 */
|
|
519
536
|
async getLocalSystemImage() {
|
|
520
|
-
const home = this.
|
|
537
|
+
const home = this.getSDKPart(_Vvd.SDKParts.SYSTEM_IMAGES);
|
|
521
538
|
const res = [];
|
|
522
539
|
if (_fs.default.existsSync(home)) {
|
|
523
540
|
const files = _fs.default.readdirSync(home);
|
|
@@ -535,7 +552,7 @@ class VvdManager {
|
|
|
535
552
|
return res;
|
|
536
553
|
}
|
|
537
554
|
getLocalSystemPath(imageId) {
|
|
538
|
-
const home = this.
|
|
555
|
+
const home = this.getSDKPart(_Vvd.SDKParts.SYSTEM_IMAGES);
|
|
539
556
|
return _path.default.resolve(home, imageId, 'nuttx');
|
|
540
557
|
}
|
|
541
558
|
hasLocaleImage(imageId) {
|
|
@@ -553,8 +570,7 @@ class VvdManager {
|
|
|
553
570
|
return false;
|
|
554
571
|
}
|
|
555
572
|
async getNotInstalledSDKPart() {
|
|
556
|
-
const allResouce = Object.values(_Vvd.
|
|
557
|
-
const res = [];
|
|
573
|
+
const allResouce = Object.values(_Vvd.SDKParts);
|
|
558
574
|
try {
|
|
559
575
|
const res = [];
|
|
560
576
|
for (const resouces of allResouce) {
|
|
@@ -572,8 +588,8 @@ class VvdManager {
|
|
|
572
588
|
}
|
|
573
589
|
|
|
574
590
|
/** 检查 SDK 有哪些部分需要更新 */
|
|
575
|
-
async
|
|
576
|
-
const allResouce = Object.values(_Vvd.
|
|
591
|
+
async hasSDKPartUpdate() {
|
|
592
|
+
const allResouce = Object.values(_Vvd.SDKParts);
|
|
577
593
|
try {
|
|
578
594
|
const res = [];
|
|
579
595
|
const localVersion = await this.getSDKVersion();
|
|
@@ -583,7 +599,7 @@ class VvdManager {
|
|
|
583
599
|
res.push(resouces);
|
|
584
600
|
continue;
|
|
585
601
|
}
|
|
586
|
-
if (resouces === _Vvd.
|
|
602
|
+
if (resouces === _Vvd.SDKParts.SYSTEM_IMAGES) {
|
|
587
603
|
if (await this.isLocalImageNeedUpdate((0, _constants.getDefaultImage)())) res.push(resouces);
|
|
588
604
|
continue;
|
|
589
605
|
}
|
|
@@ -625,10 +641,10 @@ class VvdManager {
|
|
|
625
641
|
* }
|
|
626
642
|
*/
|
|
627
643
|
async downloadSDK(opt) {
|
|
628
|
-
const updateList = opt.force ? Object.values(_Vvd.
|
|
644
|
+
const updateList = opt.force ? Object.values(_Vvd.SDKParts) : await this.hasSDKPartUpdate();
|
|
629
645
|
const urls = updateList.map(t => ({
|
|
630
646
|
name: t,
|
|
631
|
-
url: (0, _constants.
|
|
647
|
+
url: (0, _constants.getSDKPartDownloadUrl)(t)
|
|
632
648
|
}));
|
|
633
649
|
const downloads = urls.map(async u => {
|
|
634
650
|
const d = await (await ipull).downloadFile({
|
|
@@ -646,10 +662,11 @@ class VvdManager {
|
|
|
646
662
|
if (downloader.downloadStatues.some(status => status.downloadStatus !== 'Finished')) {
|
|
647
663
|
return;
|
|
648
664
|
}
|
|
665
|
+
_ColorConsole.default.warn('All file resources have been successfully downloaded and are being decompressed.');
|
|
649
666
|
for (const u of urls) {
|
|
650
667
|
// 解压
|
|
651
668
|
const targetDirName = u.name;
|
|
652
|
-
const targetDir = u.name === _Vvd.
|
|
669
|
+
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
670
|
const targetDirExist = _fs.default.existsSync(targetDir);
|
|
654
671
|
if (!targetDirExist) await _fs.default.promises.mkdir(targetDir, {
|
|
655
672
|
recursive: true
|
|
@@ -675,7 +692,7 @@ class VvdManager {
|
|
|
675
692
|
const u = downloadUrls[imageId];
|
|
676
693
|
const downloader = await (await ipull).downloadFile({
|
|
677
694
|
url: u,
|
|
678
|
-
directory: this.
|
|
695
|
+
directory: this.getSDKPart(_Vvd.SDKParts.SYSTEM_IMAGES),
|
|
679
696
|
skipExisting: false,
|
|
680
697
|
...opt
|
|
681
698
|
});
|
|
@@ -683,9 +700,9 @@ class VvdManager {
|
|
|
683
700
|
const p2 = p.then(async () => {
|
|
684
701
|
//如果下载被取消或者出错,就不再执行后续操作
|
|
685
702
|
if (downloader.status.downloadStatus !== 'Finished') return;
|
|
686
|
-
const zipFile = _path.default.resolve(this.sdkHome, _Vvd.
|
|
703
|
+
const zipFile = _path.default.resolve(this.sdkHome, _Vvd.SDKParts.SYSTEM_IMAGES, _path.default.basename(u));
|
|
687
704
|
const zip = new _admZip.default(zipFile);
|
|
688
|
-
zip.extractAllTo(_path.default.resolve(this.sdkHome, _Vvd.
|
|
705
|
+
zip.extractAllTo(_path.default.resolve(this.sdkHome, _Vvd.SDKParts.SYSTEM_IMAGES, imageId), true, true);
|
|
689
706
|
await _fs.default.promises.rm(zipFile, {
|
|
690
707
|
force: true
|
|
691
708
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/emulator",
|
|
3
|
-
"version": "2.0.3
|
|
3
|
+
"version": "2.0.3",
|
|
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.3
|
|
39
|
+
"@aiot-toolkit/shared-utils": "2.0.3",
|
|
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": "e29e61eb89c2559eb9f3a18c51fd5ce4c4196cc2"
|
|
55
55
|
}
|