@aiot-toolkit/emulator 2.0.3 → 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
  }
@@ -1,4 +1,2 @@
1
- import EmulatorLog from './EmulatorLog';
2
1
  export * from './running';
3
2
  export * from './constants';
4
- export { EmulatorLog };
@@ -3,20 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _exportNames = {
7
- EmulatorLog: true
8
- };
9
- Object.defineProperty(exports, "EmulatorLog", {
10
- enumerable: true,
11
- get: function () {
12
- return _EmulatorLog.default;
13
- }
14
- });
15
- var _EmulatorLog = _interopRequireDefault(require("./EmulatorLog"));
16
6
  var _running = require("./running");
17
7
  Object.keys(_running).forEach(function (key) {
18
8
  if (key === "default" || key === "__esModule") return;
19
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
20
9
  if (key in exports && exports[key] === _running[key]) return;
21
10
  Object.defineProperty(exports, key, {
22
11
  enumerable: true,
@@ -28,7 +17,6 @@ Object.keys(_running).forEach(function (key) {
28
17
  var _constants = require("./constants");
29
18
  Object.keys(_constants).forEach(function (key) {
30
19
  if (key === "default" || key === "__esModule") return;
31
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
32
20
  if (key in exports && exports[key] === _constants[key]) return;
33
21
  Object.defineProperty(exports, key, {
34
22
  enumerable: true,
@@ -36,5 +24,4 @@ Object.keys(_constants).forEach(function (key) {
36
24
  return _constants[key];
37
25
  }
38
26
  });
39
- });
40
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
27
+ });
@@ -5,7 +5,11 @@ import { ChildProcessWithoutNullStreams } from 'child_process';
5
5
  declare class CommonEmulatorInstance {
6
6
  imageType: VelaImageType;
7
7
  appDir: string;
8
- quickappStartedFlag: RegExp;
8
+ static emulatorStartedFlag: RegExp;
9
+ static appInstalledFlag: RegExp;
10
+ static appStartedFlag: RegExp;
11
+ static isAppInstalled(log: string): boolean;
12
+ static isEmulatorStarted(log: string): boolean;
9
13
  sn: string;
10
14
  vvdName: string;
11
15
  debugPort?: number | string;
@@ -40,6 +44,7 @@ declare class CommonEmulatorInstance {
40
44
  /** 关闭模拟器 */
41
45
  poweroff(timeout?: number): Promise<void>;
42
46
  systemed(): Promise<string>;
47
+ getApplist(): Promise<string[]>;
43
48
  /** 重启模拟器 */
44
49
  reboot(): Promise<void>;
45
50
  }
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _ColorConsole = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
8
8
  var _ILog = require("@aiot-toolkit/shared-utils/lib/interface/ILog");
9
- var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
9
+ var _adb = _interopRequireWildcard(require("@miwt/adb"));
10
+ var adbMiwt = _adb;
10
11
  var _utils = require("../utils");
11
12
  var _logcat = require("../vvd/logcat");
12
13
  var _emulatorutil = require("../emulatorutil");
@@ -15,7 +16,15 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
15
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
17
  class CommonEmulatorInstance {
17
18
  appDir = '/data/quickapp/app';
18
- quickappStartedFlag = /Start App loop/;
19
+ static emulatorStartedFlag = /quickapp_rpk_installer_init|rpk installer init done|booting completed/;
20
+ static appInstalledFlag = /InstallState_Finished|install finished/;
21
+ static appStartedFlag = /Start App loop/;
22
+ static isAppInstalled(log) {
23
+ return this.appInstalledFlag.test(log);
24
+ }
25
+ static isEmulatorStarted(log) {
26
+ return this.emulatorStartedFlag.test(log);
27
+ }
19
28
  constructor(params) {
20
29
  this.sn = `emulator-${params.serialPort}`;
21
30
  this.vvdName = params.vvdName;
@@ -86,7 +95,7 @@ class CommonEmulatorInstance {
86
95
  async isConnected() {
87
96
  return (0, _utils.tryRun)(async () => {
88
97
  const devices = await adbMiwt.getAdbDevices();
89
- _ColorConsole.default.log(`adb devices: ${JSON.stringify(devices)}`);
98
+ this.logger(`adb devices: ${JSON.stringify(devices)}`);
90
99
  const curDev = devices.find(t => t.sn === this.sn);
91
100
  return curDev?.status === 'device';
92
101
  }, 10, 500);
@@ -140,14 +149,25 @@ class CommonEmulatorInstance {
140
149
  systemed() {
141
150
  return adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} shell systemd &`);
142
151
  }
152
+ async getApplist() {
153
+ const cmd = `adb -s ${this.sn} shell ls ${this.appDir}`;
154
+ const dataStr = await (0, _adb.execAdbCmdAsync)(cmd);
155
+ if (dataStr) {
156
+ // 使用换行符分割字符串,得到数组
157
+ const appsArray = dataStr.replace(/\r\n/g, '\n').split('\n');
158
+ const cleanedAppsArray = appsArray.filter(item => item.endsWith('/')).map(item => item.trim().slice(0, -1));
159
+ return cleanedAppsArray;
160
+ }
161
+ return [];
162
+ }
143
163
 
144
164
  /** 重启模拟器 */
145
165
  async reboot() {
146
166
  const rebootCmd = `adb -s ${this.sn} shell reboot`;
147
- _ColorConsole.default.log(`Excuting: ${rebootCmd}`);
167
+ this.logger(`Excuting: ${rebootCmd}`);
148
168
  await adbMiwt.execAdbCmdAsync(rebootCmd);
149
169
  await this.isConnected();
150
- if (!this.logcatProcess.exitCode !== undefined) {
170
+ if (this.logcatProcess.exitCode !== null) {
151
171
  // 如果 logcat 进程被杀死,则重新创建
152
172
  const r = (0, _logcat.creatLogcat)(this.sn, this.onStdout, this.onErrout);
153
173
  this.logcatProcess = r.logcatProcess;
@@ -2,8 +2,8 @@ import CommonEmulatorInstance from './common';
2
2
  import { VelaImageType } from '../typing/Vvd';
3
3
  declare class GoldfishInstance extends CommonEmulatorInstance {
4
4
  imageType: VelaImageType;
5
- appDir: string;
6
- emulatorStartedFlag: string;
5
+ static appDir: string;
6
+ static emulatorStartedFlag: RegExp;
7
7
  install(rpkPath: string, appPackageName?: string): Promise<void>;
8
8
  /**
9
9
  * 在模拟器中启动快应用
@@ -12,8 +12,8 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
12
12
  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; }
13
13
  class GoldfishInstance extends _common.default {
14
14
  imageType = (() => _Vvd.VelaImageType.DEV)();
15
- appDir = '/data/app';
16
- emulatorStartedFlag = '(NSH)';
15
+ static appDir = '/data/app';
16
+ static emulatorStartedFlag = /(NSH)/;
17
17
  async install(rpkPath, appPackageName) {
18
18
  // 基于 vapp 启动的应用只需要将 rpk 解压到指定的目录下
19
19
  rpkPath = rpkPath || `${this.appDir}/${appPackageName}.rpk`;
@@ -5,6 +5,7 @@ import PreInstance from './pre';
5
5
  import { VelaImageType } from '../typing/Vvd';
6
6
  import { IEmulatorInstanceParams } from '../typing/Instance';
7
7
  import { VelaPre5Instance } from './pre5';
8
+ declare function getInstanceClass(imageType: VelaImageType): typeof GoldfishInstance | typeof MiwearInstance | typeof PreInstance | typeof VelaPre5Instance;
8
9
  /**
9
10
  * 根据镜像决定使用哪个instance
10
11
  * Vela正式版(4.0) -> MiwearInstance
@@ -12,5 +13,5 @@ import { VelaPre5Instance } from './pre5';
12
13
  * Vela开发版(dev, 0.0.2) -> OldGoldfishInstance
13
14
  * Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
14
15
  */
15
- declare function findInstance(imageType: VelaImageType, params: IEmulatorInstanceParams): GoldfishInstance | MiwearInstance;
16
- export { CommonEmulatorInstance as CommonInstance, GoldfishInstance, MiwearInstance, VelaPre5Instance, PreInstance, findInstance };
16
+ declare function findInstance(imageType: VelaImageType, params: IEmulatorInstanceParams): CommonEmulatorInstance;
17
+ export { CommonEmulatorInstance as CommonInstance, GoldfishInstance, MiwearInstance, VelaPre5Instance, PreInstance, findInstance, getInstanceClass };
@@ -34,6 +34,7 @@ Object.defineProperty(exports, "VelaPre5Instance", {
34
34
  }
35
35
  });
36
36
  exports.findInstance = findInstance;
37
+ exports.getInstanceClass = getInstanceClass;
37
38
  var _common = _interopRequireDefault(require("./common"));
38
39
  var _dev = _interopRequireDefault(require("./dev"));
39
40
  var _miwear = _interopRequireDefault(require("./miwear"));
@@ -41,6 +42,16 @@ var _pre = _interopRequireDefault(require("./pre"));
41
42
  var _Vvd = require("../typing/Vvd");
42
43
  var _pre2 = require("./pre5");
43
44
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
45
+ function getInstanceClass(imageType) {
46
+ const map = {
47
+ [_Vvd.VelaImageType.PRE]: _pre.default,
48
+ [_Vvd.VelaImageType.REL]: _miwear.default,
49
+ [_Vvd.VelaImageType.DEV]: _dev.default,
50
+ [_Vvd.VelaImageType.VELA_PRE_5]: _pre2.VelaPre5Instance
51
+ };
52
+ return map[imageType] || _dev.default;
53
+ }
54
+
44
55
  /**
45
56
  * 根据镜像决定使用哪个instance
46
57
  * Vela正式版(4.0) -> MiwearInstance
@@ -49,12 +60,6 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
49
60
  * Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
50
61
  */
51
62
  function findInstance(imageType, params) {
52
- const map = {
53
- [_Vvd.VelaImageType.PRE]: _pre.default,
54
- [_Vvd.VelaImageType.REL]: _miwear.default,
55
- [_Vvd.VelaImageType.DEV]: _dev.default,
56
- [_Vvd.VelaImageType.VELA_PRE_5]: _pre2.VelaPre5Instance
57
- };
58
- const Instance = map[imageType] || _dev.default;
63
+ const Instance = getInstanceClass(imageType);
59
64
  return new Instance(params);
60
65
  }
@@ -5,6 +5,7 @@ import { VelaImageType } from '../typing/Vvd';
5
5
  * 针对 Vela正式版(4.0)的镜像
6
6
  */
7
7
  declare class MiwearInstance extends CommonEmulatorInstance {
8
+ static appInstalledFlag: RegExp;
8
9
  imageType: VelaImageType;
9
10
  appDir: string;
10
11
  /**
@@ -8,7 +8,6 @@ var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
  var _utils = require("../utils");
10
10
  var _common = _interopRequireDefault(require("./common"));
11
- var _emulatorutil = require("../emulatorutil");
12
11
  var _Vvd = require("../typing/Vvd");
13
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
13
  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); }
@@ -18,6 +17,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
18
17
  * 针对 Vela正式版(4.0)的镜像
19
18
  */
20
19
  class MiwearInstance extends _common.default {
20
+ static appInstalledFlag = /InstallState_Finished|install finished/;
21
21
  imageType = (() => _Vvd.VelaImageType.REL)();
22
22
  appDir = '/data/quickapp/app';
23
23
 
@@ -29,7 +29,7 @@ class MiwearInstance extends _common.default {
29
29
  adbMiwt.execAdbCmd(`adb -s ${this.sn} shell pm install ${targeRpk}`);
30
30
  return new Promise((resolve, reject) => {
31
31
  const func = msg => {
32
- if (_emulatorutil.EmulatorLog.inStallIsFinshe(msg)) {
32
+ if (MiwearInstance.isAppInstalled(msg)) {
33
33
  clearTimeout(timer);
34
34
  this.logger(`Install to ${this.vvdName} ${targeRpk} successfully`);
35
35
  resolve();
@@ -68,7 +68,7 @@ class MiwearInstance extends _common.default {
68
68
  await super.reboot();
69
69
  return new Promise((resolve, reject) => {
70
70
  const func = msg => {
71
- if (_emulatorutil.EmulatorLog.rpkIsStart(msg)) {
71
+ if (MiwearInstance.isEmulatorStarted(msg)) {
72
72
  clearTimeout(timer);
73
73
  resolve();
74
74
  }
@@ -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
@@ -417,7 +417,8 @@ class VvdManager {
417
417
  const spawnArgs = cmd.split(' ');
418
418
  const spawnBin = spawnArgs.shift();
419
419
  logger(`Start CMD: ${cmd}`);
420
- const func = vvdInfo.imageType === _Vvd.VelaImageType.REL ? _emulatorutil.EmulatorLog.rpkIsStart : _emulatorutil.EmulatorLog.devIsStart;
420
+ const InstanceCalss = (0, _instance.getInstanceClass)(vvdInfo.imageType);
421
+ const func = InstanceCalss.isEmulatorStarted.bind(InstanceCalss);
421
422
  return new Promise((resolve, reject) => {
422
423
  const emulatorProcess = (0, _child_process.spawn)(spawnBin, spawnArgs, {
423
424
  stdio: 'pipe',
@@ -642,10 +643,27 @@ class VvdManager {
642
643
  */
643
644
  async downloadSDK(opt) {
644
645
  const updateList = opt.force ? Object.values(_Vvd.SDKParts) : await this.hasSDKPartUpdate();
645
- const urls = updateList.map(t => ({
646
+ let urls = updateList.map(t => ({
646
647
  name: t,
647
648
  url: (0, _constants.getSDKPartDownloadUrl)(t)
648
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
+ }
649
667
  const downloads = urls.map(async u => {
650
668
  const d = await (await ipull).downloadFile({
651
669
  url: u.url,
@@ -665,8 +683,8 @@ class VvdManager {
665
683
  _ColorConsole.default.warn('All file resources have been successfully downloaded and are being decompressed.');
666
684
  for (const u of urls) {
667
685
  // 解压
668
- const targetDirName = u.name;
669
- 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);
670
688
  const targetDirExist = _fs.default.existsSync(targetDir);
671
689
  if (!targetDirExist) await _fs.default.promises.mkdir(targetDir, {
672
690
  recursive: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/emulator",
3
- "version": "2.0.3",
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.3",
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": "e29e61eb89c2559eb9f3a18c51fd5ce4c4196cc2"
54
+ "gitHead": "e9015685f29790709c420a9f8c41ade936a85300"
55
55
  }
@@ -1,11 +0,0 @@
1
- declare class EmulatorLog {
2
- static emulatorStartedFlag: RegExp;
3
- static installFlag: RegExp;
4
- static devStartFlag: string;
5
- static preDevStartFlag: RegExp;
6
- static inStallIsFinshe(msg: string): RegExpMatchArray | null;
7
- static rpkIsStart(msg: string): RegExpMatchArray | null;
8
- static devIsStart(msg: string): boolean;
9
- static preDevIsStart(msg: string): RegExpMatchArray | null;
10
- }
11
- export default EmulatorLog;
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- class EmulatorLog {
8
- static emulatorStartedFlag = /quickapp_rpk_installer_init|rpk installer init done/;
9
- static installFlag = /InstallState_Finished|install finished/;
10
- static devStartFlag = '(NSH)';
11
- static preDevStartFlag = /Server started, listening on: 127.0.0.1:(\d+)/;
12
- static inStallIsFinshe(msg) {
13
- return msg.match(EmulatorLog.installFlag);
14
- }
15
- static rpkIsStart(msg) {
16
- return msg.match(EmulatorLog.emulatorStartedFlag);
17
- }
18
- static devIsStart(msg) {
19
- return msg.includes(EmulatorLog.devStartFlag);
20
- }
21
- static preDevIsStart(msg) {
22
- return msg.match(EmulatorLog.preDevStartFlag);
23
- }
24
- }
25
- var _default = exports.default = EmulatorLog;