aiot-toolkit 1.0.20-importfile-dev.2 → 2.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -192
- package/lib/bin.d.ts +2 -0
- package/lib/bin.js +229 -0
- package/lib/bin.js.map +1 -0
- package/lib/builder/IBuilder.d.ts +22 -0
- package/lib/builder/IBuilder.js +4 -0
- package/lib/builder/IBuilder.js.map +1 -0
- package/lib/builder/UxBuilder.d.ts +26 -0
- package/lib/builder/UxBuilder.js +102 -0
- package/lib/builder/UxBuilder.js.map +1 -0
- package/lib/builder/XtsBuilder.d.ts +15 -0
- package/lib/builder/XtsBuilder.js +65 -0
- package/lib/builder/XtsBuilder.js.map +1 -0
- package/lib/interface/CommandInterface.d.ts +15 -0
- package/lib/interface/CommandInterface.js +4 -0
- package/lib/interface/CommandInterface.js.map +1 -0
- package/lib/interface/VelaEmulatorInterface.d.ts +8 -0
- package/lib/interface/VelaEmulatorInterface.js +4 -0
- package/lib/interface/VelaEmulatorInterface.js.map +1 -0
- package/lib/utils/AdbUtils.d.ts +14 -0
- package/lib/utils/AdbUtils.js +103 -0
- package/lib/utils/AdbUtils.js.map +1 -0
- package/lib/utils/DeviceUtil.d.ts +62 -0
- package/lib/utils/DeviceUtil.js +366 -0
- package/lib/utils/DeviceUtil.js.map +1 -0
- package/lib/utils/RequestUtils.d.ts +11 -0
- package/lib/utils/RequestUtils.js +90 -0
- package/lib/utils/RequestUtils.js.map +1 -0
- package/lib/utils/VelaAvdUtils.d.ts +39 -0
- package/lib/utils/VelaAvdUtils.js +308 -0
- package/lib/utils/VelaAvdUtils.js.map +1 -0
- package/lib/waiter.d.ts +3 -0
- package/lib/waiter.js +39 -0
- package/lib/waiter.js.map +1 -0
- package/package.json +33 -47
- package/CHANGELOG.md +0 -353
- package/bin/index.js +0 -495
- package/gen-webpack-conf/get-devtool.js +0 -51
- package/gen-webpack-conf/helpers.js +0 -143
- package/gen-webpack-conf/index.js +0 -436
- package/gen-webpack-conf/manifest-schema.js +0 -284
- package/gen-webpack-conf/validate.js +0 -284
- package/lib/commands/compile.js +0 -2
- package/lib/commands/debug.js +0 -2
- package/lib/commands/init.js +0 -2
- package/lib/commands/packages.js +0 -2
- package/lib/commands/preview.js +0 -2
- package/lib/commands/report.js +0 -2
- package/lib/commands/resign.js +0 -2
- package/lib/commands/update.js +0 -2
- package/lib/commands/utils.js +0 -2
- package/lib/index.js +0 -2
- package/lib/plugins/manifest-watch-plugin.js +0 -2
- package/lib/utils.js +0 -2
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
16
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
17
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
18
|
+
const fs_1 = __importDefault(require("fs"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const AdbUtils_1 = __importDefault(require("./AdbUtils"));
|
|
21
|
+
const RequestUtils_1 = __importDefault(require("./RequestUtils"));
|
|
22
|
+
/**
|
|
23
|
+
* DeviceUtil
|
|
24
|
+
*/
|
|
25
|
+
class DeviceUtil {
|
|
26
|
+
/**
|
|
27
|
+
* 获取连接上的所有设备数组,供IDE使用
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
static getAllConnectedDevices() {
|
|
31
|
+
try {
|
|
32
|
+
return AdbUtils_1.default.getAllConnectedDevices().then((deviceList) => {
|
|
33
|
+
if (deviceList.length > 0) {
|
|
34
|
+
ColorConsole_1.default.log({
|
|
35
|
+
message: `Devices connected via adb: ${deviceList.join(', ')}.`
|
|
36
|
+
});
|
|
37
|
+
return Promise.resolve(deviceList);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
ColorConsole_1.default.log({
|
|
41
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
42
|
+
message: `No device is currently connected, please check the following preparations in turn:\n 1. Whether the device is started;\n 2. Whether in the same LAN WI-FI;\n 3. Whether the device can be connected to the computer via USB;`,
|
|
43
|
+
isOnlyPrintError: true
|
|
44
|
+
});
|
|
45
|
+
process.exit();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
ColorConsole_1.default.log({
|
|
51
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
52
|
+
message: 'Error getting connection information of adb device',
|
|
53
|
+
isOnlyPrintError: true
|
|
54
|
+
});
|
|
55
|
+
process.exit();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 安装调试器、预览版
|
|
60
|
+
* @param options
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
static installDbgAndMkp(options) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
try {
|
|
66
|
+
const { ip = '' } = options;
|
|
67
|
+
let connectDeviceList = [ip];
|
|
68
|
+
// 1. 判断设备是否连接
|
|
69
|
+
yield this.connectDevice(ip);
|
|
70
|
+
// 2. 获取连接的设备
|
|
71
|
+
const deviceList = yield AdbUtils_1.default.getUSBConnectedDevices();
|
|
72
|
+
const finalDeviceList = deviceList.length > 0
|
|
73
|
+
? yield this.queryDevice(deviceList, 'Install Quickapp debugger or previewer ')
|
|
74
|
+
: [];
|
|
75
|
+
connectDeviceList = finalDeviceList ? [...finalDeviceList] : [];
|
|
76
|
+
// 若connectDeviceList为空,应该warn并结束程序
|
|
77
|
+
connectDeviceList.length <= 0 &&
|
|
78
|
+
ColorConsole_1.default.log({
|
|
79
|
+
message: 'No device requires debugger or previewer installation',
|
|
80
|
+
level: shared_utils_1.LOG_LEVEL.Warn
|
|
81
|
+
}) &&
|
|
82
|
+
process.exit();
|
|
83
|
+
// 3. 下载并获取调试器、预览器地址
|
|
84
|
+
const debuggerPath = yield this.downloadApk(options, true);
|
|
85
|
+
const previewPath = yield this.downloadApk(options, false);
|
|
86
|
+
// // 4. 安装调试器
|
|
87
|
+
yield this.installApk(connectDeviceList, debuggerPath);
|
|
88
|
+
yield this.installApk(connectDeviceList, previewPath);
|
|
89
|
+
return Promise.resolve('All devices successfully installed the Quickapp debugger and previewer');
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
return Promise.reject(new Error(`Failed to install debugger, error message:${error.message}`));
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 如果是TV等AIOT设备,需要通过IP连接
|
|
98
|
+
* 1. 若ip为空,则询问是否要连接新设备
|
|
99
|
+
* 2. 无需连接新设备,返回
|
|
100
|
+
* 3. 连接新设备,输入ip值(可输入多个ip,以逗号隔断)
|
|
101
|
+
* 4. 判断输入值,空则输出info并返回
|
|
102
|
+
* 5. 处理ip,输入每个ip设备的端口号,尝试连接,给出连接结果
|
|
103
|
+
* @param ip
|
|
104
|
+
*/
|
|
105
|
+
static connectDevice(ip) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
try {
|
|
108
|
+
if (!ip) {
|
|
109
|
+
const WIFI_TEXT = 'Yes, connect a new wifi device';
|
|
110
|
+
const connectType = yield (0, prompts_1.select)({
|
|
111
|
+
message: '(USB devices will automatically connect) Choose whether to connect to a new wifi device, and fill in its IP address later:',
|
|
112
|
+
choices: [{ value: WIFI_TEXT }, { value: 'Skip, keep connected device' }]
|
|
113
|
+
});
|
|
114
|
+
if (connectType === WIFI_TEXT) {
|
|
115
|
+
const deviceIp = yield (0, prompts_1.input)({
|
|
116
|
+
message: 'Please enter the IP address of the device under wifi(eg:192.168.1.1),make sure that the computer and the device are under the same wifi。If you need to enter multiple IPs, please separate them with ",":'
|
|
117
|
+
});
|
|
118
|
+
ip = deviceIp;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
return Promise.resolve();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (ip.length === 0) {
|
|
125
|
+
ColorConsole_1.default.log({
|
|
126
|
+
message: `Since no ip address is entered, the connected device will be connected`
|
|
127
|
+
});
|
|
128
|
+
return Promise.resolve();
|
|
129
|
+
}
|
|
130
|
+
const ips = ip.trim().split(',');
|
|
131
|
+
const invalidIps = ips.filter((ip) => !this.ipRegExp.test(ip));
|
|
132
|
+
if (invalidIps && invalidIps.length) {
|
|
133
|
+
invalidIps.map((ip) => {
|
|
134
|
+
ColorConsole_1.default.log({
|
|
135
|
+
message: `ip: ${ip} is invalid IP`,
|
|
136
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
137
|
+
isOnlyPrintError: true
|
|
138
|
+
});
|
|
139
|
+
process.exit();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
const newDeviceListPromiseArray = Array.from(ips, (ip) => __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
const devicePort = yield (0, prompts_1.input)({
|
|
145
|
+
message: `Please enter the port of the IP(${ip})`,
|
|
146
|
+
default: '5555'
|
|
147
|
+
});
|
|
148
|
+
return AdbUtils_1.default.connect(ip, devicePort)
|
|
149
|
+
.then(() => {
|
|
150
|
+
ColorConsole_1.default.log({
|
|
151
|
+
level: shared_utils_1.LOG_LEVEL.Success,
|
|
152
|
+
message: `wifi connection ip: The device with ip of "${ip}" succeeded`
|
|
153
|
+
});
|
|
154
|
+
return Promise.resolve();
|
|
155
|
+
})
|
|
156
|
+
.catch((err) => {
|
|
157
|
+
ColorConsole_1.default.log({
|
|
158
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
159
|
+
message: err,
|
|
160
|
+
isOnlyPrintError: true
|
|
161
|
+
});
|
|
162
|
+
process.exit();
|
|
163
|
+
});
|
|
164
|
+
}));
|
|
165
|
+
return Promise.all(newDeviceListPromiseArray)
|
|
166
|
+
.then(() => {
|
|
167
|
+
ColorConsole_1.default.log({
|
|
168
|
+
message: 'All new WIFI devices are connected'
|
|
169
|
+
});
|
|
170
|
+
return Promise.resolve();
|
|
171
|
+
})
|
|
172
|
+
.catch(() => {
|
|
173
|
+
// 在抛出错误前已经弹出错误日志了,故这里直接退出
|
|
174
|
+
process.exit();
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (_a) { }
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* 选择一个或者多个设备
|
|
183
|
+
* @param deviceList
|
|
184
|
+
* @param orderText
|
|
185
|
+
* @returns
|
|
186
|
+
*/
|
|
187
|
+
static queryDevice(deviceList, orderText = '') {
|
|
188
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
if (!deviceList || deviceList.length === 0) {
|
|
190
|
+
ColorConsole_1.default.log({
|
|
191
|
+
message: `No device is connected yet, please confirm and try again`,
|
|
192
|
+
level: shared_utils_1.LOG_LEVEL.Error
|
|
193
|
+
});
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const ALL_TEXT = 'All connected devices';
|
|
197
|
+
const deviceListObj = deviceList.map((device) => {
|
|
198
|
+
return {
|
|
199
|
+
value: device
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
// 可选一台或多台设备
|
|
203
|
+
const chooseDevices = yield (0, prompts_1.checkbox)({
|
|
204
|
+
message: `Please select the device that needs to execute command "${orderText}":`,
|
|
205
|
+
choices: [{ value: ALL_TEXT }, ...deviceListObj]
|
|
206
|
+
});
|
|
207
|
+
return chooseDevices[0] === ALL_TEXT ? deviceList : chooseDevices;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* 下载apk
|
|
212
|
+
* @param options
|
|
213
|
+
* @param isQuickAppDebugger
|
|
214
|
+
* @returns
|
|
215
|
+
*/
|
|
216
|
+
static downloadApk(options, isQuickAppDebugger) {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
const { apkVersion } = options;
|
|
219
|
+
let fileName = '';
|
|
220
|
+
let newVersion = apkVersion || 'v1100';
|
|
221
|
+
if (isQuickAppDebugger) {
|
|
222
|
+
fileName = `quickapp_debugger_${newVersion}.apk`;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
fileName = `quickapp_platform_preview_release_${newVersion}.apk`;
|
|
226
|
+
}
|
|
227
|
+
const url = `${this.quickapp_url}${fileName}`;
|
|
228
|
+
const apkPath = path_1.default.join(__dirname, './apk/', fileName);
|
|
229
|
+
if (fs_1.default.existsSync(apkPath)) {
|
|
230
|
+
// apk已下载
|
|
231
|
+
ColorConsole_1.default.log({
|
|
232
|
+
message: 'The installation package has been downloaded, now use the cache file to install'
|
|
233
|
+
});
|
|
234
|
+
return apkPath;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
try {
|
|
238
|
+
const result = yield RequestUtils_1.default.downloadFile(url, fileName);
|
|
239
|
+
// 打印出成功信息
|
|
240
|
+
ColorConsole_1.default.log({
|
|
241
|
+
message: `Success to download, ${result}`,
|
|
242
|
+
level: shared_utils_1.LOG_LEVEL.Success
|
|
243
|
+
});
|
|
244
|
+
return apkPath;
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
// 打印出错误
|
|
248
|
+
ColorConsole_1.default.log({
|
|
249
|
+
message: `Failed to download the installation package, ${error}`,
|
|
250
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
251
|
+
isOnlyPrintError: true
|
|
252
|
+
});
|
|
253
|
+
process.exit();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* 获取设备上的快应用框架(需要先安装调试器)
|
|
260
|
+
* 1. 请求获取平台信息
|
|
261
|
+
* 2. 若获取结果为空或者undefined,则等待3s再次请求
|
|
262
|
+
* 3. 若获取结果不为空,但属性availablePlatforms为空,则等待3s再次请求
|
|
263
|
+
* 4. 若请求次数超过3次,则结束请求
|
|
264
|
+
* 5. 否则打印获取结果
|
|
265
|
+
* @param options
|
|
266
|
+
*/
|
|
267
|
+
static getAvailablePlatform(options) {
|
|
268
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
+
try {
|
|
270
|
+
const { ip, port, sn: deviceSn } = options;
|
|
271
|
+
let client = { ip, port };
|
|
272
|
+
let countTime = 0;
|
|
273
|
+
let data;
|
|
274
|
+
const sleep = () => {
|
|
275
|
+
ColorConsole_1.default.log({
|
|
276
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
277
|
+
message: `Error when the device gets running platforms,request again after 3s delay`,
|
|
278
|
+
isOnlyPrintError: true
|
|
279
|
+
});
|
|
280
|
+
return new Promise((resolve) => setTimeout(resolve, 3000));
|
|
281
|
+
};
|
|
282
|
+
const requestPlatform = () => __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
do {
|
|
284
|
+
if (countTime > 0) {
|
|
285
|
+
// 等待3s
|
|
286
|
+
yield sleep();
|
|
287
|
+
}
|
|
288
|
+
data = yield RequestUtils_1.default.sendReq(client, '/availablePlatforms');
|
|
289
|
+
} while (++countTime < 3 && (!data || (data && !JSON.parse(data).availablePlatforms)));
|
|
290
|
+
if (data) {
|
|
291
|
+
const dataObj = JSON.parse(data);
|
|
292
|
+
if (!dataObj.availablePlatforms) {
|
|
293
|
+
// 请求结果不存在平台信息,报错,结束程序
|
|
294
|
+
ColorConsole_1.default.log({
|
|
295
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
296
|
+
message: `the request result no avaliable platform `
|
|
297
|
+
});
|
|
298
|
+
process.exit();
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
// 打印请求的平台信息
|
|
302
|
+
const availablePlatforms = dataObj.availablePlatforms;
|
|
303
|
+
ColorConsole_1.default.log({
|
|
304
|
+
message: `The Quickapp engine list of device "${deviceSn}" is:${availablePlatforms.join(',')}`
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
//请求失败,结束程序
|
|
310
|
+
ColorConsole_1.default.log({
|
|
311
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
312
|
+
message: `the device gets running platforms error`
|
|
313
|
+
});
|
|
314
|
+
process.exit();
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
// 先打开调试器,才能获取运行平台
|
|
318
|
+
yield AdbUtils_1.default.startDebugger(deviceSn);
|
|
319
|
+
yield requestPlatform();
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
ColorConsole_1.default.log({
|
|
323
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
324
|
+
message: `Error getting the list of Quickapp engines on the device, error message:${error.message}`
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* 给设备列表中的每个设备安装apk
|
|
331
|
+
* @param deviceList
|
|
332
|
+
* @param apkPath
|
|
333
|
+
* @returns
|
|
334
|
+
*/
|
|
335
|
+
static installApk(deviceList = [], apkPath) {
|
|
336
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
337
|
+
try {
|
|
338
|
+
const newDeviceListPromiseArray = Array.from(deviceList, (deviceSn) => {
|
|
339
|
+
return AdbUtils_1.default.installApk(deviceSn, apkPath);
|
|
340
|
+
});
|
|
341
|
+
const apkName = path_1.default.basename(apkPath);
|
|
342
|
+
return Promise.all(newDeviceListPromiseArray)
|
|
343
|
+
.then(() => {
|
|
344
|
+
ColorConsole_1.default.log({
|
|
345
|
+
level: shared_utils_1.LOG_LEVEL.Success,
|
|
346
|
+
message: `All devices installed ${apkName}`
|
|
347
|
+
});
|
|
348
|
+
})
|
|
349
|
+
.catch(() => {
|
|
350
|
+
ColorConsole_1.default.log({
|
|
351
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
352
|
+
message: `Installed ${apkName} failed`
|
|
353
|
+
});
|
|
354
|
+
process.exit();
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
catch (error) { }
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
DeviceUtil.ipRegExp = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
362
|
+
DeviceUtil.CLIENT_PORT = 39517;
|
|
363
|
+
DeviceUtil.quickapp_url = 'https://statres.quickapp.cn/quickapp/quickapptool/release/platform/';
|
|
364
|
+
exports.default = DeviceUtil;
|
|
365
|
+
|
|
366
|
+
//# sourceMappingURL=DeviceUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["utils/DeviceUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6DAAsD;AACtD,+FAAsE;AACtE,+CAA2D;AAC3D,4CAAmB;AACnB,gDAAuB;AAEvB,0DAAiC;AACjC,kEAAyC;AAEzC;;GAEG;AACH,MAAM,UAAU;IAKd;;;OAGG;IACH,MAAM,CAAC,sBAAsB;QAC3B,IAAI;YACF,OAAO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OAAe;;YAChE,IAAI;gBACF,MAAM,yBAAyB,GAAG,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE;oBACpE,OAAO,kBAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;gBAC/C,CAAC,CAAC,CAAA;gBACF,MAAM,OAAO,GAAG,cAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;gBACtC,OAAO,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;qBAC1C,IAAI,CAAC,GAAG,EAAE;oBACT,sBAAY,CAAC,GAAG,CAAC;wBACf,KAAK,EAAE,wBAAS,CAAC,OAAO;wBACxB,OAAO,EAAE,yBAAyB,OAAO,EAAE;qBAC5C,CAAC,CAAA;gBACJ,CAAC,CAAC;qBACD,KAAK,CAAC,GAAG,EAAE;oBACV,sBAAY,CAAC,GAAG,CAAC;wBACf,KAAK,EAAE,wBAAS,CAAC,KAAK;wBACtB,OAAO,EAAE,aAAa,OAAO,SAAS;qBACvC,CAAC,CAAA;oBACF,OAAO,CAAC,IAAI,EAAE,CAAA;gBAChB,CAAC,CAAC,CAAA;aACL;YAAC,OAAO,KAAK,EAAE,GAAE;QACpB,CAAC;KAAA;;AApUM,mBAAQ,GACb,6FAA6F,CAAA;AACxF,sBAAW,GAAG,KAAK,CAAA;AACnB,uBAAY,GAAG,qEAAqE,CAAA;AAmU7F,kBAAe,UAAU,CAAA","file":"DeviceUtil.js","sourcesContent":["import { LOG_LEVEL } from '@aiot-toolkit/shared-utils'\nimport ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport { checkbox, input, select } from '@inquirer/prompts'\nimport fs from 'fs'\nimport path from 'path'\nimport { IGetAvailablePlatform, IInstallApkAndDbg } from '../interface/CommandInterface'\nimport AdbUtils from './AdbUtils'\nimport RequestUtils from './RequestUtils'\n\n/**\n * DeviceUtil\n */\nclass DeviceUtil {\n static ipRegExp =\n /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/\n static CLIENT_PORT = 39517\n static quickapp_url = 'https://statres.quickapp.cn/quickapp/quickapptool/release/platform/'\n /**\n * 获取连接上的所有设备数组,供IDE使用\n * @returns\n */\n static getAllConnectedDevices() {\n try {\n return AdbUtils.getAllConnectedDevices().then((deviceList) => {\n if (deviceList.length > 0) {\n ColorConsole.log({\n message: `Devices connected via adb: ${deviceList.join(', ')}.`\n })\n return Promise.resolve(deviceList)\n } else {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `No device is currently connected, please check the following preparations in turn:\\n 1. Whether the device is started;\\n 2. Whether in the same LAN WI-FI;\\n 3. Whether the device can be connected to the computer via USB;`,\n isOnlyPrintError: true\n })\n process.exit()\n }\n })\n } catch (error) {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: 'Error getting connection information of adb device',\n isOnlyPrintError: true\n })\n process.exit()\n }\n }\n /**\n * 安装调试器、预览版\n * @param options\n * @returns\n */\n static async installDbgAndMkp(options: IInstallApkAndDbg) {\n try {\n const { ip = '' } = options\n let connectDeviceList: string[] = [ip]\n // 1. 判断设备是否连接\n await this.connectDevice(ip)\n // 2. 获取连接的设备\n const deviceList = await AdbUtils.getUSBConnectedDevices()\n const finalDeviceList =\n deviceList.length > 0\n ? await this.queryDevice(deviceList, 'Install Quickapp debugger or previewer ')\n : []\n connectDeviceList = finalDeviceList ? [...finalDeviceList] : []\n // 若connectDeviceList为空,应该warn并结束程序\n connectDeviceList.length <= 0 &&\n ColorConsole.log({\n message: 'No device requires debugger or previewer installation',\n level: LOG_LEVEL.Warn\n }) &&\n process.exit()\n // 3. 下载并获取调试器、预览器地址\n const debuggerPath = await this.downloadApk(options, true)\n const previewPath = await this.downloadApk(options, false)\n // // 4. 安装调试器\n await this.installApk(connectDeviceList, debuggerPath)\n await this.installApk(connectDeviceList, previewPath)\n return Promise.resolve(\n 'All devices successfully installed the Quickapp debugger and previewer'\n )\n } catch (error) {\n return Promise.reject(\n new Error(`Failed to install debugger, error message:${(error as Error).message}`)\n )\n }\n }\n /**\n * 如果是TV等AIOT设备,需要通过IP连接\n * 1. 若ip为空,则询问是否要连接新设备\n * 2. 无需连接新设备,返回\n * 3. 连接新设备,输入ip值(可输入多个ip,以逗号隔断)\n * 4. 判断输入值,空则输出info并返回\n * 5. 处理ip,输入每个ip设备的端口号,尝试连接,给出连接结果\n * @param ip\n */\n static async connectDevice(ip: string) {\n try {\n if (!ip) {\n const WIFI_TEXT = 'Yes, connect a new wifi device'\n const connectType = await select({\n message:\n '(USB devices will automatically connect) Choose whether to connect to a new wifi device, and fill in its IP address later:',\n choices: [{ value: WIFI_TEXT }, { value: 'Skip, keep connected device' }]\n })\n if (connectType === WIFI_TEXT) {\n const deviceIp = await input({\n message:\n 'Please enter the IP address of the device under wifi(eg:192.168.1.1),make sure that the computer and the device are under the same wifi。If you need to enter multiple IPs, please separate them with \",\":'\n })\n ip = deviceIp\n } else {\n return Promise.resolve()\n }\n }\n if (ip.length === 0) {\n ColorConsole.log({\n message: `Since no ip address is entered, the connected device will be connected`\n })\n return Promise.resolve()\n }\n const ips = ip.trim().split(',')\n const invalidIps = ips.filter((ip) => !this.ipRegExp.test(ip))\n if (invalidIps && invalidIps.length) {\n invalidIps.map((ip) => {\n ColorConsole.log({\n message: `ip: ${ip} is invalid IP`,\n level: LOG_LEVEL.Error,\n isOnlyPrintError: true\n })\n process.exit()\n })\n } else {\n const newDeviceListPromiseArray = Array.from(ips, async (ip) => {\n const devicePort = await input({\n message: `Please enter the port of the IP(${ip})`,\n default: '5555'\n })\n return AdbUtils.connect(ip, devicePort)\n .then(() => {\n ColorConsole.log({\n level: LOG_LEVEL.Success,\n message: `wifi connection ip: The device with ip of \"${ip}\" succeeded`\n })\n return Promise.resolve()\n })\n .catch((err) => {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: err,\n isOnlyPrintError: true\n })\n process.exit()\n })\n })\n return Promise.all(newDeviceListPromiseArray)\n .then(() => {\n ColorConsole.log({\n message: 'All new WIFI devices are connected'\n })\n return Promise.resolve()\n })\n .catch(() => {\n // 在抛出错误前已经弹出错误日志了,故这里直接退出\n process.exit()\n })\n }\n } catch {}\n }\n /**\n * 选择一个或者多个设备\n * @param deviceList\n * @param orderText\n * @returns\n */\n static async queryDevice(deviceList: string[] | undefined, orderText: string = '') {\n if (!deviceList || deviceList.length === 0) {\n ColorConsole.log({\n message: `No device is connected yet, please confirm and try again`,\n level: LOG_LEVEL.Error\n })\n return\n }\n const ALL_TEXT = 'All connected devices'\n const deviceListObj = deviceList.map((device) => {\n return {\n value: device\n }\n })\n // 可选一台或多台设备\n const chooseDevices = await checkbox({\n message: `Please select the device that needs to execute command \"${orderText}\":`,\n choices: [{ value: ALL_TEXT }, ...deviceListObj]\n })\n return chooseDevices[0] === ALL_TEXT ? deviceList : chooseDevices\n }\n /**\n * 下载apk\n * @param options\n * @param isQuickAppDebugger\n * @returns\n */\n static async downloadApk(options: IInstallApkAndDbg, isQuickAppDebugger: boolean) {\n const { apkVersion } = options\n let fileName = ''\n let newVersion = apkVersion || 'v1100'\n if (isQuickAppDebugger) {\n fileName = `quickapp_debugger_${newVersion}.apk`\n } else {\n fileName = `quickapp_platform_preview_release_${newVersion}.apk`\n }\n const url = `${this.quickapp_url}${fileName}`\n const apkPath = path.join(__dirname, './apk/', fileName)\n if (fs.existsSync(apkPath)) {\n // apk已下载\n ColorConsole.log({\n message: 'The installation package has been downloaded, now use the cache file to install'\n })\n return apkPath\n } else {\n try {\n const result = await RequestUtils.downloadFile(url, fileName)\n // 打印出成功信息\n ColorConsole.log({\n message: `Success to download, ${result}`,\n level: LOG_LEVEL.Success\n })\n return apkPath\n } catch (error) {\n // 打印出错误\n ColorConsole.log({\n message: `Failed to download the installation package, ${error}`,\n level: LOG_LEVEL.Error,\n isOnlyPrintError: true\n })\n process.exit()\n }\n }\n }\n /**\n * 获取设备上的快应用框架(需要先安装调试器)\n * 1. 请求获取平台信息\n * 2. 若获取结果为空或者undefined,则等待3s再次请求\n * 3. 若获取结果不为空,但属性availablePlatforms为空,则等待3s再次请求\n * 4. 若请求次数超过3次,则结束请求\n * 5. 否则打印获取结果\n * @param options\n */\n static async getAvailablePlatform(options: IGetAvailablePlatform) {\n try {\n const { ip, port, sn: deviceSn } = options\n let client = { ip, port }\n let countTime = 0\n let data\n\n const sleep = () => {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `Error when the device gets running platforms,request again after 3s delay`,\n isOnlyPrintError: true\n })\n return new Promise((resolve) => setTimeout(resolve, 3000))\n }\n const requestPlatform = async () => {\n do {\n if (countTime > 0) {\n // 等待3s\n await sleep()\n }\n data = await RequestUtils.sendReq(client, '/availablePlatforms')\n } while (++countTime < 3 && (!data || (data && !JSON.parse(data).availablePlatforms)))\n if (data) {\n const dataObj = JSON.parse(data)\n if (!dataObj.availablePlatforms) {\n // 请求结果不存在平台信息,报错,结束程序\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `the request result no avaliable platform `\n })\n process.exit()\n } else {\n // 打印请求的平台信息\n const availablePlatforms = dataObj.availablePlatforms\n ColorConsole.log({\n message: `The Quickapp engine list of device \"${deviceSn}\" is:${availablePlatforms.join(\n ','\n )}`\n })\n }\n } else {\n //请求失败,结束程序\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `the device gets running platforms error`\n })\n process.exit()\n }\n }\n // 先打开调试器,才能获取运行平台\n await AdbUtils.startDebugger(deviceSn)\n await requestPlatform()\n } catch (error) {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `Error getting the list of Quickapp engines on the device, error message:${\n (error as Error).message\n }`\n })\n }\n }\n /**\n * 给设备列表中的每个设备安装apk\n * @param deviceList\n * @param apkPath\n * @returns\n */\n static async installApk(deviceList: string[] = [], apkPath: string) {\n try {\n const newDeviceListPromiseArray = Array.from(deviceList, (deviceSn) => {\n return AdbUtils.installApk(deviceSn, apkPath)\n })\n const apkName = path.basename(apkPath)\n return Promise.all(newDeviceListPromiseArray)\n .then(() => {\n ColorConsole.log({\n level: LOG_LEVEL.Success,\n message: `All devices installed ${apkName}`\n })\n })\n .catch(() => {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `Installed ${apkName} failed`\n })\n process.exit()\n })\n } catch (error) {}\n }\n}\nexport default DeviceUtil\n"],"sourceRoot":"../../src"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RequestUtils
|
|
3
|
+
*/
|
|
4
|
+
declare class RequestUtils {
|
|
5
|
+
static sendReq(client: {
|
|
6
|
+
ip: string;
|
|
7
|
+
port: string;
|
|
8
|
+
}, api: string, params?: string): Promise<string>;
|
|
9
|
+
static downloadFile(url: string, fileName: string): Promise<unknown>;
|
|
10
|
+
}
|
|
11
|
+
export default RequestUtils;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
16
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
/**
|
|
21
|
+
* RequestUtils
|
|
22
|
+
*/
|
|
23
|
+
class RequestUtils {
|
|
24
|
+
static sendReq(client, api, params) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const requrl = `http://${client.ip}:${client.port}${api}`;
|
|
28
|
+
let options = {
|
|
29
|
+
host: client.ip,
|
|
30
|
+
port: client.port,
|
|
31
|
+
path: api,
|
|
32
|
+
timeout: 3000
|
|
33
|
+
};
|
|
34
|
+
if (params) {
|
|
35
|
+
options = Object.assign({}, options, {
|
|
36
|
+
headers: params
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
axios_1.default
|
|
40
|
+
.post(requrl, options)
|
|
41
|
+
.then((data) => {
|
|
42
|
+
ColorConsole_1.default.log({
|
|
43
|
+
message: `### App Server ### Request ${requrl} succeeded`
|
|
44
|
+
});
|
|
45
|
+
resolve(data.toString());
|
|
46
|
+
})
|
|
47
|
+
.catch((error) => {
|
|
48
|
+
if (error.respose && error.response.status === 408) {
|
|
49
|
+
// 超时处理
|
|
50
|
+
ColorConsole_1.default.log({
|
|
51
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
52
|
+
message: `### App Server ### Request ${requrl} timed out, please try again`,
|
|
53
|
+
isOnlyPrintError: true
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
ColorConsole_1.default.log({
|
|
58
|
+
level: shared_utils_1.LOG_LEVEL.Error,
|
|
59
|
+
message: `### App Server ### Request ${requrl} error message: ${error.message}`,
|
|
60
|
+
isOnlyPrintError: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
static downloadFile(url, fileName) {
|
|
68
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
// 开始下载
|
|
70
|
+
ColorConsole_1.default.log({
|
|
71
|
+
message: `Start downloading file:${fileName}, address:${url}`
|
|
72
|
+
});
|
|
73
|
+
const response = yield axios_1.default.get(url, {
|
|
74
|
+
responseType: 'arraybuffer'
|
|
75
|
+
});
|
|
76
|
+
if (response.status === 200) {
|
|
77
|
+
const targetDir = path_1.default.join(__dirname, './apk');
|
|
78
|
+
fs_extra_1.default.ensureDirSync(targetDir);
|
|
79
|
+
fs_extra_1.default.writeFileSync(path_1.default.join(targetDir, fileName), response.data);
|
|
80
|
+
resolve(`Download file ${fileName} successfully`);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
reject(`Download failed, status code:${response.status}`);
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.default = RequestUtils;
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=RequestUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["utils/RequestUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6DAAsD;AACtD,+FAAsE;AACtE,kDAAyB;AACzB,wDAAyB;AACzB,gDAAuB;AACvB;;GAEG;AACH,MAAM,YAAY;IAChB,MAAM,CAAO,OAAO,CAAC,MAAoC,EAAE,GAAW,EAAE,MAAe;;YACrF,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;gBACrC,MAAM,MAAM,GAAG,UAAU,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,GAAG,GAAG,EAAE,CAAA;gBACzD,IAAI,OAAO,GAAG;oBACZ,IAAI,EAAE,MAAM,CAAC,EAAE;oBACf,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,IAAI,EAAE,GAAG;oBACT,OAAO,EAAE,IAAI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AG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,EAAE;gBACpC,YAAY,EAAE,aAAa;aAC5B,CAAC,CAAA;YACF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;gBAC3B,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;gBAC/C,kBAAE,CAAC,aAAa,CAAC,SAAS,CAAC,CAAA;gBAC3B,kBAAE,CAAC,aAAa,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAA;gBAC/D,OAAO,CAAC,iBAAiB,QAAQ,eAAe,CAAC,CAAA;aAClD;iBAAM;gBACL,MAAM,CAAC,gCAAgC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;aAC1D;QACH,CAAC,CAAA,CAAC,CAAA;IACJ,CAAC;CACF;AACD,kBAAe,YAAY,CAAA","file":"RequestUtils.js","sourcesContent":["import { LOG_LEVEL } from '@aiot-toolkit/shared-utils'\nimport ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport axios from 'axios'\nimport fs from 'fs-extra'\nimport path from 'path'\n/**\n * RequestUtils\n */\nclass RequestUtils {\n static async sendReq(client: { ip: string; port: string }, api: string, params?: string) {\n return new Promise<string>((resolve) => {\n const requrl = `http://${client.ip}:${client.port}${api}`\n let options = {\n host: client.ip,\n port: client.port,\n path: api,\n timeout: 3000\n }\n if (params) {\n options = Object.assign({}, options, {\n headers: params\n })\n }\n axios\n .post(requrl, options)\n .then((data) => {\n ColorConsole.log({\n message: `### App Server ### Request ${requrl} succeeded`\n })\n resolve(data.toString())\n })\n .catch((error) => {\n if (error.respose && error.response.status === 408) {\n // 超时处理\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `### App Server ### Request ${requrl} timed out, please try again`,\n isOnlyPrintError: true\n })\n } else {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `### App Server ### Request ${requrl} error message: ${\n (error as Error).message\n }`,\n isOnlyPrintError: true\n })\n }\n })\n })\n }\n static downloadFile(url: string, fileName: string) {\n return new Promise(async (resolve, reject) => {\n // 开始下载\n ColorConsole.log({\n message: `Start downloading file:${fileName}, address:${url}`\n })\n const response = await axios.get(url, {\n responseType: 'arraybuffer'\n })\n if (response.status === 200) {\n const targetDir = path.join(__dirname, './apk')\n fs.ensureDirSync(targetDir)\n fs.writeFileSync(path.join(targetDir, fileName), response.data)\n resolve(`Download file ${fileName} successfully`)\n } else {\n reject(`Download failed, status code:${response.status}`)\n }\n })\n }\n}\nexport default RequestUtils\n"],"sourceRoot":"../../src"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { VelaAvdCls } from '@aiot-toolkit/emulator';
|
|
2
|
+
declare class VelaAvdUtils {
|
|
3
|
+
static sdkHome: string;
|
|
4
|
+
static avdHome: string;
|
|
5
|
+
static baseUrl: string;
|
|
6
|
+
static versionUrl: string;
|
|
7
|
+
static emulatorBaseUrl: string;
|
|
8
|
+
static systemImageBaseUrl: string;
|
|
9
|
+
static velaAvdCls: VelaAvdCls;
|
|
10
|
+
static validateAvdName(avdName: string): true | "Please enter avd name" | "The avd name must starts with Vela" | "The avd already exists. Please change avd name";
|
|
11
|
+
/**
|
|
12
|
+
* 从CDN上下载资源文件
|
|
13
|
+
* @param downloadUrl 下载地址
|
|
14
|
+
* @param targetDir 下载后的文件存放的目录
|
|
15
|
+
* @param filename 下载文件的名称
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
static downloadFromCdn(downloadUrl: string, targetDir: string, filename: string): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* 下载zip文件并解压。会将zip里的所有文件解压至targetDir
|
|
21
|
+
* @param downloadUrl 下载地址
|
|
22
|
+
* @param targetDir 解压目录
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
static downloadAndUnzip(downloadUrl: string, targetDir: string): Promise<void>;
|
|
26
|
+
/** 根据host获取模拟器下载地址 */
|
|
27
|
+
static getEmulatorUrl(version?: string): string;
|
|
28
|
+
/** 根据host获取vela镜像下载地址 */
|
|
29
|
+
static getSystemImageUrl(version?: string, device?: string): string;
|
|
30
|
+
/** 根据host获取ya-vm-file-server下载地址 */
|
|
31
|
+
static getv9fsToolUrl(version?: string): string;
|
|
32
|
+
/** 获取资源文件下载地址 */
|
|
33
|
+
static getDownloadUrl(file: string, version?: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* 命令行访问方式创建模拟器
|
|
36
|
+
*/
|
|
37
|
+
static createVelaAvdByInquire(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
export default VelaAvdUtils;
|