aiot-toolkit 2.0.2-beta.10 → 2.0.2-beta.12

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.
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Copyright (C) 2017, hapjs.org. All rights reserved.
3
+ */
4
+
5
+ const $ = (selector, elem) => {
6
+ return typeof elem === 'undefined'
7
+ ? document.querySelector(selector)
8
+ : elem.querySelector(selector)
9
+ }
10
+
11
+ function init() {
12
+ const qrImgId = '#j-qr-icon'
13
+ const $qrCodeImg = $(qrImgId)
14
+ const timeStamp = Date.now() % 1e5
15
+ $qrCodeImg.src = `/qrcode?ws_id=${timeStamp}`
16
+ bindEvents()
17
+ }
18
+
19
+ function bindEvents() {
20
+ const socket = io(location.origin) // eslint-disable-line no-undef
21
+
22
+ socket.on('appRegistered', (data) => {
23
+ console.info(`on receiving appRegistered message: ${JSON.stringify(data)}`)
24
+ updateTableElement(data)
25
+ })
26
+ socket.on('informUpdate', () => {
27
+ console.info('on receiving informUpdate')
28
+ appendUpdateInfo()
29
+ })
30
+ }
31
+
32
+ /**
33
+ * 更新页面调试信息
34
+ * @param data{ inspectorUrl, application }
35
+ */
36
+ function updateTableElement(data) {
37
+ const wrapper = '.inspector-link-panel'
38
+ const tplId = '#j-tpl-appinfo'
39
+ const $panelWrapper = $(wrapper)
40
+ const $tplAppInfoElem = $(tplId)
41
+ const $tbodyElem = $('tbody', $panelWrapper)
42
+ let tplTextContent = $tplAppInfoElem.textContent
43
+
44
+ $panelWrapper.classList.add('hide')
45
+ const dataToFill = {
46
+ data_app_name: data.application,
47
+ data_href_value: data.inspectorUrl,
48
+ data_href_name: 'Enter the debug page'
49
+ }
50
+ Object.keys(dataToFill).forEach((key) => {
51
+ tplTextContent = tplTextContent.replace(`{{${key}}}`, dataToFill[key])
52
+ })
53
+
54
+ $tbodyElem.innerHTML = tplTextContent
55
+ $panelWrapper.classList.remove('hide')
56
+ }
57
+
58
+ function appendUpdateInfo() {
59
+ const tplId = '#j-tpl-updatetip'
60
+ const wrapper = '.inform-tip-wrapper'
61
+ const $tplUpdateTipElem = $(tplId)
62
+ const $panelWrapper = $(wrapper)
63
+ $panelWrapper.innerHTML = $tplUpdateTipElem.textContent
64
+ }
65
+
66
+ init()
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
38
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
39
39
  const adbMiwt = __importStar(require("@miwt/adb"));
40
40
  const adb_commander_1 = __importDefault(require("adb-commander"));
41
41
  /**
@@ -76,12 +76,12 @@ class AdbUtils {
76
76
  const adbShell = adbMiwt.execAdbCmd(`adb -s ${deviceSn} shell am start -n "org.hapjs.debugger/.MainActivity"`);
77
77
  adbShell.stdout.on('data', (data) => {
78
78
  // 监听stderr事件,获取输出内容
79
- ColorConsole_1.default.log(`### startDebugger ### ${data}`);
79
+ shared_utils_1.ColorConsole.log(`### startDebugger ### ${data}`);
80
80
  });
81
81
  adbShell.stderr.on('data', (data) => {
82
82
  // 监听stderr事件,获取输出内容
83
83
  if (data.indexOf('Error') >= 0) {
84
- ColorConsole_1.default.throw(`### startDebugger ### ${data}`);
84
+ shared_utils_1.ColorConsole.throw(`### startDebugger ### ${data}`);
85
85
  }
86
86
  });
87
87
  adbShell.on('close', () => {
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
17
16
  const prompts_1 = require("@inquirer/prompts");
18
17
  const fs_1 = __importDefault(require("fs"));
19
18
  const path_1 = __importDefault(require("path"));
@@ -31,16 +30,16 @@ class DeviceUtil {
31
30
  try {
32
31
  return AdbUtils_1.default.getAllConnectedDevices().then((deviceList) => {
33
32
  if (deviceList.length > 0) {
34
- ColorConsole_1.default.info(`Devices connected via adb: ${deviceList.join(', ')}.`);
33
+ shared_utils_1.ColorConsole.info(`Devices connected via adb: ${deviceList.join(', ')}.`);
35
34
  return Promise.resolve(deviceList);
36
35
  }
37
36
  else {
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;`);
37
+ shared_utils_1.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;`);
39
38
  }
40
39
  });
41
40
  }
42
41
  catch (error) {
43
- ColorConsole_1.default.throw('Error getting connection information of adb device');
42
+ shared_utils_1.ColorConsole.throw('Error getting connection information of adb device');
44
43
  }
45
44
  }
46
45
  /**
@@ -62,8 +61,10 @@ class DeviceUtil {
62
61
  : [];
63
62
  connectDeviceList = finalDeviceList ? [...finalDeviceList] : [];
64
63
  // 若connectDeviceList为空,应该warn并结束程序
65
- connectDeviceList.length <= 0 &&
66
- ColorConsole_1.default.throw('No device requires debugger or previewer installation');
64
+ if (connectDeviceList.length <= 0) {
65
+ shared_utils_1.ColorConsole.throw({ word: 'No device' }, 'requires debugger or previewer installation');
66
+ return Promise.reject(new Error(`No device requires debugger or previewer installation`));
67
+ }
67
68
  // 3. 下载并获取调试器、预览器地址
68
69
  const debuggerPath = yield this.downloadApk(options, true);
69
70
  const previewPath = yield this.downloadApk(options, false);
@@ -73,7 +74,7 @@ class DeviceUtil {
73
74
  return Promise.resolve('All devices successfully installed the Quickapp debugger and previewer');
74
75
  }
75
76
  catch (error) {
76
- return Promise.reject(new Error(`Failed to install debugger, error message:${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}`));
77
+ return Promise.reject(new Error(`Failed to install , error message:${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}`));
77
78
  }
78
79
  });
79
80
  }
@@ -106,14 +107,14 @@ class DeviceUtil {
106
107
  }
107
108
  }
108
109
  if (ip.length === 0) {
109
- ColorConsole_1.default.log(`Since no ip address is entered, the connected device will be connected`);
110
+ shared_utils_1.ColorConsole.log(`Since no ip address is entered, the connected device will be connected`);
110
111
  return Promise.resolve();
111
112
  }
112
113
  const ips = ip.trim().split(',');
113
114
  const invalidIps = ips.filter((ip) => !this.ipRegExp.test(ip));
114
115
  if (invalidIps && invalidIps.length) {
115
116
  invalidIps.map((ip) => {
116
- ColorConsole_1.default.throw(`ip: `, { word: ip, style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw) }, ` is invalid IP`);
117
+ shared_utils_1.ColorConsole.throw(`ip: `, { word: ip, style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.THROW) }, ` is invalid IP`);
117
118
  });
118
119
  }
119
120
  else {
@@ -124,16 +125,16 @@ class DeviceUtil {
124
125
  });
125
126
  return AdbUtils_1.default.connect(ip, devicePort)
126
127
  .then(() => {
127
- ColorConsole_1.default.success(`wifi connection ip: The device with ip of "${ip}" succeeded`);
128
+ shared_utils_1.ColorConsole.success(`wifi connection ip: The device with ip of "${ip}" succeeded`);
128
129
  return Promise.resolve();
129
130
  })
130
131
  .catch((err) => {
131
- ColorConsole_1.default.throw(`${err}`);
132
+ shared_utils_1.ColorConsole.throw(`${err}`);
132
133
  });
133
134
  }));
134
135
  return Promise.all(newDeviceListPromiseArray)
135
136
  .then(() => {
136
- ColorConsole_1.default.log(`All new WIFI devices are connected`);
137
+ shared_utils_1.ColorConsole.log(`All new WIFI devices are connected`);
137
138
  return Promise.resolve();
138
139
  })
139
140
  .catch(() => {
@@ -154,7 +155,7 @@ class DeviceUtil {
154
155
  static queryDevice(deviceList, orderText = '') {
155
156
  return __awaiter(this, void 0, void 0, function* () {
156
157
  if (!deviceList || deviceList.length === 0) {
157
- ColorConsole_1.default.throw(`No device is connected yet, please confirm and try again`);
158
+ shared_utils_1.ColorConsole.throw(`No device is connected yet, please confirm and try again`);
158
159
  return;
159
160
  }
160
161
  const ALL_TEXT = 'All connected devices';
@@ -192,19 +193,19 @@ class DeviceUtil {
192
193
  const apkPath = path_1.default.join(__dirname, './apk/', fileName);
193
194
  if (fs_1.default.existsSync(apkPath)) {
194
195
  // apk已下载
195
- ColorConsole_1.default.log(`The installation package has been downloaded, now use the cache file to install`);
196
+ shared_utils_1.ColorConsole.log(`The installation package has been downloaded, now use the cache file to install`);
196
197
  return apkPath;
197
198
  }
198
199
  else {
199
200
  try {
200
201
  const result = yield RequestUtils_1.default.downloadFile(url, fileName);
201
202
  // 打印出成功信息
202
- ColorConsole_1.default.success(`Success to download, ${result}`);
203
+ shared_utils_1.ColorConsole.success(`Success to download, ${result}`);
203
204
  return apkPath;
204
205
  }
205
206
  catch (error) {
206
207
  // 打印出错误
207
- ColorConsole_1.default.throw(`Failed to download the installation package, ${error}`);
208
+ shared_utils_1.ColorConsole.throw(`Failed to download the installation package, ${error}`);
208
209
  return '';
209
210
  }
210
211
  }
@@ -227,7 +228,7 @@ class DeviceUtil {
227
228
  let countTime = 0;
228
229
  let data;
229
230
  const sleep = () => {
230
- ColorConsole_1.default.error(`Error when the device gets running platforms,request again after 3s delay`);
231
+ shared_utils_1.ColorConsole.error(`Error when the device gets running platforms,request again after 3s delay`);
231
232
  return new Promise((resolve) => setTimeout(resolve, 3000));
232
233
  };
233
234
  const requestPlatform = () => __awaiter(this, void 0, void 0, function* () {
@@ -242,17 +243,17 @@ class DeviceUtil {
242
243
  const dataObj = JSON.parse(data);
243
244
  if (!dataObj.availablePlatforms) {
244
245
  // 请求结果不存在平台信息,报错,结束程序
245
- ColorConsole_1.default.throw(`The request result no avaliable platform `);
246
+ shared_utils_1.ColorConsole.throw(`The request result no avaliable platform `);
246
247
  }
247
248
  else {
248
249
  // 打印请求的平台信息
249
250
  const availablePlatforms = dataObj.availablePlatforms;
250
- ColorConsole_1.default.log(`The Quickapp engine list of device "${deviceSn}" is:${availablePlatforms.join(',')}`);
251
+ shared_utils_1.ColorConsole.log(`The Quickapp engine list of device "${deviceSn}" is:${availablePlatforms.join(',')}`);
251
252
  }
252
253
  }
253
254
  else {
254
255
  //请求失败,结束程序
255
- ColorConsole_1.default.throw(`The device gets running platforms error`);
256
+ shared_utils_1.ColorConsole.throw(`The device gets running platforms error`);
256
257
  }
257
258
  });
258
259
  // 先打开调试器,才能获取运行平台
@@ -260,7 +261,7 @@ class DeviceUtil {
260
261
  yield requestPlatform();
261
262
  }
262
263
  catch (error) {
263
- ColorConsole_1.default.throw(`Error getting the list of Quickapp engines on the device`);
264
+ shared_utils_1.ColorConsole.throw(`Error getting the list of Quickapp engines on the device`);
264
265
  }
265
266
  });
266
267
  }
@@ -278,11 +279,23 @@ class DeviceUtil {
278
279
  });
279
280
  const apkName = path_1.default.basename(apkPath);
280
281
  return Promise.all(newDeviceListPromiseArray)
281
- .then(() => {
282
- ColorConsole_1.default.success(`All devices installed ${apkName}`);
282
+ .then((results) => {
283
+ let statusAll = true;
284
+ results.forEach((res) => {
285
+ if (!res.status) {
286
+ shared_utils_1.ColorConsole.error(res.msg);
287
+ statusAll = false;
288
+ }
289
+ });
290
+ if (statusAll) {
291
+ shared_utils_1.ColorConsole.success(`All devices installed ${apkName}`);
292
+ }
293
+ else {
294
+ // TODO 后续从这里抛出异常
295
+ }
283
296
  })
284
297
  .catch(() => {
285
- ColorConsole_1.default.throw(`Installed ${apkName} failed`);
298
+ shared_utils_1.ColorConsole.throw(`Installed ${apkName} failed`);
286
299
  });
287
300
  }
288
301
  catch (error) { }
@@ -12,7 +12,7 @@ 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 ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
15
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
16
  const axios_1 = __importDefault(require("axios"));
17
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
18
18
  const path_1 = __importDefault(require("path"));
@@ -38,16 +38,16 @@ class RequestUtils {
38
38
  axios_1.default
39
39
  .post(requrl, options)
40
40
  .then((data) => {
41
- ColorConsole_1.default.log(`### App Server ### Request ${requrl} succeeded`);
41
+ shared_utils_1.ColorConsole.log(`### App Server ### Request ${requrl} succeeded`);
42
42
  resolve(data.toString());
43
43
  })
44
44
  .catch((error) => {
45
45
  if (error.respose && error.response.status === 408) {
46
46
  // 超时处理
47
- ColorConsole_1.default.error(`### App Server ### Request ${requrl} timed out, please try again`);
47
+ shared_utils_1.ColorConsole.error(`### App Server ### Request ${requrl} timed out, please try again`);
48
48
  }
49
49
  else {
50
- ColorConsole_1.default.error(`### App Server ### Request ${requrl} error message: ${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}`);
50
+ shared_utils_1.ColorConsole.error(`### App Server ### Request ${requrl} error message: ${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}`);
51
51
  }
52
52
  });
53
53
  });
@@ -56,7 +56,7 @@ class RequestUtils {
56
56
  static downloadFile(url, fileName) {
57
57
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
58
58
  // 开始下载
59
- ColorConsole_1.default.log(`Start downloading file:${fileName}, address:${url}`);
59
+ shared_utils_1.ColorConsole.log(`Start downloading file:${fileName}, address:${url}`);
60
60
  const response = yield axios_1.default.get(url, {
61
61
  responseType: 'arraybuffer'
62
62
  });
@@ -13,17 +13,15 @@ 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 constants_1 = require("@aiot-toolkit/emulator/lib/static/constants");
17
- const utils_1 = require("@aiot-toolkit/emulator/lib/utils");
18
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
16
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
19
17
  const prompts_1 = require("@inquirer/prompts");
20
18
  const adm_zip_1 = __importDefault(require("adm-zip"));
21
19
  const axios_1 = __importDefault(require("axios"));
22
20
  const cli_progress_1 = __importDefault(require("cli-progress"));
21
+ const dayjs_1 = __importDefault(require("dayjs"));
23
22
  const fs_extra_1 = __importDefault(require("fs-extra"));
24
23
  const os_1 = __importDefault(require("os"));
25
24
  const path_1 = __importDefault(require("path"));
26
- const dayjs_1 = __importDefault(require("dayjs"));
27
25
  class VelaAvdUtils {
28
26
  /** 校验AVD名称 */
29
27
  static validateAvdName(avdName) {
@@ -71,7 +69,7 @@ class VelaAvdUtils {
71
69
  });
72
70
  }
73
71
  catch (e) {
74
- ColorConsole_1.default.throw(`Download ${filename} failed`);
72
+ shared_utils_1.ColorConsole.throw(`Download ${filename} failed`);
75
73
  reject();
76
74
  }
77
75
  }));
@@ -106,14 +104,14 @@ class VelaAvdUtils {
106
104
  /** 根据host获取模拟器下载地址 */
107
105
  static getEmulatorUrl(version = '0.0.1') {
108
106
  const systemOs = os_1.default.platform();
109
- const hostArch = (0, utils_1.getSystemArch)();
107
+ const hostArch = (0, emulator_1.getSystemArch)();
110
108
  let hostOs = systemOs === 'win32' ? 'windows' : systemOs;
111
109
  return `${VelaAvdUtils.emulatorBaseUrl}/v${version}/${hostOs}-${hostArch}.zip`;
112
110
  }
113
111
  /** 获取模拟器平台的名称,darwin-aarch64 linux-aarch64 windows-x86_64等 */
114
112
  static getEmulatorPlatform() {
115
113
  const systemOs = os_1.default.platform();
116
- const hostArch = (0, utils_1.getSystemArch)();
114
+ const hostArch = (0, emulator_1.getSystemArch)();
117
115
  const hostOs = systemOs === 'win32' ? 'windows' : systemOs;
118
116
  return `${hostOs}-${hostArch}`;
119
117
  }
@@ -136,7 +134,7 @@ class VelaAvdUtils {
136
134
  }
137
135
  if (VelaAvdUtils.isZipInImageUrl(imageId)) {
138
136
  const stats = fs_extra_1.default.statSync(avdImagePath);
139
- const version = constants_1.VelaImageVersionList.find((item) => item.value === imageId);
137
+ const version = emulator_1.VelaImageVersionList.find((item) => item.value === imageId);
140
138
  if (version && (0, dayjs_1.default)(version.time).isAfter(stats.mtime, 'day'))
141
139
  return true;
142
140
  }
@@ -154,7 +152,7 @@ class VelaAvdUtils {
154
152
  /** 获取vela镜像的下载地址 */
155
153
  static getSystemImageUrl(version = 'vela-release-4.0') {
156
154
  if (VelaAvdUtils.isZipInImageUrl(version)) {
157
- const velaImage = constants_1.VelaImageVersionList.find((item) => item.value = version);
155
+ const velaImage = emulator_1.VelaImageVersionList.find((item) => item.value === version);
158
156
  const dayOfTime = (0, dayjs_1.default)(velaImage === null || velaImage === void 0 ? void 0 : velaImage.time).format('YYYYMMDD');
159
157
  return `${VelaAvdUtils.systemImageBaseUrl}/${version}/${dayOfTime}/${version}.zip`;
160
158
  }
@@ -167,7 +165,7 @@ class VelaAvdUtils {
167
165
  /** 根据host获取ya-vm-file-server下载地址 */
168
166
  static getv9fsToolUrl(version = '0.0.1') {
169
167
  const systemOs = os_1.default.platform();
170
- const arch = (0, utils_1.getSystemArch)();
168
+ const arch = (0, emulator_1.getSystemArch)();
171
169
  let v9fsTool = '';
172
170
  switch (systemOs) {
173
171
  case 'linux':
@@ -196,7 +194,7 @@ class VelaAvdUtils {
196
194
  return stats.mtime;
197
195
  }
198
196
  else {
199
- const time = (_a = constants_1.VelaImageVersionList.find((item) => item.value === imageId)) === null || _a === void 0 ? void 0 : _a.time;
197
+ const time = (_a = emulator_1.VelaImageVersionList.find((item) => item.value === imageId)) === null || _a === void 0 ? void 0 : _a.time;
200
198
  return time;
201
199
  }
202
200
  }
@@ -221,7 +219,7 @@ class VelaAvdUtils {
221
219
  if (versionFileExist) {
222
220
  currVersionInfo = fs_extra_1.default.readJSONSync(versionFile);
223
221
  }
224
- const onlineVersionInfo = constants_1.EmulatorEnvVersion;
222
+ const onlineVersionInfo = emulator_1.EmulatorEnvVersion;
225
223
  // 模拟器各项资源(除了镜像)是否存在
226
224
  const emulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'emulator', VelaAvdUtils.getEmulatorPlatform()));
227
225
  const qaExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'qa/font'));
@@ -238,12 +236,12 @@ class VelaAvdUtils {
238
236
  }
239
237
  });
240
238
  // 镜像
241
- const velaImage = (yield (0, prompts_1.select)({
239
+ const velaImage = yield (0, prompts_1.select)({
242
240
  message: 'vela image.',
243
- choices: constants_1.VelaImageVersionList.map((item) => {
241
+ choices: emulator_1.VelaImageVersionList.map((item) => {
244
242
  return { value: item.value, name: item.label };
245
243
  })
246
- }));
244
+ });
247
245
  // skin或者size
248
246
  let avdSkin = '';
249
247
  let avdWidth = '466';
@@ -258,8 +256,8 @@ class VelaAvdUtils {
258
256
  if (!skinsExist || (currVersionInfo && currVersionInfo.skins < onlineVersionInfo.skins)) {
259
257
  const skinsUrl = VelaAvdUtils.getDownloadUrl('skins', onlineVersionInfo.skins);
260
258
  yield VelaAvdUtils.downloadAndUnzip(skinsUrl, path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
261
- currVersionInfo.skins = constants_1.EmulatorEnvVersion.skins;
262
- ColorConsole_1.default.success(`Download skins succeed.`);
259
+ currVersionInfo.skins = emulator_1.EmulatorEnvVersion.skins;
260
+ shared_utils_1.ColorConsole.success(`Download skins succeed.`);
263
261
  }
264
262
  const skinList = VelaAvdUtils.velaAvdCls.getVelaSkinList();
265
263
  avdSkin = yield (0, prompts_1.select)({
@@ -285,11 +283,12 @@ class VelaAvdUtils {
285
283
  }
286
284
  }
287
285
  // 下载模拟器
288
- if (!emulatorExist || (currVersionInfo && currVersionInfo.emulator < onlineVersionInfo.emulator)) {
286
+ if (!emulatorExist ||
287
+ (currVersionInfo && currVersionInfo.emulator < onlineVersionInfo.emulator)) {
289
288
  const emulatorDownloadUrl = VelaAvdUtils.getEmulatorUrl(onlineVersionInfo.emulator);
290
289
  yield VelaAvdUtils.downloadAndUnzip(emulatorDownloadUrl, VelaAvdUtils.getEmulatorEnvHome('emulator'));
291
- currVersionInfo.emulator = constants_1.EmulatorEnvVersion.emulator;
292
- ColorConsole_1.default.success(`Download emulator succeed.`);
290
+ currVersionInfo.emulator = emulator_1.EmulatorEnvVersion.emulator;
291
+ shared_utils_1.ColorConsole.success(`Download emulator succeed.`);
293
292
  }
294
293
  // 下载镜像
295
294
  const imageDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', velaImage);
@@ -297,43 +296,51 @@ class VelaAvdUtils {
297
296
  const velaImageDownloadUrl = this.getSystemImageUrl(velaImage);
298
297
  if (VelaAvdUtils.isZipInImageUrl(velaImage)) {
299
298
  yield VelaAvdUtils.downloadAndUnzip(velaImageDownloadUrl, imageDir);
300
- currVersionInfo['system-images'] = constants_1.EmulatorEnvVersion['system-images'];
299
+ currVersionInfo['system-images'] = emulator_1.EmulatorEnvVersion['system-images'];
301
300
  }
302
301
  else {
303
302
  yield VelaAvdUtils.downloadFromCdn(velaImageDownloadUrl, imageDir, 'nuttx');
304
303
  }
305
- ColorConsole_1.default.success(`Download vela image succeed.`);
304
+ shared_utils_1.ColorConsole.success(`Download vela image succeed.`);
306
305
  }
307
306
  // 下载快应用qa文件
308
307
  if (!qaExist || (currVersionInfo && currVersionInfo.qa < onlineVersionInfo.qa)) {
309
308
  const qaUrl = VelaAvdUtils.getDownloadUrl('qa', onlineVersionInfo.qa);
310
309
  yield VelaAvdUtils.downloadAndUnzip(qaUrl, VelaAvdUtils.getEmulatorEnvHome('qa'));
311
- currVersionInfo.qa = constants_1.EmulatorEnvVersion.qa;
312
- ColorConsole_1.default.success(`Download quickapp font succeed.`);
310
+ currVersionInfo.qa = emulator_1.EmulatorEnvVersion.qa;
311
+ shared_utils_1.ColorConsole.success(`Download quickapp font succeed.`);
313
312
  }
314
313
  // 下载tools
315
314
  if (!toolsExist || (currVersionInfo && currVersionInfo.tools < onlineVersionInfo.tools)) {
316
315
  const v9fsToolUrl = VelaAvdUtils.getv9fsToolUrl();
317
316
  const filename = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
318
317
  yield VelaAvdUtils.downloadFromCdn(v9fsToolUrl, VelaAvdUtils.getEmulatorEnvHome('tools'), filename);
319
- currVersionInfo.tools = constants_1.EmulatorEnvVersion.tools;
320
- ColorConsole_1.default.success(`Download tools succeed.`);
318
+ currVersionInfo.tools = emulator_1.EmulatorEnvVersion.tools;
319
+ shared_utils_1.ColorConsole.success(`Download tools succeed.`);
321
320
  }
322
321
  // 下载modem_simulator
323
- if (!modemSimulatorExist || currVersionInfo.modem_simulator < constants_1.EmulatorEnvVersion.modem_simulator) {
324
- const modemSimulatorUrl = VelaAvdUtils.getDownloadUrl('modem_simulator', constants_1.EmulatorEnvVersion.modem_simulator);
322
+ if (!modemSimulatorExist ||
323
+ currVersionInfo.modem_simulator < emulator_1.EmulatorEnvVersion.modem_simulator) {
324
+ const modemSimulatorUrl = VelaAvdUtils.getDownloadUrl('modem_simulator', emulator_1.EmulatorEnvVersion.modem_simulator);
325
325
  yield VelaAvdUtils.downloadAndUnzip(modemSimulatorUrl, VelaAvdUtils.getEmulatorEnvHome('modem_simulator'));
326
- currVersionInfo.modem_simulator = constants_1.EmulatorEnvVersion.modem_simulator;
327
- ColorConsole_1.default.success(`Download modem simulator succeed.`);
326
+ currVersionInfo.modem_simulator = emulator_1.EmulatorEnvVersion.modem_simulator;
327
+ shared_utils_1.ColorConsole.success(`Download modem simulator succeed.`);
328
328
  }
329
329
  // 创建avd文本文件
330
330
  const avdImagePath = imageDir;
331
- const avdParams = { avdName, avdSkin, avdWidth, avdHeight, avdArch: emulator_1.IAvdArchType.arm, avdImagePath };
331
+ const avdParams = {
332
+ avdName,
333
+ avdSkin,
334
+ avdWidth,
335
+ avdHeight,
336
+ avdArch: emulator_1.IAvdArchType.arm,
337
+ avdImagePath
338
+ };
332
339
  VelaAvdUtils.velaAvdCls.createVelaAvd(avdParams);
333
- ColorConsole_1.default.success(`Create avd succeed.`);
340
+ shared_utils_1.ColorConsole.success(`Create avd succeed.`);
334
341
  }
335
342
  catch (e) {
336
- ColorConsole_1.default.throw(`Create avd failed. Error: ${e.message}`);
343
+ shared_utils_1.ColorConsole.throw(`Create avd failed. Error: ${e.message}`);
337
344
  }
338
345
  finally {
339
346
  // 写入versions.json
@@ -365,56 +372,57 @@ class VelaAvdUtils {
365
372
  const skinsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
366
373
  const toolsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'tools'));
367
374
  const modemSimulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'modem_simulator/modem_nvram.json'));
368
- const systemImageExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', constants_1.VelaImageVersionList[0].value, 'nuttx'));
375
+ const systemImageExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', emulator_1.VelaImageVersionList[0].value, 'nuttx'));
369
376
  try {
370
377
  // 下载皮肤
371
- if (!skinsExist || currVersionInfo.skins < constants_1.EmulatorEnvVersion.skins) {
372
- const skinsUrl = VelaAvdUtils.getDownloadUrl('skins', constants_1.EmulatorEnvVersion.skins);
378
+ if (!skinsExist || currVersionInfo.skins < emulator_1.EmulatorEnvVersion.skins) {
379
+ const skinsUrl = VelaAvdUtils.getDownloadUrl('skins', emulator_1.EmulatorEnvVersion.skins);
373
380
  yield VelaAvdUtils.downloadAndUnzip(skinsUrl, VelaAvdUtils.getEmulatorEnvHome('skins'));
374
- currVersionInfo.skins = constants_1.EmulatorEnvVersion.skins;
375
- ColorConsole_1.default.success(`Download skins succeed.`);
381
+ currVersionInfo.skins = emulator_1.EmulatorEnvVersion.skins;
382
+ shared_utils_1.ColorConsole.success(`Download skins succeed.`);
376
383
  }
377
384
  // 下载快应用font
378
- if (!qaExist || currVersionInfo.qa < constants_1.EmulatorEnvVersion.qa) {
379
- const qaUrl = VelaAvdUtils.getDownloadUrl('qa', constants_1.EmulatorEnvVersion.qa);
385
+ if (!qaExist || currVersionInfo.qa < emulator_1.EmulatorEnvVersion.qa) {
386
+ const qaUrl = VelaAvdUtils.getDownloadUrl('qa', emulator_1.EmulatorEnvVersion.qa);
380
387
  yield VelaAvdUtils.downloadAndUnzip(qaUrl, VelaAvdUtils.getEmulatorEnvHome('qa'));
381
- currVersionInfo.qa = constants_1.EmulatorEnvVersion.qa;
382
- ColorConsole_1.default.success(`Download quickapp font succeed.`);
388
+ currVersionInfo.qa = emulator_1.EmulatorEnvVersion.qa;
389
+ shared_utils_1.ColorConsole.success(`Download quickapp font succeed.`);
383
390
  }
384
391
  // 下载工具
385
- if (!toolsExist || currVersionInfo.tools < constants_1.EmulatorEnvVersion.tools) {
386
- const v9fsToolUrl = VelaAvdUtils.getv9fsToolUrl(constants_1.EmulatorEnvVersion.tools);
387
- const filename = (os_1.default.platform() === 'win32') ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
392
+ if (!toolsExist || currVersionInfo.tools < emulator_1.EmulatorEnvVersion.tools) {
393
+ const v9fsToolUrl = VelaAvdUtils.getv9fsToolUrl(emulator_1.EmulatorEnvVersion.tools);
394
+ const filename = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
388
395
  yield VelaAvdUtils.downloadFromCdn(v9fsToolUrl, VelaAvdUtils.getEmulatorEnvHome('tools'), filename);
389
- currVersionInfo.tools = constants_1.EmulatorEnvVersion.tools;
390
- ColorConsole_1.default.success(`Download tools succeed.`);
396
+ currVersionInfo.tools = emulator_1.EmulatorEnvVersion.tools;
397
+ shared_utils_1.ColorConsole.success(`Download tools succeed.`);
391
398
  }
392
399
  // 下载模拟器
393
- if (!emulatorExist || currVersionInfo.emulator < constants_1.EmulatorEnvVersion.emulator) {
394
- const emulatorUrl = VelaAvdUtils.getEmulatorUrl(constants_1.EmulatorEnvVersion.emulator);
400
+ if (!emulatorExist || currVersionInfo.emulator < emulator_1.EmulatorEnvVersion.emulator) {
401
+ const emulatorUrl = VelaAvdUtils.getEmulatorUrl(emulator_1.EmulatorEnvVersion.emulator);
395
402
  yield VelaAvdUtils.downloadAndUnzip(emulatorUrl, VelaAvdUtils.getEmulatorEnvHome('emulator'));
396
- currVersionInfo.emulator = constants_1.EmulatorEnvVersion.emulator;
397
- ColorConsole_1.default.success(`Download emulator succeed.`);
403
+ currVersionInfo.emulator = emulator_1.EmulatorEnvVersion.emulator;
404
+ shared_utils_1.ColorConsole.success(`Download emulator succeed.`);
398
405
  }
399
406
  // 下载modem_simultor
400
- if (!modemSimulatorExist || currVersionInfo.modem_simulator < constants_1.EmulatorEnvVersion.modem_simulator) {
401
- const modemSimulatorUrl = VelaAvdUtils.getDownloadUrl('modem_simulator', constants_1.EmulatorEnvVersion.modem_simulator);
407
+ if (!modemSimulatorExist ||
408
+ currVersionInfo.modem_simulator < emulator_1.EmulatorEnvVersion.modem_simulator) {
409
+ const modemSimulatorUrl = VelaAvdUtils.getDownloadUrl('modem_simulator', emulator_1.EmulatorEnvVersion.modem_simulator);
402
410
  yield VelaAvdUtils.downloadAndUnzip(modemSimulatorUrl, VelaAvdUtils.getEmulatorEnvHome('modem_simulator'));
403
- currVersionInfo.modem_simulator = constants_1.EmulatorEnvVersion.modem_simulator;
404
- ColorConsole_1.default.success(`Download modem simulator succeed.`);
411
+ currVersionInfo.modem_simulator = emulator_1.EmulatorEnvVersion.modem_simulator;
412
+ shared_utils_1.ColorConsole.success(`Download modem simulator succeed.`);
405
413
  }
406
414
  // 下载vela镜像,默认只下载最新的vela正式版,dev版本需要创建模拟器的时候手动勾选
407
- if (!systemImageExist || VelaAvdUtils.velaImageNeedUpdate(constants_1.VelaImageVersionList[0].value)) {
408
- const systemImageUrl = VelaAvdUtils.getSystemImageUrl(constants_1.VelaImageVersionList[0].value);
409
- const imageDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', constants_1.VelaImageVersionList[0].value);
415
+ if (!systemImageExist || VelaAvdUtils.velaImageNeedUpdate(emulator_1.VelaImageVersionList[0].value)) {
416
+ const systemImageUrl = VelaAvdUtils.getSystemImageUrl(emulator_1.VelaImageVersionList[0].value);
417
+ const imageDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', emulator_1.VelaImageVersionList[0].value);
410
418
  yield VelaAvdUtils.downloadAndUnzip(systemImageUrl, imageDir);
411
- currVersionInfo['system-images'] = constants_1.EmulatorEnvVersion['system-images'];
412
- ColorConsole_1.default.success(`Download vela image succeed.`);
419
+ currVersionInfo['system-images'] = emulator_1.EmulatorEnvVersion['system-images'];
420
+ shared_utils_1.ColorConsole.success(`Download vela image succeed.`);
413
421
  }
414
- ColorConsole_1.default.success(`Create emulator environment succeed.`);
422
+ shared_utils_1.ColorConsole.success(`Create emulator environment succeed.`);
415
423
  }
416
424
  catch (e) {
417
- ColorConsole_1.default.throw(`Create emulator environment failed. Error: ${e.message}`);
425
+ shared_utils_1.ColorConsole.throw(`Create emulator environment failed. Error: ${e.message}`);
418
426
  }
419
427
  finally {
420
428
  // 写入versions.json