@aiot-toolkit/emulator 2.0.2-dev.8 → 2.0.3-beta.1

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,7 +1,15 @@
1
1
  import { INewGoldfishInstanceParams } from '../typing/Instance';
2
2
  import CommonInstance from './common';
3
3
  import GoldfishInstance from './dev';
4
- import MiwearInstance from "./miwear";
4
+ import MiwearInstance from './miwear';
5
5
  import OldGoldfishInstance from './preDev';
6
+ import PreInstance from './pre';
7
+ /**
8
+ * 根据镜像决定使用哪个instance
9
+ * Vela正式版(4.0) -> MiwearInstance
10
+ * Vela正式版(不带 miwear 版本) -> PreInstance
11
+ * Vela开发版(dev, 0.0.2) -> OldGoldfishInstance
12
+ * Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
13
+ */
6
14
  declare function findInstance(avdName: string, params: INewGoldfishInstanceParams): GoldfishInstance | MiwearInstance | OldGoldfishInstance | undefined;
7
- export { CommonInstance, GoldfishInstance, MiwearInstance, OldGoldfishInstance, findInstance };
15
+ export { CommonInstance, GoldfishInstance, MiwearInstance, OldGoldfishInstance, PreInstance, findInstance };
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.findInstance = exports.OldGoldfishInstance = exports.MiwearInstance = exports.GoldfishInstance = exports.CommonInstance = void 0;
6
+ exports.PreInstance = exports.OldGoldfishInstance = exports.MiwearInstance = exports.GoldfishInstance = exports.CommonInstance = void 0;
7
+ exports.findInstance = findInstance;
7
8
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
8
9
  const avd_1 = __importDefault(require("../avd"));
9
10
  const common_1 = __importDefault(require("./common"));
@@ -14,6 +15,15 @@ const miwear_1 = __importDefault(require("./miwear"));
14
15
  exports.MiwearInstance = miwear_1.default;
15
16
  const preDev_1 = __importDefault(require("./preDev"));
16
17
  exports.OldGoldfishInstance = preDev_1.default;
18
+ const pre_1 = __importDefault(require("./pre"));
19
+ exports.PreInstance = pre_1.default;
20
+ /**
21
+ * 根据镜像决定使用哪个instance
22
+ * Vela正式版(4.0) -> MiwearInstance
23
+ * Vela正式版(不带 miwear 版本) -> PreInstance
24
+ * Vela开发版(dev, 0.0.2) -> OldGoldfishInstance
25
+ * Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
26
+ */
17
27
  function findInstance(avdName, params) {
18
28
  const { sdkHome, avdHome } = params;
19
29
  const { avdImagePath } = new avd_1.default({ sdkHome, avdHome }).getVelaAvdInfo(avdName);
@@ -21,6 +31,9 @@ function findInstance(avdName, params) {
21
31
  ColorConsole_1.default.throw(`### Emulator ### Unable to find vela image via avd`);
22
32
  return;
23
33
  }
34
+ if (avdImagePath.includes('vela-pre-4.0')) {
35
+ return new pre_1.default(params);
36
+ }
24
37
  if (avdImagePath.includes('release')) {
25
38
  return new miwear_1.default(params);
26
39
  }
@@ -29,4 +42,3 @@ function findInstance(avdName, params) {
29
42
  }
30
43
  return new dev_1.default(params);
31
44
  }
32
- exports.findInstance = findInstance;
@@ -1,28 +1,82 @@
1
+ import readline from 'readline';
1
2
  import { INewGoldfishInstanceParams, IStartOptions } from '../typing/Instance';
2
3
  import CommonInstance from './common';
3
4
  /**
4
5
  * MiwearInstance
5
- * 针对 vela4.0 的镜像
6
+ * 针对 Vela正式版(4.0)的镜像
6
7
  */
7
8
  declare class MiwearInstance extends CommonInstance {
8
- private appPathInEmulator;
9
+ private params;
10
+ private appDir;
9
11
  private debugSocket?;
10
12
  private reconnectCount;
13
+ stdoutReadline: readline.Interface;
14
+ stderrReadline: readline.Interface;
11
15
  constructor(params: INewGoldfishInstanceParams);
12
- /** 在goldfish模拟器中运行快应用 */
16
+ /**
17
+ * 1. 启动模拟器
18
+ * 2. 启动成功后,adb连接模拟器
19
+ * 3. 连接成功后,在模拟器中启动快应用
20
+ */
13
21
  start(options: IStartOptions): Promise<void>;
14
- /** 启动goldfish模拟器 */
22
+ /**
23
+ * 启动模拟器
24
+ * 1. 通过options生成模拟器的启动命令
25
+ * 2. 执行启动命令
26
+ * 3. 判断模拟器是否启动成功
27
+ * 3.1 若disableNSH=true,输出流中匹配到/quickapp_rpk_installer_init|rpk installer init done/,认为模拟器启动成功了
28
+ * 3.2 若disableNSH=false,认为8s过后模拟器启动成功了
29
+ * @param options
30
+ * @returns
31
+ */
15
32
  startGoldfish(options: IStartOptions): Promise<void>;
16
- /** 通过adb连接模拟器 */
17
- connectGoldfish(): Promise<boolean>;
18
- /** 在goldfish中启动快应用 */
33
+ /**
34
+ * 在模拟器中启动快应用
35
+ * 1. 检查release目录是否有打包好的rpk
36
+ * 2. 检查当前是否为调试模式.
37
+ * 若是,将debugger_ip.cfg推到模拟器的/data/目录下
38
+ * 若否,则要删除模拟器中已有的data/debugger_ip.cfg
39
+ * 3. 调用installRpkToAppList将当前快应用安装到模拟器的应用列表中
40
+ * @param options
41
+ */
19
42
  startupQuickApp(options: IStartOptions): Promise<void>;
20
- /** 将快应用安装到应用列表 */
21
- installRpkToAppList(rpkPath: string, targetDir: string): Promise<void>;
22
- initDebugSocket(): Promise<void> | undefined;
23
- /** 通知模拟器更新 */
43
+ /**
44
+ * 将快应用安装到模拟器的应用列表
45
+ * 1. 使用adb push将打包好的rpk推到模拟器的/data/quickapp/app/
46
+ * 2. nsh中调用pm install命令安装应用
47
+ * @param rpkPath rpk的绝对目录
48
+ * @param targetDir 要将rpk放到模拟器的哪个目录下
49
+ */
50
+ pushAndInstall(rpkPath: string, targetDir: string): Promise<void>;
51
+ /** 使用am start启动快应用 */
52
+ launchQuickapp(): Promise<void>;
53
+ /** 连接模拟器中的调试服务,创建debugSocket
54
+ * 主要用于热更新时,通过debugSocket通知调试服务更新页面
55
+ * 设置了重连机制,会重复连接8次
56
+ */
57
+ initDebugSocket(): Promise<void>;
58
+ /** 通知模拟器更新
59
+ * 1. 确保已经成功连接模拟器中的调试服务
60
+ * 2. 使用adb push将build文件下的内容推到/data/quickapp/app/${packageName}
61
+ * 3. 发送Page.reload命令给调试服务,通知更新
62
+ */
24
63
  handleUpdate(): Promise<void>;
25
- /** 创建server */
64
+ /** 热更新时push目录 */
65
+ pushBuild(): Promise<void>;
66
+ /** 通过命令行启动时,在watich模式下监听websocket消息,
67
+ * 在文件发生变动时,重新启动应用
68
+ */
69
+ restart(): Promise<void>;
70
+ /** 在模拟器中重启快应用(基于am命令,需要保证镜像中已经有am功能)
71
+ * 1. 使用adb push将build文件下的内容推到/data/quickapp/app/${packageName}
72
+ * 2. nsh中执行am stop命令退出快应用
73
+ * 3. nsh中执行am start命令启动快应用
74
+ */
75
+ pushAndReloadApp(): Promise<void>;
76
+ reloadApp(): Promise<void>;
77
+ /**
78
+ * 创建server端,监听打包过程中client端发来的消息
79
+ */
26
80
  createWebsockeServer(): Promise<void>;
27
81
  }
28
82
  export default MiwearInstance;