@aiot-toolkit/emulator 2.0.1-alpha.11 → 2.0.1-alpha.13

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.
@@ -12,6 +12,8 @@ declare class GoldfishInstance {
12
12
  private packageName;
13
13
  goldfishProcess: ChildProcess | undefined;
14
14
  v9fsProcess: ChildProcess | undefined;
15
+ isFirstStart: boolean;
16
+ private startOptions;
15
17
  constructor(params: INewGoldfishInstanceParams);
16
18
  /** 获取模拟器二进制文件所在位置 */
17
19
  getEmulatorBinPath(): string;
@@ -31,5 +33,9 @@ declare class GoldfishInstance {
31
33
  killProcess(currProcess?: ChildProcess): void;
32
34
  /** 停止模拟器并释放相关资源 */
33
35
  stop(): void;
36
+ /** 重启模拟器 */
37
+ restart(): void;
38
+ /** 创建server */
39
+ createWebsockeServer(): Promise<void>;
34
40
  }
35
41
  export default GoldfishInstance;
@@ -36,7 +36,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const UxFileUtils_1 = __importDefault(require("@aiot-toolkit/aiotpack/lib/utils/ux/UxFileUtils"));
39
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
40
39
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
41
40
  const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
42
41
  const adbMiwt = __importStar(require("@miwt/adb"));
@@ -46,13 +45,16 @@ const fs_1 = __importDefault(require("fs"));
46
45
  const os_1 = __importDefault(require("os"));
47
46
  const path_1 = __importDefault(require("path"));
48
47
  const portfinder_1 = __importDefault(require("portfinder"));
48
+ const ws_1 = require("ws");
49
49
  const avd_1 = __importDefault(require("../avd"));
50
50
  const constants_1 = require("../static/constants");
51
+ const utils_1 = require("../utils");
51
52
  class GoldfishInstance {
52
53
  constructor(params) {
53
54
  this.adbPort = 15555;
54
55
  this.debugPort = 10055;
55
56
  this.host9pPort = 7878;
57
+ this.isFirstStart = true;
56
58
  this.projectPath = params.projectPath;
57
59
  this.sdkHome = params.sdkHome || constants_1.defaultSDKHome;
58
60
  this.avdHome = params.avdHome || constants_1.defaultAvdHome;
@@ -66,34 +68,33 @@ class GoldfishInstance {
66
68
  /** 获取模拟器二进制文件所在位置 */
67
69
  getEmulatorBinPath() {
68
70
  const osPlatform = os_1.default.platform();
69
- const osArch = os_1.default.arch();
71
+ const arch = (0, utils_1.getSystemArch)();
70
72
  const platform = osPlatform === 'win32' ? 'windows' : osPlatform;
71
- const arch = (osArch === 'arm64' || osArch === 'aarch64') ? 'aarch64' : 'x86_64';
72
- return path_1.default.resolve(constants_1.defaultEmulatorHome, `${platform}-${arch}`, 'emulator');
73
+ const emulatorHome = path_1.default.resolve(this.sdkHome, 'emulator');
74
+ return path_1.default.resolve(emulatorHome, `${platform}-${arch}`, 'emulator');
73
75
  }
74
76
  /** 在goldfish模拟器中运行快应用 */
75
77
  start(options) {
76
78
  return __awaiter(this, void 0, void 0, function* () {
77
79
  // host启动9p server
78
80
  yield this.ensure9pServerRunnning();
79
- // TODO: 打包快应用
80
- // 将rpk推到host的defaultQuickappHome目录
81
+ this.startOptions = options;
82
+ // 将rpk推到host的QuickappHome目录
81
83
  this.pushRpk();
82
84
  // 启动模拟器
83
85
  yield this.startGoldfish(options);
84
86
  const connected = yield this.connectGoldfish();
85
87
  if (connected) {
86
- ColorConsole_1.default.log({
87
- message: '### Emulator ### Goldfish emulator connected successfully'
88
- });
88
+ ColorConsole_1.default.log('### Emulator ### Goldfish emulator connected successfully');
89
+ if (this.isFirstStart && this.startOptions.serverPort) {
90
+ yield this.createWebsockeServer();
91
+ }
89
92
  // 在模拟器中启动快应用
90
93
  this.startupQuickApp(options);
94
+ this.isFirstStart = false;
91
95
  }
92
96
  else {
93
- ColorConsole_1.default.log({
94
- level: shared_utils_1.LOG_LEVEL.Error,
95
- message: '### Emulator ### Failed to connect emulator, please check whether the adb is normal'
96
- });
97
+ ColorConsole_1.default.throw('### Emulator ### Failed to connect emulator, please check whether the adb is normal');
97
98
  }
98
99
  });
99
100
  }
@@ -102,22 +103,18 @@ class GoldfishInstance {
102
103
  try {
103
104
  const appMountDir = path_1.default.resolve(this.sdkHome, 'qa');
104
105
  const mountCmd = `adb -s 127.0.0.1:${this.adbPort} shell mount -t v9fs -o tag=10.0.2.2,port=${this.host9pPort},aname=${appMountDir} /data`;
105
- ColorConsole_1.default.log({ message: `### Emulator ### Excuting adb cmd: ${mountCmd}` });
106
+ ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${mountCmd}`);
106
107
  adbMiwt.execAdbCmdSync(mountCmd);
107
108
  let vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp app/${this.packageName} &`;
108
109
  if (options.devtool) {
109
110
  vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp --jsdebugger=10.0.2.15:101 app/${this.packageName} &`;
110
111
  }
111
- ColorConsole_1.default.log({ message: `### Emulator ### Excuting adb cmd: ${vappCmd}` });
112
+ ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${vappCmd}`);
112
113
  // vapp进程会一直pending,不会退出。这里必须加stdio: 'ignore',否则快应用无法运行成功
113
114
  adbMiwt.execAdbCmdAsync(vappCmd, { stdio: 'ignore', encoding: 'utf-8' });
114
115
  }
115
116
  catch (e) {
116
- ColorConsole_1.default.log({
117
- level: shared_utils_1.LOG_LEVEL.Error,
118
- message: `### Emulator ### Failed to startup quickapp: ${e.message}`,
119
- isOnlyPrintError: true
120
- });
117
+ ColorConsole_1.default.error(`### Emulator ### Failed to startup quickapp: ${e.message}`);
121
118
  }
122
119
  }
123
120
  /** host启动9pServer */
@@ -127,12 +124,13 @@ class GoldfishInstance {
127
124
  const yaFileName = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
128
125
  const pidList = yield (0, find_process_1.default)('name', yaFileName);
129
126
  if (pidList.length > 0) {
130
- ColorConsole_1.default.log({ message: '### Emulator ### 9p server started in host' });
127
+ ColorConsole_1.default.log('### Emulator ### 9p server started in host');
131
128
  return resolve();
132
129
  }
133
- ColorConsole_1.default.log({ message: '### Emulator ### Starting 9p server in host' });
130
+ ColorConsole_1.default.log('### Emulator ### Starting 9p server in host');
134
131
  const quickappMountDir = path_1.default.resolve(this.sdkHome, 'qa');
135
- const serverBinPath = path_1.default.resolve(constants_1.defaultToolsHome, yaFileName);
132
+ const toolsHome = path_1.default.resolve(this.sdkHome, 'tools');
133
+ const serverBinPath = path_1.default.resolve(toolsHome, yaFileName);
136
134
  fs_1.default.chmodSync(serverBinPath, 0o777);
137
135
  this.host9pPort = yield portfinder_1.default.getPortPromise({ port: 7878 });
138
136
  const address = `127.0.0.1:${this.host9pPort}`;
@@ -146,70 +144,77 @@ class GoldfishInstance {
146
144
  (_a = this.v9fsProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
147
145
  const output = data.toString();
148
146
  if (output.match(/Server started, listening on: 127.0.0.1:(\d+)/)) {
149
- ColorConsole_1.default.log({ message: output });
150
- ColorConsole_1.default.log({ message: '### Emulator ### 9p server starts successfully' });
147
+ ColorConsole_1.default.log(output);
148
+ ColorConsole_1.default.log('### Emulator ### 9p server starts successfully');
151
149
  return resolve();
152
150
  }
153
151
  });
154
152
  this.v9fsProcess.on('exit', (code) => {
155
- ColorConsole_1.default.log({
156
- level: shared_utils_1.LOG_LEVEL.Error,
157
- message: `### Emulator ### ya-vm-file-server exited with code ${code}`,
158
- isOnlyPrintError: true
159
- });
153
+ ColorConsole_1.default.error(`### Emulator ### ya-vm-file-server exited with code ${code}`);
160
154
  return reject();
161
155
  });
162
156
  }));
163
157
  }
164
158
  /** 启动goldfish模拟器 */
165
159
  startGoldfish(options) {
160
+ var _a;
166
161
  return __awaiter(this, void 0, void 0, function* () {
167
162
  const { avdName, devtool } = options;
168
163
  const emulatorBin = this.getEmulatorBinPath();
169
- ColorConsole_1.default.log({ message: `### Emulator ### emulator path: ${emulatorBin}` });
164
+ ColorConsole_1.default.log(`### Emulator ### emulator path: ${emulatorBin}`);
170
165
  const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName);
171
166
  const { avdArch, avdImagePath } = avdInfo;
172
167
  this.adbPort = yield portfinder_1.default.getPortPromise({ port: this.adbPort });
173
- ColorConsole_1.default.log({ message: `### Emulator ### adb port: ${this.adbPort}` });
168
+ ColorConsole_1.default.log(`### Emulator ### adb port: ${this.adbPort}`);
174
169
  if (!avdImagePath) {
175
- ColorConsole_1.default.log({
176
- level: shared_utils_1.LOG_LEVEL.Error,
177
- message: `### Emulator ### Unable to find vela image via avd`
178
- });
179
- process.exit();
170
+ return ColorConsole_1.default.throw(`### Emulator ### Unable to find vela image via avd`);
180
171
  }
181
172
  const nuttxBinPath = path_1.default.resolve(avdImagePath, 'nuttx');
182
- ColorConsole_1.default.log({ message: `### Emulator ### nuttx path: ${nuttxBinPath}` });
173
+ ColorConsole_1.default.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
183
174
  let portMappingStr = `user,id=u1,hostfwd=tcp:127.0.0.1:${this.adbPort}-10.0.2.15:5555`;
184
175
  if (devtool) {
185
176
  this.debugPort = yield portfinder_1.default.getPortPromise({ port: this.debugPort });
186
- ColorConsole_1.default.log({ message: `### Emulator ### debug port: ${this.debugPort}` });
177
+ ColorConsole_1.default.log(`### Emulator ### debug port: ${this.debugPort}`);
187
178
  portMappingStr += `,hostfwd=tcp:127.0.0.1:${this.debugPort}-10.0.2.15:101`;
188
179
  }
189
- ColorConsole_1.default.log({ message: `### Emulator ### Start qemu with TCP: ${portMappingStr}` });
180
+ ColorConsole_1.default.log(`### Emulator ### Start qemu with TCP: ${portMappingStr}`);
190
181
  const stdioType = options.disableNSH ? 'pipe' : 'inherit';
182
+ // vnc配置
183
+ let noWindow = false;
184
+ let vncStr = '';
185
+ if ((_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.vncPort) {
186
+ noWindow = true;
187
+ const portSuffix = this.startOptions.vncPort - constants_1.defaultVncPort;
188
+ vncStr = `-vnc :${portSuffix}`;
189
+ }
190
+ // 启动goldfish的命令和参数
191
+ const spawnBin = emulatorBin;
192
+ const spawnArgs = [
193
+ '-nuttx',
194
+ '-avd',
195
+ avdName,
196
+ '-avd-arch',
197
+ avdArch,
198
+ '-show-kernel',
199
+ '-kernel',
200
+ nuttxBinPath,
201
+ noWindow ? '-no-window' : '',
202
+ '-qemu',
203
+ vncStr,
204
+ '-netdev',
205
+ portMappingStr,
206
+ '-device',
207
+ 'virtio-net-device,netdev=u1,bus=virtio-mmio-bus.3'
208
+ ];
209
+ ColorConsole_1.default.log(`### Emulator ### Start CMD: ${spawnBin} ${spawnArgs.join(' ')}`);
191
210
  return new Promise((resolve) => {
192
211
  var _a, _b;
193
- this.goldfishProcess = (0, child_process_1.spawn)(emulatorBin, [
194
- '-nuttx',
195
- '-avd',
196
- avdName,
197
- '-avd-arch',
198
- avdArch,
199
- '-show-kernel',
200
- '-kernel',
201
- nuttxBinPath,
202
- '-qemu',
203
- '-netdev',
204
- portMappingStr,
205
- '-device',
206
- 'virtio-net-device,netdev=u1,bus=virtio-mmio-bus.3'
207
- ], { stdio: stdioType });
212
+ this.goldfishProcess = (0, child_process_1.spawn)(spawnBin, spawnArgs, { stdio: stdioType, shell: true });
208
213
  if (options.disableNSH) {
209
214
  (_a = this.goldfishProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
210
215
  console.log(data.toString());
211
216
  if (data.toString().includes('(NSH)')) {
212
- ColorConsole_1.default.log({ message: `### Emulator ### Goldfish emulator starts successfully` });
217
+ ColorConsole_1.default.log(`### Emulator ### Goldfish emulator starts successfully`);
213
218
  resolve();
214
219
  }
215
220
  });
@@ -219,16 +224,12 @@ class GoldfishInstance {
219
224
  }
220
225
  else {
221
226
  setTimeout(() => {
222
- ColorConsole_1.default.log({ message: `### Emulator ### Goldfish emulator starts successfully` });
227
+ ColorConsole_1.default.log(`### Emulator ### Goldfish emulator starts successfully`);
223
228
  resolve();
224
229
  }, 2000);
225
230
  }
226
231
  this.goldfishProcess.on('exit', (code) => {
227
- ColorConsole_1.default.log({
228
- level: shared_utils_1.LOG_LEVEL.Error,
229
- message: `### Emulator ### Goldfish emulator exited with code ${code}`,
230
- isOnlyPrintError: true
231
- });
232
+ ColorConsole_1.default.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
232
233
  });
233
234
  });
234
235
  });
@@ -241,14 +242,14 @@ class GoldfishInstance {
241
242
  const sn = `127.0.0.1:${this.adbPort}`;
242
243
  while (!adbConnected) {
243
244
  const adbKillCmd = `adb kill-server`;
244
- ColorConsole_1.default.log({ message: `### Emulator ### Excuting adb cmd: ${adbKillCmd}` });
245
+ ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${adbKillCmd}`);
245
246
  adbMiwt.execAdbCmdSync(adbKillCmd);
246
247
  const adbConnectCmd = `adb connect ${sn}`;
247
- ColorConsole_1.default.log({ message: `### Emulator ### Excuting adb cmd: ${adbConnectCmd}` });
248
+ ColorConsole_1.default.log(`### Emulator ### Excuting adb cmd: ${adbConnectCmd}`);
248
249
  const str = adbMiwt.execAdbCmdSync(adbConnectCmd);
249
- ColorConsole_1.default.log({ message: `### Emulator ### ${str}` });
250
+ ColorConsole_1.default.log(`### Emulator ### ${str}`);
250
251
  const devices = yield adbMiwt.getAdbDevices();
251
- ColorConsole_1.default.log({ message: `### Emulator ### adb devices: ${JSON.stringify(devices)}` });
252
+ ColorConsole_1.default.log(`### Emulator ### adb devices: ${JSON.stringify(devices)}`);
252
253
  adbConnected =
253
254
  devices.filter((item) => item.sn === sn && item.status === 'device').length > 0;
254
255
  }
@@ -268,12 +269,10 @@ class GoldfishInstance {
268
269
  const buildDir = path_1.default.resolve(this.projectPath, 'build');
269
270
  const { package: appPackageName } = UxFileUtils_1.default.getMainfestInfo(this.projectPath);
270
271
  const appRunDir = path_1.default.resolve(this.sdkHome, 'qa/app', appPackageName);
271
- ColorConsole_1.default.log({ message: `### Emulator ### Pushing ${appPackageName} to ${appRunDir}` });
272
+ ColorConsole_1.default.log(`### Emulator ### Pushing ${appPackageName} to ${appRunDir}`);
272
273
  fs_1.default.rmSync(appRunDir, { recursive: true, force: true });
273
274
  FileUtil_1.default.copyFiles(buildDir, appRunDir);
274
- ColorConsole_1.default.log({
275
- message: `### Emulator ### Push ${appPackageName} to ${appRunDir} successfully`
276
- });
275
+ ColorConsole_1.default.log(`### Emulator ### Push ${appPackageName} to ${appRunDir} successfully`);
277
276
  }
278
277
  /** 杀死进程 */
279
278
  killProcess(currProcess) {
@@ -291,7 +290,7 @@ class GoldfishInstance {
291
290
  }
292
291
  }
293
292
  catch (err) {
294
- ColorConsole_1.default.log({ message: `kill process get error :\n${err.stack}` });
293
+ ColorConsole_1.default.log(`### Emulator ### kill process get error :\n${err.stack}`);
295
294
  }
296
295
  }
297
296
  }
@@ -306,6 +305,39 @@ class GoldfishInstance {
306
305
  this.v9fsProcess = undefined;
307
306
  }
308
307
  }
308
+ /** 重启模拟器 */
309
+ restart() {
310
+ if (this.goldfishProcess) {
311
+ this.killProcess(this.goldfishProcess);
312
+ this.goldfishProcess = undefined;
313
+ }
314
+ this.start(this.startOptions);
315
+ }
316
+ /** 创建server */
317
+ createWebsockeServer() {
318
+ var _a;
319
+ return __awaiter(this, void 0, void 0, function* () {
320
+ const wsServer = new ws_1.WebSocketServer({
321
+ port: (_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.serverPort,
322
+ });
323
+ wsServer.on('connection', socket => {
324
+ ColorConsole_1.default.success(`### App Socket server ### Websocket connects to websocket server`);
325
+ socket.on('error', err => {
326
+ ColorConsole_1.default.error(`### App Socket server ### Websocket server error: ${err.message}`);
327
+ });
328
+ socket.on('message', data => {
329
+ const message = JSON.parse(data.toString());
330
+ ColorConsole_1.default.log(`### App Socket server ### Websocket server get data: ${data}`);
331
+ if (message.type === 'restart') {
332
+ this.restart();
333
+ }
334
+ else if (message.type === 'stop') {
335
+ this.stop();
336
+ }
337
+ });
338
+ });
339
+ });
340
+ }
309
341
  }
310
342
  exports.default = GoldfishInstance;
311
343
 
@@ -1 +1 @@
1
- {"version":3,"sources":["instance/goldfish.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kGAAyE;AACzE,6DAAsD;AACtD,+FAAsE;AACtE,6FAAoE;AACpE,mDAAoC;AACpC,iDAA6D;AAC7D,gEAAsC;AACtC,4CAAmB;AACnB,4CAAmB;AACnB,gDAAuB;AACvB,4DAAmC;AACnC,iDAA+B;AAC/B,mDAK4B;AAG5B,MAAM,gBAAgB;IAYpB,YAAY,MAAkC;QARtC,YAAO,GAAW,KAAK,CAAA;QACxB,cAAS,GAAW,KAAK,CAAA;QACxB,eAAU,GAAW,IAAI,CAAA;QAO/B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAA;QACrC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,0BAAc,CAAA;QAC/C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,0BAAc,CAAA;QAC/C,IAAI,CAAC,UAAU,GAAG,IAAI,aAAU,CAAC;YAC/B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;QACF,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,qBAAW,CAAC,eAAe,CAC7D,IAAI,CAAC,WAAW,EAChB,MAAM,CAAC,UAAU,CAClB,CAAA;QACD,IAAI,CAAC,WAAW,GAAG,cAAc,CAAA;IACnC,CAAC;IAED,qBAAqB;IACrB,kBAAkB;QAChB,MAAM,UAAU,GAAG,YAAE,CAAC,QAAQ,EAAE,CAAA;QAChC,MAAM,MAAM,GAAG,YAAE,CAAC,IAAI,EAAE,CAAA;QACxB,MAAM,QAAQ,GAAG,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,C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ux/UxFileUtils'\nimport { LOG_LEVEL } from '@aiot-toolkit/shared-utils'\nimport ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport FileUtil from '@aiot-toolkit/shared-utils/lib/utils/FileUtil'\nimport * as adbMiwt from '@miwt/adb'\nimport { ChildProcess, execSync, spawn } from 'child_process'\nimport findProcess from 'find-process'\nimport fs from 'fs'\nimport os from 'os'\nimport path from 'path'\nimport portfinder from 'portfinder'\nimport VelaAvdCls from '../avd'\nimport {\n defaultAvdHome,\n defaultEmulatorHome,\n defaultSDKHome,\n defaultToolsHome\n} from '../static/constants'\nimport { INewGoldfishInstanceParams, IStartOptions } from '../typing/Instance'\n\nclass GoldfishInstance {\n private projectPath: string\n private sdkHome: string\n private avdHome: string\n private adbPort: number = 15555\n public debugPort: number = 10055\n private host9pPort: number = 7878\n private velaAvdCls: VelaAvdCls\n private packageName: string\n public goldfishProcess: ChildProcess | undefined\n public v9fsProcess: ChildProcess | undefined\n\n constructor(params: INewGoldfishInstanceParams) {\n this.projectPath = params.projectPath\n this.sdkHome = params.sdkHome || defaultSDKHome\n this.avdHome = params.avdHome || defaultAvdHome\n this.velaAvdCls = new VelaAvdCls({\n sdkHome: this.sdkHome,\n avdHome: this.avdHome\n })\n const { package: appPackageName } = UxFileUtils.getMainfestInfo(\n this.projectPath,\n params.sourceRoot\n )\n this.packageName = appPackageName\n }\n\n /** 获取模拟器二进制文件所在位置 */\n getEmulatorBinPath() {\n const osPlatform = os.platform()\n const osArch = os.arch()\n const platform = osPlatform === 'win32' ? 'windows' : osPlatform\n const arch = (osArch === 'arm64' || osArch === 'aarch64') ? 'aarch64' : 'x86_64'\n return path.resolve(defaultEmulatorHome, `${platform}-${arch}`, 'emulator')\n }\n\n /** 在goldfish模拟器中运行快应用 */\n async start(options: IStartOptions) {\n // host启动9p server\n await this.ensure9pServerRunnning()\n // TODO: 打包快应用\n // 将rpk推到host的defaultQuickappHome目录\n this.pushRpk()\n // 启动模拟器\n await this.startGoldfish(options)\n const connected = await this.connectGoldfish()\n if (connected) {\n ColorConsole.log({\n message: '### Emulator ### Goldfish emulator connected successfully'\n })\n // 在模拟器中启动快应用\n this.startupQuickApp(options)\n } else {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message:\n '### Emulator ### Failed to connect emulator, please check whether the adb is normal'\n })\n }\n }\n\n /** 在goldfish中启动快应用 */\n startupQuickApp(options: IStartOptions) {\n try {\n const appMountDir = path.resolve(this.sdkHome, 'qa')\n const mountCmd = `adb -s 127.0.0.1:${this.adbPort} shell mount -t v9fs -o tag=10.0.2.2,port=${this.host9pPort},aname=${appMountDir} /data`\n ColorConsole.log({ message: `### Emulator ### Excuting adb cmd: ${mountCmd}` })\n adbMiwt.execAdbCmdSync(mountCmd)\n let vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp app/${this.packageName} &`\n if (options.devtool) {\n vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp --jsdebugger=10.0.2.15:101 app/${this.packageName} &`\n }\n ColorConsole.log({ message: `### Emulator ### Excuting adb cmd: ${vappCmd}` })\n // vapp进程会一直pending,不会退出。这里必须加stdio: 'ignore',否则快应用无法运行成功\n adbMiwt.execAdbCmdAsync(vappCmd, { stdio: 'ignore', encoding: 'utf-8' })\n } catch (e: any) {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `### Emulator ### Failed to startup quickapp: ${e.message}`,\n isOnlyPrintError: true\n })\n }\n }\n /** host启动9pServer */\n ensure9pServerRunnning(): Promise<void> {\n return new Promise(async (resolve, reject) => {\n const yaFileName = os.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server'\n const pidList = await findProcess('name', yaFileName)\n if (pidList.length > 0) {\n ColorConsole.log({ message: '### Emulator ### 9p server started in host' })\n return resolve()\n }\n ColorConsole.log({ message: '### Emulator ### Starting 9p server in host' })\n const quickappMountDir = path.resolve(this.sdkHome, 'qa')\n const serverBinPath = path.resolve(defaultToolsHome, yaFileName)\n fs.chmodSync(serverBinPath, 0o777)\n this.host9pPort = await portfinder.getPortPromise({ port: 7878 })\n const address = `127.0.0.1:${this.host9pPort}`\n this.v9fsProcess = spawn(serverBinPath, [\n '--mount-point',\n quickappMountDir,\n '--network-address',\n address,\n '--debug'\n ])\n\n this.v9fsProcess.stderr?.on('data', (data) => {\n const output = data.toString()\n if (output.match(/Server started, listening on: 127.0.0.1:(\\d+)/)) {\n ColorConsole.log({ message: output })\n ColorConsole.log({ message: '### Emulator ### 9p server starts successfully' })\n return resolve()\n }\n })\n\n this.v9fsProcess.on('exit', (code) => {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `### Emulator ### ya-vm-file-server exited with code ${code}`,\n isOnlyPrintError: true\n })\n return reject()\n })\n })\n }\n\n /** 启动goldfish模拟器 */\n async startGoldfish(options: IStartOptions) {\n const { avdName, devtool } = options\n const emulatorBin = this.getEmulatorBinPath()\n ColorConsole.log({ message: `### Emulator ### emulator path: ${emulatorBin}` })\n const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName)\n const { avdArch, avdImagePath } = avdInfo\n this.adbPort = await portfinder.getPortPromise({ port: this.adbPort })\n ColorConsole.log({ message: `### Emulator ### adb port: ${this.adbPort}` })\n if (!avdImagePath) {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `### Emulator ### Unable to find vela image via avd`\n })\n process.exit()\n }\n const nuttxBinPath = path.resolve(avdImagePath, 'nuttx')\n ColorConsole.log({ message: `### Emulator ### nuttx path: ${nuttxBinPath}` })\n let portMappingStr = `user,id=u1,hostfwd=tcp:127.0.0.1:${this.adbPort}-10.0.2.15:5555`\n if (devtool) {\n this.debugPort = await portfinder.getPortPromise({ port: this.debugPort })\n ColorConsole.log({ message: `### Emulator ### debug port: ${this.debugPort}` })\n portMappingStr += `,hostfwd=tcp:127.0.0.1:${this.debugPort}-10.0.2.15:101`\n }\n ColorConsole.log({ message: `### Emulator ### Start qemu with TCP: ${portMappingStr}` })\n const stdioType = options.disableNSH ? 'pipe' : 'inherit'\n\n return new Promise<void>((resolve) => {\n this.goldfishProcess = spawn(\n emulatorBin,\n [\n '-nuttx',\n '-avd',\n avdName,\n '-avd-arch',\n avdArch,\n '-show-kernel',\n '-kernel',\n nuttxBinPath,\n '-qemu',\n '-netdev',\n portMappingStr,\n '-device',\n 'virtio-net-device,netdev=u1,bus=virtio-mmio-bus.3'\n ],\n { stdio: stdioType }\n )\n if (options.disableNSH) {\n this.goldfishProcess.stdout?.on('data', (data: Buffer) => {\n console.log(data.toString())\n if (data.toString().includes('(NSH)')) {\n ColorConsole.log({ message: `### Emulator ### Goldfish emulator starts successfully` })\n resolve()\n }\n })\n this.goldfishProcess.stderr?.on('data', (data) => {\n console.log(data.toString())\n })\n } else {\n setTimeout(() => {\n ColorConsole.log({ message: `### Emulator ### Goldfish emulator starts successfully` })\n resolve()\n }, 2000)\n }\n this.goldfishProcess.on('exit', (code) => {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `### Emulator ### Goldfish emulator exited with code ${code}`,\n isOnlyPrintError: true\n })\n })\n })\n }\n\n /** 通过adb连接模拟器 */\n async connectGoldfish() {\n let adbConnected = false\n const connectFn = async () => {\n const sn = `127.0.0.1:${this.adbPort}`\n while (!adbConnected) {\n const adbKillCmd = `adb kill-server`\n ColorConsole.log({ message: `### Emulator ### Excuting adb cmd: ${adbKillCmd}` })\n adbMiwt.execAdbCmdSync(adbKillCmd)\n const adbConnectCmd = `adb connect ${sn}`\n ColorConsole.log({ message: `### Emulator ### Excuting adb cmd: ${adbConnectCmd}` })\n const str = adbMiwt.execAdbCmdSync(adbConnectCmd)\n ColorConsole.log({ message: `### Emulator ### ${str}` })\n const devices = await adbMiwt.getAdbDevices()\n ColorConsole.log({ message: `### Emulator ### adb devices: ${JSON.stringify(devices)}` })\n adbConnected =\n devices.filter((item) => item.sn === sn && item.status === 'device').length > 0\n }\n Promise.resolve(adbConnected)\n }\n await Promise.race([\n connectFn(),\n new Promise((resolve) => {\n setTimeout(() => resolve(false), 600 * 1000)\n })\n ])\n return adbConnected\n }\n\n /** 将打包后的文件推到挂载的快应用目录 */\n pushRpk() {\n const buildDir = path.resolve(this.projectPath, 'build')\n const { package: appPackageName } = UxFileUtils.getMainfestInfo(this.projectPath)\n const appRunDir = path.resolve(this.sdkHome, 'qa/app', appPackageName)\n ColorConsole.log({ message: `### Emulator ### Pushing ${appPackageName} to ${appRunDir}` })\n fs.rmSync(appRunDir, { recursive: true, force: true })\n FileUtil.copyFiles(buildDir, appRunDir)\n ColorConsole.log({\n message: `### Emulator ### Push ${appPackageName} to ${appRunDir} successfully`\n })\n }\n\n /** 杀死进程 */\n killProcess(currProcess?: ChildProcess) {\n if (currProcess && currProcess.pid && currProcess.exitCode === null) {\n console.log('process pid:', currProcess.pid)\n try {\n if (os.platform() === 'win32') {\n execSync(`taskkill /pid ${currProcess.pid} /T /F`)\n } else if (os.platform() === 'darwin') {\n process.kill(currProcess.pid)\n } else {\n currProcess.kill()\n }\n } catch (err) {\n ColorConsole.log({ message: `kill process get error :\\n${(err as Error).stack}` })\n }\n }\n }\n\n /** 停止模拟器并释放相关资源 */\n stop() {\n if (this.goldfishProcess) {\n this.killProcess(this.goldfishProcess)\n this.goldfishProcess = undefined\n }\n if (this.v9fsProcess) {\n this.killProcess(this.v9fsProcess)\n this.v9fsProcess = undefined\n }\n }\n}\n\nexport default GoldfishInstance\n"],"sourceRoot":"../../src"}
1
+ {"version":3,"sources":["instance/goldfish.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kGAAyE;AACzE,+FAAsE;AACtE,6FAAoE;AACpE,mDAAoC;AACpC,iDAA6D;AAC7D,gEAAsC;AACtC,4CAAmB;AACnB,4CAAmB;AACnB,gDAAuB;AACvB,4DAAmC;AACnC,2BAAoC;AACpC,iDAA+B;AAC/B,mDAI4B;AAE5B,oCAAwC;AAExC,MAAM,gBAAgB;IAcpB,YAAY,MAAkC;QAVtC,YAAO,GAAW,KAA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CAAC,OAAO,EAAE,CAAC,CAAA;gBACxF,CAAC,CAAC,CAAA;gBAEF,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE;oBAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;oBAC3C,sBAAY,CAAC,GAAG,CAAC,wDAAwD,IAAI,EAAE,CAAC,CAAA;oBAChF,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE;wBAC9B,IAAI,CAAC,OAAO,EAAE,CAAA;qBACf;yBAAM,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;wBAClC,IAAI,CAAC,IAAI,EAAE,CAAA;qBACZ;gBACH,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;;KACH;CACF;AAED,kBAAe,gBAAgB,CAAA","file":"goldfish.js","sourcesContent":["import UxFileUtils from '@aiot-toolkit/aiotpack/lib/utils/ux/UxFileUtils'\nimport ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport FileUtil from '@aiot-toolkit/shared-utils/lib/utils/FileUtil'\nimport * as adbMiwt from '@miwt/adb'\nimport { ChildProcess, execSync, spawn } from 'child_process'\nimport findProcess from 'find-process'\nimport fs from 'fs'\nimport os from 'os'\nimport path from 'path'\nimport portfinder from 'portfinder'\nimport { WebSocketServer } from 'ws'\nimport VelaAvdCls from '../avd'\nimport {\n defaultAvdHome,\n defaultSDKHome,\n defaultVncPort\n} from '../static/constants'\nimport { INewGoldfishInstanceParams, IStartOptions } from '../typing/Instance'\nimport { getSystemArch } from '../utils'\n\nclass GoldfishInstance {\n private projectPath: string\n private sdkHome: string\n private avdHome: string\n private adbPort: number = 15555\n public debugPort: number = 10055\n private host9pPort: number = 7878\n private velaAvdCls: VelaAvdCls\n private packageName: string\n public goldfishProcess: ChildProcess | undefined\n public v9fsProcess: ChildProcess | undefined\n public isFirstStart = true\n private startOptions: IStartOptions | undefined\n\n constructor(params: INewGoldfishInstanceParams) {\n this.projectPath = params.projectPath\n this.sdkHome = params.sdkHome || defaultSDKHome\n this.avdHome = params.avdHome || defaultAvdHome\n this.velaAvdCls = new VelaAvdCls({\n sdkHome: this.sdkHome,\n avdHome: this.avdHome\n })\n const { package: appPackageName } = UxFileUtils.getMainfestInfo(\n this.projectPath,\n params.sourceRoot\n )\n this.packageName = appPackageName\n }\n\n /** 获取模拟器二进制文件所在位置 */\n getEmulatorBinPath() {\n const osPlatform = os.platform()\n const arch = getSystemArch()\n const platform = osPlatform === 'win32' ? 'windows' : osPlatform\n const emulatorHome = path.resolve(this.sdkHome, 'emulator')\n return path.resolve(emulatorHome, `${platform}-${arch}`, 'emulator')\n }\n\n /** 在goldfish模拟器中运行快应用 */\n async start(options: IStartOptions) {\n // host启动9p server\n await this.ensure9pServerRunnning()\n this.startOptions = options\n // 将rpk推到host的QuickappHome目录\n this.pushRpk()\n // 启动模拟器\n await this.startGoldfish(options)\n const connected = await this.connectGoldfish()\n if (connected) {\n ColorConsole.log('### Emulator ### Goldfish emulator connected successfully')\n if (this.isFirstStart && this.startOptions.serverPort) {\n await this.createWebsockeServer()\n }\n // 在模拟器中启动快应用\n this.startupQuickApp(options)\n this.isFirstStart = false\n } else {\n ColorConsole.throw(\n '### Emulator ### Failed to connect emulator, please check whether the adb is normal'\n )\n }\n }\n\n /** 在goldfish中启动快应用 */\n startupQuickApp(options: IStartOptions) {\n try {\n const appMountDir = path.resolve(this.sdkHome, 'qa')\n const mountCmd = `adb -s 127.0.0.1:${this.adbPort} shell mount -t v9fs -o tag=10.0.2.2,port=${this.host9pPort},aname=${appMountDir} /data`\n ColorConsole.log(`### Emulator ### Excuting adb cmd: ${mountCmd}`)\n adbMiwt.execAdbCmdSync(mountCmd)\n let vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp app/${this.packageName} &`\n if (options.devtool) {\n vappCmd = `adb -s 127.0.0.1:${this.adbPort} shell vapp --jsdebugger=10.0.2.15:101 app/${this.packageName} &`\n }\n ColorConsole.log(`### Emulator ### Excuting adb cmd: ${vappCmd}`)\n // vapp进程会一直pending,不会退出。这里必须加stdio: 'ignore',否则快应用无法运行成功\n adbMiwt.execAdbCmdAsync(vappCmd, { stdio: 'ignore', encoding: 'utf-8' })\n } catch (e: any) {\n ColorConsole.error(`### Emulator ### Failed to startup quickapp: ${e.message}`)\n }\n }\n /** host启动9pServer */\n ensure9pServerRunnning(): Promise<void> {\n return new Promise(async (resolve, reject) => {\n const yaFileName = os.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server'\n const pidList = await findProcess('name', yaFileName)\n if (pidList.length > 0) {\n ColorConsole.log('### Emulator ### 9p server started in host')\n return resolve()\n }\n ColorConsole.log('### Emulator ### Starting 9p server in host')\n const quickappMountDir = path.resolve(this.sdkHome, 'qa')\n const toolsHome = path.resolve(this.sdkHome, 'tools')\n const serverBinPath = path.resolve(toolsHome, yaFileName)\n fs.chmodSync(serverBinPath, 0o777)\n this.host9pPort = await portfinder.getPortPromise({ port: 7878 })\n const address = `127.0.0.1:${this.host9pPort}`\n this.v9fsProcess = spawn(serverBinPath, [\n '--mount-point',\n quickappMountDir,\n '--network-address',\n address,\n '--debug'\n ])\n\n this.v9fsProcess.stderr?.on('data', (data) => {\n const output = data.toString()\n if (output.match(/Server started, listening on: 127.0.0.1:(\\d+)/)) {\n ColorConsole.log(output)\n ColorConsole.log('### Emulator ### 9p server starts successfully')\n return resolve()\n }\n })\n\n this.v9fsProcess.on('exit', (code) => {\n ColorConsole.error(`### Emulator ### ya-vm-file-server exited with code ${code}`)\n return reject()\n })\n })\n }\n\n /** 启动goldfish模拟器 */\n async startGoldfish(options: IStartOptions) {\n const { avdName, devtool } = options\n const emulatorBin = this.getEmulatorBinPath()\n ColorConsole.log(`### Emulator ### emulator path: ${emulatorBin}`)\n const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName)\n const { avdArch, avdImagePath } = avdInfo\n this.adbPort = await portfinder.getPortPromise({ port: this.adbPort })\n ColorConsole.log(`### Emulator ### adb port: ${this.adbPort}`)\n if (!avdImagePath) {\n return ColorConsole.throw(`### Emulator ### Unable to find vela image via avd`)\n }\n const nuttxBinPath = path.resolve(avdImagePath, 'nuttx')\n ColorConsole.log(`### Emulator ### nuttx path: ${nuttxBinPath}`)\n let portMappingStr = `user,id=u1,hostfwd=tcp:127.0.0.1:${this.adbPort}-10.0.2.15:5555`\n if (devtool) {\n this.debugPort = await portfinder.getPortPromise({ port: this.debugPort })\n ColorConsole.log(`### Emulator ### debug port: ${this.debugPort}`)\n portMappingStr += `,hostfwd=tcp:127.0.0.1:${this.debugPort}-10.0.2.15:101`\n }\n ColorConsole.log(`### Emulator ### Start qemu with TCP: ${portMappingStr}`)\n const stdioType = options.disableNSH ? 'pipe' : 'inherit'\n\n // vnc配置\n let noWindow = false\n let vncStr = ''\n if (this.startOptions?.vncPort) {\n noWindow = true\n const portSuffix = this.startOptions.vncPort - defaultVncPort\n vncStr = `-vnc :${portSuffix}`\n }\n\n // 启动goldfish的命令和参数\n const spawnBin = emulatorBin\n const spawnArgs = [\n '-nuttx',\n '-avd',\n avdName,\n '-avd-arch',\n avdArch,\n '-show-kernel',\n '-kernel',\n nuttxBinPath,\n noWindow ? '-no-window' : '',\n '-qemu',\n vncStr,\n '-netdev',\n portMappingStr,\n '-device',\n 'virtio-net-device,netdev=u1,bus=virtio-mmio-bus.3'\n ]\n ColorConsole.log(`### Emulator ### Start CMD: ${spawnBin} ${spawnArgs.join(' ')}`)\n\n return new Promise<void>((resolve) => {\n this.goldfishProcess = spawn(\n spawnBin,\n spawnArgs,\n { stdio: stdioType, shell: true }\n )\n if (options.disableNSH) {\n this.goldfishProcess.stdout?.on('data', (data: Buffer) => {\n console.log(data.toString())\n if (data.toString().includes('(NSH)')) {\n ColorConsole.log(`### Emulator ### Goldfish emulator starts successfully`)\n resolve()\n }\n })\n this.goldfishProcess.stderr?.on('data', (data) => {\n console.log(data.toString())\n })\n } else {\n setTimeout(() => {\n ColorConsole.log(`### Emulator ### Goldfish emulator starts successfully`)\n resolve()\n }, 2000)\n }\n this.goldfishProcess.on('exit', (code) => {\n ColorConsole.error(`### Emulator ### Goldfish emulator exited with code ${code}`)\n })\n })\n }\n\n /** 通过adb连接模拟器 */\n async connectGoldfish() {\n let adbConnected = false\n const connectFn = async () => {\n const sn = `127.0.0.1:${this.adbPort}`\n while (!adbConnected) {\n const adbKillCmd = `adb kill-server`\n ColorConsole.log(`### Emulator ### Excuting adb cmd: ${adbKillCmd}`)\n adbMiwt.execAdbCmdSync(adbKillCmd)\n const adbConnectCmd = `adb connect ${sn}`\n ColorConsole.log(`### Emulator ### Excuting adb cmd: ${adbConnectCmd}`)\n const str = adbMiwt.execAdbCmdSync(adbConnectCmd)\n ColorConsole.log(`### Emulator ### ${str}`)\n const devices = await adbMiwt.getAdbDevices()\n ColorConsole.log(`### Emulator ### adb devices: ${JSON.stringify(devices)}`)\n adbConnected =\n devices.filter((item) => item.sn === sn && item.status === 'device').length > 0\n }\n Promise.resolve(adbConnected)\n }\n await Promise.race([\n connectFn(),\n new Promise((resolve) => {\n setTimeout(() => resolve(false), 600 * 1000)\n })\n ])\n return adbConnected\n }\n\n /** 将打包后的文件推到挂载的快应用目录 */\n pushRpk() {\n const buildDir = path.resolve(this.projectPath, 'build')\n const { package: appPackageName } = UxFileUtils.getMainfestInfo(this.projectPath)\n const appRunDir = path.resolve(this.sdkHome, 'qa/app', appPackageName)\n ColorConsole.log(`### Emulator ### Pushing ${appPackageName} to ${appRunDir}`)\n fs.rmSync(appRunDir, { recursive: true, force: true })\n FileUtil.copyFiles(buildDir, appRunDir)\n ColorConsole.log(`### Emulator ### Push ${appPackageName} to ${appRunDir} successfully`)\n }\n\n /** 杀死进程 */\n killProcess(currProcess?: ChildProcess) {\n if (currProcess && currProcess.pid && currProcess.exitCode === null) {\n console.log('process pid:', currProcess.pid)\n try {\n if (os.platform() === 'win32') {\n execSync(`taskkill /pid ${currProcess.pid} /T /F`)\n } else if (os.platform() === 'darwin') {\n process.kill(currProcess.pid)\n } else {\n currProcess.kill()\n }\n } catch (err) {\n ColorConsole.log(`### Emulator ### kill process get error :\\n${(err as Error).stack}`)\n }\n }\n }\n\n /** 停止模拟器并释放相关资源 */\n stop() {\n if (this.goldfishProcess) {\n this.killProcess(this.goldfishProcess)\n this.goldfishProcess = undefined\n }\n if (this.v9fsProcess) {\n this.killProcess(this.v9fsProcess)\n this.v9fsProcess = undefined\n }\n }\n\n /** 重启模拟器 */\n restart() {\n if (this.goldfishProcess) {\n this.killProcess(this.goldfishProcess)\n this.goldfishProcess = undefined\n }\n this.start(this.startOptions!!)\n }\n\n /** 创建server */\n async createWebsockeServer() {\n const wsServer = new WebSocketServer({\n port: this.startOptions?.serverPort,\n })\n wsServer.on('connection', socket => {\n ColorConsole.success(`### App Socket server ### Websocket connects to websocket server`)\n\n socket.on('error', err => {\n ColorConsole.error(`### App Socket server ### Websocket server error: ${err.message}`)\n })\n\n socket.on('message', data => {\n const message = JSON.parse(data.toString())\n ColorConsole.log(`### App Socket server ### Websocket server get data: ${data}`)\n if (message.type === 'restart') { \n this.restart()\n } else if (message.type === 'stop') {\n this.stop()\n }\n })\n })\n }\n}\n\nexport default GoldfishInstance\n"],"sourceRoot":"../../src"}
@@ -5,3 +5,4 @@ export declare const defaultEmulatorHome: string;
5
5
  export declare const defaultSkinHome: string;
6
6
  export declare const defaultQuickappHome: string;
7
7
  export declare const defaultToolsHome: string;
8
+ export declare const defaultVncPort = 5900;
@@ -3,7 +3,7 @@ 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.defaultToolsHome = exports.defaultQuickappHome = exports.defaultSkinHome = exports.defaultEmulatorHome = exports.defaultImageHome = exports.defaultAvdHome = exports.defaultSDKHome = void 0;
6
+ exports.defaultVncPort = exports.defaultToolsHome = exports.defaultQuickappHome = exports.defaultSkinHome = exports.defaultEmulatorHome = exports.defaultImageHome = exports.defaultAvdHome = exports.defaultSDKHome = void 0;
7
7
  const os_1 = __importDefault(require("os"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  exports.defaultSDKHome = path_1.default.resolve(os_1.default.homedir(), '.export');
@@ -13,5 +13,6 @@ exports.defaultEmulatorHome = path_1.default.resolve(exports.defaultSDKHome, 'em
13
13
  exports.defaultSkinHome = path_1.default.resolve(exports.defaultSDKHome, 'skins');
14
14
  exports.defaultQuickappHome = path_1.default.resolve(exports.defaultSDKHome, 'qa');
15
15
  exports.defaultToolsHome = path_1.default.resolve(exports.defaultSDKHome, 'tools');
16
+ exports.defaultVncPort = 5900;
16
17
 
17
18
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["static/constants.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AAEV,QAAA,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAA;AACtD,QAAA,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC,CAAA;AAC9D,QAAA,gBAAgB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,mBAAmB,CAAC,CAAA;AACpE,QAAA,mBAAmB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,UAAU,CAAC,CAAA;AAC9D,QAAA,eAAe,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,OAAO,CAAC,CAAA;AACvD,QAAA,mBAAmB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,IAAI,CAAC,CAAA;AACxD,QAAA,gBAAgB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,OAAO,CAAC,CAAA","file":"constants.js","sourcesContent":["import os from 'os'\nimport path from 'path'\n\nexport const defaultSDKHome = path.resolve(os.homedir(), '.export')\nexport const defaultAvdHome = path.resolve(os.homedir(), '.android', 'avd')\nexport const defaultImageHome = path.resolve(defaultSDKHome, 'system-images/arm')\nexport const defaultEmulatorHome = path.resolve(defaultSDKHome, 'emulator')\nexport const defaultSkinHome = path.resolve(defaultSDKHome, 'skins')\nexport const defaultQuickappHome = path.resolve(defaultSDKHome, 'qa')\nexport const defaultToolsHome = path.resolve(defaultSDKHome, 'tools')"],"sourceRoot":"../../src"}
1
+ {"version":3,"sources":["static/constants.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AAEV,QAAA,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAA;AACtD,QAAA,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC,CAAA;AAC9D,QAAA,gBAAgB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,mBAAmB,CAAC,CAAA;AACpE,QAAA,mBAAmB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,UAAU,CAAC,CAAA;AAC9D,QAAA,eAAe,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,OAAO,CAAC,CAAA;AACvD,QAAA,mBAAmB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,IAAI,CAAC,CAAA;AACxD,QAAA,gBAAgB,GAAG,cAAI,CAAC,OAAO,CAAC,sBAAc,EAAE,OAAO,CAAC,CAAA;AAExD,QAAA,cAAc,GAAG,IAAI,CAAA","file":"constants.js","sourcesContent":["import os from 'os'\nimport path from 'path'\n\nexport const defaultSDKHome = path.resolve(os.homedir(), '.export')\nexport const defaultAvdHome = path.resolve(os.homedir(), '.android', 'avd')\nexport const defaultImageHome = path.resolve(defaultSDKHome, 'system-images/arm')\nexport const defaultEmulatorHome = path.resolve(defaultSDKHome, 'emulator')\nexport const defaultSkinHome = path.resolve(defaultSDKHome, 'skins')\nexport const defaultQuickappHome = path.resolve(defaultSDKHome, 'qa')\nexport const defaultToolsHome = path.resolve(defaultSDKHome, 'tools')\n\nexport const defaultVncPort = 5900"],"sourceRoot":"../../src"}
@@ -7,4 +7,6 @@ export interface IStartOptions {
7
7
  avdName: string;
8
8
  devtool?: string;
9
9
  disableNSH?: boolean;
10
+ serverPort?: number;
11
+ vncPort?: number;
10
12
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["typing/Instance.ts"],"names":[],"mappings":"","file":"Instance.js","sourcesContent":["import { IAvdResourcePaths } from \"./Avd\";\n\nexport interface INewGoldfishInstanceParams extends IAvdResourcePaths {\n projectPath: string\n sourceRoot?: string\n}\n\nexport interface IStartOptions {\n avdName: string;\n devtool?: string;\n disableNSH?: boolean;\n}"],"sourceRoot":"../../src"}
1
+ {"version":3,"sources":["typing/Instance.ts"],"names":[],"mappings":"","file":"Instance.js","sourcesContent":["import { IAvdResourcePaths } from \"./Avd\";\n\nexport interface INewGoldfishInstanceParams extends IAvdResourcePaths {\n projectPath: string\n sourceRoot?: string\n}\n\nexport interface IStartOptions {\n avdName: string\n devtool?: string\n disableNSH?: boolean\n serverPort?: number\n vncPort?: number\n}"],"sourceRoot":"../../src"}
@@ -0,0 +1,5 @@
1
+ /** 获取mac电脑的CPU架构
2
+ * node 15.0.0之后,m1芯片的mac的os.arch()才是arm64,在这之前都是x86
3
+ * 所以15.0.0之前无法通过os.arch()区分,也无法通过execSync('uname -m')区分
4
+ */
5
+ export declare function getSystemArch(): string | void;
@@ -0,0 +1,41 @@
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
+ exports.getSystemArch = void 0;
7
+ const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
8
+ const child_process_1 = require("child_process");
9
+ const os_1 = __importDefault(require("os"));
10
+ const semver_1 = __importDefault(require("semver"));
11
+ const cpuArch = {
12
+ arm64: 'aarch64',
13
+ aarch64: 'aarch64',
14
+ x64: 'x86_64',
15
+ x86_64: 'x86_64',
16
+ };
17
+ /** 获取mac电脑的CPU架构
18
+ * node 15.0.0之后,m1芯片的mac的os.arch()才是arm64,在这之前都是x86
19
+ * 所以15.0.0之前无法通过os.arch()区分,也无法通过execSync('uname -m')区分
20
+ */
21
+ function getSystemArch() {
22
+ const platform = os_1.default.platform();
23
+ let osArch = os_1.default.arch();
24
+ const nodeVersion = process.version;
25
+ if (semver_1.default.lt(nodeVersion, '15.0.0') && platform === 'darwin') {
26
+ try {
27
+ (0, child_process_1.execSync)('sysctl -n sysctl.proc_translated');
28
+ osArch = 'arm64';
29
+ }
30
+ catch (_a) {
31
+ osArch = 'x64';
32
+ }
33
+ }
34
+ if (osArch !== 'arm64' && osArch !== 'x64') {
35
+ return ColorConsole_1.default.throw(`unsupport system`);
36
+ }
37
+ return cpuArch[osArch];
38
+ }
39
+ exports.getSystemArch = getSystemArch;
40
+
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/index.ts"],"names":[],"mappings":";;;;;;AAAA,+FAAsE;AACtE,iDAAwC;AACxC,4CAAmB;AACnB,oDAA2B;AAG3B,MAAM,OAAO,GAAI;IACf,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,SAAS;IAClB,GAAG,EAAE,QAAQ;IACb,MAAM,EAAE,QAAQ;CACjB,CAAA;AAED;;;GAGG;AACH,SAAgB,aAAa;IAC3B,MAAM,QAAQ,GAAG,YAAE,CAAC,QAAQ,EAAE,CAAA;IAC9B,IAAI,MAAM,GAAG,YAAE,CAAC,IAAI,EAAE,CAAA;IACtB,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAA;IACnC,IAAI,gBAAM,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC,IAAI,QAAQ,KAAK,QAAQ,EAAE;QAC7D,IAAI;YACF,IAAA,wBAAQ,EAAC,kCAAkC,CAAC,CAAA;YAC5C,MAAM,GAAG,OAAO,CAAA;SACjB;QAAC,WAAM;YACN,MAAM,GAAG,KAAK,CAAA;SACf;KACF;IACD,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,KAAK,EAAE;QAC1C,OAAO,sBAAY,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAA;KAC9C;IACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAA;AACxB,CAAC;AAhBD,sCAgBC","file":"index.js","sourcesContent":["import ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport { execSync } from 'child_process'\nimport os from 'os'\nimport semver from 'semver'\n\n\nconst cpuArch = {\n arm64: 'aarch64',\n aarch64: 'aarch64',\n x64: 'x86_64',\n x86_64: 'x86_64',\n}\n\n/** 获取mac电脑的CPU架构\n * node 15.0.0之后,m1芯片的mac的os.arch()才是arm64,在这之前都是x86\n * 所以15.0.0之前无法通过os.arch()区分,也无法通过execSync('uname -m')区分\n */\nexport function getSystemArch() {\n const platform = os.platform()\n let osArch = os.arch()\n const nodeVersion = process.version\n if (semver.lt(nodeVersion, '15.0.0') && platform === 'darwin') {\n try {\n execSync('sysctl -n sysctl.proc_translated')\n osArch = 'arm64'\n } catch {\n osArch = 'x64'\n }\n }\n if (osArch !== 'arm64' && osArch !== 'x64') {\n return ColorConsole.throw(`unsupport system`)\n }\n return cpuArch[osArch]\n}"],"sourceRoot":"../../src"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/emulator",
3
- "version": "2.0.1-alpha.11",
3
+ "version": "2.0.1-alpha.13",
4
4
  "description": "vela emulator tool.",
5
5
  "homepage": "",
6
6
  "license": "ISC",
@@ -35,10 +35,10 @@
35
35
  "emulator"
36
36
  ],
37
37
  "dependencies": {
38
- "@aiot-toolkit/aiotpack": "2.0.1-alpha.11",
39
- "@aiot-toolkit/shared-utils": "2.0.1-alpha.11",
38
+ "@aiot-toolkit/aiotpack": "2.0.1-alpha.13",
39
+ "@aiot-toolkit/shared-utils": "2.0.1-alpha.13",
40
40
  "find-process": "^1.4.7",
41
41
  "portfinder": "^1.0.32"
42
42
  },
43
- "gitHead": "efd50ce0ed4755bc2cd12aebc5114319e75d9927"
43
+ "gitHead": "49040b26a267943df4d0b202b200d4df5bcbc1ef"
44
44
  }