aiot-toolkit 2.0.2 → 2.0.3-beta.10

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,445 +1,136 @@
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 emulator_1 = require("@aiot-toolkit/emulator");
16
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
17
- const prompts_1 = require("@inquirer/prompts");
18
- const adm_zip_1 = __importDefault(require("adm-zip"));
19
- const axios_1 = __importDefault(require("axios"));
20
- const cli_progress_1 = __importDefault(require("cli-progress"));
21
- const dayjs_1 = __importDefault(require("dayjs"));
22
- const fs_extra_1 = __importDefault(require("fs-extra"));
23
- const os_1 = __importDefault(require("os"));
24
- const path_1 = __importDefault(require("path"));
25
- class VelaAvdUtils {
26
- /** 校验AVD名称 */
27
- static validateAvdName(avdName) {
28
- if (!avdName) {
29
- return `Please enter avd name`;
30
- }
31
- if (!avdName.startsWith('Vela')) {
32
- return 'The avd name must starts with Vela';
33
- }
34
- const avdDir = path_1.default.resolve(VelaAvdUtils.avdHome, `${avdName}.avd`);
35
- if (fs_extra_1.default.existsSync(avdDir)) {
36
- return `The avd already exists. Please change avd name`;
37
- }
38
- return true;
39
- }
40
- /**
41
- * 从CDN上下载资源文件
42
- * @param downloadUrl 下载地址
43
- * @param targetDir 下载后的文件存放的目录
44
- * @param filename 下载文件的名称
45
- * @returns
46
- */
47
- static downloadFromCdn(downloadUrl, targetDir, filename) {
48
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
49
- fs_extra_1.default.mkdirSync(targetDir, { recursive: true });
50
- const targetFile = path_1.default.resolve(targetDir, filename);
51
- const progress = new cli_progress_1.default.Bar({
52
- format: `downloading ${filename}| [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}`,
53
- clearOnComplete: true,
54
- stopOnComplete: true
55
- });
56
- progress.start(100, 0);
57
- try {
58
- const fwrite = fs_extra_1.default.createWriteStream(targetFile);
59
- const response = yield (0, axios_1.default)({
60
- method: 'get',
61
- url: downloadUrl,
62
- responseType: 'stream',
63
- onDownloadProgress(evt) {
64
- evt.total && progress.update((evt.loaded / evt.total) * 100);
65
- }
66
- });
67
- response.data.pipe(fwrite).on('close', () => {
68
- resolve();
69
- });
70
- }
71
- catch (e) {
72
- shared_utils_1.ColorConsole.throw(`Download ${filename} failed`);
73
- reject();
74
- }
75
- }));
76
- }
77
- /**
78
- * 下载zip文件并解压。会将zip里的所有文件解压至targetDir
79
- * @param downloadUrl 下载地址
80
- * @param targetDir 解压目录
81
- * @returns
82
- */
83
- static downloadAndUnzip(downloadUrl, targetDir) {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- const filename = path_1.default.basename(downloadUrl);
86
- const targetFile = path_1.default.resolve(targetDir, filename);
87
- try {
88
- fs_extra_1.default.mkdirSync(targetDir, { recursive: true });
89
- yield VelaAvdUtils.downloadFromCdn(downloadUrl, targetDir, filename);
90
- fs_extra_1.default.chmodSync(targetFile, 0o777);
91
- const zip = new adm_zip_1.default(targetFile);
92
- zip.extractAllTo(targetDir, true, true);
93
- fs_extra_1.default.rmSync(targetFile);
94
- return Promise.resolve();
95
- }
96
- catch (e) {
97
- if (fs_extra_1.default.existsSync(targetFile)) {
98
- fs_extra_1.default.rmSync(targetFile);
99
- }
100
- return Promise.reject();
101
- }
102
- });
103
- }
104
- /** 根据host获取模拟器下载地址 */
105
- static getEmulatorUrl(version = '0.0.1') {
106
- const systemOs = os_1.default.platform();
107
- const hostArch = (0, emulator_1.getSystemArch)();
108
- let hostOs = systemOs === 'win32' ? 'windows' : systemOs;
109
- return `${VelaAvdUtils.emulatorBaseUrl}/v${version}/${hostOs}-${hostArch}.zip`;
110
- }
111
- /** 获取模拟器平台的名称,darwin-aarch64 linux-aarch64 windows-x86_64等 */
112
- static getEmulatorPlatform() {
113
- const systemOs = os_1.default.platform();
114
- const hostArch = (0, emulator_1.getSystemArch)();
115
- const hostOs = systemOs === 'win32' ? 'windows' : systemOs;
116
- return `${hostOs}-${hostArch}`;
117
- }
118
- /** 获取各项模拟器资源的根目录 */
119
- static getEmulatorEnvHome(resourceName) {
120
- return path_1.default.resolve(VelaAvdUtils.sdkHome, resourceName);
121
- }
122
- /**
123
- * Vela镜像需要更新
124
- * @param imageId 镜像id
125
- * @returns {boolean}
126
- */
127
- static velaImageNeedUpdate(imageId) {
128
- // 兼容之前的version.json
129
- if (typeof imageId !== 'string' || !imageId)
130
- return true;
131
- let avdImagePath = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', imageId, 'nuttx');
132
- if (!fs_extra_1.default.existsSync(avdImagePath)) {
133
- return true;
134
- }
135
- if (VelaAvdUtils.isZipInImageUrl(imageId)) {
136
- const stats = fs_extra_1.default.statSync(avdImagePath);
137
- const version = emulator_1.VelaImageVersionList.find((item) => item.value === imageId);
138
- if (version && (0, dayjs_1.default)(version.time).isAfter(stats.mtime, 'day'))
139
- return true;
140
- }
141
- return false;
142
- }
143
- /**
144
- * Vela镜像是否为zip包(是否为0.0.2版本)
145
- * 只有Vela开发版(dev, 0.0.2)这个版本的镜像不是zip包
146
- * @param velaImage
147
- * @returns
148
- */
149
- static isZipInImageUrl(velaImage) {
150
- return velaImage.indexOf('0.0.2') < 0;
151
- }
152
- /** 获取vela镜像的下载地址 */
153
- static getSystemImageUrl(version = 'vela-release-4.0') {
154
- if (VelaAvdUtils.isZipInImageUrl(version)) {
155
- const velaImage = emulator_1.VelaImageVersionList.find((item) => item.value === version);
156
- const dayOfTime = (0, dayjs_1.default)(velaImage === null || velaImage === void 0 ? void 0 : velaImage.time).format('YYYYMMDD');
157
- return `${VelaAvdUtils.systemImageBaseUrl}/${version}/${dayOfTime}/${version}.zip`;
158
- }
159
- return `${VelaAvdUtils.systemImageBaseUrl}/${version}/nuttx`;
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _emulator = require("@aiot-toolkit/emulator");
8
+ var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
+ var _prompts = require("@inquirer/prompts");
10
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
+ var _path = _interopRequireDefault(require("path"));
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ class VelaVvdUtils {
14
+ static sdkHome = (() => _emulator.defaultSDKHome)();
15
+ static vvdHome = (() => _emulator.defaultVvdHome)();
16
+ static vvdManager = (() => new _emulator.VvdManager({
17
+ sdkHome: VelaVvdUtils.sdkHome,
18
+ vvdHome: VelaVvdUtils.vvdHome
19
+ }))();
20
+
21
+ /** 校验VVD名称 */
22
+ static validateVvdName(vvdName) {
23
+ if (!vvdName) {
24
+ return `Please enter vvd name`;
160
25
  }
161
- /** 获取模拟器其他资源的下载地址 */
162
- static getDownloadUrl(dir, version = '0.0.1', filename = dir) {
163
- return `${VelaAvdUtils.baseUrl}/${dir}/v${version}/${filename}.zip`;
26
+ if (!vvdName.startsWith('Vela')) {
27
+ return 'The vvd name must starts with Vela';
164
28
  }
165
- /** 根据host获取ya-vm-file-server下载地址 */
166
- static getv9fsToolUrl(version = '0.0.1') {
167
- const systemOs = os_1.default.platform();
168
- const arch = (0, emulator_1.getSystemArch)();
169
- let v9fsTool = '';
170
- switch (systemOs) {
171
- case 'linux':
172
- v9fsTool = 'ya-vm-file-server-linux-x86_64';
173
- break;
174
- case 'win32':
175
- v9fsTool = 'ya-vm-file-server-windows.exe';
176
- break;
177
- case 'darwin':
178
- v9fsTool = `ya-vm-file-server-darwin-${arch}`;
179
- break;
180
- default:
181
- break;
182
- }
183
- return `${VelaAvdUtils.baseUrl}/tools/v${version}/${v9fsTool}`;
29
+ const vvdDir = this.vvdManager.getVvdDir(vvdName);
30
+ if (_fsExtra.default.existsSync(vvdDir)) {
31
+ return `The vvd already exists. Please change vvd name`;
184
32
  }
185
- /** 获取镜像构建时间 */
186
- static getImageBuildTime(imageId) {
187
- var _a;
188
- if (!imageId)
189
- return;
190
- const imagePath = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', imageId, 'nuttx');
191
- if (fs_extra_1.default.existsSync(imagePath)) {
192
- if (VelaAvdUtils.isZipInImageUrl(imageId)) {
193
- const stats = fs_extra_1.default.statSync(imagePath);
194
- return stats.mtime;
195
- }
196
- else {
197
- const time = (_a = emulator_1.VelaImageVersionList.find((item) => item.value === imageId)) === null || _a === void 0 ? void 0 : _a.time;
198
- return time;
199
- }
33
+ return true;
34
+ }
35
+
36
+ /**
37
+ * 命令行访问方式创建模拟器
38
+ */
39
+ static async createVelaVvdByInquire() {
40
+ try {
41
+ // vvdName
42
+ const name = await (0, _prompts.input)({
43
+ message: 'vvd name starting with Vela. (eg. Vela_Virtual_Device)',
44
+ default: 'Vela_Virtual_Device',
45
+ validate(value) {
46
+ return VelaVvdUtils.validateVvdName(value);
200
47
  }
201
- return;
202
- }
203
- /**
204
- * 命令行访问方式创建模拟器
205
- */
206
- static createVelaAvdByInquire() {
207
- return __awaiter(this, void 0, void 0, function* () {
208
- const versionFile = path_1.default.resolve(VelaAvdUtils.sdkHome, 'versions.json');
209
- const versionFileExist = fs_extra_1.default.existsSync(versionFile);
210
- let currVersionInfo = {
211
- name: '模拟器资源版本管理',
212
- emulator: '',
213
- qa: '',
214
- skins: '',
215
- 'system-images': '',
216
- tools: '',
217
- modem_simulator: ''
218
- };
219
- if (versionFileExist) {
220
- currVersionInfo = fs_extra_1.default.readJSONSync(versionFile);
221
- }
222
- const onlineVersionInfo = emulator_1.EmulatorEnvVersion;
223
- // 模拟器各项资源(除了镜像)是否存在
224
- const emulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'emulator', VelaAvdUtils.getEmulatorPlatform()));
225
- const qaExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'qa/font'));
226
- const skinsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
227
- const toolsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'tools'));
228
- const modemSimulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'modem_simulator/modem_nvram.json'));
229
- try {
230
- // avdName
231
- const avdName = yield (0, prompts_1.input)({
232
- message: 'avd name starting with Vela. (eg. Vela_Virtual_Device)',
233
- default: 'Vela_Virtual_Device',
234
- validate(value) {
235
- return VelaAvdUtils.validateAvdName(value);
236
- }
237
- });
238
- // 镜像
239
- const velaImage = yield (0, prompts_1.select)({
240
- message: 'vela image.',
241
- choices: emulator_1.VelaImageVersionList.map((item) => {
242
- return { value: item.value, name: item.label };
243
- })
244
- });
245
- // skin或者size
246
- let avdSkin = '';
247
- let avdWidth = '466';
248
- let avdHeight = '466';
249
- // vela4.0不允许自定义分辨率
250
- if (velaImage.indexOf('vela-release') < 0) {
251
- const needSkin = yield (0, prompts_1.confirm)({
252
- message: 'need avd skin?',
253
- default: true
254
- });
255
- if (needSkin) {
256
- if (!skinsExist || (currVersionInfo && currVersionInfo.skins < onlineVersionInfo.skins)) {
257
- const skinsUrl = VelaAvdUtils.getDownloadUrl('skins', onlineVersionInfo.skins);
258
- yield VelaAvdUtils.downloadAndUnzip(skinsUrl, path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
259
- currVersionInfo.skins = emulator_1.EmulatorEnvVersion.skins;
260
- shared_utils_1.ColorConsole.success(`Download skins succeed.`);
261
- }
262
- const skinList = VelaAvdUtils.velaAvdCls.getVelaSkinList();
263
- avdSkin = yield (0, prompts_1.select)({
264
- message: 'avd skin.',
265
- choices: skinList.map((item) => {
266
- return {
267
- name: item,
268
- value: item,
269
- description: item
270
- };
271
- })
272
- });
273
- }
274
- else {
275
- avdWidth = yield (0, prompts_1.input)({
276
- message: 'avd width.',
277
- default: '466'
278
- });
279
- avdHeight = yield (0, prompts_1.input)({
280
- message: 'avd height.',
281
- default: '466'
282
- });
283
- }
284
- }
285
- // 下载模拟器
286
- if (!emulatorExist ||
287
- (currVersionInfo && currVersionInfo.emulator < onlineVersionInfo.emulator)) {
288
- const emulatorDownloadUrl = VelaAvdUtils.getEmulatorUrl(onlineVersionInfo.emulator);
289
- yield VelaAvdUtils.downloadAndUnzip(emulatorDownloadUrl, VelaAvdUtils.getEmulatorEnvHome('emulator'));
290
- currVersionInfo.emulator = emulator_1.EmulatorEnvVersion.emulator;
291
- shared_utils_1.ColorConsole.success(`Download emulator succeed.`);
292
- }
293
- // 下载镜像
294
- const imageDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', velaImage);
295
- if (this.velaImageNeedUpdate(velaImage)) {
296
- const velaImageDownloadUrl = this.getSystemImageUrl(velaImage);
297
- if (VelaAvdUtils.isZipInImageUrl(velaImage)) {
298
- yield VelaAvdUtils.downloadAndUnzip(velaImageDownloadUrl, imageDir);
299
- currVersionInfo['system-images'] = emulator_1.EmulatorEnvVersion['system-images'];
300
- }
301
- else {
302
- yield VelaAvdUtils.downloadFromCdn(velaImageDownloadUrl, imageDir, 'nuttx');
303
- }
304
- shared_utils_1.ColorConsole.success(`Download vela image succeed.`);
305
- }
306
- // 下载快应用qa文件
307
- if (!qaExist || (currVersionInfo && currVersionInfo.qa < onlineVersionInfo.qa)) {
308
- const qaUrl = VelaAvdUtils.getDownloadUrl('qa', onlineVersionInfo.qa);
309
- yield VelaAvdUtils.downloadAndUnzip(qaUrl, VelaAvdUtils.getEmulatorEnvHome('qa'));
310
- currVersionInfo.qa = emulator_1.EmulatorEnvVersion.qa;
311
- shared_utils_1.ColorConsole.success(`Download quickapp font succeed.`);
312
- }
313
- // 下载tools
314
- if (!toolsExist || (currVersionInfo && currVersionInfo.tools < onlineVersionInfo.tools)) {
315
- const v9fsToolUrl = VelaAvdUtils.getv9fsToolUrl();
316
- const filename = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
317
- yield VelaAvdUtils.downloadFromCdn(v9fsToolUrl, VelaAvdUtils.getEmulatorEnvHome('tools'), filename);
318
- currVersionInfo.tools = emulator_1.EmulatorEnvVersion.tools;
319
- shared_utils_1.ColorConsole.success(`Download tools succeed.`);
320
- }
321
- // 下载modem_simulator
322
- if (!modemSimulatorExist ||
323
- currVersionInfo.modem_simulator < emulator_1.EmulatorEnvVersion.modem_simulator) {
324
- const modemSimulatorUrl = VelaAvdUtils.getDownloadUrl('modem_simulator', emulator_1.EmulatorEnvVersion.modem_simulator);
325
- yield VelaAvdUtils.downloadAndUnzip(modemSimulatorUrl, VelaAvdUtils.getEmulatorEnvHome('modem_simulator'));
326
- currVersionInfo.modem_simulator = emulator_1.EmulatorEnvVersion.modem_simulator;
327
- shared_utils_1.ColorConsole.success(`Download modem simulator succeed.`);
328
- }
329
- // 创建avd文本文件
330
- const avdImagePath = imageDir;
331
- const avdParams = {
332
- avdName,
333
- avdSkin,
334
- avdWidth,
335
- avdHeight,
336
- avdArch: emulator_1.IAvdArchType.arm,
337
- avdImagePath
338
- };
339
- VelaAvdUtils.velaAvdCls.createVelaAvd(avdParams);
340
- shared_utils_1.ColorConsole.success(`Create avd succeed.`);
341
- }
342
- catch (e) {
343
- shared_utils_1.ColorConsole.throw(`Create avd failed. Error: ${e.message}`);
344
- }
345
- finally {
346
- // 写入versions.json
347
- const versionJson = JSON.stringify(currVersionInfo, null, 2);
348
- fs_extra_1.default.writeFileSync(versionFile, versionJson);
349
- }
48
+ });
49
+ // 镜像
50
+ const velaImage = await (0, _prompts.select)({
51
+ message: 'vela image.',
52
+ choices: _emulator.VelaImageVersionList.map(item => {
53
+ return {
54
+ value: item.value,
55
+ name: item.label
56
+ };
57
+ })
58
+ });
59
+ // skin或者size
60
+ let skin = '';
61
+ let width = '466';
62
+ let height = '466';
63
+ // vela4.0不允许自定义分辨率
64
+ if (velaImage === _emulator.VelaImageType.REL) {
65
+ const needSkin = await (0, _prompts.confirm)({
66
+ message: 'need vvd skin?',
67
+ default: true
350
68
  });
351
- }
352
- /** 初始化/重置模拟器环境 */
353
- static initEmulatorEnv() {
354
- return __awaiter(this, void 0, void 0, function* () {
355
- const versionFile = path_1.default.resolve(VelaAvdUtils.sdkHome, 'versions.json');
356
- const versionFileExist = fs_extra_1.default.existsSync(versionFile);
357
- let currVersionInfo = {
358
- name: '模拟器资源版本管理',
359
- emulator: '',
360
- qa: '',
361
- skins: '',
362
- 'system-images': '',
363
- tools: '',
364
- modem_simulator: ''
365
- };
366
- if (versionFileExist) {
367
- currVersionInfo = fs_extra_1.default.readJSONSync(versionFile);
368
- }
369
- // 模拟器的各项资源是否存在
370
- const emulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'emulator', VelaAvdUtils.getEmulatorPlatform()));
371
- const qaExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'qa/font'));
372
- const skinsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
373
- const toolsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'tools'));
374
- const modemSimulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'modem_simulator/modem_nvram.json'));
375
- const systemImageExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', emulator_1.VelaImageVersionList[0].value, 'nuttx'));
376
- try {
377
- // 下载皮肤
378
- if (!skinsExist || currVersionInfo.skins < emulator_1.EmulatorEnvVersion.skins) {
379
- const skinsUrl = VelaAvdUtils.getDownloadUrl('skins', emulator_1.EmulatorEnvVersion.skins);
380
- yield VelaAvdUtils.downloadAndUnzip(skinsUrl, VelaAvdUtils.getEmulatorEnvHome('skins'));
381
- currVersionInfo.skins = emulator_1.EmulatorEnvVersion.skins;
382
- shared_utils_1.ColorConsole.success(`Download skins succeed.`);
383
- }
384
- // 下载快应用font
385
- if (!qaExist || currVersionInfo.qa < emulator_1.EmulatorEnvVersion.qa) {
386
- const qaUrl = VelaAvdUtils.getDownloadUrl('qa', emulator_1.EmulatorEnvVersion.qa);
387
- yield VelaAvdUtils.downloadAndUnzip(qaUrl, VelaAvdUtils.getEmulatorEnvHome('qa'));
388
- currVersionInfo.qa = emulator_1.EmulatorEnvVersion.qa;
389
- shared_utils_1.ColorConsole.success(`Download quickapp font succeed.`);
390
- }
391
- // 下载工具
392
- if (!toolsExist || currVersionInfo.tools < emulator_1.EmulatorEnvVersion.tools) {
393
- const v9fsToolUrl = VelaAvdUtils.getv9fsToolUrl(emulator_1.EmulatorEnvVersion.tools);
394
- const filename = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
395
- yield VelaAvdUtils.downloadFromCdn(v9fsToolUrl, VelaAvdUtils.getEmulatorEnvHome('tools'), filename);
396
- currVersionInfo.tools = emulator_1.EmulatorEnvVersion.tools;
397
- shared_utils_1.ColorConsole.success(`Download tools succeed.`);
398
- }
399
- // 下载模拟器
400
- if (!emulatorExist || currVersionInfo.emulator < emulator_1.EmulatorEnvVersion.emulator) {
401
- const emulatorUrl = VelaAvdUtils.getEmulatorUrl(emulator_1.EmulatorEnvVersion.emulator);
402
- yield VelaAvdUtils.downloadAndUnzip(emulatorUrl, VelaAvdUtils.getEmulatorEnvHome('emulator'));
403
- currVersionInfo.emulator = emulator_1.EmulatorEnvVersion.emulator;
404
- shared_utils_1.ColorConsole.success(`Download emulator succeed.`);
405
- }
406
- // 下载modem_simultor
407
- if (!modemSimulatorExist ||
408
- currVersionInfo.modem_simulator < emulator_1.EmulatorEnvVersion.modem_simulator) {
409
- const modemSimulatorUrl = VelaAvdUtils.getDownloadUrl('modem_simulator', emulator_1.EmulatorEnvVersion.modem_simulator);
410
- yield VelaAvdUtils.downloadAndUnzip(modemSimulatorUrl, VelaAvdUtils.getEmulatorEnvHome('modem_simulator'));
411
- currVersionInfo.modem_simulator = emulator_1.EmulatorEnvVersion.modem_simulator;
412
- shared_utils_1.ColorConsole.success(`Download modem simulator succeed.`);
413
- }
414
- // 下载vela镜像,默认只下载最新的vela正式版,dev版本需要创建模拟器的时候手动勾选
415
- if (!systemImageExist || VelaAvdUtils.velaImageNeedUpdate(emulator_1.VelaImageVersionList[0].value)) {
416
- const systemImageUrl = VelaAvdUtils.getSystemImageUrl(emulator_1.VelaImageVersionList[0].value);
417
- const imageDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', emulator_1.VelaImageVersionList[0].value);
418
- yield VelaAvdUtils.downloadAndUnzip(systemImageUrl, imageDir);
419
- currVersionInfo['system-images'] = emulator_1.EmulatorEnvVersion['system-images'];
420
- shared_utils_1.ColorConsole.success(`Download vela image succeed.`);
421
- }
422
- shared_utils_1.ColorConsole.success(`Create emulator environment succeed.`);
423
- }
424
- catch (e) {
425
- shared_utils_1.ColorConsole.throw(`Create emulator environment failed. Error: ${e.message}`);
426
- }
427
- finally {
428
- // 写入versions.json
429
- const versionJson = JSON.stringify(currVersionInfo, null, 2);
430
- fs_extra_1.default.writeFileSync(versionFile, versionJson);
431
- }
69
+ if (needSkin) {
70
+ const skinList = await VelaVvdUtils.vvdManager.getVelaSkinList();
71
+ skin = await (0, _prompts.select)({
72
+ message: 'vvd skin.',
73
+ choices: skinList.map(item => {
74
+ return {
75
+ name: item.name,
76
+ value: item.name,
77
+ description: item.name
78
+ };
79
+ })
80
+ });
81
+ } else {
82
+ width = await (0, _prompts.input)({
83
+ message: 'vvd width.',
84
+ default: '466'
85
+ });
86
+ height = await (0, _prompts.input)({
87
+ message: 'vvd height.',
88
+ default: '466'
89
+ });
90
+ }
91
+ }
92
+ const vvdManager = new _emulator.VvdManager({
93
+ sdkHome: VelaVvdUtils.sdkHome
94
+ });
95
+ if ((await vvdManager.hasSDKChildrenUpdate()).length > 0) {
96
+ const downloder = await vvdManager.downloadSDK({
97
+ force: false,
98
+ cliProgress: true,
99
+ parallelDownloads: 6
432
100
  });
101
+ await downloder.downlodPromise;
102
+ }
103
+ const imageDir = _path.default.resolve(VelaVvdUtils.sdkHome, _emulator.SDKChildren.SYSTEM_IMAGES, velaImage);
104
+
105
+ // 创建vvd文本文件
106
+ const vvdParams = {
107
+ name,
108
+ skin,
109
+ width,
110
+ height,
111
+ arch: _emulator.IVvdArchType.arm,
112
+ imageDir,
113
+ imageType: velaImage,
114
+ customLcdRadius: ''
115
+ };
116
+ VelaVvdUtils.vvdManager.createVvd(vvdParams);
117
+ _sharedUtils.ColorConsole.success(`Create vvd succeed.`);
118
+ } catch (e) {
119
+ _sharedUtils.ColorConsole.throw(`Create vvd failed. Error: ${e.message}`);
433
120
  }
121
+ }
122
+ static async checkEmulatorEnv() {
123
+ return (await this.vvdManager.hasSDKChildrenUpdate()).length === 0;
124
+ }
125
+
126
+ /** 初始化/重置模拟器环境 */
127
+ static async initEmulatorEnv() {
128
+ const downloder = await VelaVvdUtils.vvdManager.downloadSDK({
129
+ force: true,
130
+ cliProgress: true,
131
+ parallelDownloads: 6
132
+ });
133
+ await downloder.downlodPromise;
134
+ }
434
135
  }
435
- VelaAvdUtils.sdkHome = path_1.default.resolve(os_1.default.homedir(), '.export');
436
- VelaAvdUtils.avdHome = path_1.default.resolve(os_1.default.homedir(), '.android', 'avd');
437
- VelaAvdUtils.baseUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide';
438
- VelaAvdUtils.versionUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/versions.json';
439
- VelaAvdUtils.emulatorBaseUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/emulator';
440
- VelaAvdUtils.systemImageBaseUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/system-images';
441
- VelaAvdUtils.velaAvdCls = new emulator_1.VelaAvdCls({
442
- sdkHome: VelaAvdUtils.sdkHome,
443
- avdHome: VelaAvdUtils.avdHome
444
- });
445
- exports.default = VelaAvdUtils;
136
+ var _default = exports.default = VelaVvdUtils;
package/lib/waiter.js CHANGED
@@ -1,37 +1,37 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const commander_1 = require("@aiot-toolkit/commander");
4
- const waiter = new commander_1.PersistentCommand({
5
- description: 'aiot-toolkit 常驻命令',
6
- options: [
7
- {
8
- key: 'a',
9
- description: '获取设备列表',
10
- action() {
11
- return new Promise((resolve) => {
12
- console.log('获取中...');
13
- setTimeout(() => {
14
- console.log('设备列表:123');
15
- resolve();
16
- }, 3000);
17
- });
18
- }
19
- },
20
- {
21
- key: 'i',
22
- description: '自我介绍',
23
- action() {
24
- console.log('我就是一个没用的快捷命令');
25
- }
26
- },
27
- {
28
- key: '?',
29
- description: '显示所有命令',
30
- action() {
31
- waiter.clearLog();
32
- waiter.describe();
33
- }
34
- }
35
- ]
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
36
5
  });
37
- exports.default = waiter;
6
+ exports.default = void 0;
7
+ var _commander = require("@aiot-toolkit/commander");
8
+ const waiter = new _commander.PersistentCommand({
9
+ description: 'aiot-toolkit 常驻命令',
10
+ options: [{
11
+ key: 'a',
12
+ description: '获取设备列表',
13
+ action() {
14
+ return new Promise(resolve => {
15
+ console.log('获取中...');
16
+ setTimeout(() => {
17
+ console.log('设备列表:123');
18
+ resolve();
19
+ }, 3000);
20
+ });
21
+ }
22
+ }, {
23
+ key: 'i',
24
+ description: '自我介绍',
25
+ action() {
26
+ console.log('我就是一个没用的快捷命令');
27
+ }
28
+ }, {
29
+ key: '?',
30
+ description: '显示所有命令',
31
+ action() {
32
+ waiter.clearLog();
33
+ waiter.describe();
34
+ }
35
+ }]
36
+ });
37
+ var _default = exports.default = waiter;