@react-native-oh/react-native-harmony-cli 0.0.36 → 0.0.40-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/autolinking/Autolinking.js +14 -11
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +2 -1
- package/dist/codegen/generators/LibGlueCodeGenerator.js +2 -2
- package/dist/codegen/generators/UberGeneratorV1.js +9 -2
- package/dist/codegen/generators/UberGeneratorV2.js +8 -1
- package/dist/codegen/templates/BasePackageHTemplate.js +12 -1
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +12 -1
- package/dist/commands/codegen-harmony.js +16 -5
- package/dist/commands/run-harmony.js +49 -27
- package/dist/core/ProjectDependenciesManager.js +5 -7
- package/dist/simulator/LaunchSimulator.js +318 -0
- package/dist/simulator/index.js +23 -0
- package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
- package/package.json +13 -5
- package/.prettierrc +0 -6
- package/src/assetResolver.ts +0 -134
- package/src/autolinking/Autolinking.test.ts +0 -483
- package/src/autolinking/Autolinking.ts +0 -382
- package/src/autolinking/index.ts +0 -8
- package/src/codegen/core/CodeGenerator.ts +0 -16
- package/src/codegen/core/CodegenError.ts +0 -10
- package/src/codegen/core/EventUtils.ts +0 -23
- package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
- package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
- package/src/codegen/core/UberSchema.ts +0 -152
- package/src/codegen/core/index.ts +0 -12
- package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -120
- package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
- package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
- package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
- package/src/codegen/generators/UberGeneratorV1.ts +0 -75
- package/src/codegen/generators/UberGeneratorV2.ts +0 -114
- package/src/codegen/generators/index.ts +0 -15
- package/src/codegen/index.ts +0 -9
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
- package/src/codegen/templates/BasePackageHTemplate.ts +0 -147
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
- package/src/codegen/templates/IndexTSTemplate.ts +0 -62
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -138
- package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
- package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
- package/src/codegen/templates/index.ts +0 -16
- package/src/commands/bundle-harmony.ts +0 -134
- package/src/commands/codegen-harmony.ts +0 -297
- package/src/commands/codegen-lib-harmony.ts +0 -389
- package/src/commands/create-metro-host-constants.ts +0 -55
- package/src/commands/index.ts +0 -16
- package/src/commands/init.ts +0 -755
- package/src/commands/link-harmony.ts +0 -102
- package/src/commands/pack-harmony.ts +0 -128
- package/src/commands/run-harmony.ts +0 -478
- package/src/commands/types.ts +0 -21
- package/src/commands/unpack-harmony.ts +0 -238
- package/src/commands/verify-package-harmony.ts +0 -113
- package/src/core/AbsolutePath.ts +0 -66
- package/src/core/CodegenConfig.ts +0 -67
- package/src/core/DescriptiveError.ts +0 -68
- package/src/core/FileSystem.ts +0 -57
- package/src/core/OHPackageJSON5.ts +0 -30
- package/src/core/PackageJSON.ts +0 -104
- package/src/core/ProjectDependenciesManager.ts +0 -103
- package/src/core/ValidationError.ts +0 -8
- package/src/core/ValueObject.ts +0 -9
- package/src/core/fs.ts +0 -38
- package/src/core/index.ts +0 -17
- package/src/index.ts +0 -33
- package/src/io/CliExecutor.ts +0 -69
- package/src/io/Logger.ts +0 -112
- package/src/io/RealFS.ts +0 -62
- package/src/io/TarGz.ts +0 -33
- package/src/io/__fixtures__.ts +0 -139
- package/src/io/fsUtils.ts +0 -44
- package/src/io/index.ts +0 -11
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
- package/src/package-verifier/checks/index.ts +0 -11
- package/src/package-verifier/index.ts +0 -9
- package/src/package-verifier/types.ts +0 -19
- package/src/package-verifier/verify-package.ts +0 -123
|
@@ -0,0 +1,318 @@
|
|
|
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
|
+
let simulatorInfosFromStderr = '';
|
|
49
|
+
yield cli.run(`"${emulator}"`, {
|
|
50
|
+
args: ['--list'],
|
|
51
|
+
shell: true,
|
|
52
|
+
onStdout: (msg) => {
|
|
53
|
+
simulatorInfos += msg;
|
|
54
|
+
},
|
|
55
|
+
onStderr: (msg) => {
|
|
56
|
+
simulatorInfosFromStderr += msg;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
if (simulatorInfos == null || simulatorInfos.trim() === '') {
|
|
60
|
+
simulatorInfos = simulatorInfosFromStderr;
|
|
61
|
+
}
|
|
62
|
+
if (!simulatorInfos || simulatorInfos.trim() === '' ||
|
|
63
|
+
simulatorInfos.trim() === '[Empty]' ||
|
|
64
|
+
simulatorInfos.includes('not ')) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
return simulatorInfos.split('\n').filter(line => line.trim() !== '');
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
throw new core_1.DescriptiveError({
|
|
71
|
+
whatHappened: `Failed to get simulator list: ${(error === null || error === void 0 ? void 0 : error.message) || error}`,
|
|
72
|
+
whatCanUserDo: [
|
|
73
|
+
'Ensure DevEco Studio is properly installed and configured.',
|
|
74
|
+
'Check if the emulator path is correct.',
|
|
75
|
+
'Verify that the emulator has read/write permissions.'
|
|
76
|
+
],
|
|
77
|
+
extraData: error,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function getDevEcoVersion(devEcoStudioToolsPath) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
try {
|
|
85
|
+
let productInfoPath = path_1.default.join(devEcoStudioToolsPath.toString(), '..', 'Resources', 'product-info.json');
|
|
86
|
+
if (process.platform === 'win32') {
|
|
87
|
+
productInfoPath = path_1.default.join(devEcoStudioToolsPath.toString(), '..', 'product-info.json');
|
|
88
|
+
}
|
|
89
|
+
const content = yield fs_extra_1.default.readFile(productInfoPath, 'utf-8');
|
|
90
|
+
const info = JSON.parse(content);
|
|
91
|
+
return info.version || null;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw new core_1.DescriptiveError({
|
|
95
|
+
whatHappened: `Failed to read DevEco Studio version from product-info.json: ${(error === null || error === void 0 ? void 0 : error.message) || error}`,
|
|
96
|
+
whatCanUserDo: [
|
|
97
|
+
'Verify DevEco Studio installation is complete and not corrupted.',
|
|
98
|
+
'Check if the DevEco Studio tools path is correct.',
|
|
99
|
+
'Ensure product-info.json file exists and is readable.'
|
|
100
|
+
],
|
|
101
|
+
extraData: error,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function resolveDeviceManagerXml(env, devEcoVersion) {
|
|
107
|
+
const candidates = [];
|
|
108
|
+
if (process.platform === 'darwin') {
|
|
109
|
+
const home = env.HOME || '';
|
|
110
|
+
candidates.push(path_1.default.join(home, 'Library', 'Application Support', 'Huawei', `DevEcoStudio${devEcoVersion}`, 'options', 'deviceManager.xml'));
|
|
111
|
+
}
|
|
112
|
+
else if (process.platform === 'win32') {
|
|
113
|
+
const appdata = env.APPDATA || '';
|
|
114
|
+
candidates.push(path_1.default.join(appdata, 'Huawei', `DevEcoStudio${devEcoVersion}`, 'options', 'deviceManager.xml'));
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
throw new core_1.DescriptiveError({
|
|
118
|
+
whatHappened: `Unsupported operating system.`,
|
|
119
|
+
whatCanUserDo: ['Please run the RNOH project on Windows or macOS.']
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return candidates;
|
|
123
|
+
}
|
|
124
|
+
function parseDeviceManagerXml(xmlContent) {
|
|
125
|
+
const info = {};
|
|
126
|
+
const optionRegex = /<option\b[^>]*?>/gi;
|
|
127
|
+
let m;
|
|
128
|
+
while ((m = optionRegex.exec(xmlContent))) {
|
|
129
|
+
const tag = m[0];
|
|
130
|
+
const nameMatch = tag.match(/\bname=["']([^"']+)["']/i);
|
|
131
|
+
if (!nameMatch)
|
|
132
|
+
continue;
|
|
133
|
+
const valueMatch = tag.match(/\bvalue=["']([^"']+)["']/i);
|
|
134
|
+
if (!valueMatch)
|
|
135
|
+
continue;
|
|
136
|
+
const name = nameMatch[1];
|
|
137
|
+
const value = valueMatch[1];
|
|
138
|
+
if (name === 'imageDeployPath' && !info.imageRoot) {
|
|
139
|
+
info.imageRoot = value;
|
|
140
|
+
}
|
|
141
|
+
else if (name === 'openharmonyDeployPath' && !info.instancePath) {
|
|
142
|
+
info.instancePath = value;
|
|
143
|
+
}
|
|
144
|
+
if (info.imageRoot && info.instancePath)
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
return info;
|
|
148
|
+
}
|
|
149
|
+
function candidateEmulatorExecutables(devEcoStudioToolsPath) {
|
|
150
|
+
const list = [];
|
|
151
|
+
const add = (...segs) => list.push(devEcoStudioToolsPath.copyWithNewSegment(...segs).toString());
|
|
152
|
+
if (process.platform === 'win32') {
|
|
153
|
+
add('emulator', 'Emulator.exe');
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
add('emulator', 'Emulator');
|
|
157
|
+
}
|
|
158
|
+
return list;
|
|
159
|
+
}
|
|
160
|
+
function pickExisting(paths) {
|
|
161
|
+
return paths.find(p => fs_extra_1.default.existsSync(p));
|
|
162
|
+
}
|
|
163
|
+
function resolveInstanceAndImageRoot(env, devEcoVersion) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
const defaultInstanceCandidates = [];
|
|
166
|
+
const defaultImageCandidates = [];
|
|
167
|
+
if (process.platform === 'darwin') {
|
|
168
|
+
const home = env.HOME || '';
|
|
169
|
+
defaultInstanceCandidates.push(path_1.default.join(home, '.Huawei', 'Emulator', 'deployed'));
|
|
170
|
+
defaultImageCandidates.push(path_1.default.join(home, 'Library', 'Huawei', 'Sdk'));
|
|
171
|
+
}
|
|
172
|
+
else if (process.platform === 'win32') {
|
|
173
|
+
const localAppData = env.LOCALAPPDATA || '';
|
|
174
|
+
defaultInstanceCandidates.push(path_1.default.join(localAppData, 'Huawei', 'Emulator', 'deployed'));
|
|
175
|
+
defaultImageCandidates.push(path_1.default.join(localAppData, 'Huawei', 'Sdk'));
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
throw new core_1.DescriptiveError({
|
|
179
|
+
whatHappened: `Unsupported operating system.`,
|
|
180
|
+
whatCanUserDo: ['Please run the RNOH project on Windows or macOS.']
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
let xmlInfo = {};
|
|
184
|
+
for (const xmlPath of resolveDeviceManagerXml(env, devEcoVersion)) {
|
|
185
|
+
if (fs_extra_1.default.existsSync(xmlPath)) {
|
|
186
|
+
try {
|
|
187
|
+
const content = yield fs_extra_1.default.readFile(xmlPath, 'utf-8');
|
|
188
|
+
xmlInfo = parseDeviceManagerXml(content);
|
|
189
|
+
if (xmlInfo.instancePath || xmlInfo.imageRoot)
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
throw new core_1.DescriptiveError({
|
|
194
|
+
whatHappened: `Failed to read or parse device manager XML at ${xmlPath}: ${(error === null || error === void 0 ? void 0 : error.message) || error}`,
|
|
195
|
+
whatCanUserDo: [
|
|
196
|
+
'Verify that the DevEco Studio deviceManager.xml file exists and is readable.',
|
|
197
|
+
'Check if DEVECO_SDK_HOME environment variable is set correctly.',
|
|
198
|
+
'Ensure DevEco Studio has been launched at least once to generate configuration files.',
|
|
199
|
+
'Check file permissions for the DevEco Studio configuration directory.'
|
|
200
|
+
],
|
|
201
|
+
extraData: error,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
let resolvedInstance = pickExisting(defaultInstanceCandidates);
|
|
207
|
+
let resolvedImageRoot = pickExisting(defaultImageCandidates);
|
|
208
|
+
if (xmlInfo.imageRoot) {
|
|
209
|
+
resolvedImageRoot = xmlInfo.imageRoot;
|
|
210
|
+
}
|
|
211
|
+
if (xmlInfo.instancePath) {
|
|
212
|
+
resolvedInstance = xmlInfo.instancePath;
|
|
213
|
+
}
|
|
214
|
+
if (!resolvedInstance || !resolvedImageRoot) {
|
|
215
|
+
throw new core_1.DescriptiveError({
|
|
216
|
+
whatHappened: `No simulator instance or image root directory detected.`,
|
|
217
|
+
whatCanUserDo: [
|
|
218
|
+
'Have you already launched the simulator via DevEco Studio?'
|
|
219
|
+
]
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return { instancePath: resolvedInstance, imageRoot: resolvedImageRoot };
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function launchHarmonySimulator(opt) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
const { devEcoStudioToolsPath, cli, logger, } = opt;
|
|
228
|
+
const devEcoVersion = yield getDevEcoVersion(devEcoStudioToolsPath);
|
|
229
|
+
if (!devEcoVersion) {
|
|
230
|
+
throw new core_1.DescriptiveError({
|
|
231
|
+
whatHappened: `DevEco Studio version could not be obtained.`,
|
|
232
|
+
whatCanUserDo: [
|
|
233
|
+
'Verify DevEco Studio is properly installed and the tools path is correct.',
|
|
234
|
+
'Check if product-info.json file exists in the DevEco Studio installation directory.',
|
|
235
|
+
'Ensure you have the latest version of DevEco Studio installed.'
|
|
236
|
+
]
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
if (!isSupportedVersion(devEcoVersion)) {
|
|
240
|
+
throw new core_1.DescriptiveError({
|
|
241
|
+
whatHappened: `Current DevEco SDK version (${devEcoVersion}) does not support launching the simulator via command line (requires >= ${MIN_SUPPORTED_VERSION.join('.')}).`,
|
|
242
|
+
whatCanUserDo: [
|
|
243
|
+
`Update DevEco Studio to version ${MIN_SUPPORTED_VERSION.join('.')} or higher.`,
|
|
244
|
+
'Check the official DevEco Studio website for the latest version.',
|
|
245
|
+
'Launch the simulator manually from DevEco Studio IDE.'
|
|
246
|
+
]
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
const versionList = devEcoVersion.split('.');
|
|
250
|
+
const majorVersion = `${versionList[0]}.${versionList[1]}`;
|
|
251
|
+
const paths = yield resolveInstanceAndImageRoot(opt.env, majorVersion);
|
|
252
|
+
if (!paths) {
|
|
253
|
+
throw new core_1.DescriptiveError({
|
|
254
|
+
whatHappened: `Could not resolve simulator instance path or image root.`,
|
|
255
|
+
whatCanUserDo: [
|
|
256
|
+
'Open DevEco Studio and launch the simulator at least once to generate configuration files.',
|
|
257
|
+
'Check if DEVECO_SDK_HOME environment variable is set correctly.',
|
|
258
|
+
'Verify that the simulator has been properly configured in DevEco Studio.',
|
|
259
|
+
'Ensure the default simulator paths exist in your system.'
|
|
260
|
+
]
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
const emulatorExe = pickExisting(candidateEmulatorExecutables(devEcoStudioToolsPath));
|
|
264
|
+
if (!emulatorExe) {
|
|
265
|
+
throw new core_1.DescriptiveError({
|
|
266
|
+
whatHappened: `Emulator executable not found in DevEco Studio installation.`,
|
|
267
|
+
whatCanUserDo: [
|
|
268
|
+
'Verify DevEco Studio installation is complete and not corrupted.',
|
|
269
|
+
'Check if the emulator component is installed in DevEco Studio.',
|
|
270
|
+
'Reinstall DevEco Studio if the emulator binary is missing.',
|
|
271
|
+
'Ensure the DevEco Studio tools path is correctly configured.'
|
|
272
|
+
]
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
const simulatorName = yield getCreatedSimulators(cli, emulatorExe);
|
|
276
|
+
if (simulatorName.length <= 0) {
|
|
277
|
+
throw new core_1.DescriptiveError({
|
|
278
|
+
whatHappened: `No existing HarmonyOS simulator instance detected.`,
|
|
279
|
+
whatCanUserDo: [
|
|
280
|
+
'Create a simulator instance in DevEco Studio first.',
|
|
281
|
+
'Open DevEco Studio Device Manager and create a new virtual device.',
|
|
282
|
+
'Ensure the simulator instance is properly configured and available.',
|
|
283
|
+
'Check if the emulator --list command returns any valid instances.'
|
|
284
|
+
]
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
const quoteIfNeeded = (p) => process.platform === 'win32' ? `"${p}"` : p;
|
|
289
|
+
const args = [
|
|
290
|
+
'-hvd',
|
|
291
|
+
quoteIfNeeded(simulatorName[0].trim()),
|
|
292
|
+
'-path',
|
|
293
|
+
quoteIfNeeded(paths.instancePath),
|
|
294
|
+
'-imageRoot',
|
|
295
|
+
quoteIfNeeded(paths.imageRoot),
|
|
296
|
+
];
|
|
297
|
+
const child = (0, child_process_1.spawn)(quoteIfNeeded(emulatorExe), args, {
|
|
298
|
+
cwd: path_1.default.dirname(emulatorExe),
|
|
299
|
+
detached: true,
|
|
300
|
+
stdio: 'ignore',
|
|
301
|
+
shell: process.platform === 'win32',
|
|
302
|
+
});
|
|
303
|
+
child.unref();
|
|
304
|
+
logger.info(() => `Launching HarmonyOS simulator in background: ${simulatorName[0]}`);
|
|
305
|
+
}
|
|
306
|
+
catch (e) {
|
|
307
|
+
throw new core_1.DescriptiveError({
|
|
308
|
+
whatHappened: `Failed to start simulator process: ${(e === null || e === void 0 ? void 0 : e.message) || e}`,
|
|
309
|
+
whatCanUserDo: [
|
|
310
|
+
'Confirm that the DevEco Simulator can be started manually from DevEco Studio.',
|
|
311
|
+
'Ensure no stale simulator process is blocking required ports.',
|
|
312
|
+
'Reinstall or repair DevEco Studio if the simulator binary is corrupted.'
|
|
313
|
+
],
|
|
314
|
+
extraData: e,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
@@ -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);
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-oh/react-native-harmony-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.40-1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc --outDir dist -p tsconfig.build.json",
|
|
11
|
-
"prepack": "npm run build",
|
|
11
|
+
"prepack": "npm run build && npm run _recreate-hvigor-plugin",
|
|
12
|
+
"_recreate-hvigor-plugin": "cd ../react-native-harmony-hvigor-plugin && npm i && npm run deploy && cd ../react-native-harmony-cli",
|
|
12
13
|
"verify": "tsc --noEmit && npm run test",
|
|
13
14
|
"test": "npm run build && jest",
|
|
14
15
|
"test:codegen": "jest ./src/codegen/.* && npm run build && jest tests/codegen.*",
|
|
@@ -25,6 +26,13 @@
|
|
|
25
26
|
"metro": "*"
|
|
26
27
|
},
|
|
27
28
|
"main": "dist/index.js",
|
|
29
|
+
"files": [
|
|
30
|
+
"./*.js",
|
|
31
|
+
"./*.json",
|
|
32
|
+
"./dist/*",
|
|
33
|
+
"./harmony/*",
|
|
34
|
+
"./README.md"
|
|
35
|
+
],
|
|
28
36
|
"devDependencies": {
|
|
29
37
|
"@react-native-community/cli": "^15.0.0",
|
|
30
38
|
"@react-native-community/cli-types": "^11.3.0",
|
|
@@ -62,9 +70,9 @@
|
|
|
62
70
|
"tmp": "^0.2.1",
|
|
63
71
|
"metro": "0.82.5"
|
|
64
72
|
},
|
|
65
|
-
"homepage": "https://
|
|
73
|
+
"homepage": "https://gitcode.com/openharmony-sig/ohos_react_native",
|
|
66
74
|
"repository": {
|
|
67
|
-
"type": "
|
|
68
|
-
"url": "https://
|
|
75
|
+
"type": "gitcode",
|
|
76
|
+
"url": "https://gitcode.com/openharmony-sig/ohos_react_native"
|
|
69
77
|
}
|
|
70
78
|
}
|
package/.prettierrc
DELETED
package/src/assetResolver.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import fs from 'fs';
|
|
8
|
-
import pathUtils from 'path';
|
|
9
|
-
import type { AssetData } from 'metro';
|
|
10
|
-
import { Logger } from './io';
|
|
11
|
-
|
|
12
|
-
type Path = string;
|
|
13
|
-
type CopiedFiles = Record<Path, Path>;
|
|
14
|
-
|
|
15
|
-
const ALLOWED_SCALES: number[] = [1, 2, 3, 4];
|
|
16
|
-
|
|
17
|
-
function filterAssetScales(
|
|
18
|
-
scales: readonly number[],
|
|
19
|
-
): readonly number[] {
|
|
20
|
-
const result = scales.filter(scale => ALLOWED_SCALES.includes(scale));
|
|
21
|
-
if (result.length === 0 && scales.length > 0) {
|
|
22
|
-
// No matching scale found, but there are some available. Ideally we don't
|
|
23
|
-
// want to be in this situation and should throw, but for now as a fallback
|
|
24
|
-
// let's just use the closest larger image
|
|
25
|
-
const maxScale = ALLOWED_SCALES[ALLOWED_SCALES.length - 1];
|
|
26
|
-
for (const scale of scales) {
|
|
27
|
-
if (scale > maxScale) {
|
|
28
|
-
result.push(scale);
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// There is no larger scales available, use the largest we have
|
|
33
|
-
if (result.length === 0) {
|
|
34
|
-
result.push(scales[scales.length - 1]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function copyAssets(
|
|
41
|
-
logger: Logger,
|
|
42
|
-
assetsData: readonly AssetData[],
|
|
43
|
-
assetsDest: Path
|
|
44
|
-
): Promise<void> {
|
|
45
|
-
if (assetsDest == null) {
|
|
46
|
-
logger.warn((s) => 'Assets destination folder is not set, skipping...');
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const filesToCopy: CopiedFiles = {};
|
|
51
|
-
const addAssetToCopy = (asset: AssetData) => {
|
|
52
|
-
const validScales = filterAssetScales(asset.scales);
|
|
53
|
-
asset.scales.forEach((scale, idx) => {
|
|
54
|
-
if (!validScales.includes(scale)) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const src = asset.files[idx];
|
|
58
|
-
const dest = pathUtils.join(assetsDest, getAssetDestRelativePath(asset, scale));
|
|
59
|
-
filesToCopy[src] = dest;
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
assetsData.forEach(addAssetToCopy);
|
|
64
|
-
|
|
65
|
-
return copyFiles(logger, filesToCopy);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function getAssetDestRelativePath(asset: AssetData, scale: number = 1): string {
|
|
69
|
-
const suffix = scale === 1 ? '' : `@${scale}x`;
|
|
70
|
-
const fileName = getResourceIdentifier(asset);
|
|
71
|
-
// Assets can have relative paths outside of the project root.
|
|
72
|
-
// Replace `../` with `_` to make sure they don't end up outside of
|
|
73
|
-
// the expected assets directory.
|
|
74
|
-
return `${fileName + suffix}.${asset.type}`.replace(/\.\.\//g, '_');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function getResourceIdentifier(asset: AssetData): string {
|
|
78
|
-
const folderPath = getBasePath(asset);
|
|
79
|
-
return `${folderPath}/${asset.name}`.replace(/^assets\//, '');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function getBasePath(asset: AssetData): string {
|
|
83
|
-
const basePath = asset.httpServerLocation;
|
|
84
|
-
return basePath.startsWith('/') ? basePath.slice(1) : basePath;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function copyFiles(logger: Logger, fileDestBySrc: CopiedFiles) {
|
|
88
|
-
const fileSources = Object.keys(fileDestBySrc);
|
|
89
|
-
if (fileSources.length === 0) {
|
|
90
|
-
return Promise.resolve();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const assetFilesCount = fileSources.length;
|
|
94
|
-
return new Promise<void>((resolve, reject) => {
|
|
95
|
-
const copyNext = (error?: Error) => {
|
|
96
|
-
if (error) {
|
|
97
|
-
reject(error);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (fileSources.length === 0) {
|
|
101
|
-
logger.info(
|
|
102
|
-
() =>
|
|
103
|
-
`Copied ${assetFilesCount} ${
|
|
104
|
-
assetFilesCount === 1 ? 'asset' : 'assets'
|
|
105
|
-
}`
|
|
106
|
-
);
|
|
107
|
-
resolve();
|
|
108
|
-
} else {
|
|
109
|
-
// fileSources.length === 0 is checked in previous branch, so this is string
|
|
110
|
-
const src = fileSources.shift()!;
|
|
111
|
-
const dest = fileDestBySrc[src];
|
|
112
|
-
copyFile(src, dest, copyNext);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
copyNext();
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function copyFile(
|
|
120
|
-
src: string,
|
|
121
|
-
dest: string,
|
|
122
|
-
onFinished: (error?: Error) => void
|
|
123
|
-
): void {
|
|
124
|
-
const destDir = pathUtils.dirname(dest);
|
|
125
|
-
fs.mkdir(destDir, { recursive: true }, (err?) => {
|
|
126
|
-
if (err) {
|
|
127
|
-
onFinished(err);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
fs.createReadStream(src)
|
|
131
|
-
.pipe(fs.createWriteStream(dest))
|
|
132
|
-
.on('finish', onFinished);
|
|
133
|
-
});
|
|
134
|
-
}
|