@aiot-toolkit/emulator 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.
- package/lib/avd/index.d.ts +4 -0
- package/lib/avd/index.js +35 -30
- package/lib/index.d.ts +3 -1
- package/lib/index.js +4 -1
- package/lib/instance/common.d.ts +5 -0
- package/lib/instance/common.js +25 -11
- package/lib/instance/dev.d.ts +11 -1
- package/lib/instance/dev.js +91 -46
- package/lib/instance/index.d.ts +4 -2
- package/lib/instance/index.js +9 -3
- package/lib/instance/miwear.d.ts +3 -0
- package/lib/instance/miwear.js +68 -97
- package/lib/instance/pre.d.ts +8 -0
- package/lib/instance/pre.js +19 -0
- package/lib/instance/preDev.js +27 -28
- package/lib/static/avdConfigIni.json +3 -3
- package/lib/static/constants.d.ts +7 -0
- package/lib/static/constants.js +30 -6
- package/lib/typing/Avd.d.ts +1 -0
- package/lib/typing/Instance.d.ts +2 -2
- package/lib/utils/index.d.ts +20 -0
- package/lib/utils/index.js +65 -8
- package/package.json +7 -5
package/lib/typing/Instance.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import IJavascriptCompileOption from '@aiot-toolkit/aiotpack
|
|
2
|
+
import { IJavascriptCompileOption } from '@aiot-toolkit/aiotpack';
|
|
3
3
|
import { IAvdResourcePaths } from './Avd';
|
|
4
4
|
export interface INewGoldfishInstanceParams extends IAvdResourcePaths {
|
|
5
5
|
projectPath: string;
|
|
@@ -13,7 +13,7 @@ export interface IStartOptions {
|
|
|
13
13
|
disableNSH?: boolean;
|
|
14
14
|
origin?: 'ide' | 'terminal';
|
|
15
15
|
serverPort?: number;
|
|
16
|
-
|
|
16
|
+
grpcPort?: number;
|
|
17
17
|
adbPort: number;
|
|
18
18
|
debugPort?: number;
|
|
19
19
|
stdoutCallback?: (buffer: Buffer) => void;
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -11,3 +11,23 @@ export declare function killProcessByPid(pid: string): void;
|
|
|
11
11
|
export declare function killProcessByCmd(cmd: string): Promise<void>;
|
|
12
12
|
/** 延迟函数 */
|
|
13
13
|
export declare function sleep(time: number): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* 重复执行某个任务直到成功,或者超过最大次数
|
|
16
|
+
* @param task 任务,需要返回 bool 值表示是否执行成功
|
|
17
|
+
* @param {Number=} maxCount 最大重试次数
|
|
18
|
+
* @param {number=} duration 每次重试的间隔
|
|
19
|
+
*/
|
|
20
|
+
export declare function tryRun(task: (...args: any[]) => Promise<any>, maxCount?: number, duration?: number, currentCount?: number): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* 延迟执行某个任务
|
|
23
|
+
* @param task
|
|
24
|
+
* @param duration
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
export declare function delayRun<T = any>(task: (...args: any[]) => Promise<T> | T, duration?: number): Promise<T>;
|
|
28
|
+
/**
|
|
29
|
+
* 为avdPort寻找一个不被占用的端口
|
|
30
|
+
* 端口号必须是偶数且在5555和5585之间
|
|
31
|
+
* @returns {number}
|
|
32
|
+
*/
|
|
33
|
+
export declare function getEvenPort(): Promise<number | false | undefined>;
|
package/lib/utils/index.js
CHANGED
|
@@ -12,17 +12,18 @@ 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
|
-
exports.sleep = exports.killProcessByCmd = exports.killProcessByPid = exports.getSystemArch = void 0;
|
|
16
|
-
const
|
|
15
|
+
exports.getEvenPort = exports.delayRun = exports.tryRun = exports.sleep = exports.killProcessByCmd = exports.killProcessByPid = exports.getSystemArch = void 0;
|
|
16
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
17
17
|
const child_process_1 = require("child_process");
|
|
18
18
|
const find_process_1 = __importDefault(require("find-process"));
|
|
19
19
|
const os_1 = __importDefault(require("os"));
|
|
20
20
|
const semver_1 = __importDefault(require("semver"));
|
|
21
|
+
const portfinder_1 = __importDefault(require("portfinder"));
|
|
21
22
|
const cpuArch = {
|
|
22
23
|
arm64: 'aarch64',
|
|
23
24
|
aarch64: 'aarch64',
|
|
24
25
|
x64: 'x86_64',
|
|
25
|
-
x86_64: 'x86_64'
|
|
26
|
+
x86_64: 'x86_64'
|
|
26
27
|
};
|
|
27
28
|
/** 获取mac电脑的CPU架构
|
|
28
29
|
* node 15.0.0之后,m1芯片的mac的os.arch()才是arm64,在这之前都是x86
|
|
@@ -42,7 +43,7 @@ function getSystemArch() {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
if (osArch !== 'arm64' && osArch !== 'x64') {
|
|
45
|
-
return
|
|
46
|
+
return shared_utils_1.ColorConsole.throw(`unsupport system`);
|
|
46
47
|
}
|
|
47
48
|
return cpuArch[osArch];
|
|
48
49
|
}
|
|
@@ -50,9 +51,7 @@ exports.getSystemArch = getSystemArch;
|
|
|
50
51
|
/** 根据PID杀死进程 */
|
|
51
52
|
function killProcessByPid(pid) {
|
|
52
53
|
try {
|
|
53
|
-
const cmd = os_1.default.platform() ===
|
|
54
|
-
? `taskkill /pid ${pid} /T /F`
|
|
55
|
-
: `kill -9 ${pid}`;
|
|
54
|
+
const cmd = os_1.default.platform() === 'win32' ? `taskkill /pid ${pid} /T /F` : `kill -9 ${pid}`;
|
|
56
55
|
(0, child_process_1.execSync)(cmd);
|
|
57
56
|
}
|
|
58
57
|
catch (e) {
|
|
@@ -82,7 +81,65 @@ exports.killProcessByCmd = killProcessByCmd;
|
|
|
82
81
|
/** 延迟函数 */
|
|
83
82
|
function sleep(time) {
|
|
84
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
return new Promise(resolve => setTimeout(resolve, time));
|
|
84
|
+
return new Promise((resolve) => setTimeout(resolve, time));
|
|
86
85
|
});
|
|
87
86
|
}
|
|
88
87
|
exports.sleep = sleep;
|
|
88
|
+
/**
|
|
89
|
+
* 重复执行某个任务直到成功,或者超过最大次数
|
|
90
|
+
* @param task 任务,需要返回 bool 值表示是否执行成功
|
|
91
|
+
* @param {Number=} maxCount 最大重试次数
|
|
92
|
+
* @param {number=} duration 每次重试的间隔
|
|
93
|
+
*/
|
|
94
|
+
function tryRun(task, maxCount = 5, duration = 1000, currentCount = 0) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
if (currentCount > maxCount)
|
|
97
|
+
return false;
|
|
98
|
+
return (Boolean(yield task()) ||
|
|
99
|
+
(yield delayRun(() => tryRun(task, maxCount, duration, currentCount + 1), duration)));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
exports.tryRun = tryRun;
|
|
103
|
+
/**
|
|
104
|
+
* 延迟执行某个任务
|
|
105
|
+
* @param task
|
|
106
|
+
* @param duration
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
function delayRun(task, duration = 1000) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
return new Promise((resolve) => {
|
|
112
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
return resolve(task());
|
|
114
|
+
}), duration);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.delayRun = delayRun;
|
|
119
|
+
/**
|
|
120
|
+
* 为avdPort寻找一个不被占用的端口
|
|
121
|
+
* 端口号必须是偶数且在5555和5585之间
|
|
122
|
+
* @returns {number}
|
|
123
|
+
*/
|
|
124
|
+
function getEvenPort() {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
const startPort = 5555;
|
|
127
|
+
const stopPort = 5585;
|
|
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 > 30)
|
|
135
|
+
return false;
|
|
136
|
+
port = yield portfinder_1.default.getPortPromise({
|
|
137
|
+
port: startPort + index,
|
|
138
|
+
stopPort
|
|
139
|
+
});
|
|
140
|
+
index++;
|
|
141
|
+
return port;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
exports.getEvenPort = getEvenPort;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/emulator",
|
|
3
|
-
"version": "2.0.2-beta.
|
|
3
|
+
"version": "2.0.2-beta.12",
|
|
4
4
|
"description": "vela emulator tool.",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -35,14 +35,16 @@
|
|
|
35
35
|
"emulator"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@aiot-toolkit/aiotpack": "2.0.2-beta.
|
|
39
|
-
"@aiot-toolkit/shared-utils": "2.0.2-beta.
|
|
38
|
+
"@aiot-toolkit/aiotpack": "2.0.2-beta.12",
|
|
39
|
+
"@aiot-toolkit/shared-utils": "2.0.2-beta.12",
|
|
40
40
|
"find-process": "^1.4.7",
|
|
41
|
+
"fs-extra": "^11.2.0",
|
|
42
|
+
"ini": "^4.1.3",
|
|
41
43
|
"portfinder": "^1.0.32"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@types/fs-extra": "^11.0.4",
|
|
45
|
-
"
|
|
47
|
+
"@types/ini": "^4.1.1"
|
|
46
48
|
},
|
|
47
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "3d2f9f8f48bb88492013d867f6eff27cb33365a0"
|
|
48
50
|
}
|