@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/README.md
CHANGED
|
@@ -1,15 +1,140 @@
|
|
|
1
1
|
## emulator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Vela 模拟器 SDK
|
|
4
4
|
|
|
5
5
|
模拟器的介绍可参考[开发帮助文档](https://xiaomi.f.mioffice.cn/docx/doxk4Rk6x67GanHlzQ8bEOrxtEe)里的「模拟器」章节
|
|
6
6
|
|
|
7
7
|
## 目录结构
|
|
8
8
|
|
|
9
|
-
| 目录 | 描述
|
|
10
|
-
| -------- |
|
|
11
|
-
| avd
|
|
12
|
-
| instance | 模拟器实例,不同的Vela镜像版本会使用不同的instance,通过findInstance确定
|
|
13
|
-
| static | 创建AVD时需要用到的静态资源,常量配置文件
|
|
14
|
-
| typing
|
|
15
|
-
| utils
|
|
9
|
+
| 目录 | 描述 |
|
|
10
|
+
| -------- | ------------------------------------------------------------------------ |
|
|
11
|
+
| avd | 模拟器的AVD,配置统一放置$HOME/.vela/vvd 目录下 |
|
|
12
|
+
| instance | 模拟器实例,不同的Vela镜像版本会使用不同的instance,通过findInstance确定 |
|
|
13
|
+
| static | 创建AVD时需要用到的静态资源,常量配置文件 |
|
|
14
|
+
| typing | 接口定义 |
|
|
15
|
+
| utils | 工具函数 |
|
|
16
|
+
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @aiot/emulator
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 使用
|
|
24
|
+
|
|
25
|
+
### 创建 VVD
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import os from 'os'
|
|
29
|
+
import path from 'path'
|
|
30
|
+
import { IAvdArchType, VelaAvdCls, VelaImageType } from '@aiot/emulator'
|
|
31
|
+
|
|
32
|
+
const sdkHome = path.resolve(os.homedir(), '.export_dev')
|
|
33
|
+
const velaAvdCls = new VelaAvdCls({ sdkHome })
|
|
34
|
+
|
|
35
|
+
/** 创建一个 466 × 466 带 miwear 的模拟器 */
|
|
36
|
+
export async function createVVd() {
|
|
37
|
+
velaAvdCls.createVvd({
|
|
38
|
+
avdName: 'test',
|
|
39
|
+
avdArch: IAvdArchType.arm64,
|
|
40
|
+
avdHeight: '466',
|
|
41
|
+
avdWidth: '466',
|
|
42
|
+
imageType: VelaImageType.REL
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 启动 VVD
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import os from 'os'
|
|
51
|
+
import path from 'path'
|
|
52
|
+
import { IAvdArchType, VelaAvdCls, VelaImageType } from '../src'
|
|
53
|
+
|
|
54
|
+
const sdkHome = path.resolve(os.homedir(), '.export_dev')
|
|
55
|
+
const velaAvdCls = new VelaAvdCls({ sdkHome })
|
|
56
|
+
|
|
57
|
+
export async function startVvd(vvdName: string) {
|
|
58
|
+
velaAvdCls.startVvd({
|
|
59
|
+
avdName: vvdName
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 初始化环境
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import os from 'os'
|
|
68
|
+
import path from 'path'
|
|
69
|
+
import { VelaAvdCls } from '@aiot/emulator'
|
|
70
|
+
|
|
71
|
+
async function main() {
|
|
72
|
+
const sdkHome = path.resolve(os.homedir(), '.export_dev')
|
|
73
|
+
const velaAvdCls = new VelaAvdCls({ sdkHome })
|
|
74
|
+
|
|
75
|
+
const downloder = await velaAvdCls.downloadSDK({
|
|
76
|
+
force: true,
|
|
77
|
+
cliProgress: false,
|
|
78
|
+
parallelDownloads: 6
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
downloder.on('progress', (progress) => {
|
|
82
|
+
console.log(
|
|
83
|
+
`progress: ${progress.formattedSpeed} ${progress.formattedPercentage} ${progress.formatTotal} ${progress.formatTimeLeft}`
|
|
84
|
+
)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
await downloder.downlodPromise
|
|
88
|
+
|
|
89
|
+
console.log('download success')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
main()
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 完整示例
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
// 安装 npm install @aiot/emulator
|
|
99
|
+
import { IAvdArchType, VelaAvdCls, VelaImageType } from '@aiot/emulator'
|
|
100
|
+
|
|
101
|
+
const velaAvdCls = new VelaAvdCls({})
|
|
102
|
+
|
|
103
|
+
/** 创建一个 466 × 466 带 miwear 的模拟器 */
|
|
104
|
+
velaAvdCls.createVvd({
|
|
105
|
+
avdName: 'O62',
|
|
106
|
+
avdArch: IAvdArchType.arm64,
|
|
107
|
+
avdHeight: '466',
|
|
108
|
+
avdWidth: '466',
|
|
109
|
+
imageType: VelaImageType.REL
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
/** 启动名为 'O62' 的模拟器 */
|
|
113
|
+
velaAvdCls.startVvd({
|
|
114
|
+
avdName: 'O62'
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
export async function startVvd(vvdName: string) {}
|
|
118
|
+
|
|
119
|
+
export async function createVVd() {}
|
|
120
|
+
|
|
121
|
+
async function main() {
|
|
122
|
+
const downloder = await velaAvdCls.downloadSDK({
|
|
123
|
+
force: true,
|
|
124
|
+
cliProgress: false,
|
|
125
|
+
parallelDownloads: 6
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
downloder.on('progress', (progress) => {
|
|
129
|
+
console.log(
|
|
130
|
+
`progress: ${progress.formattedSpeed} ${progress.formattedPercentage} ${progress.formatTotal} ${progress.formatTimeLeft}`
|
|
131
|
+
)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
await downloder.downlodPromise
|
|
135
|
+
|
|
136
|
+
console.log('download success')
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
main()
|
|
140
|
+
```
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
3
7
|
class EmulatorLog {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
}
|
|
16
24
|
}
|
|
17
|
-
|
|
18
|
-
EmulatorLog.installFlag = /InstallState_Finished|install finished/;
|
|
19
|
-
EmulatorLog.devStartFlag = '(NSH)';
|
|
20
|
-
EmulatorLog.preDevStartFlag = /Server started, listening on: 127.0.0.1:(\d+)/;
|
|
21
|
-
exports.default = EmulatorLog;
|
|
25
|
+
var _default = exports.default = EmulatorLog;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { SDKChildren, VelaImageType } from '../typing/Vvd';
|
|
1
2
|
export declare const defaultSDKHome: string;
|
|
2
|
-
export declare const
|
|
3
|
+
export declare const defaultVvdHome: string;
|
|
3
4
|
export declare const defaultImageHome: string;
|
|
4
5
|
export declare const defaultEmulatorHome: string;
|
|
5
6
|
export declare const defaultSkinHome: string;
|
|
@@ -8,6 +9,10 @@ export declare const defaultToolsHome: string;
|
|
|
8
9
|
export declare const defaultVncPort = 5900;
|
|
9
10
|
export declare const defaultAdbPort = 5555;
|
|
10
11
|
export declare const defaultDebugPort = 10055;
|
|
12
|
+
export declare const baseUrl = "https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide";
|
|
13
|
+
export declare const versionUrl = "https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/versions.json";
|
|
14
|
+
export declare const emulatorBaseUrl = "https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/emulator";
|
|
15
|
+
export declare const systemImageBaseUrl = "https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/system-images";
|
|
11
16
|
/**
|
|
12
17
|
* vela-release-4.0 : vela 4.0 带 miwear
|
|
13
18
|
* vela-pre-4.0 : vela 4.0 不带 miwear
|
|
@@ -15,17 +20,25 @@ export declare const defaultDebugPort = 10055;
|
|
|
15
20
|
*/
|
|
16
21
|
export declare const VelaImageVersionList: {
|
|
17
22
|
label: string;
|
|
18
|
-
value:
|
|
23
|
+
value: VelaImageType;
|
|
19
24
|
time: string;
|
|
20
25
|
hide: boolean;
|
|
21
|
-
icon:
|
|
26
|
+
icon: string;
|
|
22
27
|
}[];
|
|
23
28
|
export declare const EmulatorEnvVersion: {
|
|
24
29
|
name: string;
|
|
25
30
|
emulator: string;
|
|
26
31
|
qa: string;
|
|
27
32
|
skins: string;
|
|
28
|
-
|
|
29
|
-
tools: string;
|
|
33
|
+
"system-images": string;
|
|
30
34
|
modem_simulator: string;
|
|
31
35
|
};
|
|
36
|
+
/** 获取镜像下载地址 */
|
|
37
|
+
export declare function getImageDownloadUrl(): Record<VelaImageType, string>;
|
|
38
|
+
/**
|
|
39
|
+
* 获取各种 SKD 最新版本的下载地址;
|
|
40
|
+
* 镜像地址默认返回 REL 版本的地址,如果需要获取其他版本,请使用
|
|
41
|
+
* {@link getImageDownloadUrl}
|
|
42
|
+
*/
|
|
43
|
+
export declare function getSDKChildDownloadUrl(type: SDKChildren): string;
|
|
44
|
+
export declare function getDefaultImage(): VelaImageType;
|
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
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
|
+
exports.getDefaultImage = getDefaultImage;
|
|
8
|
+
exports.getImageDownloadUrl = getImageDownloadUrl;
|
|
9
|
+
exports.getSDKChildDownloadUrl = getSDKChildDownloadUrl;
|
|
10
|
+
exports.versionUrl = exports.systemImageBaseUrl = void 0;
|
|
11
|
+
var _os = _interopRequireDefault(require("os"));
|
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
|
13
|
+
var _Vvd = require("../typing/Vvd");
|
|
14
|
+
var _utils = require("../utils");
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
const defaultSDKHome = exports.defaultSDKHome = _path.default.resolve(_os.default.homedir(), _Vvd.VELAHOME.SDK);
|
|
17
|
+
const defaultVvdHome = exports.defaultVvdHome = _path.default.resolve(_os.default.homedir(), _Vvd.VELAHOME.VVD);
|
|
18
|
+
const defaultImageHome = exports.defaultImageHome = _path.default.resolve(defaultSDKHome, 'system-images/arm');
|
|
19
|
+
const defaultEmulatorHome = exports.defaultEmulatorHome = _path.default.resolve(defaultSDKHome, 'emulator');
|
|
20
|
+
const defaultSkinHome = exports.defaultSkinHome = _path.default.resolve(defaultSDKHome, 'skins');
|
|
21
|
+
const defaultQuickappHome = exports.defaultQuickappHome = _path.default.resolve(defaultSDKHome, 'qa');
|
|
22
|
+
const defaultToolsHome = exports.defaultToolsHome = _path.default.resolve(defaultSDKHome, 'tools');
|
|
23
|
+
const defaultVncPort = exports.defaultVncPort = 5900;
|
|
24
|
+
const defaultAdbPort = exports.defaultAdbPort = 5555;
|
|
25
|
+
const defaultDebugPort = exports.defaultDebugPort = 10055;
|
|
26
|
+
const baseUrl = exports.baseUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide';
|
|
27
|
+
const versionUrl = exports.versionUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/versions.json';
|
|
28
|
+
const emulatorBaseUrl = exports.emulatorBaseUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/emulator';
|
|
29
|
+
const systemImageBaseUrl = exports.systemImageBaseUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/system-images';
|
|
30
|
+
|
|
19
31
|
// 不确定vela镜像的发布策略,暂时需要手动更新此列表
|
|
20
32
|
// 0.0.2和0.0.3版本比较特殊,线上是一个nuttx文件。其他版本都是一个zip包,包含nuttx data.img和vela_source.img
|
|
21
33
|
/**
|
|
@@ -23,41 +35,70 @@ exports.defaultDebugPort = 10055;
|
|
|
23
35
|
* vela-pre-4.0 : vela 4.0 不带 miwear
|
|
24
36
|
* vela-dev-0.0.4 : vela 4.0 dev 分支
|
|
25
37
|
*/
|
|
26
|
-
exports.VelaImageVersionList = [
|
|
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
|
-
icon: null
|
|
53
|
-
}
|
|
38
|
+
const VelaImageVersionList = exports.VelaImageVersionList = [{
|
|
39
|
+
label: 'vela-4.0-正式版',
|
|
40
|
+
value: _Vvd.VelaImageType.REL,
|
|
41
|
+
time: '20241105',
|
|
42
|
+
hide: false,
|
|
43
|
+
icon: ''
|
|
44
|
+
}, {
|
|
45
|
+
label: 'vela-4.0-测试版',
|
|
46
|
+
value: _Vvd.VelaImageType.PRE,
|
|
47
|
+
time: '20241105',
|
|
48
|
+
hide: false,
|
|
49
|
+
icon: ''
|
|
50
|
+
}, {
|
|
51
|
+
label: 'vela-5.0-测试版',
|
|
52
|
+
value: _Vvd.VelaImageType.VELA_PRE_5,
|
|
53
|
+
time: '20241107',
|
|
54
|
+
hide: true,
|
|
55
|
+
icon: ''
|
|
56
|
+
}
|
|
57
|
+
// {
|
|
58
|
+
// label: 'vela-dev-开发版',
|
|
59
|
+
// value: VelaImageType.DEV,
|
|
60
|
+
// time: '20240712',
|
|
61
|
+
// hide: true,
|
|
62
|
+
// icon: ''
|
|
63
|
+
// }
|
|
54
64
|
];
|
|
55
|
-
exports.EmulatorEnvVersion = {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
modem_simulator: '0.0.1'
|
|
65
|
+
const EmulatorEnvVersion = exports.EmulatorEnvVersion = {
|
|
66
|
+
name: '模拟器资源版本管理',
|
|
67
|
+
[_Vvd.SDKChildren.EMULATOR]: '0.0.9',
|
|
68
|
+
[_Vvd.SDKChildren.QA]: '0.0.1',
|
|
69
|
+
[_Vvd.SDKChildren.SKINS]: '0.0.7',
|
|
70
|
+
[_Vvd.SDKChildren.SYSTEM_IMAGES]: VelaImageVersionList[0].time,
|
|
71
|
+
[_Vvd.SDKChildren.MODEM_SIMULATOR]: '0.0.3'
|
|
63
72
|
};
|
|
73
|
+
|
|
74
|
+
/** 获取镜像下载地址 */
|
|
75
|
+
function getImageDownloadUrl() {
|
|
76
|
+
return VelaImageVersionList.reduce((res, t) => {
|
|
77
|
+
res[t.value] = `${systemImageBaseUrl}/${t.value}/${t.time}/${t.value}.zip`;
|
|
78
|
+
return res;
|
|
79
|
+
}, {});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 获取各种 SKD 最新版本的下载地址;
|
|
84
|
+
* 镜像地址默认返回 REL 版本的地址,如果需要获取其他版本,请使用
|
|
85
|
+
* {@link getImageDownloadUrl}
|
|
86
|
+
*/
|
|
87
|
+
function getSDKChildDownloadUrl(type) {
|
|
88
|
+
switch (type) {
|
|
89
|
+
case _Vvd.SDKChildren.EMULATOR:
|
|
90
|
+
const systemOs = _os.default.platform();
|
|
91
|
+
const hostArch = (0, _utils.getSystemArch)();
|
|
92
|
+
let hostOs = systemOs === 'win32' ? 'windows' : systemOs;
|
|
93
|
+
return `${emulatorBaseUrl}/v${EmulatorEnvVersion.emulator}/${hostOs}-${hostArch}.zip`;
|
|
94
|
+
case _Vvd.SDKChildren.SYSTEM_IMAGES:
|
|
95
|
+
return getImageDownloadUrl()[_Vvd.VelaImageType.REL];
|
|
96
|
+
case _Vvd.SDKChildren.QA:
|
|
97
|
+
case _Vvd.SDKChildren.MODEM_SIMULATOR:
|
|
98
|
+
case _Vvd.SDKChildren.SKINS:
|
|
99
|
+
return `${baseUrl}/${type}/v${EmulatorEnvVersion[type]}/${type}.zip`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function getDefaultImage() {
|
|
103
|
+
return _Vvd.VelaImageType.REL;
|
|
104
|
+
}
|
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
EmulatorLog: true
|
|
4
8
|
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
Object.defineProperty(exports, "EmulatorLog", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _EmulatorLog.default;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
var _EmulatorLog = _interopRequireDefault(require("./EmulatorLog"));
|
|
16
|
+
var _running = require("./running");
|
|
17
|
+
Object.keys(_running).forEach(function (key) {
|
|
18
|
+
if (key === "default" || key === "__esModule") return;
|
|
19
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
20
|
+
if (key in exports && exports[key] === _running[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _running[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _constants = require("./constants");
|
|
29
|
+
Object.keys(_constants).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
32
|
+
if (key in exports && exports[key] === _constants[key]) return;
|
|
33
|
+
Object.defineProperty(exports, key, {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () {
|
|
36
|
+
return _constants[key];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const defaultDirRelativePath = "avd/running";
|
|
2
|
+
export declare const fileNamePattern: RegExp;
|
|
3
|
+
export declare function getPlatform(): "darwin" | "linux" | "win32";
|
|
4
|
+
/**
|
|
5
|
+
* @returns 获取模拟器配置文件目录
|
|
6
|
+
*/
|
|
7
|
+
export declare function getEmulatorDefaultConfigDir(): string;
|
|
8
|
+
export declare function getRunningAvdConfigFiles(): string[];
|
|
9
|
+
export interface EmulatorConfig {
|
|
10
|
+
path: string;
|
|
11
|
+
'port.serial': string;
|
|
12
|
+
'port.adb': string;
|
|
13
|
+
'avd.name': string;
|
|
14
|
+
'avd.dir': string;
|
|
15
|
+
'avd.id': string;
|
|
16
|
+
cmdline: string;
|
|
17
|
+
'grpc.token': string;
|
|
18
|
+
'grpc.port': string;
|
|
19
|
+
[i: string]: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function getRunningAvdConfig(): EmulatorConfig[];
|
|
22
|
+
export declare function getRunningVvds(): Promise<EmulatorConfig[]>;
|
|
23
|
+
export declare function getRunningAvdConfigByName(name: string): EmulatorConfig | undefined;
|
|
24
|
+
export declare function getRunningVvdDebugPort(name: string): string | undefined;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fileNamePattern = exports.defaultDirRelativePath = void 0;
|
|
7
|
+
exports.getEmulatorDefaultConfigDir = getEmulatorDefaultConfigDir;
|
|
8
|
+
exports.getPlatform = getPlatform;
|
|
9
|
+
exports.getRunningAvdConfig = getRunningAvdConfig;
|
|
10
|
+
exports.getRunningAvdConfigByName = getRunningAvdConfigByName;
|
|
11
|
+
exports.getRunningAvdConfigFiles = getRunningAvdConfigFiles;
|
|
12
|
+
exports.getRunningVvdDebugPort = getRunningVvdDebugPort;
|
|
13
|
+
exports.getRunningVvds = getRunningVvds;
|
|
14
|
+
var _os = _interopRequireDefault(require("os"));
|
|
15
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
16
|
+
var _ini = _interopRequireDefault(require("ini"));
|
|
17
|
+
var _path = _interopRequireDefault(require("path"));
|
|
18
|
+
var _adb = require("@miwt/adb");
|
|
19
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
|
+
const defaultDirRelativePath = exports.defaultDirRelativePath = 'avd/running';
|
|
21
|
+
const fileNamePattern = exports.fileNamePattern = /pid_\d+\.ini/;
|
|
22
|
+
function getPlatform() {
|
|
23
|
+
const platform = _os.default.platform();
|
|
24
|
+
return platform === 'darwin' ? 'darwin' : platform === 'win32' ? 'win32' : 'linux';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns the Emulator registration directory.
|
|
29
|
+
*/
|
|
30
|
+
function computeRegistrationDirectoryContainer() {
|
|
31
|
+
const platform = getPlatform();
|
|
32
|
+
switch (platform) {
|
|
33
|
+
case 'darwin':
|
|
34
|
+
return resolvePath(_path.default.join(_os.default.homedir(), 'Library', 'Caches', 'TemporaryItems'));
|
|
35
|
+
case 'win32':
|
|
36
|
+
return resolvePath(_path.default.join(process.env.LOCALAPPDATA, 'Temp'));
|
|
37
|
+
default:
|
|
38
|
+
return resolveLinuxPath();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @returns 获取模拟器配置文件目录
|
|
44
|
+
*/
|
|
45
|
+
function getEmulatorDefaultConfigDir() {
|
|
46
|
+
const dir = computeRegistrationDirectoryContainer();
|
|
47
|
+
if (!dir) {
|
|
48
|
+
throw new Error('Unable to determine Emulator registration directory');
|
|
49
|
+
}
|
|
50
|
+
return _path.default.join(dir, defaultDirRelativePath);
|
|
51
|
+
}
|
|
52
|
+
function resolveLinuxPath() {
|
|
53
|
+
const linuxPatterns = [process.env.XDG_RUNTIME_DIR, `/run/user/${process.env.UID}`, _path.default.join(_os.default.homedir(), '.android')];
|
|
54
|
+
for (const pattern of linuxPatterns) {
|
|
55
|
+
if (!pattern) continue;
|
|
56
|
+
const dir = resolvePath(pattern);
|
|
57
|
+
if (dir && _fs.default.existsSync(dir) && _fs.default.lstatSync(dir).isDirectory()) {
|
|
58
|
+
return dir;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return resolvePath(_path.default.join(_os.default.tmpdir(), `android-${_os.default.userInfo().username}`));
|
|
62
|
+
}
|
|
63
|
+
function resolvePath(filePath) {
|
|
64
|
+
if (!filePath) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Replace environment variables in the filePath
|
|
69
|
+
filePath = filePath.replace(/{(\w+)}/g, (match, key) => {
|
|
70
|
+
return process.env[key] || match;
|
|
71
|
+
});
|
|
72
|
+
return _path.default.resolve(filePath);
|
|
73
|
+
}
|
|
74
|
+
function getRunningAvdConfigFiles() {
|
|
75
|
+
const dir = getEmulatorDefaultConfigDir();
|
|
76
|
+
try {
|
|
77
|
+
const files = _fs.default.readdirSync(dir);
|
|
78
|
+
return files.filter(t => fileNamePattern.test(t)).map(t => _path.default.join(dir, t));
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function getRunningAvdConfig() {
|
|
84
|
+
const file = getRunningAvdConfigFiles();
|
|
85
|
+
const result = [];
|
|
86
|
+
file.forEach(f => {
|
|
87
|
+
result.push({
|
|
88
|
+
..._ini.default.parse(_fs.default.readFileSync(f, 'utf-8')),
|
|
89
|
+
path: f
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
async function getRunningVvds() {
|
|
95
|
+
const config = getRunningAvdConfig();
|
|
96
|
+
// running 文件中的数据可能会因为上次模拟器未正常退出而残留,所以需要过滤一下
|
|
97
|
+
const adbDevices = await (0, _adb.getAdbDevices)();
|
|
98
|
+
return config.filter(c => adbDevices.some(e => e.sn === `emulator-${c['port.serial']}`));
|
|
99
|
+
}
|
|
100
|
+
function getRunningAvdConfigByName(name) {
|
|
101
|
+
const config = getRunningAvdConfig();
|
|
102
|
+
return config.find(t => t['avd.name'] === name);
|
|
103
|
+
}
|
|
104
|
+
function getRunningVvdDebugPort(name) {
|
|
105
|
+
const e = getRunningAvdConfigByName(name);
|
|
106
|
+
const regex = /hostfwd=tcp:(.*?):(\d+)-10\.0\.2\.15:101/;
|
|
107
|
+
return e?.cmdline?.match(regex)?.[2];
|
|
108
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare enum Status {
|
|
2
|
+
NAME = 1,
|
|
3
|
+
VALUE = 2,
|
|
4
|
+
COMMENT = 3
|
|
5
|
+
}
|
|
6
|
+
export type ParseResult = {
|
|
7
|
+
comments: string[];
|
|
8
|
+
values: Record<string, string | ParseResult>;
|
|
9
|
+
};
|
|
10
|
+
export declare class ConfigParser {
|
|
11
|
+
private static isEndChar;
|
|
12
|
+
parse(str: string): ParseResult;
|
|
13
|
+
toObject(target: ParseResult): any;
|
|
14
|
+
}
|