aiot-toolkit 2.0.1-alpha.11 → 2.0.1-alpha.13

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["utils/AdbUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAAsD;AACtD,+FAAsE;AACtE,mDAAoC;AACpC,kEAAwC;AAExC;;GAEG;AACH,MAAM,QAAQ;IACZ,OAAO;IACP,MAAM,CAAO,OAAO,CAAC,EAAU,EAAE,IAAY;;YAC3C,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,eAAe,EAAE,IAAI,IAAI,EAAE,CAAC,CAAA;YAC5E,OAAO,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;QAC/C,CAAC;KAAA;IACD,uBAAuB;IACvB,MAAM,CAAO,sBAAsB;;YACjC,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,aAAa,EAAE,CAAA;YACzC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA;QAChC,CAAC;KAAA;IACD,aAAa;IACb,MAAM,CAAO,sBAAsB;;YACjC,MAAM,GAAG,GAAG,MAAM,uBAAY,CAAC,UAAU,EAAE,CAAA;YAC3C,OAAO,GAAG,CAAC,UAAU,CAAA;QACvB,CAAC;KAAA;IACD,OAAO;IACP,MAAM,CAAO,UAAU,CAAC,EAAU,EAAE,OAAe;;YACjD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;YACpD,OAAO,MAAM,CAAA;QACf,CAAC;KAAA;IACD,QAAQ;IACR,MAAM,CAAO,aAAa,CAAC,QAAgB;;YACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CACjC,UAAU,QAAQ,uDAAuD,CAC1E,CAAA;YACD,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;gBAC1C,oBAAoB;gBACpB,sBAAY,CAAC,GAAG,CAAC;oBACf,OAAO,EAAE,IAAI;iBACd,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;YACF,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;gBAC1C,oBAAoB;gBACpB,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;oBAC9B,sBAAY,CAAC,GAAG,CAAC;wBACf,KAAK,EAAE,wBAAS,CAAC,KAAK;wBACtB,OAAO,EAAE,IAAI;qBACd,CAAC,CAAA;oBACF,OAAO,CAAC,IAAI,EAAE,CAAA;iBACf;YACH,CAAC,CAAC,CAAA;YACF,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACxB,WAAW;gBACX,OAAO,CAAC,OAAO,EAAE,CAAA;YACnB,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;CACF;AACD,kBAAe,QAAQ,CAAA","file":"AdbUtils.js","sourcesContent":["import { LOG_LEVEL } from '@aiot-toolkit/shared-utils'\nimport ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport * as adbMiwt from '@miwt/adb'\nimport adbCommander from 'adb-commander'\n\n/**\n * AdbUtils\n */\nclass AdbUtils {\n // 连接设备\n static async connect(ip: string, port: string) {\n const adbConnet = await adbMiwt.execAdbCmdAsync(`adb connect ${ip}:${port}`)\n return adbConnet.indexOf('connected to') >= 0\n }\n // 获取所有已连接的设备(包含无线连接设备)\n static async getAllConnectedDevices() {\n const res = await adbMiwt.getAdbDevices()\n return res.map(({ sn }) => sn)\n }\n // 获取USB连接的设备\n static async getUSBConnectedDevices() {\n const res = await adbCommander.deviceList()\n return res.deviceList\n }\n // 安装设备\n static async installApk(sn: string, apkPath: string) {\n const result = await adbMiwt.installApk(sn, apkPath)\n return result\n }\n // 启动调试器\n static async startDebugger(deviceSn: string) {\n const adbShell = adbMiwt.execAdbCmd(\n `adb -s ${deviceSn} shell am start -n \"org.hapjs.debugger/.MainActivity\"`\n )\n adbShell.stdout.on('data', (data: string) => {\n // 监听stderr事件,获取输出内容\n ColorConsole.log({\n message: data\n })\n })\n adbShell.stderr.on('data', (data: string) => {\n // 监听stderr事件,获取输出内容\n if (data.indexOf('Error') >= 0) {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: data\n })\n process.exit()\n }\n })\n adbShell.on('close', () => {\n // 处理命令正常结束\n Promise.resolve()\n })\n }\n}\nexport default AdbUtils\n"],"sourceRoot":"../../src"}
1
+ {"version":3,"sources":["utils/AdbUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+FAAsE;AACtE,mDAAoC;AACpC,kEAAwC;AAExC;;GAEG;AACH,MAAM,QAAQ;IACZ,OAAO;IACP,MAAM,CAAO,OAAO,CAAC,EAAU,EAAE,IAAY;;YAC3C,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,eAAe,EAAE,IAAI,IAAI,EAAE,CAAC,CAAA;YAC5E,OAAO,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;QAC/C,CAAC;KAAA;IACD,uBAAuB;IACvB,MAAM,CAAO,sBAAsB;;YACjC,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,aAAa,EAAE,CAAA;YACzC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA;QAChC,CAAC;KAAA;IACD,aAAa;IACb,MAAM,CAAO,sBAAsB;;YACjC,MAAM,GAAG,GAAG,MAAM,uBAAY,CAAC,UAAU,EAAE,CAAA;YAC3C,OAAO,GAAG,CAAC,UAAU,CAAA;QACvB,CAAC;KAAA;IACD,OAAO;IACP,MAAM,CAAO,UAAU,CAAC,EAAU,EAAE,OAAe;;YACjD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;YACpD,OAAO,MAAM,CAAA;QACf,CAAC;KAAA;IACD,QAAQ;IACR,MAAM,CAAO,aAAa,CAAC,QAAgB;;YACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CACjC,UAAU,QAAQ,uDAAuD,CAC1E,CAAA;YACD,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;gBAC1C,oBAAoB;gBACpB,sBAAY,CAAC,GAAG,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAA;YACnD,CAAC,CAAC,CAAA;YACF,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;gBAC1C,oBAAoB;gBACpB,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;oBAC9B,sBAAY,CAAC,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAA;iBACpD;YACH,CAAC,CAAC,CAAA;YACF,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACxB,WAAW;gBACX,OAAO,CAAC,OAAO,EAAE,CAAA;YACnB,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;CACF;AACD,kBAAe,QAAQ,CAAA","file":"AdbUtils.js","sourcesContent":["import ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport * as adbMiwt from '@miwt/adb'\nimport adbCommander from 'adb-commander'\n\n/**\n * AdbUtils\n */\nclass AdbUtils {\n // 连接设备\n static async connect(ip: string, port: string) {\n const adbConnet = await adbMiwt.execAdbCmdAsync(`adb connect ${ip}:${port}`)\n return adbConnet.indexOf('connected to') >= 0\n }\n // 获取所有已连接的设备(包含无线连接设备)\n static async getAllConnectedDevices() {\n const res = await adbMiwt.getAdbDevices()\n return res.map(({ sn }) => sn)\n }\n // 获取USB连接的设备\n static async getUSBConnectedDevices() {\n const res = await adbCommander.deviceList()\n return res.deviceList\n }\n // 安装设备\n static async installApk(sn: string, apkPath: string) {\n const result = await adbMiwt.installApk(sn, apkPath)\n return result\n }\n // 启动调试器\n static async startDebugger(deviceSn: string) {\n const adbShell = adbMiwt.execAdbCmd(\n `adb -s ${deviceSn} shell am start -n \"org.hapjs.debugger/.MainActivity\"`\n )\n adbShell.stdout.on('data', (data: string) => {\n // 监听stderr事件,获取输出内容\n ColorConsole.log(`### startDebugger ### ${data}`)\n })\n adbShell.stderr.on('data', (data: string) => {\n // 监听stderr事件,获取输出内容\n if (data.indexOf('Error') >= 0) {\n ColorConsole.throw(`### startDebugger ### ${data}`)\n }\n })\n adbShell.on('close', () => {\n // 处理命令正常结束\n Promise.resolve()\n })\n }\n}\nexport default AdbUtils\n"],"sourceRoot":"../../src"}
@@ -10,7 +10,7 @@ declare class DeviceUtil {
10
10
  * 获取连接上的所有设备数组,供IDE使用
11
11
  * @returns
12
12
  */
13
- static getAllConnectedDevices(): Promise<string[]>;
13
+ static getAllConnectedDevices(): Promise<string[] | undefined> | undefined;
14
14
  /**
15
15
  * 安装调试器、预览版
16
16
  * @param options
@@ -31,28 +31,16 @@ class DeviceUtil {
31
31
  try {
32
32
  return AdbUtils_1.default.getAllConnectedDevices().then((deviceList) => {
33
33
  if (deviceList.length > 0) {
34
- ColorConsole_1.default.log({
35
- message: `Devices connected via adb: ${deviceList.join(', ')}.`
36
- });
34
+ ColorConsole_1.default.info(`Devices connected via adb: ${deviceList.join(', ')}.`);
37
35
  return Promise.resolve(deviceList);
38
36
  }
39
37
  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();
38
+ ColorConsole_1.default.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;`);
46
39
  }
47
40
  });
48
41
  }
49
42
  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();
43
+ ColorConsole_1.default.throw('Error getting connection information of adb device');
56
44
  }
57
45
  }
58
46
  /**
@@ -75,11 +63,7 @@ class DeviceUtil {
75
63
  connectDeviceList = finalDeviceList ? [...finalDeviceList] : [];
76
64
  // 若connectDeviceList为空,应该warn并结束程序
77
65
  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();
66
+ ColorConsole_1.default.throw('No device requires debugger or previewer installation');
83
67
  // 3. 下载并获取调试器、预览器地址
84
68
  const debuggerPath = yield this.downloadApk(options, true);
85
69
  const previewPath = yield this.downloadApk(options, false);
@@ -89,7 +73,7 @@ class DeviceUtil {
89
73
  return Promise.resolve('All devices successfully installed the Quickapp debugger and previewer');
90
74
  }
91
75
  catch (error) {
92
- return Promise.reject(new Error(`Failed to install debugger, error message:${error.message}`));
76
+ return Promise.reject(new Error(`Failed to install debugger, error message:${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}`));
93
77
  }
94
78
  });
95
79
  }
@@ -122,21 +106,14 @@ class DeviceUtil {
122
106
  }
123
107
  }
124
108
  if (ip.length === 0) {
125
- ColorConsole_1.default.log({
126
- message: `Since no ip address is entered, the connected device will be connected`
127
- });
109
+ ColorConsole_1.default.log(`Since no ip address is entered, the connected device will be connected`);
128
110
  return Promise.resolve();
129
111
  }
130
112
  const ips = ip.trim().split(',');
131
113
  const invalidIps = ips.filter((ip) => !this.ipRegExp.test(ip));
132
114
  if (invalidIps && invalidIps.length) {
133
115
  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();
116
+ ColorConsole_1.default.throw(`ip: `, { word: ip, style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw) }, ` is invalid IP`);
140
117
  });
141
118
  }
142
119
  else {
@@ -147,26 +124,16 @@ class DeviceUtil {
147
124
  });
148
125
  return AdbUtils_1.default.connect(ip, devicePort)
149
126
  .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
- });
127
+ ColorConsole_1.default.success(`wifi connection ip: The device with ip of "${ip}" succeeded`);
154
128
  return Promise.resolve();
155
129
  })
156
130
  .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();
131
+ ColorConsole_1.default.throw(`${err}`);
163
132
  });
164
133
  }));
165
134
  return Promise.all(newDeviceListPromiseArray)
166
135
  .then(() => {
167
- ColorConsole_1.default.log({
168
- message: 'All new WIFI devices are connected'
169
- });
136
+ ColorConsole_1.default.log(`All new WIFI devices are connected`);
170
137
  return Promise.resolve();
171
138
  })
172
139
  .catch(() => {
@@ -187,10 +154,7 @@ class DeviceUtil {
187
154
  static queryDevice(deviceList, orderText = '') {
188
155
  return __awaiter(this, void 0, void 0, function* () {
189
156
  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
- });
157
+ ColorConsole_1.default.throw(`No device is connected yet, please confirm and try again`);
194
158
  return;
195
159
  }
196
160
  const ALL_TEXT = 'All connected devices';
@@ -228,29 +192,20 @@ class DeviceUtil {
228
192
  const apkPath = path_1.default.join(__dirname, './apk/', fileName);
229
193
  if (fs_1.default.existsSync(apkPath)) {
230
194
  // apk已下载
231
- ColorConsole_1.default.log({
232
- message: 'The installation package has been downloaded, now use the cache file to install'
233
- });
195
+ ColorConsole_1.default.log(`The installation package has been downloaded, now use the cache file to install`);
234
196
  return apkPath;
235
197
  }
236
198
  else {
237
199
  try {
238
200
  const result = yield RequestUtils_1.default.downloadFile(url, fileName);
239
201
  // 打印出成功信息
240
- ColorConsole_1.default.log({
241
- message: `Success to download, ${result}`,
242
- level: shared_utils_1.LOG_LEVEL.Success
243
- });
202
+ ColorConsole_1.default.success(`Success to download, ${result}`);
244
203
  return apkPath;
245
204
  }
246
205
  catch (error) {
247
206
  // 打印出错误
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();
207
+ ColorConsole_1.default.throw(`Failed to download the installation package, ${error}`);
208
+ return '';
254
209
  }
255
210
  }
256
211
  });
@@ -272,11 +227,7 @@ class DeviceUtil {
272
227
  let countTime = 0;
273
228
  let data;
274
229
  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
- });
230
+ ColorConsole_1.default.error(`Error when the device gets running platforms,request again after 3s delay`);
280
231
  return new Promise((resolve) => setTimeout(resolve, 3000));
281
232
  };
282
233
  const requestPlatform = () => __awaiter(this, void 0, void 0, function* () {
@@ -291,27 +242,17 @@ class DeviceUtil {
291
242
  const dataObj = JSON.parse(data);
292
243
  if (!dataObj.availablePlatforms) {
293
244
  // 请求结果不存在平台信息,报错,结束程序
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();
245
+ ColorConsole_1.default.throw(`The request result no avaliable platform `);
299
246
  }
300
247
  else {
301
248
  // 打印请求的平台信息
302
249
  const availablePlatforms = dataObj.availablePlatforms;
303
- ColorConsole_1.default.log({
304
- message: `The Quickapp engine list of device "${deviceSn}" is:${availablePlatforms.join(',')}`
305
- });
250
+ ColorConsole_1.default.log(`The Quickapp engine list of device "${deviceSn}" is:${availablePlatforms.join(',')}`);
306
251
  }
307
252
  }
308
253
  else {
309
254
  //请求失败,结束程序
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();
255
+ ColorConsole_1.default.throw(`The device gets running platforms error`);
315
256
  }
316
257
  });
317
258
  // 先打开调试器,才能获取运行平台
@@ -319,10 +260,7 @@ class DeviceUtil {
319
260
  yield requestPlatform();
320
261
  }
321
262
  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
- });
263
+ ColorConsole_1.default.throw(`Error getting the list of Quickapp engines on the device`);
326
264
  }
327
265
  });
328
266
  }
@@ -341,17 +279,10 @@ class DeviceUtil {
341
279
  const apkName = path_1.default.basename(apkPath);
342
280
  return Promise.all(newDeviceListPromiseArray)
343
281
  .then(() => {
344
- ColorConsole_1.default.log({
345
- level: shared_utils_1.LOG_LEVEL.Success,
346
- message: `All devices installed ${apkName}`
347
- });
282
+ ColorConsole_1.default.success(`All devices installed ${apkName}`);
348
283
  })
349
284
  .catch(() => {
350
- ColorConsole_1.default.log({
351
- level: shared_utils_1.LOG_LEVEL.Error,
352
- message: `Installed ${apkName} failed`
353
- });
354
- process.exit();
285
+ ColorConsole_1.default.throw(`Installed ${apkName} failed`);
355
286
  });
356
287
  }
357
288
  catch (error) { }
@@ -1 +1 @@
1
- {"version":3,"sources":["utils/DeviceUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6DAAsD;AACtD,+FAAsE;AACtE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AAC,KAAK;oBACtB,OAAO,EAAE,2EACN,KAAe,CAAC,OACnB,EAAE;iBACH,CAAC,CAAA;aACH;QACH,CAAC;KAAA;IACD;;;;;OAKG;IACH,MAAM,CAAO,UAAU,CAAC,aAAuB,EAAE,EAAE,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"}
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,kBAAQ,CAAC,sBAAsB,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;gBAC3D,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;oBACzB,sBAAY,CAAC,IAAI,CAAC,8BAA8B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;oBACzE,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;iBACnC;qBAAM;oBACL,sBAAY,CAAC,KAAK,CAChB,iOAAiO,CAClO,CAAA;iBACF;YACH,CAAC,CAAC,CAAA;SACH;QAAC,OAAO,KAAK,EAAE;YACd,sBAAY,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAA;SACzE;IACH,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAO,gBAAgB,CAAC,OAA0B;;YACtD,IAAI;gBACF,MAAM,EAAE,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BACnD,CAAC,CAAC,CAAA;aACL;YAAC,OAAO,KAAK,EAAE,GAAE;QACpB,CAAC;KAAA;;AA5QM,mBAAQ,GACb,6FAA6F,CAAA;AACxF,sBAAW,GAAG,KAAK,CAAA;AACnB,uBAAY,GAAG,qEAAqE,CAAA;AA2Q7F,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.info(`Devices connected via adb: ${deviceList.join(', ')}.`)\n return Promise.resolve(deviceList)\n } else {\n ColorConsole.throw(\n `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 )\n }\n })\n } catch (error) {\n ColorConsole.throw('Error getting connection information of adb device')\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.throw('No device requires debugger or previewer installation')\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(\n `Failed to install debugger, error message:${error?.toString() || 'unknown error'}`\n )\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(`Since no ip address is entered, the connected device will be connected`)\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.throw(\n `ip: `,\n { word: ip, style: ColorConsole.getStyle(LOG_LEVEL.Throw) },\n ` is invalid IP`\n )\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.success(`wifi connection ip: The device with ip of \"${ip}\" succeeded`)\n return Promise.resolve()\n })\n .catch((err) => {\n ColorConsole.throw(`${err}`)\n })\n })\n return Promise.all(newDeviceListPromiseArray)\n .then(() => {\n ColorConsole.log(`All new WIFI devices are connected`)\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.throw(`No device is connected yet, please confirm and try again`)\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(\n options: IInstallApkAndDbg,\n isQuickAppDebugger: boolean\n ): Promise<string> {\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 `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.success(`Success to download, ${result}`)\n return apkPath\n } catch (error) {\n // 打印出错误\n ColorConsole.throw(`Failed to download the installation package, ${error}`)\n return ''\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.error(\n `Error when the device gets running platforms,request again after 3s delay`\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.throw(`The request result no avaliable platform `)\n } else {\n // 打印请求的平台信息\n const availablePlatforms = dataObj.availablePlatforms\n ColorConsole.log(\n `The Quickapp engine list of device \"${deviceSn}\" is:${availablePlatforms.join(',')}`\n )\n }\n } else {\n //请求失败,结束程序\n ColorConsole.throw(`The device gets running platforms error`)\n }\n }\n // 先打开调试器,才能获取运行平台\n await AdbUtils.startDebugger(deviceSn)\n await requestPlatform()\n } catch (error) {\n ColorConsole.throw(`Error getting the list of Quickapp engines on the device`)\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.success(`All devices installed ${apkName}`)\n })\n .catch(() => {\n ColorConsole.throw(`Installed ${apkName} failed`)\n })\n } catch (error) {}\n }\n}\nexport default DeviceUtil\n"],"sourceRoot":"../../src"}
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
15
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
17
16
  const axios_1 = __importDefault(require("axios"));
18
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -39,26 +38,16 @@ class RequestUtils {
39
38
  axios_1.default
40
39
  .post(requrl, options)
41
40
  .then((data) => {
42
- ColorConsole_1.default.log({
43
- message: `### App Server ### Request ${requrl} succeeded`
44
- });
41
+ ColorConsole_1.default.log(`### App Server ### Request ${requrl} succeeded`);
45
42
  resolve(data.toString());
46
43
  })
47
44
  .catch((error) => {
48
45
  if (error.respose && error.response.status === 408) {
49
46
  // 超时处理
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
- });
47
+ ColorConsole_1.default.error(`### App Server ### Request ${requrl} timed out, please try again`);
55
48
  }
56
49
  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
- });
50
+ ColorConsole_1.default.error(`### App Server ### Request ${requrl} error message: ${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}`);
62
51
  }
63
52
  });
64
53
  });
@@ -67,9 +56,7 @@ class RequestUtils {
67
56
  static downloadFile(url, fileName) {
68
57
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
69
58
  // 开始下载
70
- ColorConsole_1.default.log({
71
- message: `Start downloading file:${fileName}, address:${url}`
72
- });
59
+ ColorConsole_1.default.log(`Start downloading file:${fileName}, address:${url}`);
73
60
  const response = yield axios_1.default.get(url, {
74
61
  responseType: 'arraybuffer'
75
62
  });
@@ -1 +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;iBACd,CAAA;gBACD,IAAI,MAAM,EAAE;oBACV,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE;wBACnC,OAAO,EAAE,MAAM;qBAChB,CAAC,CAAA;iBACH;gBACD,eAAK;qBACF,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;qBACrB,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;oBACb,sBAAY,CAAC,GAAG,CAAC;wBACf,OAAO,EAAE,8BAA8B,MAAM,YAAY;qBAC1D,CAAC,CAAA;oBACF,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;gBAC1B,CAAC,CA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AAiB,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"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EAAE,KAAI,eACvB,EAAE,CACH,CAAA;qBACF;gBACH,CAAC,CAAC,CAAA;YACN,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;IACD,MAAM,CAAC,YAAY,CAAC,GAAW,EAAE,QAAgB;QAC/C,OAAO,IAAI,OAAO,CAAC,CAAO,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,OAAO;YACP,sBAAY,CAAC,GAAG,CAAC,0BAA0B,QAAQ,aAAa,GAAG,EAAE,CAAC,CAAA;YACtE,MAAM,QAAQ,GAAG,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 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(`### App Server ### Request ${requrl} succeeded`)\n resolve(data.toString())\n })\n .catch((error) => {\n if (error.respose && error.response.status === 408) {\n // 超时处理\n ColorConsole.error(`### App Server ### Request ${requrl} timed out, please try again`)\n } else {\n ColorConsole.error(\n `### App Server ### Request ${requrl} error message: ${\n error?.toString() || 'unknown error'\n }`\n )\n }\n })\n })\n }\n static downloadFile(url: string, fileName: string) {\n return new Promise(async (resolve, reject) => {\n // 开始下载\n ColorConsole.log(`Start downloading file:${fileName}, address:${url}`)\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"}
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const emulator_1 = require("@aiot-toolkit/emulator");
16
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
+ const utils_1 = require("@aiot-toolkit/emulator/lib/utils");
17
17
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
18
18
  const prompts_1 = require("@inquirer/prompts");
19
19
  const adm_zip_1 = __importDefault(require("adm-zip"));
@@ -68,11 +68,7 @@ class VelaAvdUtils {
68
68
  });
69
69
  }
70
70
  catch (e) {
71
- ColorConsole_1.default.log({
72
- level: shared_utils_1.LOG_LEVEL.Error,
73
- message: `download ${filename} failed`
74
- });
75
- progress.stop();
71
+ ColorConsole_1.default.throw(`Download ${filename} failed`);
76
72
  reject();
77
73
  }
78
74
  }));
@@ -107,24 +103,8 @@ class VelaAvdUtils {
107
103
  /** 根据host获取模拟器下载地址 */
108
104
  static getEmulatorUrl(version = '0.0.1') {
109
105
  const systemOs = os_1.default.platform();
110
- const arch = os_1.default.arch();
111
- let hostOs = '';
112
- let hostArch = '';
113
- switch (systemOs) {
114
- case 'linux':
115
- hostOs = 'linux';
116
- hostArch = arch === 'x64' ? 'x86_64' : 'aarch64';
117
- break;
118
- case 'win32':
119
- hostOs = 'windows';
120
- hostArch = arch === 'x64' ? 'x86_64' : 'aarch64';
121
- break;
122
- case 'darwin':
123
- hostOs = 'darwin';
124
- hostArch = arch === 'x64' ? 'x86_64' : 'aarch64';
125
- default:
126
- break;
127
- }
106
+ const hostArch = (0, utils_1.getSystemArch)();
107
+ let hostOs = systemOs === 'win32' ? 'windows' : systemOs;
128
108
  return `${VelaAvdUtils.emulatorBaseUrl}/v${version}/${hostOs}-${hostArch}.zip`;
129
109
  }
130
110
  /** 根据host获取vela镜像下载地址 */
@@ -134,17 +114,17 @@ class VelaAvdUtils {
134
114
  /** 根据host获取ya-vm-file-server下载地址 */
135
115
  static getv9fsToolUrl(version = '0.0.1') {
136
116
  const systemOs = os_1.default.platform();
137
- const arch = os_1.default.arch();
117
+ const arch = (0, utils_1.getSystemArch)();
138
118
  let v9fsTool = '';
139
119
  switch (systemOs) {
140
120
  case 'linux':
141
- v9fsTool = 'ya-vm-file-server-linux-x86_64';
121
+ v9fsTool = `ya-vm-file-server-linux-${arch}`;
142
122
  break;
143
123
  case 'win32':
144
124
  v9fsTool = 'ya-vm-file-server-windows.exe';
145
125
  break;
146
126
  case 'darwin':
147
- v9fsTool = (arch === 'x64') ? 'ya-vm-file-server-darwin-x84_64' : 'ya-vm-file-server-darwin-aarch64';
127
+ v9fsTool = `ya-vm-file-server-darwin-${arch}`;
148
128
  default:
149
129
  break;
150
130
  }
@@ -192,10 +172,7 @@ class VelaAvdUtils {
192
172
  if (!skinExists || (versionInfo && versionInfo.skins < onlineVersionInfo.skins)) {
193
173
  const skinsUrl = VelaAvdUtils.getDownloadUrl('skins', onlineVersionInfo.skins);
194
174
  yield VelaAvdUtils.downloadAndUnzip(skinsUrl, path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
195
- ColorConsole_1.default.log({
196
- level: shared_utils_1.LOG_LEVEL.Success,
197
- message: `download skins succeed.`
198
- });
175
+ ColorConsole_1.default.success(`Download skins succeed.`);
199
176
  }
200
177
  const skinList = VelaAvdUtils.velaAvdCls.getVelaSkinList();
201
178
  avdSkin = yield (0, prompts_1.select)({
@@ -230,10 +207,7 @@ class VelaAvdUtils {
230
207
  if (!emulatorExists || (versionInfo && versionInfo.emulator < onlineVersionInfo.emulator)) {
231
208
  const emulatorDownloadUrl = VelaAvdUtils.getEmulatorUrl(onlineVersionInfo.emulator);
232
209
  yield VelaAvdUtils.downloadAndUnzip(emulatorDownloadUrl, emulatorDir);
233
- ColorConsole_1.default.log({
234
- level: shared_utils_1.LOG_LEVEL.Success,
235
- message: `download emulator succeed.`
236
- });
210
+ ColorConsole_1.default.success(`Download emulator succeed.`);
237
211
  }
238
212
  // 下载镜像
239
213
  const velaImageDownloadUrl = this.getSystemImageUrl(onlineVersionInfo['system-images'], avdArch);
@@ -242,10 +216,7 @@ class VelaAvdUtils {
242
216
  if (!imageExists ||
243
217
  (versionInfo && versionInfo['system-images'] < onlineVersionInfo['system-images'])) {
244
218
  yield VelaAvdUtils.downloadFromCdn(velaImageDownloadUrl, imageDir, 'nuttx');
245
- ColorConsole_1.default.log({
246
- level: shared_utils_1.LOG_LEVEL.Success,
247
- message: `download vela image succeed.`
248
- });
219
+ ColorConsole_1.default.success(`Download vela image succeed.`);
249
220
  }
250
221
  // 下载快应用qa文件
251
222
  const qaDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'qa');
@@ -253,22 +224,16 @@ class VelaAvdUtils {
253
224
  if (!qaExists || (versionInfo && versionInfo.qa < onlineVersionInfo.qa)) {
254
225
  const qaUrl = VelaAvdUtils.getDownloadUrl('qa', onlineVersionInfo.qa);
255
226
  yield VelaAvdUtils.downloadAndUnzip(qaUrl, qaDir);
256
- ColorConsole_1.default.log({
257
- level: shared_utils_1.LOG_LEVEL.Success,
258
- message: `download quickapp font succeed.`
259
- });
227
+ ColorConsole_1.default.success(`Download quickapp font succeed.`);
260
228
  }
261
229
  // 下载tools
262
230
  const toolsDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'tools');
263
231
  const toolsExists = fs_extra_1.default.existsSync(toolsDir);
264
232
  if (!toolsExists || (versionInfo && versionInfo.tools < onlineVersionInfo.tools)) {
265
233
  const v9fsToolUrl = VelaAvdUtils.getv9fsToolUrl();
266
- const filename = (os_1.default.platform() === 'win32') ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
234
+ const filename = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
267
235
  yield VelaAvdUtils.downloadFromCdn(v9fsToolUrl, toolsDir, filename);
268
- ColorConsole_1.default.log({
269
- level: shared_utils_1.LOG_LEVEL.Success,
270
- message: `download tools succeed.`
271
- });
236
+ ColorConsole_1.default.success(`Download tools succeed.`);
272
237
  }
273
238
  // 替换version.json
274
239
  if (versionFileExist) {
@@ -279,16 +244,10 @@ class VelaAvdUtils {
279
244
  const avdImagePath = imageDir;
280
245
  const avdParams = { avdName, avdSkin, avdWidth, avdHeight, avdArch, avdImagePath };
281
246
  VelaAvdUtils.velaAvdCls.createVelaAvd(avdParams);
282
- ColorConsole_1.default.log({
283
- level: shared_utils_1.LOG_LEVEL.Success,
284
- message: `create avd succeed.`
285
- });
247
+ ColorConsole_1.default.success(`Create avd succeed.`);
286
248
  }
287
249
  catch (e) {
288
- ColorConsole_1.default.log({
289
- level: shared_utils_1.LOG_LEVEL.Error,
290
- message: `create avd failed. Error: ${e.message}`
291
- });
250
+ ColorConsole_1.default.throw(`Create avd failed. Error: ${e.message}`);
292
251
  }
293
252
  });
294
253
  }