aiot-toolkit 2.0.3-beta.7 → 2.0.3-beta.9

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,75 +1,61 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
- const axios_1 = __importDefault(require("axios"));
17
- const fs_extra_1 = __importDefault(require("fs-extra"));
18
- const path_1 = __importDefault(require("path"));
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
+ var _axios = _interopRequireDefault(require("axios"));
9
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
10
+ var _path = _interopRequireDefault(require("path"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
12
  /**
20
13
  * RequestUtils
21
14
  */
22
15
  class RequestUtils {
23
- static sendReq(client, api, params) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- return new Promise((resolve) => {
26
- const requrl = `http://${client.ip}:${client.port}${api}`;
27
- let options = {
28
- host: client.ip,
29
- port: client.port,
30
- path: api,
31
- timeout: 3000
32
- };
33
- if (params) {
34
- options = Object.assign({}, options, {
35
- headers: params
36
- });
37
- }
38
- axios_1.default
39
- .post(requrl, options)
40
- .then((data) => {
41
- shared_utils_1.ColorConsole.log(`### App Server ### Request ${requrl} succeeded`);
42
- resolve(data.toString());
43
- })
44
- .catch((error) => {
45
- if (error.respose && error.response.status === 408) {
46
- // 超时处理
47
- shared_utils_1.ColorConsole.error(`### App Server ### Request ${requrl} timed out, please try again`);
48
- }
49
- else {
50
- shared_utils_1.ColorConsole.error(`### App Server ### Request ${requrl} error message: ${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}`);
51
- }
52
- });
53
- });
16
+ static async sendReq(client, api, params) {
17
+ return new Promise(resolve => {
18
+ const requrl = `http://${client.ip}:${client.port}${api}`;
19
+ let options = {
20
+ host: client.ip,
21
+ port: client.port,
22
+ path: api,
23
+ timeout: 3000
24
+ };
25
+ if (params) {
26
+ options = Object.assign({}, options, {
27
+ headers: params
54
28
  });
55
- }
56
- static downloadFile(url, fileName) {
57
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
58
- // 开始下载
59
- shared_utils_1.ColorConsole.log(`Start downloading file:${fileName}, address:${url}`);
60
- const response = yield axios_1.default.get(url, {
61
- responseType: 'arraybuffer'
62
- });
63
- if (response.status === 200) {
64
- const targetDir = path_1.default.join(__dirname, './apk');
65
- fs_extra_1.default.ensureDirSync(targetDir);
66
- fs_extra_1.default.writeFileSync(path_1.default.join(targetDir, fileName), response.data);
67
- resolve(`Download file ${fileName} successfully`);
68
- }
69
- else {
70
- reject(`Download failed, status code:${response.status}`);
71
- }
72
- }));
73
- }
29
+ }
30
+ _axios.default.post(requrl, options).then(data => {
31
+ _sharedUtils.ColorConsole.log(`### App Server ### Request ${requrl} succeeded`);
32
+ resolve(data.toString());
33
+ }).catch(error => {
34
+ if (error.respose && error.response.status === 408) {
35
+ // 超时处理
36
+ _sharedUtils.ColorConsole.error(`### App Server ### Request ${requrl} timed out, please try again`);
37
+ } else {
38
+ _sharedUtils.ColorConsole.error(`### App Server ### Request ${requrl} error message: ${error?.toString() || 'unknown error'}`);
39
+ }
40
+ });
41
+ });
42
+ }
43
+ static downloadFile(url, fileName) {
44
+ return new Promise(async (resolve, reject) => {
45
+ // 开始下载
46
+ _sharedUtils.ColorConsole.log(`Start downloading file:${fileName}, address:${url}`);
47
+ const response = await _axios.default.get(url, {
48
+ responseType: 'arraybuffer'
49
+ });
50
+ if (response.status === 200) {
51
+ const targetDir = _path.default.join(__dirname, './apk');
52
+ _fsExtra.default.ensureDirSync(targetDir);
53
+ _fsExtra.default.writeFileSync(_path.default.join(targetDir, fileName), response.data);
54
+ resolve(`Download file ${fileName} successfully`);
55
+ } else {
56
+ reject(`Download failed, status code:${response.status}`);
57
+ }
58
+ });
59
+ }
74
60
  }
75
- exports.default = RequestUtils;
61
+ var _default = exports.default = RequestUtils;
@@ -1,61 +1,16 @@
1
- import { VelaAvdCls } from '@aiot-toolkit/emulator';
2
- declare class VelaAvdUtils {
1
+ import { VvdManager } from '@aiot-toolkit/emulator';
2
+ declare class VelaVvdUtils {
3
3
  static sdkHome: string;
4
- static avdHome: string;
5
- static baseUrl: string;
6
- static versionUrl: string;
7
- static emulatorBaseUrl: string;
8
- static systemImageBaseUrl: string;
9
- static velaAvdCls: VelaAvdCls;
10
- /** 校验AVD名称 */
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";
12
- /**
13
- * 从CDN上下载资源文件
14
- * @param downloadUrl 下载地址
15
- * @param targetDir 下载后的文件存放的目录
16
- * @param filename 下载文件的名称
17
- * @returns
18
- */
19
- static downloadFromCdn(downloadUrl: string, targetDir: string, filename: string): Promise<void>;
20
- /**
21
- * 下载zip文件并解压。会将zip里的所有文件解压至targetDir
22
- * @param downloadUrl 下载地址
23
- * @param targetDir 解压目录
24
- * @returns
25
- */
26
- static downloadAndUnzip(downloadUrl: string, targetDir: string): Promise<void>;
27
- /** 根据host获取模拟器下载地址 */
28
- static getEmulatorUrl(version?: 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;
50
- /** 根据host获取ya-vm-file-server下载地址 */
51
- static getv9fsToolUrl(version?: string): string;
52
- /** 获取镜像构建时间 */
53
- static getImageBuildTime(imageId: string): string | Date | undefined;
4
+ static vvdHome: string;
5
+ static vvdManager: VvdManager;
6
+ /** 校验VVD名称 */
7
+ static validateVvdName(vvdName: string): true | "Please enter vvd name" | "The vvd name must starts with Vela" | "The vvd already exists. Please change vvd name";
54
8
  /**
55
9
  * 命令行访问方式创建模拟器
56
10
  */
57
- static createVelaAvdByInquire(): Promise<void>;
11
+ static createVelaVvdByInquire(): Promise<void>;
12
+ static checkEmulatorEnv(): Promise<boolean>;
58
13
  /** 初始化/重置模拟器环境 */
59
14
  static initEmulatorEnv(): Promise<void>;
60
15
  }
61
- export default VelaAvdUtils;
16
+ export default VelaVvdUtils;