aiot-toolkit 2.0.3-beta.1 → 2.0.3-beta.10
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 +2 -0
- package/lib/bin.js +158 -184
- package/lib/builder/AndroidUxBuilder.js +14 -15
- package/lib/builder/IBuilder.d.ts +6 -0
- package/lib/builder/IBuilder.js +1 -2
- package/lib/builder/UxBuilderBase.d.ts +8 -7
- package/lib/builder/UxBuilderBase.js +130 -111
- package/lib/builder/VelaUxBuilder.d.ts +11 -10
- package/lib/builder/VelaUxBuilder.js +65 -61
- package/lib/builder/XtsBuilder.d.ts +2 -0
- package/lib/builder/XtsBuilder.js +85 -78
- package/lib/index.js +48 -13
- package/lib/interface/CommandInterface.js +4 -1
- package/lib/interface/VelaEmulatorInterface.js +4 -1
- package/lib/starter/AndroidUxStart.js +158 -158
- package/lib/starter/IStarter.js +39 -37
- package/lib/starter/VelaUxStarter.d.ts +8 -3
- package/lib/starter/VelaUxStarter.js +158 -189
- package/lib/starter/XtsStarter.js +16 -17
- package/lib/starter/androidRouter/LinkMode.js +12 -8
- package/lib/starter/androidRouter/PackageRouter.js +144 -140
- package/lib/utils/AdbUtils.js +48 -76
- package/lib/utils/DeviceUtil.js +277 -293
- package/lib/utils/RequestUtils.js +54 -68
- package/lib/utils/VelaAvdUtils.d.ts +9 -54
- package/lib/utils/VelaAvdUtils.js +127 -436
- package/lib/waiter.js +35 -35
- package/package.json +9 -15
package/lib/utils/DeviceUtil.js
CHANGED
|
@@ -1,308 +1,292 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
16
|
-
const prompts_1 = require("@inquirer/prompts");
|
|
17
|
-
const fs_1 = __importDefault(require("fs"));
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
const AdbUtils_1 = __importDefault(require("./AdbUtils"));
|
|
20
|
-
const RequestUtils_1 = __importDefault(require("./RequestUtils"));
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
8
|
+
var _prompts = require("@inquirer/prompts");
|
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _AdbUtils = _interopRequireDefault(require("./AdbUtils"));
|
|
12
|
+
var _RequestUtils = _interopRequireDefault(require("./RequestUtils"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
14
|
/**
|
|
22
15
|
* DeviceUtil
|
|
23
16
|
*/
|
|
24
17
|
class DeviceUtil {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
shared_utils_1.ColorConsole.throw('Error getting connection information of adb device');
|
|
18
|
+
static 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]?)$/;
|
|
19
|
+
static CLIENT_PORT = 39517;
|
|
20
|
+
static quickapp_url = 'https://statres.quickapp.cn/quickapp/quickapptool/release/platform/';
|
|
21
|
+
/**
|
|
22
|
+
* 获取连接上的所有设备数组,供IDE使用
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
static getAllConnectedDevices() {
|
|
26
|
+
try {
|
|
27
|
+
return _AdbUtils.default.getAllConnectedDevices().then(deviceList => {
|
|
28
|
+
if (deviceList.length > 0) {
|
|
29
|
+
_sharedUtils.ColorConsole.info(`Devices connected via adb: ${deviceList.join(', ')}.`);
|
|
30
|
+
return Promise.resolve(deviceList);
|
|
31
|
+
} else {
|
|
32
|
+
_sharedUtils.ColorConsole.throw(`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
33
|
}
|
|
34
|
+
});
|
|
35
|
+
} catch (error) {
|
|
36
|
+
_sharedUtils.ColorConsole.throw('Error getting connection information of adb device');
|
|
44
37
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 安装调试器、预览版
|
|
41
|
+
* @param options
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
static async installDbgAndMkp(options) {
|
|
45
|
+
try {
|
|
46
|
+
const {
|
|
47
|
+
ip = ''
|
|
48
|
+
} = options;
|
|
49
|
+
let connectDeviceList = [ip];
|
|
50
|
+
// 1. 判断设备是否连接
|
|
51
|
+
await this.connectDevice(ip);
|
|
52
|
+
// 2. 获取连接的设备
|
|
53
|
+
const deviceList = await _AdbUtils.default.getAllConnectedDevices();
|
|
54
|
+
const finalDeviceList = deviceList.length > 0 ? await this.queryDevice(deviceList, 'Install Quickapp debugger or previewer ') : [];
|
|
55
|
+
connectDeviceList = finalDeviceList ? [...finalDeviceList] : [];
|
|
56
|
+
// 若connectDeviceList为空,应该warn并结束程序
|
|
57
|
+
if (connectDeviceList.length <= 0) {
|
|
58
|
+
_sharedUtils.ColorConsole.throw({
|
|
59
|
+
word: 'No device'
|
|
60
|
+
}, 'requires debugger or previewer installation');
|
|
61
|
+
return Promise.reject(new Error(`No device requires debugger or previewer installation`));
|
|
62
|
+
}
|
|
63
|
+
// 3. 下载并获取调试器、预览器地址
|
|
64
|
+
const debuggerPath = await this.downloadApk(options, true);
|
|
65
|
+
const previewPath = await this.downloadApk(options, false);
|
|
66
|
+
// // 4. 安装调试器
|
|
67
|
+
await this.installApk(connectDeviceList, debuggerPath);
|
|
68
|
+
await this.installApk(connectDeviceList, previewPath);
|
|
69
|
+
return Promise.resolve('All devices successfully installed the Quickapp debugger and previewer');
|
|
70
|
+
} catch (error) {
|
|
71
|
+
return Promise.reject(new Error(`Failed to install , error message:${error?.toString() || 'unknown error'}`));
|
|
80
72
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
103
|
-
ip = deviceIp;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
return Promise.resolve();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (ip.length === 0) {
|
|
110
|
-
shared_utils_1.ColorConsole.log(`Since no ip address is entered, the connected device will be connected`);
|
|
111
|
-
return Promise.resolve();
|
|
112
|
-
}
|
|
113
|
-
const ips = ip.trim().split(',');
|
|
114
|
-
const invalidIps = ips.filter((ip) => !this.ipRegExp.test(ip));
|
|
115
|
-
if (invalidIps && invalidIps.length) {
|
|
116
|
-
invalidIps.map((ip) => {
|
|
117
|
-
shared_utils_1.ColorConsole.throw(`ip: `, { word: ip, style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.THROW) }, ` is invalid IP`);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
const newDeviceListPromiseArray = Array.from(ips, (ip) => __awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
const devicePort = yield (0, prompts_1.input)({
|
|
123
|
-
message: `Please enter the port of the IP(${ip})`,
|
|
124
|
-
default: '5555'
|
|
125
|
-
});
|
|
126
|
-
return AdbUtils_1.default.connect(ip, devicePort)
|
|
127
|
-
.then(() => {
|
|
128
|
-
shared_utils_1.ColorConsole.success(`wifi connection ip: The device with ip of "${ip}" succeeded`);
|
|
129
|
-
return Promise.resolve();
|
|
130
|
-
})
|
|
131
|
-
.catch((err) => {
|
|
132
|
-
shared_utils_1.ColorConsole.throw(`${err}`);
|
|
133
|
-
});
|
|
134
|
-
}));
|
|
135
|
-
return Promise.all(newDeviceListPromiseArray)
|
|
136
|
-
.then(() => {
|
|
137
|
-
shared_utils_1.ColorConsole.log(`All new WIFI devices are connected`);
|
|
138
|
-
return Promise.resolve();
|
|
139
|
-
})
|
|
140
|
-
.catch(() => {
|
|
141
|
-
// 在抛出错误前已经弹出错误日志了,故这里直接退出
|
|
142
|
-
process.exit();
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch (_a) { }
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 如果是TV等AIOT设备,需要通过IP连接
|
|
76
|
+
* 1. 若ip为空,则询问是否要连接新设备
|
|
77
|
+
* 2. 无需连接新设备,返回
|
|
78
|
+
* 3. 连接新设备,输入ip值(可输入多个ip,以逗号隔断)
|
|
79
|
+
* 4. 判断输入值,空则输出info并返回
|
|
80
|
+
* 5. 处理ip,输入每个ip设备的端口号,尝试连接,给出连接结果
|
|
81
|
+
* @param ip
|
|
82
|
+
*/
|
|
83
|
+
static async connectDevice(ip) {
|
|
84
|
+
try {
|
|
85
|
+
if (!ip) {
|
|
86
|
+
const WIFI_TEXT = 'Yes, connect a new wifi device';
|
|
87
|
+
const connectType = await (0, _prompts.select)({
|
|
88
|
+
message: '(USB devices will automatically connect) Choose whether to connect to a new wifi device, and fill in its IP address later:',
|
|
89
|
+
choices: [{
|
|
90
|
+
value: WIFI_TEXT
|
|
91
|
+
}, {
|
|
92
|
+
value: 'Skip, keep connected device'
|
|
93
|
+
}]
|
|
147
94
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
message: `Please select the device that needs to execute command "${orderText}":`,
|
|
170
|
-
choices: [{ value: ALL_TEXT }, ...deviceListObj]
|
|
171
|
-
});
|
|
172
|
-
return chooseDevices[0] === ALL_TEXT ? deviceList : chooseDevices;
|
|
95
|
+
if (connectType === WIFI_TEXT) {
|
|
96
|
+
const deviceIp = await (0, _prompts.input)({
|
|
97
|
+
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 ",":'
|
|
98
|
+
});
|
|
99
|
+
ip = deviceIp;
|
|
100
|
+
} else {
|
|
101
|
+
return Promise.resolve();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (ip.length === 0) {
|
|
105
|
+
_sharedUtils.ColorConsole.log(`Since no ip address is entered, the connected device will be connected`);
|
|
106
|
+
return Promise.resolve();
|
|
107
|
+
}
|
|
108
|
+
const ips = ip.trim().split(',');
|
|
109
|
+
const invalidIps = ips.filter(ip => !this.ipRegExp.test(ip));
|
|
110
|
+
if (invalidIps && invalidIps.length) {
|
|
111
|
+
invalidIps.map(ip => {
|
|
112
|
+
_sharedUtils.ColorConsole.throw(`ip: `, {
|
|
113
|
+
word: ip,
|
|
114
|
+
style: _sharedUtils.ColorConsole.getStyle(_sharedUtils.Loglevel.THROW)
|
|
115
|
+
}, ` is invalid IP`);
|
|
173
116
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (isQuickAppDebugger) {
|
|
187
|
-
fileName = `quickapp_debugger_${newVersion}.apk`;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
fileName = `quickapp_platform_preview_release_${newVersion}.apk`;
|
|
191
|
-
}
|
|
192
|
-
const url = `${this.quickapp_url}${fileName}`;
|
|
193
|
-
const apkPath = path_1.default.join(__dirname, './apk/', fileName);
|
|
194
|
-
if (fs_1.default.existsSync(apkPath)) {
|
|
195
|
-
// apk已下载
|
|
196
|
-
shared_utils_1.ColorConsole.log(`The installation package has been downloaded, now use the cache file to install`);
|
|
197
|
-
return apkPath;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
try {
|
|
201
|
-
const result = yield RequestUtils_1.default.downloadFile(url, fileName);
|
|
202
|
-
// 打印出成功信息
|
|
203
|
-
shared_utils_1.ColorConsole.success(`Success to download, ${result}`);
|
|
204
|
-
return apkPath;
|
|
205
|
-
}
|
|
206
|
-
catch (error) {
|
|
207
|
-
// 打印出错误
|
|
208
|
-
shared_utils_1.ColorConsole.throw(`Failed to download the installation package, ${error}`);
|
|
209
|
-
return '';
|
|
210
|
-
}
|
|
211
|
-
}
|
|
117
|
+
} else {
|
|
118
|
+
const newDeviceListPromiseArray = Array.from(ips, async ip => {
|
|
119
|
+
const devicePort = await (0, _prompts.input)({
|
|
120
|
+
message: `Please enter the port of the IP(${ip})`,
|
|
121
|
+
default: '5555'
|
|
122
|
+
});
|
|
123
|
+
return _AdbUtils.default.connect(ip, devicePort).then(() => {
|
|
124
|
+
_sharedUtils.ColorConsole.success(`wifi connection ip: The device with ip of "${ip}" succeeded`);
|
|
125
|
+
return Promise.resolve();
|
|
126
|
+
}).catch(err => {
|
|
127
|
+
_sharedUtils.ColorConsole.throw(`${err}`);
|
|
128
|
+
});
|
|
212
129
|
});
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
* 4. 若请求次数超过3次,则结束请求
|
|
220
|
-
* 5. 否则打印获取结果
|
|
221
|
-
* @param options
|
|
222
|
-
*/
|
|
223
|
-
static getAvailablePlatform(options) {
|
|
224
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
-
try {
|
|
226
|
-
const { ip, port, sn: deviceSn } = options;
|
|
227
|
-
let client = { ip, port };
|
|
228
|
-
let countTime = 0;
|
|
229
|
-
let data;
|
|
230
|
-
const sleep = () => {
|
|
231
|
-
shared_utils_1.ColorConsole.error(`Error when the device gets running platforms,request again after 3s delay`);
|
|
232
|
-
return new Promise((resolve) => setTimeout(resolve, 3000));
|
|
233
|
-
};
|
|
234
|
-
const requestPlatform = () => __awaiter(this, void 0, void 0, function* () {
|
|
235
|
-
do {
|
|
236
|
-
if (countTime > 0) {
|
|
237
|
-
// 等待3s
|
|
238
|
-
yield sleep();
|
|
239
|
-
}
|
|
240
|
-
data = yield RequestUtils_1.default.sendReq(client, '/availablePlatforms');
|
|
241
|
-
} while (++countTime < 3 && (!data || (data && !JSON.parse(data).availablePlatforms)));
|
|
242
|
-
if (data) {
|
|
243
|
-
const dataObj = JSON.parse(data);
|
|
244
|
-
if (!dataObj.availablePlatforms) {
|
|
245
|
-
// 请求结果不存在平台信息,报错,结束程序
|
|
246
|
-
shared_utils_1.ColorConsole.throw(`The request result no avaliable platform `);
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
// 打印请求的平台信息
|
|
250
|
-
const availablePlatforms = dataObj.availablePlatforms;
|
|
251
|
-
shared_utils_1.ColorConsole.log(`The Quickapp engine list of device "${deviceSn}" is:${availablePlatforms.join(',')}`);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
//请求失败,结束程序
|
|
256
|
-
shared_utils_1.ColorConsole.throw(`The device gets running platforms error`);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
// 先打开调试器,才能获取运行平台
|
|
260
|
-
yield AdbUtils_1.default.startDebugger(deviceSn);
|
|
261
|
-
yield requestPlatform();
|
|
262
|
-
}
|
|
263
|
-
catch (error) {
|
|
264
|
-
shared_utils_1.ColorConsole.throw(`Error getting the list of Quickapp engines on the device`);
|
|
265
|
-
}
|
|
130
|
+
return Promise.all(newDeviceListPromiseArray).then(() => {
|
|
131
|
+
_sharedUtils.ColorConsole.log(`All new WIFI devices are connected`);
|
|
132
|
+
return Promise.resolve();
|
|
133
|
+
}).catch(() => {
|
|
134
|
+
// 在抛出错误前已经弹出错误日志了,故这里直接退出
|
|
135
|
+
process.exit();
|
|
266
136
|
});
|
|
137
|
+
}
|
|
138
|
+
} catch {}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 选择一个或者多个设备
|
|
142
|
+
* @param deviceList
|
|
143
|
+
* @param orderText
|
|
144
|
+
* @returns
|
|
145
|
+
*/
|
|
146
|
+
static async queryDevice(deviceList) {
|
|
147
|
+
let orderText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
148
|
+
if (!deviceList || deviceList.length === 0) {
|
|
149
|
+
_sharedUtils.ColorConsole.throw(`No device is connected yet, please confirm and try again`);
|
|
150
|
+
return;
|
|
267
151
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
catch (error) { }
|
|
302
|
-
});
|
|
152
|
+
const ALL_TEXT = 'All connected devices';
|
|
153
|
+
const deviceListObj = deviceList.map(device => {
|
|
154
|
+
return {
|
|
155
|
+
value: device
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
// 可选一台或多台设备
|
|
159
|
+
const chooseDevices = await (0, _prompts.checkbox)({
|
|
160
|
+
message: `Please select the device that needs to execute command "${orderText}":`,
|
|
161
|
+
choices: [{
|
|
162
|
+
value: ALL_TEXT
|
|
163
|
+
}, ...deviceListObj]
|
|
164
|
+
});
|
|
165
|
+
return chooseDevices[0] === ALL_TEXT ? deviceList : chooseDevices;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 下载apk
|
|
169
|
+
* @param options
|
|
170
|
+
* @param isQuickAppDebugger
|
|
171
|
+
* @returns
|
|
172
|
+
*/
|
|
173
|
+
static async downloadApk(options, isQuickAppDebugger) {
|
|
174
|
+
const {
|
|
175
|
+
apkVersion
|
|
176
|
+
} = options;
|
|
177
|
+
let fileName = '';
|
|
178
|
+
let newVersion = apkVersion || 'v1100';
|
|
179
|
+
if (isQuickAppDebugger) {
|
|
180
|
+
fileName = `quickapp_debugger_${newVersion}.apk`;
|
|
181
|
+
} else {
|
|
182
|
+
fileName = `quickapp_platform_preview_release_${newVersion}.apk`;
|
|
303
183
|
}
|
|
184
|
+
const url = `${this.quickapp_url}${fileName}`;
|
|
185
|
+
const apkPath = _path.default.join(__dirname, './apk/', fileName);
|
|
186
|
+
if (_fs.default.existsSync(apkPath)) {
|
|
187
|
+
// apk已下载
|
|
188
|
+
_sharedUtils.ColorConsole.log(`The installation package has been downloaded, now use the cache file to install`);
|
|
189
|
+
return apkPath;
|
|
190
|
+
} else {
|
|
191
|
+
try {
|
|
192
|
+
const result = await _RequestUtils.default.downloadFile(url, fileName);
|
|
193
|
+
// 打印出成功信息
|
|
194
|
+
_sharedUtils.ColorConsole.success(`Success to download, ${result}`);
|
|
195
|
+
return apkPath;
|
|
196
|
+
} catch (error) {
|
|
197
|
+
// 打印出错误
|
|
198
|
+
_sharedUtils.ColorConsole.throw(`Failed to download the installation package, ${error}`);
|
|
199
|
+
return '';
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 获取设备上的快应用框架(需要先安装调试器)
|
|
205
|
+
* 1. 请求获取平台信息
|
|
206
|
+
* 2. 若获取结果为空或者undefined,则等待3s再次请求
|
|
207
|
+
* 3. 若获取结果不为空,但属性availablePlatforms为空,则等待3s再次请求
|
|
208
|
+
* 4. 若请求次数超过3次,则结束请求
|
|
209
|
+
* 5. 否则打印获取结果
|
|
210
|
+
* @param options
|
|
211
|
+
*/
|
|
212
|
+
static async getAvailablePlatform(options) {
|
|
213
|
+
try {
|
|
214
|
+
const {
|
|
215
|
+
ip,
|
|
216
|
+
port,
|
|
217
|
+
sn: deviceSn
|
|
218
|
+
} = options;
|
|
219
|
+
let client = {
|
|
220
|
+
ip,
|
|
221
|
+
port
|
|
222
|
+
};
|
|
223
|
+
let countTime = 0;
|
|
224
|
+
let data;
|
|
225
|
+
const sleep = () => {
|
|
226
|
+
_sharedUtils.ColorConsole.error(`Error when the device gets running platforms,request again after 3s delay`);
|
|
227
|
+
return new Promise(resolve => setTimeout(resolve, 3000));
|
|
228
|
+
};
|
|
229
|
+
const requestPlatform = async () => {
|
|
230
|
+
do {
|
|
231
|
+
if (countTime > 0) {
|
|
232
|
+
// 等待3s
|
|
233
|
+
await sleep();
|
|
234
|
+
}
|
|
235
|
+
data = await _RequestUtils.default.sendReq(client, '/availablePlatforms');
|
|
236
|
+
} while (++countTime < 3 && (!data || data && !JSON.parse(data).availablePlatforms));
|
|
237
|
+
if (data) {
|
|
238
|
+
const dataObj = JSON.parse(data);
|
|
239
|
+
if (!dataObj.availablePlatforms) {
|
|
240
|
+
// 请求结果不存在平台信息,报错,结束程序
|
|
241
|
+
_sharedUtils.ColorConsole.throw(`The request result no avaliable platform `);
|
|
242
|
+
} else {
|
|
243
|
+
// 打印请求的平台信息
|
|
244
|
+
const availablePlatforms = dataObj.availablePlatforms;
|
|
245
|
+
_sharedUtils.ColorConsole.log(`The Quickapp engine list of device "${deviceSn}" is:${availablePlatforms.join(',')}`);
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
//请求失败,结束程序
|
|
249
|
+
_sharedUtils.ColorConsole.throw(`The device gets running platforms error`);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
// 先打开调试器,才能获取运行平台
|
|
253
|
+
await _AdbUtils.default.startDebugger(deviceSn);
|
|
254
|
+
await requestPlatform();
|
|
255
|
+
} catch (error) {
|
|
256
|
+
_sharedUtils.ColorConsole.throw(`Error getting the list of Quickapp engines on the device`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* 给设备列表中的每个设备安装apk
|
|
261
|
+
* @param deviceList
|
|
262
|
+
* @param apkPath
|
|
263
|
+
* @returns
|
|
264
|
+
*/
|
|
265
|
+
static async installApk() {
|
|
266
|
+
let deviceList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
267
|
+
let apkPath = arguments.length > 1 ? arguments[1] : undefined;
|
|
268
|
+
try {
|
|
269
|
+
const newDeviceListPromiseArray = Array.from(deviceList, deviceSn => {
|
|
270
|
+
return _AdbUtils.default.installApk(deviceSn, apkPath);
|
|
271
|
+
});
|
|
272
|
+
const apkName = _path.default.basename(apkPath);
|
|
273
|
+
return Promise.all(newDeviceListPromiseArray).then(results => {
|
|
274
|
+
let statusAll = true;
|
|
275
|
+
results.forEach(res => {
|
|
276
|
+
if (!res.status) {
|
|
277
|
+
_sharedUtils.ColorConsole.error(res.msg);
|
|
278
|
+
statusAll = false;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
if (statusAll) {
|
|
282
|
+
_sharedUtils.ColorConsole.success(`All devices installed ${apkName}`);
|
|
283
|
+
} else {
|
|
284
|
+
// TODO 后续从这里抛出异常
|
|
285
|
+
}
|
|
286
|
+
}).catch(() => {
|
|
287
|
+
_sharedUtils.ColorConsole.throw(`Installed ${apkName} failed`);
|
|
288
|
+
});
|
|
289
|
+
} catch (error) {}
|
|
290
|
+
}
|
|
304
291
|
}
|
|
305
|
-
|
|
306
|
-
DeviceUtil.CLIENT_PORT = 39517;
|
|
307
|
-
DeviceUtil.quickapp_url = 'https://statres.quickapp.cn/quickapp/quickapptool/release/platform/';
|
|
308
|
-
exports.default = DeviceUtil;
|
|
292
|
+
var _default = exports.default = DeviceUtil;
|