@aiot-toolkit/emulator 2.0.4-beta.1 → 2.0.4-beta.2

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.
@@ -42,3 +42,4 @@ export declare function getImageDownloadUrl(): Record<VelaImageType, string>;
42
42
  */
43
43
  export declare function getSDKPartDownloadUrl(type: SDKParts): string;
44
44
  export declare function getDefaultImage(): VelaImageType;
45
+ export declare function isVelaImageType(value: any): value is VelaImageType;
@@ -7,6 +7,7 @@ exports.emulatorBaseUrl = exports.defaultVvdHome = exports.defaultVncPort = expo
7
7
  exports.getDefaultImage = getDefaultImage;
8
8
  exports.getImageDownloadUrl = getImageDownloadUrl;
9
9
  exports.getSDKPartDownloadUrl = getSDKPartDownloadUrl;
10
+ exports.isVelaImageType = isVelaImageType;
10
11
  exports.versionUrl = exports.systemImageBaseUrl = void 0;
11
12
  var _os = _interopRequireDefault(require("os"));
12
13
  var _path = _interopRequireDefault(require("path"));
@@ -101,4 +102,7 @@ function getSDKPartDownloadUrl(type) {
101
102
  }
102
103
  function getDefaultImage() {
103
104
  return _Vvd.VelaImageType.REL;
105
+ }
106
+ function isVelaImageType(value) {
107
+ return Object.values(_Vvd.VelaImageType).includes(value);
104
108
  }
@@ -95,7 +95,7 @@ class CommonEmulatorInstance {
95
95
  async isConnected() {
96
96
  return (0, _utils.tryRun)(async () => {
97
97
  const devices = await adbMiwt.getAdbDevices();
98
- _ColorConsole.default.log(`adb devices: ${JSON.stringify(devices)}`);
98
+ this.logger(`adb devices: ${JSON.stringify(devices)}`);
99
99
  const curDev = devices.find(t => t.sn === this.sn);
100
100
  return curDev?.status === 'device';
101
101
  }, 10, 500);
@@ -164,10 +164,10 @@ class CommonEmulatorInstance {
164
164
  /** 重启模拟器 */
165
165
  async reboot() {
166
166
  const rebootCmd = `adb -s ${this.sn} shell reboot`;
167
- _ColorConsole.default.log(`Excuting: ${rebootCmd}`);
167
+ this.logger(`Excuting: ${rebootCmd}`);
168
168
  await adbMiwt.execAdbCmdAsync(rebootCmd);
169
169
  await this.isConnected();
170
- if (!this.logcatProcess.exitCode !== undefined) {
170
+ if (this.logcatProcess.exitCode !== null) {
171
171
  // 如果 logcat 进程被杀死,则重新创建
172
172
  const r = (0, _logcat.creatLogcat)(this.sn, this.onStdout, this.onErrout);
173
173
  this.logcatProcess = r.logcatProcess;
@@ -81,6 +81,10 @@ export interface SkinInfo {
81
81
  density?: string;
82
82
  };
83
83
  }
84
+ export interface DownloadItem {
85
+ name: string;
86
+ url: string;
87
+ }
84
88
  export interface EmulatorSkin {
85
89
  name: string;
86
90
  info: SkinInfo;
@@ -102,4 +106,5 @@ export declare enum VELAHOME {
102
106
  export type SDKDownloadOpt = {
103
107
  force?: boolean;
104
108
  parallelStreams?: number;
109
+ imageTypeArr?: VelaImageType[];
105
110
  } & Parameters<typeof import('ipull').downloadSequence>[0];
package/lib/vvd/index.js CHANGED
@@ -643,10 +643,27 @@ class VvdManager {
643
643
  */
644
644
  async downloadSDK(opt) {
645
645
  const updateList = opt.force ? Object.values(_Vvd.SDKParts) : await this.hasSDKPartUpdate();
646
- const urls = updateList.map(t => ({
646
+ let urls = updateList.map(t => ({
647
647
  name: t,
648
648
  url: (0, _constants.getSDKPartDownloadUrl)(t)
649
649
  }));
650
+ if (opt.imageTypeArr) {
651
+ // 首先过滤掉 REL 类型
652
+ const filteredTypes = opt.imageTypeArr.filter(type => type !== _Vvd.VelaImageType.REL);
653
+
654
+ // 异步检查每个类型是否需要更新
655
+ const updateChecks = await Promise.all(filteredTypes.map(async type => ({
656
+ type,
657
+ needsUpdate: await this.isLocalImageNeedUpdate(type)
658
+ })));
659
+
660
+ // 过滤和映射
661
+ const newUrls = updateChecks.filter(item => item.needsUpdate).map(item => ({
662
+ name: item.type,
663
+ url: (0, _constants.getImageDownloadUrl)()[item.type]
664
+ }));
665
+ urls = urls.concat(newUrls);
666
+ }
650
667
  const downloads = urls.map(async u => {
651
668
  const d = await (await ipull).downloadFile({
652
669
  url: u.url,
@@ -666,8 +683,8 @@ class VvdManager {
666
683
  _ColorConsole.default.warn('All file resources have been successfully downloaded and are being decompressed.');
667
684
  for (const u of urls) {
668
685
  // 解压
669
- const targetDirName = u.name;
670
- const targetDir = u.name === _Vvd.SDKParts.SYSTEM_IMAGES ? _path.default.resolve(this.sdkHome, targetDirName, _path.default.basename(u.url).replace('.zip', '')) : _path.default.resolve(this.sdkHome, targetDirName);
686
+ const targetDirName = (0, _constants.isVelaImageType)(u.name) ? _Vvd.SDKParts.SYSTEM_IMAGES : u.name;
687
+ const targetDir = u.name === _Vvd.SDKParts.SYSTEM_IMAGES || (0, _constants.isVelaImageType)(u.name) ? _path.default.resolve(this.sdkHome, targetDirName, _path.default.basename(u.url).replace('.zip', '')) : _path.default.resolve(this.sdkHome, targetDirName);
671
688
  const targetDirExist = _fs.default.existsSync(targetDir);
672
689
  if (!targetDirExist) await _fs.default.promises.mkdir(targetDir, {
673
690
  recursive: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/emulator",
3
- "version": "2.0.4-beta.1",
3
+ "version": "2.0.4-beta.2",
4
4
  "description": "vela emulator tool.",
5
5
  "homepage": "",
6
6
  "license": "ISC",
@@ -36,7 +36,7 @@
36
36
  "emulator"
37
37
  ],
38
38
  "dependencies": {
39
- "@aiot-toolkit/shared-utils": "2.0.4-beta.1",
39
+ "@aiot-toolkit/shared-utils": "2.0.4-beta.2",
40
40
  "@miwt/adb": "^0.9.0",
41
41
  "adm-zip": "^0.5.16",
42
42
  "dayjs": "^1.11.12",
@@ -51,5 +51,5 @@
51
51
  "@types/adm-zip": "^0.5.5",
52
52
  "@types/ini": "^4.1.1"
53
53
  },
54
- "gitHead": "85c4287c7b9468c83d468cfc39b147f4975f8285"
54
+ "gitHead": "e9015685f29790709c420a9f8c41ade936a85300"
55
55
  }