aiot-toolkit 2.0.3-beta.6 → 2.0.3-beta.8
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/bin.js +158 -184
- package/lib/builder/AndroidUxBuilder.js +14 -15
- package/lib/builder/IBuilder.js +1 -2
- package/lib/builder/UxBuilderBase.js +130 -136
- package/lib/builder/VelaUxBuilder.d.ts +3 -2
- package/lib/builder/VelaUxBuilder.js +65 -75
- package/lib/builder/XtsBuilder.js +85 -92
- package/lib/index.js +48 -13
- package/lib/interface/CommandInterface.js +4 -1
- package/lib/interface/VelaEmulatorInterface.js +4 -1
- package/lib/starter/AndroidUxStart.js +158 -158
- package/lib/starter/IStarter.js +39 -37
- package/lib/starter/VelaUxStarter.d.ts +8 -3
- package/lib/starter/VelaUxStarter.js +155 -196
- package/lib/starter/XtsStarter.js +16 -17
- package/lib/starter/androidRouter/LinkMode.js +12 -8
- package/lib/starter/androidRouter/PackageRouter.js +144 -140
- package/lib/utils/AdbUtils.js +48 -76
- package/lib/utils/DeviceUtil.js +277 -293
- package/lib/utils/RequestUtils.js +54 -68
- package/lib/utils/VelaAvdUtils.d.ts +9 -54
- package/lib/utils/VelaAvdUtils.js +126 -437
- package/lib/waiter.js +35 -35
- package/package.json +9 -15
|
@@ -1,205 +1,164 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const portfinder_1 = __importDefault(require("portfinder"));
|
|
24
|
-
const VelaUxBuilder_1 = __importDefault(require("../builder/VelaUxBuilder"));
|
|
25
|
-
const VelaAvdUtils_1 = __importDefault(require("../utils/VelaAvdUtils"));
|
|
26
|
-
const IStarter_1 = __importDefault(require("./IStarter"));
|
|
27
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
28
|
-
const ws_1 = __importDefault(require("ws"));
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _emulator = require("@aiot-toolkit/emulator");
|
|
8
|
+
var _constants = require("@aiot-toolkit/emulator/lib/emulatorutil/constants");
|
|
9
|
+
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
10
|
+
var _prompts = require("@inquirer/prompts");
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
var _portfinder = _interopRequireDefault(require("portfinder"));
|
|
13
|
+
var _VelaUxBuilder = _interopRequireWildcard(require("../builder/VelaUxBuilder"));
|
|
14
|
+
var _VelaAvdUtils = _interopRequireDefault(require("../utils/VelaAvdUtils"));
|
|
15
|
+
var _IStarter = _interopRequireDefault(require("./IStarter"));
|
|
16
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
17
|
+
var _aiotpack = require("@aiot-toolkit/aiotpack");
|
|
18
|
+
var _events = _interopRequireDefault(require("events"));
|
|
19
|
+
var _FileLaneTriggerType = _interopRequireDefault(require("file-lane/lib/enum/FileLaneTriggerType"));
|
|
20
|
+
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); }
|
|
21
|
+
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; }
|
|
22
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
29
23
|
/**
|
|
30
24
|
* VelaUxStarter
|
|
31
25
|
* ux快应用启动器
|
|
32
26
|
*/
|
|
33
|
-
class VelaUxStarter extends
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
27
|
+
class VelaUxStarter extends _IStarter.default {
|
|
28
|
+
constructor(name, description) {
|
|
29
|
+
super(name, description);
|
|
30
|
+
this.name = name;
|
|
31
|
+
this.description = description;
|
|
32
|
+
this.event = new _events.default();
|
|
33
|
+
this.builder = new _VelaUxBuilder.default({
|
|
34
|
+
onBuildSuccess: data => {
|
|
35
|
+
this.lastRpk = data.info?.rpk;
|
|
36
|
+
this.event.emit('buildSuccess', data);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
params = (() => [{
|
|
41
|
+
name: 'disableNSH',
|
|
42
|
+
description: 'disable goldfish NSH terminal',
|
|
43
|
+
defaultValue: false,
|
|
44
|
+
type: 'confirm'
|
|
45
|
+
}, {
|
|
46
|
+
name: 'watch',
|
|
47
|
+
description: 'recompile project while file changes',
|
|
48
|
+
defaultValue: false,
|
|
49
|
+
type: 'confirm'
|
|
50
|
+
}, {
|
|
51
|
+
name: 'openVNC',
|
|
52
|
+
description: 'open vnc',
|
|
53
|
+
defaultValue: false,
|
|
54
|
+
type: 'confirm'
|
|
55
|
+
}, {
|
|
56
|
+
type: 'confirm',
|
|
57
|
+
name: 'open-nuttx',
|
|
58
|
+
description: 'deprecated',
|
|
59
|
+
deprecated: 'please remove it now',
|
|
60
|
+
deprecatedVersion: '2.1.0'
|
|
61
|
+
}, ..._VelaUxBuilder.velaUxBuilderParams])();
|
|
62
|
+
async start(projectPath, options) {
|
|
63
|
+
const check = await _VelaAvdUtils.default.checkEmulatorEnv();
|
|
64
|
+
if (!check) {
|
|
65
|
+
const errorMsg = 'Your Vela emulator is not ready. Please use the `npx aiot initEmulatorEnv` command to initialize the emulator environment.';
|
|
66
|
+
_sharedUtils.ColorConsole.throw(errorMsg);
|
|
67
|
+
throw new Error(errorMsg);
|
|
68
|
+
}
|
|
69
|
+
// 获取已经创建的模拟器列表
|
|
70
|
+
const vvdList = _VelaAvdUtils.default.vvdManager.getVvdList();
|
|
71
|
+
let vvdName;
|
|
72
|
+
if (vvdList.length === 0) {
|
|
73
|
+
_sharedUtils.ColorConsole.error('no vela emulator available, please create it first.');
|
|
74
|
+
_VelaAvdUtils.default.createVelaVvdByInquire();
|
|
75
|
+
return;
|
|
76
|
+
} else if (vvdList.length === 1) {
|
|
77
|
+
const needtoRun = await (0, _prompts.confirm)({
|
|
78
|
+
message: 'there is only one emulator, need to Run?',
|
|
79
|
+
default: true
|
|
80
|
+
});
|
|
81
|
+
if (!needtoRun) {
|
|
82
|
+
_VelaAvdUtils.default.createVelaVvdByInquire();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
vvdName = vvdList[0].name;
|
|
86
|
+
_sharedUtils.ColorConsole.warn(`Start run by :${vvdName} `);
|
|
87
|
+
} else {
|
|
88
|
+
vvdName = await (0, _prompts.select)({
|
|
89
|
+
message: 'name of the avd to start',
|
|
90
|
+
choices: vvdList.map(item => {
|
|
91
|
+
return {
|
|
92
|
+
value: item.name
|
|
93
|
+
};
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// 检查选择的模拟器是否符合要求
|
|
98
|
+
if (vvdName && !this.isAvailableEmulator(vvdName)) {
|
|
99
|
+
_sharedUtils.ColorConsole.throw(`this emulator is unavailable, please create a new emulator.`);
|
|
100
|
+
return;
|
|
78
101
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
message: 'there is only one emulator, need to Run?',
|
|
92
|
-
default: true
|
|
93
|
-
});
|
|
94
|
-
if (!needtoRun) {
|
|
95
|
-
VelaAvdUtils_1.default.createVelaAvdByInquire();
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
avdName = avdList[0].avdName;
|
|
99
|
-
shared_utils_1.ColorConsole.warn(`Start run by :${avdName} `);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
avdName = yield (0, prompts_1.select)({
|
|
103
|
-
message: 'name of the avd to start',
|
|
104
|
-
choices: avdList.map((item) => {
|
|
105
|
-
return { value: item.avdName };
|
|
106
|
-
})
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
// 检查选择的模拟器是否符合要求
|
|
110
|
-
if (avdName && !this.isAvailableEmulator(avdName)) {
|
|
111
|
-
shared_utils_1.ColorConsole.throw(`this emulator is unavailable, please create a new emulator.`);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
let serverPort;
|
|
115
|
-
// watch模型下开启server
|
|
116
|
-
serverPort = yield portfinder_1.default.getPortPromise({
|
|
117
|
-
port: aiotpack_1.JavascriptDefaultCompileOption.serverPort
|
|
118
|
-
});
|
|
119
|
-
(0, aiotpack_1.setServerPort)(serverPort);
|
|
120
|
-
// build
|
|
121
|
-
const compilerOption = this.builder.getCompilerOption(projectPath, options);
|
|
122
|
-
yield this.builder.build(projectPath, options);
|
|
123
|
-
// start
|
|
124
|
-
const params = {
|
|
125
|
-
sdkHome: path_1.default.resolve(os_1.default.homedir(), '.export'),
|
|
126
|
-
avdHome: path_1.default.resolve(os_1.default.homedir(), '.android/avd'),
|
|
127
|
-
projectPath,
|
|
128
|
-
compilerOption
|
|
129
|
-
};
|
|
130
|
-
// 寻找对应的模拟器instance
|
|
131
|
-
this.currentGoldfishInstance = (0, emulator_1.findInstance)(avdName, params);
|
|
132
|
-
if (!this.currentGoldfishInstance) {
|
|
133
|
-
shared_utils_1.ColorConsole.throw('no corresponding emulator found, please recreate it');
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
let grpcPort;
|
|
137
|
-
// 设置vncPort
|
|
138
|
-
if (options.openVNC) {
|
|
139
|
-
grpcPort = yield portfinder_1.default.getPortPromise({
|
|
140
|
-
port: constants_1.defaultVncPort,
|
|
141
|
-
stopPort: constants_1.defaultVncPort + 100
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
// 设置adbPort
|
|
145
|
-
const adbPort = yield (0, index_1.getEvenPort)();
|
|
146
|
-
if (!adbPort) {
|
|
147
|
-
shared_utils_1.ColorConsole.throw(`${adbPort},the port numbers between 5555 and 5585 are all occupied. please resolve the port conflict before starting the emulator`);
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
// 设置debugPort
|
|
151
|
-
let debugPort;
|
|
152
|
-
if (options.devtool) {
|
|
153
|
-
debugPort = yield portfinder_1.default.getPortPromise({ port: constants_1.defaultDebugPort });
|
|
154
|
-
}
|
|
155
|
-
const startOptions = {
|
|
156
|
-
avdName,
|
|
157
|
-
devtool: options.devtool,
|
|
158
|
-
disableNSH: options.disableNSH,
|
|
159
|
-
serverPort,
|
|
160
|
-
grpcPort,
|
|
161
|
-
adbPort,
|
|
162
|
-
debugPort
|
|
163
|
-
};
|
|
164
|
-
yield this.currentGoldfishInstance.start(startOptions);
|
|
165
|
-
this.ws = new ws_1.default(`ws://localhost:${serverPort}`);
|
|
166
|
-
// waiter
|
|
167
|
-
// const startWaiter: PersistentCommand = new PersistentCommand({
|
|
168
|
-
// description: 'aiot-toolkit start 的常驻命令',
|
|
169
|
-
// options: [
|
|
170
|
-
// {
|
|
171
|
-
// key: '?',
|
|
172
|
-
// description: '显示所有命令',
|
|
173
|
-
// action() {
|
|
174
|
-
// startWaiter.clearLog()
|
|
175
|
-
// startWaiter.describe()
|
|
176
|
-
// }
|
|
177
|
-
// }
|
|
178
|
-
// ]
|
|
179
|
-
// })
|
|
180
|
-
// startWaiter.describe()
|
|
181
|
-
// startWaiter.start()
|
|
182
|
-
});
|
|
102
|
+
|
|
103
|
+
// build
|
|
104
|
+
const compilerOption = this.builder.getCompilerOption(projectPath, options);
|
|
105
|
+
// start build
|
|
106
|
+
await this.builder.build(projectPath, options);
|
|
107
|
+
|
|
108
|
+
// 设置 debugPort
|
|
109
|
+
let debugPort;
|
|
110
|
+
if (options.devtool) {
|
|
111
|
+
debugPort = await _portfinder.default.getPortPromise({
|
|
112
|
+
port: _constants.defaultDebugPort
|
|
113
|
+
});
|
|
183
114
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
115
|
+
|
|
116
|
+
// start emulator
|
|
117
|
+
const startRes = await _VelaAvdUtils.default.vvdManager.startVvd({
|
|
118
|
+
vvdName,
|
|
119
|
+
origin: _emulator.IStartOrigin.Terminal,
|
|
120
|
+
debugPort
|
|
121
|
+
});
|
|
122
|
+
this.emulatorInstance = startRes.emulatorInstance;
|
|
123
|
+
if (!this.emulatorInstance) {
|
|
124
|
+
throw new Error('emulatorInstance is undefined');
|
|
125
|
+
}
|
|
126
|
+
const projectInfo = _aiotpack.UxFileUtils.getMainfestInfo(projectPath, compilerOption.sourceRoot);
|
|
127
|
+
if (this.lastRpk && _fsExtra.default.existsSync(this.lastRpk)) {
|
|
128
|
+
const targetPath = await this.emulatorInstance?.pushRpk(this.lastRpk, projectInfo.package);
|
|
129
|
+
await this.emulatorInstance?.install(targetPath);
|
|
130
|
+
await this.emulatorInstance?.startApp(projectInfo.package, options.devtool);
|
|
131
|
+
}
|
|
132
|
+
this.event.on('buildSuccess', async data => {
|
|
133
|
+
if (data.info?.diffFile) {
|
|
134
|
+
const targetPath = `/data/tmp/${projectInfo.package}`;
|
|
135
|
+
await this.emulatorInstance?.push(data.info.diffFile, targetPath);
|
|
136
|
+
await this.emulatorInstance?.unzip(targetPath, `${this.emulatorInstance.appDir}/${projectInfo.package}`);
|
|
137
|
+
await this.emulatorInstance?.reloadApp(projectInfo.package);
|
|
138
|
+
} else if (data.info?.trigger === _FileLaneTriggerType.default.START && data.info.rpk) {
|
|
139
|
+
const targetPath = await this.emulatorInstance?.pushRpk(data.info.rpk, projectInfo.package);
|
|
140
|
+
await this.emulatorInstance?.install(targetPath);
|
|
141
|
+
await this.emulatorInstance?.startApp(projectInfo.package, options.devtool);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 检查选择的模拟器在当前环境下是否可以使用
|
|
148
|
+
* 下面的几种情况会导致模拟器不可用:1. 模拟器绑定的Vela镜像不存在;2. Vela4.0缺少coredump.core或者vela_data.bin文件
|
|
149
|
+
* @param avdName 模拟器名称
|
|
150
|
+
* @returns {boolean}
|
|
151
|
+
*/
|
|
152
|
+
isAvailableEmulator(avdName) {
|
|
153
|
+
const {
|
|
154
|
+
imageDir
|
|
155
|
+
} = _VelaAvdUtils.default.vvdManager.getVvdInfo(avdName);
|
|
156
|
+
// 没有avdImagePath,即对应的configIni里没有 image.sysdir.1 字段
|
|
157
|
+
// 有avdImagePath,但是这个目录下没有nuttx
|
|
158
|
+
if (!imageDir || !_fsExtra.default.existsSync(_path.default.resolve(imageDir, 'nuttx'))) {
|
|
159
|
+
return false;
|
|
203
160
|
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
204
163
|
}
|
|
205
|
-
exports.default = VelaUxStarter;
|
|
164
|
+
var _default = exports.default = VelaUxStarter;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _XtsBuilder = _interopRequireDefault(require("../builder/XtsBuilder"));
|
|
8
|
+
var _IStarter = _interopRequireDefault(require("./IStarter"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
class XtsStarter extends _IStarter.default {
|
|
11
|
+
builder = (() => new _XtsBuilder.default())();
|
|
12
|
+
params = [];
|
|
13
|
+
start(projectPath, options) {
|
|
14
|
+
console.log(projectPath, options);
|
|
15
|
+
throw new Error('Method not implemented.');
|
|
16
|
+
}
|
|
18
17
|
}
|
|
19
|
-
exports.default = XtsStarter;
|
|
18
|
+
var _default = exports.default = XtsStarter;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
3
7
|
/**
|
|
4
8
|
* 连接类型
|
|
5
9
|
*/
|
|
6
|
-
var LinkMode
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
exports.default = LinkMode;
|
|
10
|
+
var LinkMode = /*#__PURE__*/function (LinkMode) {
|
|
11
|
+
LinkMode[LinkMode["NULL"] = 0] = "NULL";
|
|
12
|
+
LinkMode[LinkMode["WIFI"] = 1] = "WIFI";
|
|
13
|
+
LinkMode[LinkMode["ADB"] = 2] = "ADB";
|
|
14
|
+
return LinkMode;
|
|
15
|
+
}(LinkMode || {});
|
|
16
|
+
var _default = exports.default = LinkMode;
|