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.
@@ -1,205 +1,164 @@
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 aiotpack_1 = require("@aiot-toolkit/aiotpack");
16
- const emulator_1 = require("@aiot-toolkit/emulator");
17
- const constants_1 = require("@aiot-toolkit/emulator/lib/emulatorutil/constants");
18
- const index_1 = require("@aiot-toolkit/emulator/lib/utils/index");
19
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
20
- const prompts_1 = require("@inquirer/prompts");
21
- const os_1 = __importDefault(require("os"));
22
- const path_1 = __importDefault(require("path"));
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 IStarter_1.default {
34
- constructor() {
35
- super(...arguments);
36
- this.builder = new VelaUxBuilder_1.default({
37
- onBuildSuccess: (data) => {
38
- var _a;
39
- shared_utils_1.ColorConsole.info(`build time: ${data.costTime}ms`);
40
- if (this.ws) {
41
- this.ws.send(JSON.stringify({
42
- type: 'restart'
43
- }));
44
- }
45
- else {
46
- (_a = this.currentGoldfishInstance) === null || _a === void 0 ? void 0 : _a.restart();
47
- }
48
- }
49
- });
50
- this.params = [
51
- {
52
- name: 'disableNSH',
53
- description: 'disable goldfish NSH terminal',
54
- defaultValue: false,
55
- type: 'confirm'
56
- },
57
- {
58
- name: 'watch',
59
- description: 'recompile project while file changes',
60
- defaultValue: false,
61
- type: 'confirm'
62
- },
63
- {
64
- name: 'openVNC',
65
- description: 'open vnc',
66
- defaultValue: false,
67
- type: 'confirm'
68
- },
69
- {
70
- type: 'confirm',
71
- name: 'open-nuttx',
72
- description: 'deprecated',
73
- deprecated: 'please remove it now',
74
- deprecatedVersion: '2.1.0'
75
- },
76
- ...this.builder.params
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
- start(projectPath, options) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- // 获取已经创建的模拟器列表
82
- const avdList = VelaAvdUtils_1.default.velaAvdCls.getVelaAvdList();
83
- let avdName;
84
- if (avdList.length === 0) {
85
- shared_utils_1.ColorConsole.error('no vela emulator available, please create it first.');
86
- VelaAvdUtils_1.default.createVelaAvdByInquire();
87
- return;
88
- }
89
- else if (avdList.length === 1) {
90
- const needtoRun = yield (0, prompts_1.confirm)({
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
- * 下面的几种情况会导致模拟器不可用:1. 模拟器绑定的Vela镜像不存在;2. Vela4.0缺少coredump.core或者vela_data.bin文件
187
- * @param avdName 模拟器名称
188
- * @returns {boolean}
189
- */
190
- isAvailableEmulator(avdName) {
191
- const { avdImagePath } = VelaAvdUtils_1.default.velaAvdCls.getVelaAvdInfo(avdName);
192
- // 没有avdImagePath,即对应的configIni里没有 image.sysdir.1 字段
193
- // 有avdImagePath,但是这个目录下没有nuttx
194
- if (!avdImagePath || !fs_extra_1.default.existsSync(path_1.default.resolve(avdImagePath, 'nuttx'))) {
195
- return false;
196
- }
197
- if (avdImagePath.includes('vela-release') &&
198
- (!fs_extra_1.default.existsSync(path_1.default.resolve(avdImagePath, 'coredump.core')) ||
199
- !fs_extra_1.default.existsSync(path_1.default.resolve(avdImagePath, 'vela_data.bin')))) {
200
- return false;
201
- }
202
- return true;
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
- 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
- }
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
- Object.defineProperty(exports, "__esModule", { value: true });
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
- (function (LinkMode) {
8
- LinkMode[LinkMode["NULL"] = 0] = "NULL";
9
- LinkMode[LinkMode["WIFI"] = 1] = "WIFI";
10
- LinkMode[LinkMode["ADB"] = 2] = "ADB";
11
- })(LinkMode || (LinkMode = {}));
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;