@react-native-oh/react-native-harmony-cli 0.0.40 → 0.0.41
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/README.md +11 -11
- package/dist/assetResolver.js +43 -74
- package/dist/autolinking/Autolinking.js +178 -179
- package/dist/codegen/core/CodegenError.js +3 -23
- package/dist/codegen/core/EventUtils.js +3 -3
- package/dist/codegen/core/TypeAnnotationToTS.js +24 -28
- package/dist/codegen/core/UberSchema.js +57 -96
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +28 -41
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +27 -34
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +25 -33
- package/dist/codegen/generators/CppComponentCodeGenerator.js +23 -28
- package/dist/codegen/generators/LibGlueCodeGenerator.js +26 -29
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +25 -30
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
- package/dist/codegen/generators/UberGeneratorV1.js +24 -23
- package/dist/codegen/generators/UberGeneratorV2.js +34 -35
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +50 -24
- package/dist/codegen/templates/BasePackageHTemplate.js +120 -21
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +53 -8
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +75 -27
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +162 -29
- package/dist/codegen/templates/IndexTSTemplate.js +37 -17
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +119 -24
- package/dist/codegen/templates/TurboModuleCppTemplate.js +38 -15
- package/dist/codegen/templates/TurboModuleHTemplate.js +32 -11
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +52 -19
- package/dist/commands/bundle-harmony.js +53 -138
- package/dist/commands/codegen-harmony.js +105 -165
- package/dist/commands/codegen-lib-harmony.js +76 -116
- package/dist/commands/create-metro-host-constants.js +18 -47
- package/dist/commands/init.js +537 -961
- package/dist/commands/link-harmony.js +33 -71
- package/dist/commands/pack-harmony.js +47 -108
- package/dist/commands/run-harmony.js +372 -518
- package/dist/commands/unpack-harmony.js +105 -198
- package/dist/commands/verify-package-harmony.js +54 -108
- package/dist/core/AbsolutePath.js +31 -47
- package/dist/core/CodegenConfig.js +24 -22
- package/dist/core/DescriptiveError.js +18 -37
- package/dist/core/FileSystem.js +14 -18
- package/dist/core/OHPackageJSON5.js +17 -23
- package/dist/core/PackageJSON.js +26 -42
- package/dist/core/ProjectDependenciesManager.js +40 -92
- package/dist/core/ValidationError.js +2 -22
- package/dist/core/fs.js +9 -6
- package/dist/index.js +1 -1
- package/dist/io/CliExecutor.js +46 -98
- package/dist/io/Logger.js +40 -46
- package/dist/io/RealFS.js +35 -88
- package/dist/io/TarGz.js +11 -8
- package/dist/io/__fixtures__.js +79 -141
- package/dist/io/fsUtils.js +13 -12
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +19 -47
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +13 -41
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +8 -38
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +22 -54
- package/dist/package-verifier/verify-package.js +55 -132
- package/dist/simulator/LaunchSimulator.js +224 -301
- package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
- package/jest.config.js +12 -12
- package/package.json +78 -78
- package/react-native.config.js +17 -17
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
|
@@ -14,171 +14,131 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
-
function step(op) {
|
|
22
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
-
switch (op[0]) {
|
|
27
|
-
case 0: case 1: t = op; break;
|
|
28
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
-
default:
|
|
32
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
-
if (t[2]) _.ops.pop();
|
|
37
|
-
_.trys.pop(); continue;
|
|
38
|
-
}
|
|
39
|
-
op = body.call(thisArg, _);
|
|
40
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
-
}
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
19
|
};
|
|
44
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
21
|
exports.launchHarmonySimulator = launchHarmonySimulator;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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];
|
|
51
27
|
function compareVersionTuple(a, b) {
|
|
52
28
|
var _a, _b;
|
|
53
|
-
for (
|
|
54
|
-
|
|
55
|
-
|
|
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;
|
|
56
32
|
if (av !== bv)
|
|
57
33
|
return av - bv;
|
|
58
34
|
}
|
|
59
35
|
return 0;
|
|
60
36
|
}
|
|
61
37
|
function isSupportedVersion(versionDir) {
|
|
62
|
-
|
|
38
|
+
const m = versionDir.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)/);
|
|
63
39
|
if (!m)
|
|
64
40
|
return false;
|
|
65
|
-
|
|
41
|
+
const current = m.slice(1).map(n => parseInt(n, 10));
|
|
66
42
|
return compareVersionTuple(current, MIN_SUPPORTED_VERSION) >= 0;
|
|
67
43
|
}
|
|
68
44
|
function getCreatedSimulators(cli, emulator) {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
})];
|
|
87
|
-
case 1:
|
|
88
|
-
_a.sent();
|
|
89
|
-
if (simulatorInfos_1 == null || simulatorInfos_1.trim() === '') {
|
|
90
|
-
simulatorInfos_1 = simulatorInfosFromStderr_1;
|
|
91
|
-
}
|
|
92
|
-
if (!simulatorInfos_1 || simulatorInfos_1.trim() === '' ||
|
|
93
|
-
simulatorInfos_1.trim() === '[Empty]' ||
|
|
94
|
-
simulatorInfos_1.includes('not ')) {
|
|
95
|
-
return [2 /*return*/, []];
|
|
96
|
-
}
|
|
97
|
-
return [2 /*return*/, simulatorInfos_1.split('\n').filter(function (line) { return line.trim() !== ''; })];
|
|
98
|
-
case 2:
|
|
99
|
-
error_1 = _a.sent();
|
|
100
|
-
throw new core_1.DescriptiveError({
|
|
101
|
-
whatHappened: "Failed to get simulator list: ".concat((error_1 === null || error_1 === void 0 ? void 0 : error_1.message) || error_1),
|
|
102
|
-
whatCanUserDo: [
|
|
103
|
-
'Ensure DevEco Studio is properly installed and configured.',
|
|
104
|
-
'Check if the emulator path is correct.',
|
|
105
|
-
'Verify that the emulator has read/write permissions.'
|
|
106
|
-
],
|
|
107
|
-
extraData: error_1,
|
|
108
|
-
});
|
|
109
|
-
case 3: return [2 /*return*/];
|
|
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;
|
|
110
61
|
}
|
|
111
|
-
|
|
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
|
+
}
|
|
112
80
|
});
|
|
113
81
|
}
|
|
114
82
|
function getDevEcoVersion(devEcoStudioToolsPath) {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
_a.trys.push([0, 2, , 3]);
|
|
121
|
-
productInfoPath = path_1.default.join(devEcoStudioToolsPath.toString(), '..', 'Resources', 'product-info.json');
|
|
122
|
-
if (process.platform === 'win32') {
|
|
123
|
-
productInfoPath = path_1.default.join(devEcoStudioToolsPath.toString(), '..', 'product-info.json');
|
|
124
|
-
}
|
|
125
|
-
return [4 /*yield*/, fs_extra_1.default.readFile(productInfoPath, 'utf-8')];
|
|
126
|
-
case 1:
|
|
127
|
-
content = _a.sent();
|
|
128
|
-
info = JSON.parse(content);
|
|
129
|
-
return [2 /*return*/, info.version || null];
|
|
130
|
-
case 2:
|
|
131
|
-
error_2 = _a.sent();
|
|
132
|
-
throw new core_1.DescriptiveError({
|
|
133
|
-
whatHappened: "Failed to read DevEco Studio version from product-info.json: ".concat((error_2 === null || error_2 === void 0 ? void 0 : error_2.message) || error_2),
|
|
134
|
-
whatCanUserDo: [
|
|
135
|
-
'Verify DevEco Studio installation is complete and not corrupted.',
|
|
136
|
-
'Check if the DevEco Studio tools path is correct.',
|
|
137
|
-
'Ensure product-info.json file exists and is readable.'
|
|
138
|
-
],
|
|
139
|
-
extraData: error_2,
|
|
140
|
-
});
|
|
141
|
-
case 3: return [2 /*return*/];
|
|
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');
|
|
142
88
|
}
|
|
143
|
-
|
|
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
|
+
}
|
|
144
104
|
});
|
|
145
105
|
}
|
|
146
106
|
function resolveDeviceManagerXml(env, devEcoVersion) {
|
|
147
|
-
|
|
107
|
+
const candidates = [];
|
|
148
108
|
if (process.platform === 'darwin') {
|
|
149
|
-
|
|
150
|
-
candidates.push(path_1.default.join(home, 'Library', 'Application Support', 'Huawei',
|
|
109
|
+
const home = env.HOME || '';
|
|
110
|
+
candidates.push(path_1.default.join(home, 'Library', 'Application Support', 'Huawei', `DevEcoStudio${devEcoVersion}`, 'options', 'deviceManager.xml'));
|
|
151
111
|
}
|
|
152
112
|
else if (process.platform === 'win32') {
|
|
153
|
-
|
|
154
|
-
candidates.push(path_1.default.join(appdata, 'Huawei',
|
|
113
|
+
const appdata = env.APPDATA || '';
|
|
114
|
+
candidates.push(path_1.default.join(appdata, 'Huawei', `DevEcoStudio${devEcoVersion}`, 'options', 'deviceManager.xml'));
|
|
155
115
|
}
|
|
156
116
|
else {
|
|
157
117
|
throw new core_1.DescriptiveError({
|
|
158
|
-
whatHappened:
|
|
118
|
+
whatHappened: `Unsupported operating system.`,
|
|
159
119
|
whatCanUserDo: ['Please run the RNOH project on Windows or macOS.']
|
|
160
120
|
});
|
|
161
121
|
}
|
|
162
122
|
return candidates;
|
|
163
123
|
}
|
|
164
124
|
function parseDeviceManagerXml(xmlContent) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
125
|
+
const info = {};
|
|
126
|
+
const optionRegex = /<option\b[^>]*?>/gi;
|
|
127
|
+
let m;
|
|
168
128
|
while ((m = optionRegex.exec(xmlContent))) {
|
|
169
|
-
|
|
170
|
-
|
|
129
|
+
const tag = m[0];
|
|
130
|
+
const nameMatch = tag.match(/\bname=["']([^"']+)["']/i);
|
|
171
131
|
if (!nameMatch)
|
|
172
132
|
continue;
|
|
173
|
-
|
|
133
|
+
const valueMatch = tag.match(/\bvalue=["']([^"']+)["']/i);
|
|
174
134
|
if (!valueMatch)
|
|
175
135
|
continue;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (
|
|
136
|
+
const name = nameMatch[1];
|
|
137
|
+
const value = valueMatch[1];
|
|
138
|
+
if (name === 'imageDeployPath' && !info.imageRoot) {
|
|
179
139
|
info.imageRoot = value;
|
|
180
140
|
}
|
|
181
|
-
else if (
|
|
141
|
+
else if (name === 'openharmonyDeployPath' && !info.instancePath) {
|
|
182
142
|
info.instancePath = value;
|
|
183
143
|
}
|
|
184
144
|
if (info.imageRoot && info.instancePath)
|
|
@@ -187,14 +147,8 @@ function parseDeviceManagerXml(xmlContent) {
|
|
|
187
147
|
return info;
|
|
188
148
|
}
|
|
189
149
|
function candidateEmulatorExecutables(devEcoStudioToolsPath) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
var segs = [];
|
|
193
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
194
|
-
segs[_i] = arguments[_i];
|
|
195
|
-
}
|
|
196
|
-
return list.push(devEcoStudioToolsPath.copyWithNewSegment.apply(devEcoStudioToolsPath, segs).toString());
|
|
197
|
-
};
|
|
150
|
+
const list = [];
|
|
151
|
+
const add = (...segs) => list.push(devEcoStudioToolsPath.copyWithNewSegment(...segs).toString());
|
|
198
152
|
if (process.platform === 'win32') {
|
|
199
153
|
add('emulator', 'Emulator.exe');
|
|
200
154
|
}
|
|
@@ -204,192 +158,161 @@ function candidateEmulatorExecutables(devEcoStudioToolsPath) {
|
|
|
204
158
|
return list;
|
|
205
159
|
}
|
|
206
160
|
function pickExisting(paths) {
|
|
207
|
-
return paths.find(
|
|
161
|
+
return paths.find(p => fs_extra_1.default.existsSync(p));
|
|
208
162
|
}
|
|
209
163
|
function resolveInstanceAndImageRoot(env, devEcoVersion) {
|
|
210
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
_i = 0, _a = resolveDeviceManagerXml(env, devEcoVersion);
|
|
235
|
-
_b.label = 1;
|
|
236
|
-
case 1:
|
|
237
|
-
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
238
|
-
xmlPath = _a[_i];
|
|
239
|
-
if (!fs_extra_1.default.existsSync(xmlPath)) return [3 /*break*/, 5];
|
|
240
|
-
_b.label = 2;
|
|
241
|
-
case 2:
|
|
242
|
-
_b.trys.push([2, 4, , 5]);
|
|
243
|
-
return [4 /*yield*/, fs_extra_1.default.readFile(xmlPath, 'utf-8')];
|
|
244
|
-
case 3:
|
|
245
|
-
content = _b.sent();
|
|
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');
|
|
246
188
|
xmlInfo = parseDeviceManagerXml(content);
|
|
247
189
|
if (xmlInfo.instancePath || xmlInfo.imageRoot)
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
error_3 = _b.sent();
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
252
193
|
throw new core_1.DescriptiveError({
|
|
253
|
-
whatHappened:
|
|
194
|
+
whatHappened: `Failed to read or parse device manager XML at ${xmlPath}: ${(error === null || error === void 0 ? void 0 : error.message) || error}`,
|
|
254
195
|
whatCanUserDo: [
|
|
255
196
|
'Verify that the DevEco Studio deviceManager.xml file exists and is readable.',
|
|
256
197
|
'Check if DEVECO_SDK_HOME environment variable is set correctly.',
|
|
257
198
|
'Ensure DevEco Studio has been launched at least once to generate configuration files.',
|
|
258
199
|
'Check file permissions for the DevEco Studio configuration directory.'
|
|
259
200
|
],
|
|
260
|
-
extraData:
|
|
201
|
+
extraData: error,
|
|
261
202
|
});
|
|
262
|
-
|
|
263
|
-
_i++;
|
|
264
|
-
return [3 /*break*/, 1];
|
|
265
|
-
case 6:
|
|
266
|
-
resolvedInstance = pickExisting(defaultInstanceCandidates);
|
|
267
|
-
resolvedImageRoot = pickExisting(defaultImageCandidates);
|
|
268
|
-
if (xmlInfo.imageRoot) {
|
|
269
|
-
resolvedImageRoot = xmlInfo.imageRoot;
|
|
270
|
-
}
|
|
271
|
-
if (xmlInfo.instancePath) {
|
|
272
|
-
resolvedInstance = xmlInfo.instancePath;
|
|
273
|
-
}
|
|
274
|
-
if (!resolvedInstance || !resolvedImageRoot) {
|
|
275
|
-
throw new core_1.DescriptiveError({
|
|
276
|
-
whatHappened: "No simulator instance or image root directory detected.",
|
|
277
|
-
whatCanUserDo: [
|
|
278
|
-
'Have you already launched the simulator via DevEco Studio?'
|
|
279
|
-
]
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
return [2 /*return*/, { instancePath: resolvedInstance, imageRoot: resolvedImageRoot }];
|
|
203
|
+
}
|
|
283
204
|
}
|
|
284
|
-
}
|
|
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 };
|
|
285
223
|
});
|
|
286
224
|
}
|
|
287
225
|
function launchHarmonySimulator(opt) {
|
|
288
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
paths
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
catch (e) {
|
|
381
|
-
throw new core_1.DescriptiveError({
|
|
382
|
-
whatHappened: "Failed to start simulator process: ".concat((e === null || e === void 0 ? void 0 : e.message) || e),
|
|
383
|
-
whatCanUserDo: [
|
|
384
|
-
'Confirm that the DevEco Simulator can be started manually from DevEco Studio.',
|
|
385
|
-
'Ensure no stale simulator process is blocking required ports.',
|
|
386
|
-
'Reinstall or repair DevEco Studio if the simulator binary is corrupted.'
|
|
387
|
-
],
|
|
388
|
-
extraData: e,
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
return [2 /*return*/];
|
|
392
|
-
}
|
|
393
|
-
});
|
|
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
|
+
}
|
|
394
317
|
});
|
|
395
318
|
}
|
|
Binary file
|
package/jest.config.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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
|
-
|
|
8
|
-
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
9
|
-
module.exports = {
|
|
10
|
-
preset: 'ts-jest',
|
|
11
|
-
testEnvironment: 'node',
|
|
12
|
-
};
|
|
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
|
+
|
|
8
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
9
|
+
module.exports = {
|
|
10
|
+
preset: 'ts-jest',
|
|
11
|
+
testEnvironment: 'node',
|
|
12
|
+
};
|