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