@react-native-oh/react-native-harmony-cli 0.77.18-1 → 0.77.22

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.
Files changed (106) hide show
  1. package/dist/commands/run-harmony.js +49 -25
  2. package/dist/init/templates/harmony/entry/src/main/module.json5 +7 -0
  3. package/dist/simulator/LaunchSimulator.js +311 -0
  4. package/dist/simulator/index.js +23 -0
  5. package/harmony/{rnoh-hvigor-plugin-0.77.18.tgz → rnoh-hvigor-plugin-0.77.22.tgz} +0 -0
  6. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/02febc14 +0 -0
  7. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0429e5b7 +0 -0
  8. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/05339e68 +0 -0
  9. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/070be2fe +0 -0
  10. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/07851ff1 +0 -0
  11. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/12e10c06 +0 -0
  12. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/12e1d696 +0 -0
  13. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/14950087 +0 -0
  14. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/15e87372 +0 -0
  15. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/19e6ecbe +0 -0
  16. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1aac0ac4 +0 -0
  17. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1b8db102 +0 -0
  18. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1c181646 +0 -0
  19. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/203e747c +0 -0
  20. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/21ba4c08 +0 -0
  21. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/259939e5 +0 -0
  22. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/288ba98c +0 -0
  23. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2a45461c +0 -0
  24. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2d773091 +0 -0
  25. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2eda89fc +0 -0
  26. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2f584eca +0 -0
  27. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/35b495ca +0 -0
  28. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/36478aed +0 -0
  29. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/3844e772 +0 -0
  30. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/3ee777f4 +0 -0
  31. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/471ac436 +0 -0
  32. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4a91abcc +0 -0
  33. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4d1a5094 +0 -0
  34. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4d3ef38f +0 -0
  35. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4daf5855 +0 -0
  36. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4ef0389f +0 -0
  37. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4f72da28 +0 -0
  38. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/59d3e924 +0 -0
  39. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5a8edfaa +0 -0
  40. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5d28a510 +0 -0
  41. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/61a6391d +0 -0
  42. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/65921a14 +0 -0
  43. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6624e7fc +0 -0
  44. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/66d28144 +0 -0
  45. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6aceb8d2 +0 -0
  46. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/702393d3 +0 -0
  47. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/714f932b +0 -0
  48. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/73f9d4a6 +0 -0
  49. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/78d3adae +0 -0
  50. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7b6564b8 +0 -0
  51. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7c7c3e6e +0 -0
  52. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7cbc9b6a +0 -0
  53. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7dd579e0 +0 -0
  54. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7e0b7d06 +0 -0
  55. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7e153eef +0 -0
  56. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7ee84fd7 +0 -0
  57. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7f5146a4 +0 -0
  58. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/844e633a +0 -0
  59. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8a1af22c +0 -0
  60. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/90a1680d +0 -0
  61. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a15fb79a +0 -0
  62. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ac288a8a +0 -0
  63. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ad7a66b4 +0 -0
  64. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/aee8805e +0 -0
  65. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b0487ec8 +0 -0
  66. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b10e16d2 +0 -0
  67. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b32d42ac +0 -0
  68. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b7d8f35c +0 -0
  69. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b96748af +0 -0
  70. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/bedb2fea +0 -0
  71. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c01ad640 +0 -0
  72. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c0472cf5 +0 -0
  73. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c102ed0f +0 -0
  74. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c1a91819 +0 -0
  75. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c243857a +0 -0
  76. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c407792f +0 -0
  77. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c4459bee +0 -0
  78. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c72a4dcd +0 -0
  79. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c83537a9 +0 -0
  80. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c88f7498 +0 -0
  81. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c8d04070 +0 -0
  82. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cc44d6f1 +0 -0
  83. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d4d913f6 +0 -0
  84. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/da97f202 +0 -0
  85. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/dc965522 +0 -0
  86. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/dff6f700 +0 -0
  87. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e507c001 +0 -0
  88. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e52f3f2d +0 -0
  89. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e5c3890d +0 -0
  90. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e720074d +0 -0
  91. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e7656fa7 +0 -0
  92. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e80bcaac +0 -0
  93. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e8e7900e +0 -0
  94. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ee8993f9 +0 -0
  95. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ef8cf362 +0 -0
  96. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f1405b1d +0 -0
  97. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f20f0e0d +0 -0
  98. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f2586978 +0 -0
  99. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f53cd716 +0 -0
  100. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/fe71f6bb +0 -0
  101. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/febfc20b +0 -0
  102. package/package.json +1 -1
  103. package/src/commands/run-harmony.ts +67 -39
  104. package/src/init/templates/harmony/entry/src/main/module.json5 +7 -0
  105. package/src/simulator/LaunchSimulator.ts +352 -0
  106. package/src/simulator/index.ts +8 -0
@@ -28,7 +28,10 @@ const json5_1 = __importDefault(require("json5"));
28
28
  const inquirer_1 = __importDefault(require("inquirer"));
29
29
  const path_1 = __importDefault(require("path"));
30
30
  const cli_tools_1 = require("@react-native-community/cli-tools");
31
+ const simulator_1 = require("../simulator");
31
32
  const COMMAND_NAME = 'run-harmony';
33
+ const LOOPBACK_IP = '127.0.0.1';
34
+ const DEFAULT_SIMULATOR_NAME = `${LOOPBACK_IP}:5555`;
32
35
  exports.commandRunHarmony = {
33
36
  name: COMMAND_NAME,
34
37
  description: 'Builds your app and starts it on your phone.',
@@ -112,7 +115,7 @@ exports.commandRunHarmony = {
112
115
  const buildMode = rawArgs.buildMode;
113
116
  const moduleName = rawArgs.module;
114
117
  const abilityName = rawArgs.ability;
115
- const simulatorName = rawArgs.simulator;
118
+ let simulatorName = rawArgs.simulator;
116
119
  const defaultPort = rawArgs.port;
117
120
  const packager = rawArgs.packager;
118
121
  const devEcoStudioToolsPath = new core_1.AbsolutePath(DEVECO_SDK_HOME).copyWithNewSegment('..', 'tools');
@@ -122,6 +125,19 @@ exports.commandRunHarmony = {
122
125
  });
123
126
  }
124
127
  const bundleName = json5_1.default.parse(fs.readTextSync(harmonyProjectPath.copyWithNewSegment('AppScope', 'app.json5'))).app.bundleName;
128
+ let currentPort = defaultPort;
129
+ if (packager) {
130
+ const root = _config.root || '.';
131
+ const reactNativePath = _config.reactNativePath || path_1.default.dirname(require.resolve('react-native', { paths: [root] }));
132
+ const { port: newPort, startPackager } = yield (0, cli_tools_1.findDevServerPort)(defaultPort, root);
133
+ if (newPort !== 8081) {
134
+ yield trySetMetroPort(harmonyProjectPath.copyWithNewSegment('entry', 'src', 'main', 'ets', 'pages', 'Index.ets').toString(), newPort);
135
+ }
136
+ if (startPackager) {
137
+ (0, cli_tools_1.startServerInNewWindow)(newPort, root, reactNativePath, (0, cli_tools_1.getDefaultUserTerminal)());
138
+ }
139
+ currentPort = newPort;
140
+ }
125
141
  const selectDevice = (deviceAndSimulatorInfos) => __awaiter(void 0, void 0, void 0, function* () {
126
142
  const lines = deviceAndSimulatorInfos.trim().split('\n');
127
143
  const availableDevices = lines.map((line) => {
@@ -147,6 +163,9 @@ exports.commandRunHarmony = {
147
163
  return simulatorName;
148
164
  }
149
165
  const connectedDevices = availableDevices.filter((deviceOrSimulator) => deviceOrSimulator.state === 'Connected');
166
+ if (connectedDevices.length === 1) {
167
+ return connectedDevices[0].name;
168
+ }
150
169
  if (connectedDevices.length > 1) {
151
170
  const answers = yield inquirer_1.default.prompt([
152
171
  {
@@ -158,15 +177,32 @@ exports.commandRunHarmony = {
158
177
  ]);
159
178
  return connectedDevices[parseInt(answers.selectedDeviceIndex) - 1].name;
160
179
  }
161
- else if (connectedDevices.length === 1) {
162
- return connectedDevices[0].name;
180
+ try {
181
+ yield (0, simulator_1.launchHarmonySimulator)({
182
+ devEcoStudioToolsPath,
183
+ sdkToolchainsPath,
184
+ cli,
185
+ logger,
186
+ env: process.env,
187
+ });
188
+ simulatorName = DEFAULT_SIMULATOR_NAME;
189
+ return simulatorName;
163
190
  }
164
- else {
191
+ catch (e) {
192
+ if (e instanceof core_1.DescriptiveError) {
193
+ throw new core_1.DescriptiveError({
194
+ whatHappened: `${e.getMessage()} \n No devices are connected. Failed to auto-launch simulator.`,
195
+ whatCanUserDo: [...e.getSuggestions()],
196
+ extraData: e.getRawData().extraData,
197
+ });
198
+ }
165
199
  throw new core_1.DescriptiveError({
166
- whatHappened: `No devices are connected in the current environment.`,
200
+ whatHappened: `No devices are connected in the current environment (auto-launch attempt failed).`,
167
201
  whatCanUserDo: [
168
- 'Please connect your HarmonyOS device or open the simulator.',
169
- ]
202
+ 'Connect a HarmonyOS device via USB or start the simulator manually.',
203
+ 'Re-run the command after a device is listed by: hdc list targets -v',
204
+ ],
205
+ extraData: e,
170
206
  });
171
207
  }
172
208
  });
@@ -175,18 +211,8 @@ exports.commandRunHarmony = {
175
211
  cwd: harmonyProjectPath,
176
212
  });
177
213
  const deviceOrSimulatorName = yield selectDevice(deviceAndSimulatorInfo);
178
- let currentPort = defaultPort;
179
- if (packager) {
180
- const root = _config.root || '.';
181
- const reactNativePath = _config.reactNativePath || path_1.default.dirname(require.resolve('react-native', { paths: [root] }));
182
- const { port: newPort, startPackager } = yield (0, cli_tools_1.findDevServerPort)(defaultPort, root);
183
- if (newPort !== 8081) {
184
- yield trySetMetroPort(harmonyProjectPath.copyWithNewSegment('entry', 'src', 'main', 'ets', 'pages', 'Index.ets').toString(), newPort);
185
- }
186
- if (startPackager) {
187
- (0, cli_tools_1.startServerInNewWindow)(newPort, root, reactNativePath, (0, cli_tools_1.getDefaultUserTerminal)());
188
- }
189
- currentPort = newPort;
214
+ if (deviceOrSimulatorName.includes(`${LOOPBACK_IP}:`)) {
215
+ simulatorName = deviceOrSimulatorName;
190
216
  }
191
217
  const runJob = (name, job) => __awaiter(void 0, void 0, void 0, function* () {
192
218
  const stop = logger.start((s) => s.bold(name));
@@ -215,8 +241,7 @@ exports.commandRunHarmony = {
215
241
  ohpmPath = devEcoStudioToolsPath
216
242
  .copyWithNewSegment('ohpm', 'bin', 'ohpm.bat');
217
243
  }
218
- yield cli.run(process.platform === 'win32' ? `"${ohpmPath.toString()}"` :
219
- ohpmPath.toString(), {
244
+ yield cli.run(`"${ohpmPath.toString()}"`, {
220
245
  args: [
221
246
  'install',
222
247
  '--all',
@@ -243,9 +268,8 @@ exports.commandRunHarmony = {
243
268
  nodePath = devEcoStudioToolsPath.copyWithNewSegment('node', 'node');
244
269
  }
245
270
  let hvigorPathRaw = devEcoStudioToolsPath.copyWithNewSegment('hvigor', 'bin', 'hvigorw.js').toString();
246
- const hvigorPath = process.platform === 'win32' ? `"${hvigorPathRaw}"` : hvigorPathRaw;
247
- yield cli.run(process.platform === 'win32' ? `"${nodePath.toString()}"` :
248
- nodePath.toString(), {
271
+ const hvigorPath = `"${hvigorPathRaw}"`;
272
+ yield cli.run(`"${nodePath.toString()}"`, {
249
273
  args: [
250
274
  hvigorPath,
251
275
  `-p`,
@@ -294,7 +318,7 @@ exports.commandRunHarmony = {
294
318
  const hdcPathStrRaw = sdkToolchainsPath
295
319
  .copyWithNewSegment('hdc')
296
320
  .toString();
297
- const hdcPathStr = process.platform === 'win32' ? `"${hdcPathStrRaw.toString()}"` : hdcPathStrRaw;
321
+ const hdcPathStr = `"${hdcPathStrRaw.toString()}"`;
298
322
  const tryRemoveForwardPorting = () => __awaiter(void 0, void 0, void 0, function* () {
299
323
  let fportInfo = '';
300
324
  yield cli.run(hdcPathStrRaw, {
@@ -10,6 +10,13 @@
10
10
  "deliveryWithInstall": true,
11
11
  "installationFree": false,
12
12
  "pages": "$profile:main_pages",
13
+ // This is needed by bundleManager.canOpenLink to check if the app can open some url
14
+ "querySchemes": [
15
+ "maps",
16
+ "http",
17
+ "https",
18
+ "customDomain"
19
+ ],
13
20
  "requestPermissions": [
14
21
  {
15
22
  "name": "ohos.permission.INTERNET"
@@ -0,0 +1,311 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.launchHarmonySimulator = launchHarmonySimulator;
22
+ const path_1 = __importDefault(require("path"));
23
+ const fs_extra_1 = __importDefault(require("fs-extra"));
24
+ const child_process_1 = require("child_process");
25
+ const core_1 = require("../core");
26
+ const MIN_SUPPORTED_VERSION = [6, 0, 0, 828];
27
+ function compareVersionTuple(a, b) {
28
+ var _a, _b;
29
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
30
+ const av = (_a = a[i]) !== null && _a !== void 0 ? _a : 0;
31
+ const bv = (_b = b[i]) !== null && _b !== void 0 ? _b : 0;
32
+ if (av !== bv)
33
+ return av - bv;
34
+ }
35
+ return 0;
36
+ }
37
+ function isSupportedVersion(versionDir) {
38
+ const m = versionDir.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)/);
39
+ if (!m)
40
+ return false;
41
+ const current = m.slice(1).map(n => parseInt(n, 10));
42
+ return compareVersionTuple(current, MIN_SUPPORTED_VERSION) >= 0;
43
+ }
44
+ function getCreatedSimulators(cli, emulator) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ try {
47
+ let simulatorInfos = '';
48
+ yield cli.run(`"${emulator}"`, {
49
+ args: ['--list'],
50
+ shell: true,
51
+ onStderr: (msg) => {
52
+ simulatorInfos += msg;
53
+ },
54
+ });
55
+ if (!simulatorInfos || simulatorInfos.trim() === '' ||
56
+ simulatorInfos.trim() === '[Empty]' ||
57
+ simulatorInfos.includes('not ')) {
58
+ return [];
59
+ }
60
+ return simulatorInfos.split('\n').filter(line => line.trim() !== '');
61
+ }
62
+ catch (error) {
63
+ throw new core_1.DescriptiveError({
64
+ whatHappened: `Failed to get simulator list: ${(error === null || error === void 0 ? void 0 : error.message) || error}`,
65
+ whatCanUserDo: [
66
+ 'Ensure DevEco Studio is properly installed and configured.',
67
+ 'Check if the emulator path is correct.',
68
+ 'Verify that the emulator has read/write permissions.'
69
+ ],
70
+ extraData: error,
71
+ });
72
+ }
73
+ });
74
+ }
75
+ function getDevEcoVersion(devEcoStudioToolsPath) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ try {
78
+ let productInfoPath = path_1.default.join(devEcoStudioToolsPath.toString(), '..', 'Resources', 'product-info.json');
79
+ if (process.platform === 'win32') {
80
+ productInfoPath = path_1.default.join(devEcoStudioToolsPath.toString(), '..', 'product-info.json');
81
+ }
82
+ const content = yield fs_extra_1.default.readFile(productInfoPath, 'utf-8');
83
+ const info = JSON.parse(content);
84
+ return info.version || null;
85
+ }
86
+ catch (error) {
87
+ throw new core_1.DescriptiveError({
88
+ whatHappened: `Failed to read DevEco Studio version from product-info.json: ${(error === null || error === void 0 ? void 0 : error.message) || error}`,
89
+ whatCanUserDo: [
90
+ 'Verify DevEco Studio installation is complete and not corrupted.',
91
+ 'Check if the DevEco Studio tools path is correct.',
92
+ 'Ensure product-info.json file exists and is readable.'
93
+ ],
94
+ extraData: error,
95
+ });
96
+ }
97
+ });
98
+ }
99
+ function resolveDeviceManagerXml(env, devEcoVersion) {
100
+ const candidates = [];
101
+ if (process.platform === 'darwin') {
102
+ const home = env.HOME || '';
103
+ candidates.push(path_1.default.join(home, 'Library', 'Application Support', 'Huawei', `DevEcoStudio${devEcoVersion}`, 'options', 'deviceManager.xml'));
104
+ }
105
+ else if (process.platform === 'win32') {
106
+ const appdata = env.APPDATA || '';
107
+ candidates.push(path_1.default.join(appdata, 'Huawei', `DevEcoStudio${devEcoVersion}`, 'options', 'deviceManager.xml'));
108
+ }
109
+ else {
110
+ throw new core_1.DescriptiveError({
111
+ whatHappened: `Unsupported operating system.`,
112
+ whatCanUserDo: ['Please run the RNOH project on Windows or macOS.']
113
+ });
114
+ }
115
+ return candidates;
116
+ }
117
+ function parseDeviceManagerXml(xmlContent) {
118
+ const info = {};
119
+ const optionRegex = /<option\b[^>]*?>/gi;
120
+ let m;
121
+ while ((m = optionRegex.exec(xmlContent))) {
122
+ const tag = m[0];
123
+ const nameMatch = tag.match(/\bname=["']([^"']+)["']/i);
124
+ if (!nameMatch)
125
+ continue;
126
+ const valueMatch = tag.match(/\bvalue=["']([^"']+)["']/i);
127
+ if (!valueMatch)
128
+ continue;
129
+ const name = nameMatch[1];
130
+ const value = valueMatch[1];
131
+ if (name === 'imageDeployPath' && !info.imageRoot) {
132
+ info.imageRoot = value;
133
+ }
134
+ else if (name === 'openharmonyDeployPath' && !info.instancePath) {
135
+ info.instancePath = value;
136
+ }
137
+ if (info.imageRoot && info.instancePath)
138
+ break;
139
+ }
140
+ return info;
141
+ }
142
+ function candidateEmulatorExecutables(devEcoStudioToolsPath) {
143
+ const list = [];
144
+ const add = (...segs) => list.push(devEcoStudioToolsPath.copyWithNewSegment(...segs).toString());
145
+ if (process.platform === 'win32') {
146
+ add('emulator', 'Emulator.exe');
147
+ }
148
+ else {
149
+ add('emulator', 'Emulator');
150
+ }
151
+ return list;
152
+ }
153
+ function pickExisting(paths) {
154
+ return paths.find(p => fs_extra_1.default.existsSync(p));
155
+ }
156
+ function resolveInstanceAndImageRoot(env, devEcoVersion) {
157
+ return __awaiter(this, void 0, void 0, function* () {
158
+ const defaultInstanceCandidates = [];
159
+ const defaultImageCandidates = [];
160
+ if (process.platform === 'darwin') {
161
+ const home = env.HOME || '';
162
+ defaultInstanceCandidates.push(path_1.default.join(home, '.Huawei', 'Emulator', 'deployed'));
163
+ defaultImageCandidates.push(path_1.default.join(home, 'Library', 'Huawei', 'Sdk'));
164
+ }
165
+ else if (process.platform === 'win32') {
166
+ const localAppData = env.LOCALAPPDATA || '';
167
+ defaultInstanceCandidates.push(path_1.default.join(localAppData, 'Huawei', 'Emulator', 'deployed'));
168
+ defaultImageCandidates.push(path_1.default.join(localAppData, 'Huawei', 'Sdk'));
169
+ }
170
+ else {
171
+ throw new core_1.DescriptiveError({
172
+ whatHappened: `Unsupported operating system.`,
173
+ whatCanUserDo: ['Please run the RNOH project on Windows or macOS.']
174
+ });
175
+ }
176
+ let xmlInfo = {};
177
+ for (const xmlPath of resolveDeviceManagerXml(env, devEcoVersion)) {
178
+ if (fs_extra_1.default.existsSync(xmlPath)) {
179
+ try {
180
+ const content = yield fs_extra_1.default.readFile(xmlPath, 'utf-8');
181
+ xmlInfo = parseDeviceManagerXml(content);
182
+ if (xmlInfo.instancePath || xmlInfo.imageRoot)
183
+ break;
184
+ }
185
+ catch (error) {
186
+ throw new core_1.DescriptiveError({
187
+ whatHappened: `Failed to read or parse device manager XML at ${xmlPath}: ${(error === null || error === void 0 ? void 0 : error.message) || error}`,
188
+ whatCanUserDo: [
189
+ 'Verify that the DevEco Studio deviceManager.xml file exists and is readable.',
190
+ 'Check if DEVECO_SDK_HOME environment variable is set correctly.',
191
+ 'Ensure DevEco Studio has been launched at least once to generate configuration files.',
192
+ 'Check file permissions for the DevEco Studio configuration directory.'
193
+ ],
194
+ extraData: error,
195
+ });
196
+ }
197
+ }
198
+ }
199
+ let resolvedInstance = pickExisting(defaultInstanceCandidates);
200
+ let resolvedImageRoot = pickExisting(defaultImageCandidates);
201
+ if (xmlInfo.imageRoot) {
202
+ resolvedImageRoot = xmlInfo.imageRoot;
203
+ }
204
+ if (xmlInfo.instancePath) {
205
+ resolvedInstance = xmlInfo.instancePath;
206
+ }
207
+ if (!resolvedInstance || !resolvedImageRoot) {
208
+ throw new core_1.DescriptiveError({
209
+ whatHappened: `No simulator instance or image root directory detected.`,
210
+ whatCanUserDo: [
211
+ 'Have you already launched the simulator via DevEco Studio?'
212
+ ]
213
+ });
214
+ }
215
+ return { instancePath: resolvedInstance, imageRoot: resolvedImageRoot };
216
+ });
217
+ }
218
+ function launchHarmonySimulator(opt) {
219
+ return __awaiter(this, void 0, void 0, function* () {
220
+ const { devEcoStudioToolsPath, cli, logger, } = opt;
221
+ const devEcoVersion = yield getDevEcoVersion(devEcoStudioToolsPath);
222
+ if (!devEcoVersion) {
223
+ throw new core_1.DescriptiveError({
224
+ whatHappened: `DevEco Studio version could not be obtained.`,
225
+ whatCanUserDo: [
226
+ 'Verify DevEco Studio is properly installed and the tools path is correct.',
227
+ 'Check if product-info.json file exists in the DevEco Studio installation directory.',
228
+ 'Ensure you have the latest version of DevEco Studio installed.'
229
+ ]
230
+ });
231
+ }
232
+ if (!isSupportedVersion(devEcoVersion)) {
233
+ throw new core_1.DescriptiveError({
234
+ whatHappened: `Current DevEco SDK version (${devEcoVersion}) does not support launching the simulator via command line (requires >= ${MIN_SUPPORTED_VERSION.join('.')}).`,
235
+ whatCanUserDo: [
236
+ `Update DevEco Studio to version ${MIN_SUPPORTED_VERSION.join('.')} or higher.`,
237
+ 'Check the official DevEco Studio website for the latest version.',
238
+ 'Launch the simulator manually from DevEco Studio IDE.'
239
+ ]
240
+ });
241
+ }
242
+ const versionList = devEcoVersion.split('.');
243
+ const majorVersion = `${versionList[0]}.${versionList[1]}`;
244
+ const paths = yield resolveInstanceAndImageRoot(opt.env, majorVersion);
245
+ if (!paths) {
246
+ throw new core_1.DescriptiveError({
247
+ whatHappened: `Could not resolve simulator instance path or image root.`,
248
+ whatCanUserDo: [
249
+ 'Open DevEco Studio and launch the simulator at least once to generate configuration files.',
250
+ 'Check if DEVECO_SDK_HOME environment variable is set correctly.',
251
+ 'Verify that the simulator has been properly configured in DevEco Studio.',
252
+ 'Ensure the default simulator paths exist in your system.'
253
+ ]
254
+ });
255
+ }
256
+ const emulatorExe = pickExisting(candidateEmulatorExecutables(devEcoStudioToolsPath));
257
+ if (!emulatorExe) {
258
+ throw new core_1.DescriptiveError({
259
+ whatHappened: `Emulator executable not found in DevEco Studio installation.`,
260
+ whatCanUserDo: [
261
+ 'Verify DevEco Studio installation is complete and not corrupted.',
262
+ 'Check if the emulator component is installed in DevEco Studio.',
263
+ 'Reinstall DevEco Studio if the emulator binary is missing.',
264
+ 'Ensure the DevEco Studio tools path is correctly configured.'
265
+ ]
266
+ });
267
+ }
268
+ const simulatorName = yield getCreatedSimulators(cli, emulatorExe);
269
+ if (simulatorName.length <= 0) {
270
+ throw new core_1.DescriptiveError({
271
+ whatHappened: `No existing HarmonyOS simulator instance detected.`,
272
+ whatCanUserDo: [
273
+ 'Create a simulator instance in DevEco Studio first.',
274
+ 'Open DevEco Studio Device Manager and create a new virtual device.',
275
+ 'Ensure the simulator instance is properly configured and available.',
276
+ 'Check if the emulator --list command returns any valid instances.'
277
+ ]
278
+ });
279
+ }
280
+ try {
281
+ const quoteIfNeeded = (p) => process.platform === 'win32' ? `"${p}"` : p;
282
+ const args = [
283
+ '-hvd',
284
+ simulatorName[0].trim(),
285
+ '-path',
286
+ quoteIfNeeded(paths.instancePath),
287
+ '-imageRoot',
288
+ quoteIfNeeded(paths.imageRoot),
289
+ ];
290
+ const child = (0, child_process_1.spawn)(quoteIfNeeded(emulatorExe), args, {
291
+ cwd: path_1.default.dirname(emulatorExe),
292
+ detached: true,
293
+ stdio: 'ignore',
294
+ shell: process.platform === 'win32',
295
+ });
296
+ child.unref();
297
+ logger.info(() => `Launching HarmonyOS simulator in background: ${simulatorName[0]}`);
298
+ }
299
+ catch (e) {
300
+ throw new core_1.DescriptiveError({
301
+ whatHappened: `Failed to start simulator process: ${(e === null || e === void 0 ? void 0 : e.message) || e}`,
302
+ whatCanUserDo: [
303
+ 'Confirm that the DevEco Simulator can be started manually from DevEco Studio.',
304
+ 'Ensure no stale simulator process is blocking required ports.',
305
+ 'Reinstall or repair DevEco Studio if the simulator binary is corrupted.'
306
+ ],
307
+ extraData: e,
308
+ });
309
+ }
310
+ });
311
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./LaunchSimulator"), exports);