aiot-toolkit 2.0.1-alpha.9 → 2.0.2-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.
Files changed (39) hide show
  1. package/README.md +32 -29
  2. package/lib/bin.js +102 -41
  3. package/lib/builder/IBuilder.js +0 -2
  4. package/lib/builder/UxBuilder.d.ts +9 -0
  5. package/lib/builder/UxBuilder.js +69 -23
  6. package/lib/builder/XtsBuilder.js +30 -12
  7. package/lib/interface/CommandInterface.js +0 -2
  8. package/lib/interface/VelaEmulatorInterface.d.ts +6 -0
  9. package/lib/interface/VelaEmulatorInterface.js +0 -2
  10. package/lib/starter/IStarter.d.ts +23 -0
  11. package/lib/starter/IStarter.js +39 -0
  12. package/lib/starter/UxStarter.d.ts +21 -0
  13. package/lib/starter/UxStarter.js +186 -0
  14. package/lib/starter/XtsStarter.d.ts +9 -0
  15. package/lib/starter/XtsStarter.js +19 -0
  16. package/lib/utils/AdbUtils.js +2 -11
  17. package/lib/utils/DeviceUtil.d.ts +1 -1
  18. package/lib/utils/DeviceUtil.js +22 -93
  19. package/lib/utils/RequestUtils.js +4 -19
  20. package/lib/utils/UxBuilderUtils.d.ts +8 -0
  21. package/lib/utils/UxBuilderUtils.js +51 -0
  22. package/lib/utils/VelaAvdUtils.d.ts +26 -4
  23. package/lib/utils/VelaAvdUtils.js +263 -134
  24. package/lib/waiter.js +0 -2
  25. package/package.json +17 -11
  26. package/lib/bin.js.map +0 -1
  27. package/lib/builder/IBuilder.js.map +0 -1
  28. package/lib/builder/UxBuilder.js.map +0 -1
  29. package/lib/builder/XtsBuilder.js.map +0 -1
  30. package/lib/interface/CommandInterface.js.map +0 -1
  31. package/lib/interface/VelaEmulatorInterface.js.map +0 -1
  32. package/lib/starter/GoldfishStarter.d.ts +0 -9
  33. package/lib/starter/GoldfishStarter.js +0 -108
  34. package/lib/starter/GoldfishStarter.js.map +0 -1
  35. package/lib/utils/AdbUtils.js.map +0 -1
  36. package/lib/utils/DeviceUtil.js.map +0 -1
  37. package/lib/utils/RequestUtils.js.map +0 -1
  38. package/lib/utils/VelaAvdUtils.js.map +0 -1
  39. package/lib/waiter.js.map +0 -1
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const JavascriptDefaultCompileOption_1 = __importStar(require("@aiot-toolkit/aiotpack/lib/compiler/javascript/JavascriptDefaultCompileOption"));
39
+ const emulator_1 = require("@aiot-toolkit/emulator");
40
+ const constants_1 = require("@aiot-toolkit/emulator/lib/static/constants");
41
+ const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
42
+ const prompts_1 = require("@inquirer/prompts");
43
+ const os_1 = __importDefault(require("os"));
44
+ const path_1 = __importDefault(require("path"));
45
+ const portfinder_1 = __importDefault(require("portfinder"));
46
+ const UxBuilder_1 = __importDefault(require("../builder/UxBuilder"));
47
+ const VelaAvdUtils_1 = __importDefault(require("../utils/VelaAvdUtils"));
48
+ const IStarter_1 = __importDefault(require("./IStarter"));
49
+ const fs_extra_1 = __importDefault(require("fs-extra"));
50
+ /**
51
+ * UxStarter
52
+ * ux快应用启动器
53
+ */
54
+ class UxStarter extends IStarter_1.default {
55
+ constructor() {
56
+ super(...arguments);
57
+ this.builder = new UxBuilder_1.default();
58
+ this.params = [
59
+ {
60
+ name: 'disableNSH',
61
+ description: 'disable goldfish NSH terminal',
62
+ defaultValue: false,
63
+ type: 'confirm'
64
+ },
65
+ {
66
+ name: 'watch',
67
+ description: 'recompile project while file changes',
68
+ defaultValue: false,
69
+ type: 'confirm'
70
+ },
71
+ {
72
+ name: 'openVNC',
73
+ description: 'open vnc',
74
+ defaultValue: false,
75
+ type: 'confirm'
76
+ },
77
+ ...this.builder.params
78
+ ];
79
+ }
80
+ start(projectPath, options) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ // 获取已经创建的模拟器列表
83
+ const avdList = VelaAvdUtils_1.default.velaAvdCls.getVelaAvdList();
84
+ if (avdList.length === 0) {
85
+ ColorConsole_1.default.error('no vela emulator available, please create it first.');
86
+ VelaAvdUtils_1.default.createVelaAvdByInquire();
87
+ return;
88
+ }
89
+ const avdName = yield (0, prompts_1.select)({
90
+ message: 'name of the avd to start',
91
+ choices: avdList.map((item) => {
92
+ return { value: item.avdName };
93
+ })
94
+ });
95
+ // 检查选择的模拟器是否符合要求
96
+ if (!this.isAvailableEmulator(avdName)) {
97
+ ColorConsole_1.default.throw(`this emulator is unavailable, please create a new emulator.`);
98
+ return;
99
+ }
100
+ let serverPort;
101
+ // watch模型下开启server
102
+ if (options.watch) {
103
+ serverPort = yield portfinder_1.default.getPortPromise({
104
+ port: JavascriptDefaultCompileOption_1.default.serverPort
105
+ });
106
+ (0, JavascriptDefaultCompileOption_1.setServerPort)(serverPort);
107
+ }
108
+ // build
109
+ const compilerOption = this.builder.getCompilerOption(projectPath, options);
110
+ yield this.builder.build(projectPath, options);
111
+ // start
112
+ const params = {
113
+ sdkHome: path_1.default.resolve(os_1.default.homedir(), '.export'),
114
+ avdHome: path_1.default.resolve(os_1.default.homedir(), '.android/avd'),
115
+ projectPath,
116
+ compilerOption
117
+ };
118
+ // 寻找对应的模拟器instance
119
+ const goldfishInstance = (0, emulator_1.findInstance)(avdName, params);
120
+ if (!goldfishInstance)
121
+ return;
122
+ let vncPort;
123
+ // 设置vncPort
124
+ if (options.openVNC) {
125
+ vncPort = yield portfinder_1.default.getPortPromise({
126
+ port: constants_1.defaultVncPort,
127
+ stopPort: constants_1.defaultVncPort + 100
128
+ });
129
+ }
130
+ // 设置adbPort
131
+ const adbPort = yield portfinder_1.default.getPortPromise({ port: constants_1.defaultAdbPort });
132
+ // 设置debugPort
133
+ let debugPort;
134
+ if (options.devtool) {
135
+ debugPort = yield portfinder_1.default.getPortPromise({ port: constants_1.defaultDebugPort });
136
+ }
137
+ const startOptions = {
138
+ avdName,
139
+ devtool: options.devtool,
140
+ disableNSH: options.disableNSH,
141
+ serverPort,
142
+ vncPort,
143
+ adbPort,
144
+ debugPort
145
+ };
146
+ goldfishInstance.start(startOptions);
147
+ // waiter
148
+ // const startWaiter: PersistentCommand = new PersistentCommand({
149
+ // description: 'aiot-toolkit start 的常驻命令',
150
+ // options: [
151
+ // {
152
+ // key: '?',
153
+ // description: '显示所有命令',
154
+ // action() {
155
+ // startWaiter.clearLog()
156
+ // startWaiter.describe()
157
+ // }
158
+ // }
159
+ // ]
160
+ // })
161
+ // startWaiter.describe()
162
+ // startWaiter.start()
163
+ });
164
+ }
165
+ /**
166
+ * 检查选择的模拟器在当前环境下是否可以使用
167
+ * 下面的几种情况会导致模拟器不可用:1. 模拟器绑定的Vela镜像不存在;2. Vela4.0缺少coredump.core或者vela_data.bin文件
168
+ * @param avdName 模拟器名称
169
+ * @returns {boolean}
170
+ */
171
+ isAvailableEmulator(avdName) {
172
+ const { avdImagePath } = VelaAvdUtils_1.default.velaAvdCls.getVelaAvdInfo(avdName);
173
+ // 没有avdImagePath,即对应的configIni里没有 image.sysdir.1 字段
174
+ // 有avdImagePath,但是这个目录下没有nuttx
175
+ if (!avdImagePath || !fs_extra_1.default.existsSync(path_1.default.resolve(avdImagePath, 'nuttx'))) {
176
+ return false;
177
+ }
178
+ if (avdImagePath.includes('vela-release') &&
179
+ (!fs_extra_1.default.existsSync(path_1.default.resolve(avdImagePath, 'coredump.core')) ||
180
+ !fs_extra_1.default.existsSync(path_1.default.resolve(avdImagePath, 'vela_data.bin')))) {
181
+ return false;
182
+ }
183
+ return true;
184
+ }
185
+ }
186
+ exports.default = UxStarter;
@@ -0,0 +1,9 @@
1
+ import ParamType from '@aiot-toolkit/commander/lib/interface/IParam';
2
+ import XtsBuilder from '../builder/XtsBuilder';
3
+ import IStarter from './IStarter';
4
+ declare class XtsStarter extends IStarter {
5
+ builder: XtsBuilder;
6
+ params: ParamType[];
7
+ start(projectPath: string, options: any): void;
8
+ }
9
+ export default XtsStarter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const XtsBuilder_1 = __importDefault(require("../builder/XtsBuilder"));
7
+ const IStarter_1 = __importDefault(require("./IStarter"));
8
+ class XtsStarter extends IStarter_1.default {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.builder = new XtsBuilder_1.default();
12
+ this.params = [];
13
+ }
14
+ start(projectPath, options) {
15
+ console.log(projectPath, options);
16
+ throw new Error('Method not implemented.');
17
+ }
18
+ }
19
+ exports.default = XtsStarter;
@@ -35,7 +35,6 @@ 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 shared_utils_1 = require("@aiot-toolkit/shared-utils");
39
38
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
40
39
  const adbMiwt = __importStar(require("@miwt/adb"));
41
40
  const adb_commander_1 = __importDefault(require("adb-commander"));
@@ -77,18 +76,12 @@ class AdbUtils {
77
76
  const adbShell = adbMiwt.execAdbCmd(`adb -s ${deviceSn} shell am start -n "org.hapjs.debugger/.MainActivity"`);
78
77
  adbShell.stdout.on('data', (data) => {
79
78
  // 监听stderr事件,获取输出内容
80
- ColorConsole_1.default.log({
81
- message: data
82
- });
79
+ ColorConsole_1.default.log(`### startDebugger ### ${data}`);
83
80
  });
84
81
  adbShell.stderr.on('data', (data) => {
85
82
  // 监听stderr事件,获取输出内容
86
83
  if (data.indexOf('Error') >= 0) {
87
- ColorConsole_1.default.log({
88
- level: shared_utils_1.LOG_LEVEL.Error,
89
- message: data
90
- });
91
- process.exit();
84
+ ColorConsole_1.default.throw(`### startDebugger ### ${data}`);
92
85
  }
93
86
  });
94
87
  adbShell.on('close', () => {
@@ -99,5 +92,3 @@ class AdbUtils {
99
92
  }
100
93
  }
101
94
  exports.default = AdbUtils;
102
-
103
- //# sourceMappingURL=AdbUtils.js.map
@@ -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) { }
@@ -362,5 +293,3 @@ DeviceUtil.ipRegExp = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0
362
293
  DeviceUtil.CLIENT_PORT = 39517;
363
294
  DeviceUtil.quickapp_url = 'https://statres.quickapp.cn/quickapp/quickapptool/release/platform/';
364
295
  exports.default = DeviceUtil;
365
-
366
- //# sourceMappingURL=DeviceUtil.js.map
@@ -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
  });
@@ -86,5 +73,3 @@ class RequestUtils {
86
73
  }
87
74
  }
88
75
  exports.default = RequestUtils;
89
-
90
- //# sourceMappingURL=RequestUtils.js.map
@@ -0,0 +1,8 @@
1
+ import CompileMode from '@aiot-toolkit/aiotpack/lib/compiler/enum/CompileMode';
2
+ /**
3
+ * UxBuilderUtils
4
+ */
5
+ declare class UxBuilderUtils {
6
+ static getDevtoolValue(mode: CompileMode, devtool: string): string | boolean;
7
+ }
8
+ export default UxBuilderUtils;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
7
+ /**
8
+ * UxBuilderUtils
9
+ */
10
+ class UxBuilderUtils {
11
+ static getDevtoolValue(mode, devtool) {
12
+ const sourcemaps = {
13
+ development: {
14
+ default: 'cheap-source-map',
15
+ options: [
16
+ false,
17
+ 'cheap-source-map',
18
+ 'cheap-module-source-map',
19
+ 'inline-cheap-source-map',
20
+ 'inline-cheap-module-source-map',
21
+ 'source-map',
22
+ 'inline-source-map',
23
+ 'hidden-source-map',
24
+ 'nosources-source-map'
25
+ ]
26
+ },
27
+ production: {
28
+ default: false,
29
+ options: [
30
+ false,
31
+ 'cheap-source-map',
32
+ 'cheap-module-source-map',
33
+ 'source-map',
34
+ 'hidden-source-map',
35
+ 'nosources-source-map'
36
+ ]
37
+ }
38
+ };
39
+ const sourcemapArr = sourcemaps[mode].options;
40
+ const defaultSourcemap = sourcemaps[mode].default;
41
+ if (typeof devtool !== 'string' && typeof devtool !== 'boolean') {
42
+ return defaultSourcemap;
43
+ }
44
+ if (sourcemapArr.indexOf(devtool) === -1) {
45
+ ColorConsole_1.default.warn(`The devtool in ${mode} mode does not support '${devtool}', change to default '${defaultSourcemap}'`);
46
+ return defaultSourcemap;
47
+ }
48
+ return devtool;
49
+ }
50
+ }
51
+ exports.default = UxBuilderUtils;
@@ -7,6 +7,7 @@ declare class VelaAvdUtils {
7
7
  static emulatorBaseUrl: string;
8
8
  static systemImageBaseUrl: string;
9
9
  static velaAvdCls: VelaAvdCls;
10
+ /** 校验AVD名称 */
10
11
  static validateAvdName(avdName: string): true | "Please enter avd name" | "The avd name must starts with Vela" | "The avd already exists. Please change avd name";
11
12
  /**
12
13
  * 从CDN上下载资源文件
@@ -25,15 +26,36 @@ declare class VelaAvdUtils {
25
26
  static downloadAndUnzip(downloadUrl: string, targetDir: string): Promise<void>;
26
27
  /** 根据host获取模拟器下载地址 */
27
28
  static getEmulatorUrl(version?: string): string;
28
- /** 根据host获取vela镜像下载地址 */
29
- static getSystemImageUrl(version?: string, device?: string): string;
29
+ /** 获取模拟器平台的名称,darwin-aarch64 linux-aarch64 windows-x86_64等 */
30
+ static getEmulatorPlatform(): string;
31
+ /** 获取各项模拟器资源的根目录 */
32
+ static getEmulatorEnvHome(resourceName: string): string;
33
+ /**
34
+ * Vela镜像需要更新
35
+ * @param imageId 镜像id
36
+ * @returns {boolean}
37
+ */
38
+ static velaImageNeedUpdate(imageId: string): boolean;
39
+ /**
40
+ * Vela镜像是否为zip包(是否为0.0.2版本)
41
+ * 只有Vela开发版(dev, 0.0.2)这个版本的镜像不是zip包
42
+ * @param velaImage
43
+ * @returns
44
+ */
45
+ static isZipInImageUrl(velaImage: string): boolean;
46
+ /** 获取vela镜像的下载地址 */
47
+ static getSystemImageUrl(version?: string): string;
48
+ /** 获取模拟器其他资源的下载地址 */
49
+ static getDownloadUrl(dir: string, version?: string, filename?: string): string;
30
50
  /** 根据host获取ya-vm-file-server下载地址 */
31
51
  static getv9fsToolUrl(version?: string): string;
32
- /** 获取资源文件下载地址 */
33
- static getDownloadUrl(file: string, version?: string): string;
52
+ /** 获取镜像构建时间 */
53
+ static getImageBuildTime(imageId: string): string | Date | undefined;
34
54
  /**
35
55
  * 命令行访问方式创建模拟器
36
56
  */
37
57
  static createVelaAvdByInquire(): Promise<void>;
58
+ /** 初始化/重置模拟器环境 */
59
+ static initEmulatorEnv(): Promise<void>;
38
60
  }
39
61
  export default VelaAvdUtils;