@aiot-toolkit/emulator 2.0.3-beta.1 → 2.0.3-beta.11

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 (45) hide show
  1. package/README.md +133 -8
  2. package/lib/emulatorutil/EmulatorLog.js +22 -18
  3. package/lib/emulatorutil/constants.d.ts +18 -5
  4. package/lib/emulatorutil/constants.js +94 -53
  5. package/lib/emulatorutil/index.d.ts +3 -2
  6. package/lib/emulatorutil/index.js +38 -8
  7. package/lib/emulatorutil/running.d.ts +24 -0
  8. package/lib/emulatorutil/running.js +108 -0
  9. package/lib/emulatorutil/skinLayoutParser.d.ts +14 -0
  10. package/lib/emulatorutil/skinLayoutParser.js +111 -0
  11. package/lib/index.d.ts +5 -5
  12. package/lib/index.js +76 -26
  13. package/lib/instance/common.d.ts +39 -39
  14. package/lib/instance/common.js +151 -221
  15. package/lib/instance/dev.d.ts +7 -42
  16. package/lib/instance/dev.js +53 -235
  17. package/lib/instance/index.d.ts +6 -5
  18. package/lib/instance/index.js +51 -35
  19. package/lib/instance/miwear.d.ts +14 -75
  20. package/lib/instance/miwear.js +92 -370
  21. package/lib/instance/pre.d.ts +11 -3
  22. package/lib/instance/pre.js +54 -93
  23. package/lib/instance/pre5.d.ts +11 -0
  24. package/lib/instance/pre5.js +37 -0
  25. package/lib/static/avdConfigIni.json +5 -5
  26. package/lib/typing/Instance.d.ts +32 -15
  27. package/lib/typing/Instance.js +13 -6
  28. package/lib/typing/Vvd.d.ts +105 -0
  29. package/lib/typing/Vvd.js +31 -0
  30. package/lib/utils/file.d.ts +0 -0
  31. package/lib/utils/file.js +1 -0
  32. package/lib/utils/index.js +86 -100
  33. package/lib/vvd/index.d.ts +107 -0
  34. package/lib/vvd/index.js +715 -0
  35. package/lib/vvd/logcat.d.ts +16 -0
  36. package/lib/vvd/logcat.js +67 -0
  37. package/package.json +9 -8
  38. package/lib/avd/index.d.ts +0 -28
  39. package/lib/avd/index.js +0 -173
  40. package/lib/emulatorutil/EmulatorCmd.d.ts +0 -9
  41. package/lib/emulatorutil/EmulatorCmd.js +0 -226
  42. package/lib/instance/preDev.d.ts +0 -53
  43. package/lib/instance/preDev.js +0 -249
  44. package/lib/typing/Avd.d.ts +0 -23
  45. package/lib/typing/Avd.js +0 -8
@@ -0,0 +1,11 @@
1
+ import { VelaImageType } from '../typing/Vvd';
2
+ import MiwearInstance from './miwear';
3
+ export declare class VelaPre5Instance extends MiwearInstance {
4
+ imageType: VelaImageType;
5
+ appDir: string;
6
+ /**
7
+ * 使用 pm 安装快应用
8
+ * @param targeRpk 快应用的rpk文件路径
9
+ */
10
+ install(targeRpk: string): Promise<void>;
11
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VelaPre5Instance = void 0;
7
+ var _Vvd = require("../typing/Vvd");
8
+ var _miwear = _interopRequireDefault(require("./miwear"));
9
+ var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
10
+ var _util = require("util");
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ class VelaPre5Instance extends _miwear.default {
15
+ imageType = (() => _Vvd.VelaImageType.VELA_PRE_5)();
16
+ appDir = '/data/app';
17
+
18
+ /**
19
+ * 使用 pm 安装快应用
20
+ * @param targeRpk 快应用的rpk文件路径
21
+ */
22
+ async install(targeRpk) {
23
+ const installCmd = `adb -s ${this.sn} shell pm install ${targeRpk}`;
24
+ this.logger(`Excuting: ${installCmd}`);
25
+ const res = await adbMiwt.execAdbCmdAsync(installCmd);
26
+ await (0, _util.promisify)(process.nextTick)();
27
+ this.logger(`Install result: ${res}`);
28
+ // vela 5 安装成功的日志为:
29
+ // onInstallResult: com.application.watch.demo(success 0)
30
+ if (res.includes('(success 0)')) {
31
+ return Promise.resolve();
32
+ } else {
33
+ return Promise.reject(res);
34
+ }
35
+ }
36
+ }
37
+ exports.VelaPre5Instance = VelaPre5Instance;
@@ -6,7 +6,7 @@
6
6
  "fastboot.forceChosenSnapshotBoot": "no",
7
7
  "fastboot.forceColdBoot": "yes",
8
8
  "fastboot.forceFastBoot": "no",
9
- "hw.accelerometer": "no",
9
+ "hw.accelerometer": "yes",
10
10
  "hw.arc": false,
11
11
  "hw.audioInput": "yes",
12
12
  "hw.battery": "yes",
@@ -17,19 +17,19 @@
17
17
  "hw.dPad": "no",
18
18
  "hw.gps": "yes",
19
19
  "hw.gpu.enabled": "no",
20
- "hw.gpu.mode": "off",
20
+ "hw.gpu.mode": "host",
21
21
  "hw.initialOrientation": "Portrait",
22
22
  "hw.keyboard": "yes",
23
23
  "hw.lcd.density": 420,
24
- "hw.lcd.height": 480,
25
- "hw.lcd.width": 480,
24
+ "hw.lcd.height": 466,
25
+ "hw.lcd.width": 466,
26
26
  "hw.mainKeys": "no",
27
27
  "hw.ramSize": 512,
28
28
  "hw.sdCard": "no",
29
29
  "hw.sensors.orientation": "yes",
30
30
  "hw.sensors.proximity": "yes",
31
31
  "hw.trackBall": "no",
32
- "image.sysdir.1": "",
32
+ "image.sysdir.2": "",
33
33
  "runtime.network.latency": "none",
34
34
  "runtime.network.speed": "full",
35
35
  "showDeviceFrame": "yes",
@@ -1,27 +1,44 @@
1
- import { IJavascriptCompileOption } from '@aiot-toolkit/aiotpack';
2
- import { IAvdResourcePaths } from './Avd';
3
- export interface INewGoldfishInstanceParams extends IAvdResourcePaths {
4
- projectPath: string;
5
- sourceRoot?: string;
6
- compilerOption?: Partial<IJavascriptCompileOption>;
1
+ import readline from 'readline';
2
+ import { ChildProcessWithoutNullStreams } from 'child_process';
3
+ export interface EmulatorReadlines {
4
+ stdoutReadline: readline.Interface;
5
+ stderrReadline: readline.Interface;
6
+ dispose(): void;
7
+ }
8
+ export interface IEmulatorInstanceParams extends Partial<EmulatorReadlines> {
9
+ serialPort: string;
10
+ debugPort?: number | string;
11
+ vvdName: string;
12
+ onStdout?: (msg: string) => void;
13
+ onErrout?: (msg: string) => void;
14
+ /** 模拟器日志输出进程 */
15
+ logcatProcess?: ChildProcessWithoutNullStreams;
16
+ customLogger?: (log: string) => void;
7
17
  }
8
18
  export interface IStartOptions {
9
- avdName: string;
19
+ vvdName: string;
20
+ isRpk?: boolean;
10
21
  devtool?: string;
11
22
  /** @deprecated */
12
23
  disableNSH?: boolean;
13
24
  origin?: IStartOrigin;
14
- serverPort?: number;
25
+ sdkHome?: string;
15
26
  grpcPort?: number;
16
- adbPort: number;
27
+ qtHideWindow?: boolean;
28
+ verbose?: boolean;
17
29
  debugPort?: number;
18
- stdoutCallback?: (buffer: Buffer) => void;
19
- stderrCallback?: (buffer: Buffer) => void;
30
+ stdoutCallback?: (buffer: string) => void;
31
+ stderrCallback?: (buffer: string) => void;
20
32
  exitCallback?: (code: number | null) => void;
21
- /** 要推送的目录路径 */
22
- dist?: string;
23
- /** 要推送到的目的路径 */
24
- tar?: string;
33
+ customLogger?: (log: string) => void;
34
+ }
35
+ /**
36
+ * 如果指定了 serialPort 则必须同时指定 grpcPort
37
+ * 否则
38
+ */
39
+ export interface IStartWithSerialPort extends IStartOptions {
40
+ serialPort: number;
41
+ grpcPort: number;
25
42
  }
26
43
  export declare enum IStartOrigin {
27
44
  Terminal = "terminal",
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.IStartOrigin = void 0;
4
- var IStartOrigin;
5
- (function (IStartOrigin) {
6
- IStartOrigin["Terminal"] = "terminal";
7
- IStartOrigin["Ide"] = "ide";
8
- })(IStartOrigin || (exports.IStartOrigin = IStartOrigin = {}));
7
+ /**
8
+ * 如果指定了 serialPort 则必须同时指定 grpcPort
9
+ * 否则
10
+ */
11
+ let IStartOrigin = exports.IStartOrigin = /*#__PURE__*/function (IStartOrigin) {
12
+ IStartOrigin["Terminal"] = "terminal";
13
+ IStartOrigin["Ide"] = "ide";
14
+ return IStartOrigin;
15
+ }({});
@@ -0,0 +1,105 @@
1
+ export interface IVvdResourcePaths {
2
+ vvdHome?: string;
3
+ sdkHome?: string;
4
+ imageHome?: string;
5
+ }
6
+ export declare enum IVvdArchType {
7
+ arm = "arm",
8
+ arm64 = "arm64"
9
+ }
10
+ export declare enum VelaImageType {
11
+ VELA_PRE_5 = "vela-pre-5.0",
12
+ REL = "vela-release-4.0",
13
+ PRE = "vela-pre-4.0",
14
+ DEV = "vela-dev-0.0.4"
15
+ }
16
+ export interface IVvdParams {
17
+ name: string;
18
+ arch: IVvdArchType;
19
+ width: string;
20
+ height: string;
21
+ skin?: string;
22
+ 'skin.path'?: string;
23
+ imageDir?: string;
24
+ customImagePath?: string;
25
+ shape?: string;
26
+ flavor?: string;
27
+ density?: string;
28
+ customLcdRadius?: string;
29
+ imageType: VelaImageType;
30
+ skinInfo?: EmulatorSkin;
31
+ }
32
+ export interface EmulatorPart {
33
+ display: {
34
+ width: string;
35
+ height: string;
36
+ x: string;
37
+ y: string;
38
+ shape?: string;
39
+ flavor?: string;
40
+ density?: string;
41
+ [i: string]: any;
42
+ };
43
+ background: {
44
+ mask?: string;
45
+ image: string;
46
+ [i: string]: any;
47
+ };
48
+ foreground: {
49
+ image?: string;
50
+ mask?: string;
51
+ [i: string]: any;
52
+ };
53
+ }
54
+ export interface EmulatorLayout {
55
+ width: string;
56
+ height: string;
57
+ part1: {
58
+ x: string;
59
+ y: string;
60
+ name: string;
61
+ value: EmulatorPart;
62
+ };
63
+ part2: {
64
+ x: string;
65
+ y: string;
66
+ name: string;
67
+ value: EmulatorPart;
68
+ };
69
+ [i: string]: any;
70
+ }
71
+ export interface SkinInfo {
72
+ parts: Record<string, EmulatorPart>;
73
+ layouts: {
74
+ portrait?: EmulatorLayout;
75
+ landscape?: EmulatorLayout;
76
+ };
77
+ props: {
78
+ default?: 'yes' | 'no';
79
+ shape?: string;
80
+ flavor?: string;
81
+ density?: string;
82
+ };
83
+ }
84
+ export interface EmulatorSkin {
85
+ name: string;
86
+ info: SkinInfo;
87
+ backgroundImage: string;
88
+ maskImage: string | undefined;
89
+ defaultLayout: EmulatorLayout;
90
+ }
91
+ export declare enum SDKParts {
92
+ EMULATOR = "emulator",
93
+ QA = "qa",
94
+ SKINS = "skins",
95
+ SYSTEM_IMAGES = "system-images",
96
+ MODEM_SIMULATOR = "modem_simulator"
97
+ }
98
+ export declare enum VELAHOME {
99
+ SDK = ".export",
100
+ VVD = ".vela/vvd"
101
+ }
102
+ export type SDKDownloadOpt = {
103
+ force?: boolean;
104
+ parallelStreams?: number;
105
+ } & Parameters<typeof import('ipull').downloadSequence>[0];
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VelaImageType = exports.VELAHOME = exports.SDKParts = exports.IVvdArchType = void 0;
7
+ let IVvdArchType = exports.IVvdArchType = /*#__PURE__*/function (IVvdArchType) {
8
+ IVvdArchType["arm"] = "arm";
9
+ IVvdArchType["arm64"] = "arm64";
10
+ return IVvdArchType;
11
+ }({});
12
+ let VelaImageType = exports.VelaImageType = /*#__PURE__*/function (VelaImageType) {
13
+ VelaImageType["VELA_PRE_5"] = "vela-pre-5.0";
14
+ VelaImageType["REL"] = "vela-release-4.0";
15
+ VelaImageType["PRE"] = "vela-pre-4.0";
16
+ VelaImageType["DEV"] = "vela-dev-0.0.4";
17
+ return VelaImageType;
18
+ }({});
19
+ let SDKParts = exports.SDKParts = /*#__PURE__*/function (SDKParts) {
20
+ SDKParts["EMULATOR"] = "emulator";
21
+ SDKParts["QA"] = "qa";
22
+ SDKParts["SKINS"] = "skins";
23
+ SDKParts["SYSTEM_IMAGES"] = "system-images";
24
+ SDKParts["MODEM_SIMULATOR"] = "modem_simulator";
25
+ return SDKParts;
26
+ }({});
27
+ let VELAHOME = exports.VELAHOME = /*#__PURE__*/function (VELAHOME) {
28
+ VELAHOME["SDK"] = ".export";
29
+ VELAHOME["VVD"] = ".vela/vvd";
30
+ return VELAHOME;
31
+ }({});
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1,144 +1,130 @@
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 });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.delayRun = delayRun;
7
+ exports.getEvenPort = getEvenPort;
15
8
  exports.getSystemArch = getSystemArch;
16
- exports.killProcessByPid = killProcessByPid;
17
9
  exports.killProcessByCmd = killProcessByCmd;
10
+ exports.killProcessByPid = killProcessByPid;
18
11
  exports.sleep = sleep;
19
12
  exports.tryRun = tryRun;
20
- exports.delayRun = delayRun;
21
- exports.getEvenPort = getEvenPort;
22
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
23
- const child_process_1 = require("child_process");
24
- const find_process_1 = __importDefault(require("find-process"));
25
- const os_1 = __importDefault(require("os"));
26
- const semver_1 = __importDefault(require("semver"));
27
- const portfinder_1 = __importDefault(require("portfinder"));
13
+ var _ColorConsole = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
14
+ var _child_process = require("child_process");
15
+ var _findProcess = _interopRequireDefault(require("find-process"));
16
+ var _os = _interopRequireDefault(require("os"));
17
+ var _semver = _interopRequireDefault(require("semver"));
18
+ var _portfinder = _interopRequireDefault(require("portfinder"));
19
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
28
20
  const cpuArch = {
29
- arm64: 'aarch64',
30
- aarch64: 'aarch64',
31
- x64: 'x86_64',
32
- x86_64: 'x86_64'
21
+ arm64: 'aarch64',
22
+ aarch64: 'aarch64',
23
+ x64: 'x86_64',
24
+ x86_64: 'x86_64'
33
25
  };
26
+
34
27
  /** 获取mac电脑的CPU架构
35
28
  * node 15.0.0之后,m1芯片的mac的os.arch()才是arm64,在这之前都是x86
36
29
  * 所以15.0.0之前无法通过os.arch()区分,也无法通过execSync('uname -m')区分
37
30
  */
38
31
  function getSystemArch() {
39
- const platform = os_1.default.platform();
40
- let osArch = os_1.default.arch();
41
- const nodeVersion = process.version;
42
- if (semver_1.default.lt(nodeVersion, '15.0.0') && platform === 'darwin') {
43
- try {
44
- (0, child_process_1.execSync)('sysctl -n sysctl.proc_translated');
45
- osArch = 'arm64';
46
- }
47
- catch (_a) {
48
- osArch = 'x64';
49
- }
50
- }
51
- if (osArch !== 'arm64' && osArch !== 'x64') {
52
- return ColorConsole_1.default.throw(`unsupport system`);
32
+ const platform = _os.default.platform();
33
+ let osArch = _os.default.arch();
34
+ const nodeVersion = process.version;
35
+ if (_semver.default.lt(nodeVersion, '15.0.0') && platform === 'darwin') {
36
+ try {
37
+ (0, _child_process.execSync)('sysctl -n sysctl.proc_translated');
38
+ osArch = 'arm64';
39
+ } catch {
40
+ osArch = 'x64';
53
41
  }
54
- return cpuArch[osArch];
42
+ }
43
+ if (osArch !== 'arm64' && osArch !== 'x64') {
44
+ return _ColorConsole.default.throw(`unsupport system`);
45
+ }
46
+ return cpuArch[osArch];
55
47
  }
48
+
56
49
  /** 根据PID杀死进程 */
57
50
  function killProcessByPid(pid) {
58
- try {
59
- const cmd = os_1.default.platform() === 'win32' ? `taskkill /pid ${pid} /T /F` : `kill -9 ${pid}`;
60
- (0, child_process_1.execSync)(cmd);
61
- }
62
- catch (e) {
63
- console.error(`kill process ${pid} get error: ${e}`);
64
- }
51
+ try {
52
+ const cmd = _os.default.platform() === 'win32' ? `taskkill /pid ${pid} /T /F` : `kill -9 ${pid}`;
53
+ (0, _child_process.execSync)(cmd);
54
+ } catch (e) {
55
+ console.error(`kill process ${pid} get error: ${e}`);
56
+ }
65
57
  }
58
+
66
59
  /**
67
60
  * 根据命令杀死进程
68
61
  */
69
- function killProcessByCmd(cmd) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- if (!cmd)
72
- return;
73
- try {
74
- const list = yield (0, find_process_1.default)('name', cmd);
75
- list.forEach((item) => __awaiter(this, void 0, void 0, function* () {
76
- killProcessByPid(item.pid.toString());
77
- }));
78
- }
79
- catch (e) {
80
- console.error(`kill process ${cmd} get error: ${e}`);
81
- }
62
+ async function killProcessByCmd(cmd) {
63
+ if (!cmd) return;
64
+ try {
65
+ const list = await (0, _findProcess.default)('name', cmd);
66
+ list.forEach(async item => {
67
+ killProcessByPid(item.pid.toString());
82
68
  });
69
+ } catch (e) {
70
+ console.error(`kill process ${cmd} get error: ${e}`);
71
+ }
83
72
  }
73
+
84
74
  /** 延迟函数 */
85
- function sleep(time) {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- return new Promise((resolve) => setTimeout(resolve, time));
88
- });
75
+ async function sleep(time) {
76
+ return new Promise(resolve => setTimeout(resolve, time));
89
77
  }
78
+
90
79
  /**
91
80
  * 重复执行某个任务直到成功,或者超过最大次数
92
81
  * @param task 任务,需要返回 bool 值表示是否执行成功
93
82
  * @param {Number=} maxCount 最大重试次数
94
83
  * @param {number=} duration 每次重试的间隔
95
84
  */
96
- function tryRun(task_1) {
97
- return __awaiter(this, arguments, void 0, function* (task, maxCount = 5, duration = 1000, currentCount = 0) {
98
- if (currentCount > maxCount)
99
- return false;
100
- return (Boolean(yield task()) ||
101
- (yield delayRun(() => tryRun(task, maxCount, duration, currentCount + 1), duration)));
102
- });
85
+ async function tryRun(task) {
86
+ let maxCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
87
+ let duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1000;
88
+ let currentCount = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
89
+ if (currentCount > maxCount) return false;
90
+ return Boolean(await task()) || (await delayRun(() => tryRun(task, maxCount, duration, currentCount + 1), duration));
103
91
  }
92
+
104
93
  /**
105
94
  * 延迟执行某个任务
106
95
  * @param task
107
96
  * @param duration
108
97
  * @returns
109
98
  */
110
- function delayRun(task_1) {
111
- return __awaiter(this, arguments, void 0, function* (task, duration = 1000) {
112
- return new Promise((resolve) => {
113
- setTimeout(() => __awaiter(this, void 0, void 0, function* () {
114
- return resolve(task());
115
- }), duration);
116
- });
117
- });
99
+ async function delayRun(task) {
100
+ let duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
101
+ return new Promise(resolve => {
102
+ setTimeout(async () => {
103
+ return resolve(task());
104
+ }, duration);
105
+ });
118
106
  }
107
+
119
108
  /**
120
109
  * 为avdPort寻找一个不被占用的端口
121
110
  * 端口号必须是偶数且在5555和5585之间
122
111
  * @returns {number}
123
112
  */
124
- function getEvenPort() {
125
- return __awaiter(this, void 0, void 0, function* () {
126
- const startPort = 5556;
127
- const stopPort = 5584;
128
- let index = 1;
129
- let port = yield portfinder_1.default.getPortPromise({
130
- port: startPort,
131
- stopPort
132
- });
133
- while (port % 2 !== 0) {
134
- if (index > 13)
135
- return false;
136
- port = yield portfinder_1.default.getPortPromise({
137
- port: startPort + 2,
138
- stopPort
139
- });
140
- index++;
141
- }
142
- return port;
113
+ async function getEvenPort() {
114
+ const startPort = 5556;
115
+ const stopPort = 5584;
116
+ let index = 1;
117
+ let port = await _portfinder.default.getPortPromise({
118
+ port: startPort,
119
+ stopPort
120
+ });
121
+ while (port % 2 !== 0) {
122
+ if (index > 13) return false;
123
+ port = await _portfinder.default.getPortPromise({
124
+ port: startPort + 2,
125
+ stopPort
143
126
  });
144
- }
127
+ index++;
128
+ }
129
+ return port;
130
+ }
@@ -0,0 +1,107 @@
1
+ import { IVvdParams, IVvdResourcePaths, SDKParts, SDKDownloadOpt, SkinInfo, VelaImageType } from '../typing/Vvd';
2
+ import { IStartOptions, IStartWithSerialPort } from '../typing/Instance';
3
+ import { findInstance } from '../instance';
4
+ import type { DownloadFileOptions } from 'ipull';
5
+ export declare class VvdManager {
6
+ private vvdHome;
7
+ private sdkHome;
8
+ constructor(vvdResourcePaths: IVvdResourcePaths);
9
+ /**
10
+ * 创建Vela端的 VVD ,统一保存在 .vela/vvd 目录下
11
+ * 1. 创建.vela/advancedFeatures.ini文件
12
+ * 2. 创建.vela/vvd/${avdName}.ini文件
13
+ * 3. 创建.vela/vvd/${avdName}.vvd/config.ini文件
14
+ * @param vvdParams VVD参数,宽高、绑定的镜像路径等
15
+ * @returns
16
+ */
17
+ createVvd(vvdParams: IVvdParams): boolean;
18
+ getVvdDir(vvdName: string): string;
19
+ /** 根据AVD名字获取模拟器的详细信息 */
20
+ getVvdInfo(vvdName: string): IVvdParams;
21
+ /** 根据名字删除AVD */
22
+ deleteVvd(vvdName: string): boolean;
23
+ /** 获取已经创建的模拟器列表 */
24
+ getVvdList(): IVvdParams[];
25
+ /** 获取 SDK 子目录 */
26
+ getSDKPart(name: SDKParts): string;
27
+ getSkinInfo(skinName: string, skinPath: string): {
28
+ name: string;
29
+ path: string;
30
+ info: SkinInfo;
31
+ backgroundImage: string;
32
+ maskImage: string | undefined;
33
+ defaultLayout: import("../typing/Vvd").EmulatorLayout;
34
+ } | undefined;
35
+ /** 获取模拟器皮肤列表 */
36
+ getVelaSkinList(): Promise<{
37
+ name: string;
38
+ path: string;
39
+ info: SkinInfo;
40
+ backgroundImage: string;
41
+ maskImage: string | undefined;
42
+ defaultLayout: import("../typing/Vvd").EmulatorLayout;
43
+ }[]>;
44
+ /** 自定义模拟器的镜像目录 */
45
+ customImageDir(vvdName: string, target: string): void;
46
+ /** 重置自定义的镜像目录 */
47
+ resetImageDir(vvdName: string): void;
48
+ getEmulatorBinPath(sdkHome: string): string;
49
+ getVvdStartCmd(options: IStartOptions | IStartWithSerialPort): Promise<string>;
50
+ startVvd(options: IStartOptions | IStartWithSerialPort): Promise<{
51
+ coldBoot: boolean;
52
+ emulatorInstance: ReturnType<typeof findInstance>;
53
+ }>;
54
+ stopVvd(name: string, timeout?: number): Promise<void>;
55
+ /** 获取模拟器平台的名称,darwin-aarch64 linux-aarch64 windows-x86_64等 */
56
+ getEmulatorPlatform(): string;
57
+ /** 获取本地镜像的构建时间 */
58
+ getLocalImageBuildTime(imagePath: string): Promise<Date | undefined>;
59
+ getSDKVersionPath(): string;
60
+ /** 获取本地 SDK 的版本信息 */
61
+ getSDKVersion(): Promise<Record<SDKParts, string>>;
62
+ /** 获取本地已经下载的镜像 */
63
+ getLocalSystemImage(): Promise<{
64
+ value: string;
65
+ time: Date | undefined;
66
+ }[]>;
67
+ getLocalSystemPath(imageId: VelaImageType): string;
68
+ hasLocaleImage(imageId: VelaImageType): boolean;
69
+ /** 判断本地的某个 vela 镜像是否需要更新 */
70
+ isLocalImageNeedUpdate(imageId: VelaImageType): Promise<boolean>;
71
+ getNotInstalledSDKPart(): Promise<SDKParts[]>;
72
+ /** 检查 SDK 有哪些部分需要更新 */
73
+ hasSDKPartUpdate(): Promise<SDKParts[]>;
74
+ /**
75
+ * 下载 SDK,默认只下载需要更新的部分
76
+ * @param opt.force 强制下载所有部分
77
+ *
78
+ * @example
79
+ * async function main() {
80
+ * const sdkHome = path.resolve(os.homedir(), '.export_dev1')
81
+ * const velaAvdCls = new VelaAvdCls({ sdkHome })
82
+ *
83
+ * const downloder = await velaAvdCls.downloadSDK({
84
+ * force: true,
85
+ * cliProgress: false,
86
+ * parallelDownloads: 6
87
+ * })
88
+ *
89
+ * downloder.on('progress', (progress) => {
90
+ * console.log(
91
+ * `progress: ${progress.formattedSpeed} ${progress.formattedPercentage} ${progress.formatTotal} ${progress.formatTimeLeft}`
92
+ * )
93
+ * })
94
+ *
95
+ * await downloder.downlodPromise
96
+ *
97
+ * console.log('download success')
98
+ * }
99
+ */
100
+ downloadSDK(opt: SDKDownloadOpt): Promise<import("ipull").DownloadEngineMultiDownload<import("ipull").BaseDownloadEngine> & {
101
+ downlodPromise: Promise<void>;
102
+ }>;
103
+ /** 下载vela系统镜像 */
104
+ downloadImage(imageId: VelaImageType, opt?: Partial<DownloadFileOptions>): Promise<import("ipull").DownloadEngineNodejs<import("ipull/dist/download/download-engine/streams/download-engine-write-stream/download-engine-write-stream-nodejs").default> & {
105
+ downlodPromise: Promise<void>;
106
+ }>;
107
+ }