@react-native-oh/react-native-harmony-cli 0.0.37 → 0.0.40

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 (138) hide show
  1. package/README.md +11 -11
  2. package/dist/assetResolver.js +74 -43
  3. package/dist/autolinking/Autolinking.js +183 -179
  4. package/dist/codegen/core/CodegenError.js +23 -3
  5. package/dist/codegen/core/EventUtils.js +3 -3
  6. package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
  7. package/dist/codegen/core/UberSchema.js +96 -57
  8. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +41 -28
  9. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
  10. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
  11. package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
  12. package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
  13. package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
  14. package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
  15. package/dist/codegen/generators/UberGeneratorV1.js +24 -18
  16. package/dist/codegen/generators/UberGeneratorV2.js +36 -28
  17. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
  18. package/dist/codegen/templates/BasePackageHTemplate.js +21 -120
  19. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -53
  20. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
  21. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
  22. package/dist/codegen/templates/IndexTSTemplate.js +17 -37
  23. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -119
  24. package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
  25. package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
  26. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
  27. package/dist/commands/bundle-harmony.js +138 -53
  28. package/dist/commands/codegen-harmony.js +175 -104
  29. package/dist/commands/codegen-lib-harmony.js +116 -76
  30. package/dist/commands/create-metro-host-constants.js +47 -18
  31. package/dist/commands/init.js +961 -537
  32. package/dist/commands/link-harmony.js +71 -33
  33. package/dist/commands/pack-harmony.js +108 -47
  34. package/dist/commands/run-harmony.js +518 -374
  35. package/dist/commands/unpack-harmony.js +198 -105
  36. package/dist/commands/verify-package-harmony.js +108 -54
  37. package/dist/core/AbsolutePath.js +47 -31
  38. package/dist/core/CodegenConfig.js +22 -24
  39. package/dist/core/DescriptiveError.js +37 -18
  40. package/dist/core/FileSystem.js +18 -14
  41. package/dist/core/OHPackageJSON5.js +23 -17
  42. package/dist/core/PackageJSON.js +42 -26
  43. package/dist/core/ProjectDependenciesManager.js +96 -46
  44. package/dist/core/ValidationError.js +22 -2
  45. package/dist/core/fs.js +6 -9
  46. package/dist/index.js +1 -1
  47. package/dist/io/CliExecutor.js +98 -46
  48. package/dist/io/Logger.js +46 -40
  49. package/dist/io/RealFS.js +88 -35
  50. package/dist/io/TarGz.js +8 -11
  51. package/dist/io/__fixtures__.js +141 -79
  52. package/dist/io/fsUtils.js +12 -13
  53. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
  54. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
  55. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
  56. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
  57. package/dist/package-verifier/verify-package.js +132 -55
  58. package/dist/simulator/LaunchSimulator.js +301 -217
  59. package/jest.config.js +12 -12
  60. package/package.json +78 -70
  61. package/react-native.config.js +17 -17
  62. package/tsconfig.build.json +6 -6
  63. package/tsconfig.json +2 -2
  64. package/.prettierrc +0 -6
  65. package/src/assetResolver.ts +0 -134
  66. package/src/autolinking/Autolinking.test.ts +0 -483
  67. package/src/autolinking/Autolinking.ts +0 -382
  68. package/src/autolinking/index.ts +0 -8
  69. package/src/codegen/core/CodeGenerator.ts +0 -16
  70. package/src/codegen/core/CodegenError.ts +0 -10
  71. package/src/codegen/core/EventUtils.ts +0 -23
  72. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
  73. package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
  74. package/src/codegen/core/UberSchema.ts +0 -152
  75. package/src/codegen/core/index.ts +0 -12
  76. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -124
  77. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
  78. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
  79. package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
  80. package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
  81. package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
  82. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
  83. package/src/codegen/generators/UberGeneratorV1.ts +0 -75
  84. package/src/codegen/generators/UberGeneratorV2.ts +0 -114
  85. package/src/codegen/generators/index.ts +0 -15
  86. package/src/codegen/index.ts +0 -9
  87. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
  88. package/src/codegen/templates/BasePackageHTemplate.ts +0 -159
  89. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
  90. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
  91. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
  92. package/src/codegen/templates/IndexTSTemplate.ts +0 -62
  93. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -150
  94. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
  95. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
  96. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
  97. package/src/codegen/templates/index.ts +0 -16
  98. package/src/commands/bundle-harmony.ts +0 -134
  99. package/src/commands/codegen-harmony.ts +0 -297
  100. package/src/commands/codegen-lib-harmony.ts +0 -389
  101. package/src/commands/create-metro-host-constants.ts +0 -55
  102. package/src/commands/index.ts +0 -16
  103. package/src/commands/init.ts +0 -755
  104. package/src/commands/link-harmony.ts +0 -102
  105. package/src/commands/pack-harmony.ts +0 -128
  106. package/src/commands/run-harmony.ts +0 -506
  107. package/src/commands/types.ts +0 -21
  108. package/src/commands/unpack-harmony.ts +0 -238
  109. package/src/commands/verify-package-harmony.ts +0 -113
  110. package/src/core/AbsolutePath.ts +0 -66
  111. package/src/core/CodegenConfig.ts +0 -67
  112. package/src/core/DescriptiveError.ts +0 -68
  113. package/src/core/FileSystem.ts +0 -57
  114. package/src/core/OHPackageJSON5.ts +0 -30
  115. package/src/core/PackageJSON.ts +0 -104
  116. package/src/core/ProjectDependenciesManager.ts +0 -103
  117. package/src/core/ValidationError.ts +0 -8
  118. package/src/core/ValueObject.ts +0 -9
  119. package/src/core/fs.ts +0 -38
  120. package/src/core/index.ts +0 -17
  121. package/src/index.ts +0 -33
  122. package/src/io/CliExecutor.ts +0 -69
  123. package/src/io/Logger.ts +0 -112
  124. package/src/io/RealFS.ts +0 -62
  125. package/src/io/TarGz.ts +0 -33
  126. package/src/io/__fixtures__.ts +0 -139
  127. package/src/io/fsUtils.ts +0 -44
  128. package/src/io/index.ts +0 -11
  129. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
  130. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
  131. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
  132. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
  133. package/src/package-verifier/checks/index.ts +0 -11
  134. package/src/package-verifier/index.ts +0 -9
  135. package/src/package-verifier/types.ts +0 -19
  136. package/src/package-verifier/verify-package.ts +0 -123
  137. package/src/simulator/LaunchSimulator.ts +0 -352
  138. package/src/simulator/index.ts +0 -8
@@ -14,124 +14,171 @@ 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 __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ var __generator = (this && this.__generator) || function (thisArg, body) {
18
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
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
+ }
19
43
  };
20
44
  Object.defineProperty(exports, "__esModule", { value: true });
21
45
  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];
46
+ var path_1 = require("path");
47
+ var fs_extra_1 = require("fs-extra");
48
+ var child_process_1 = require("child_process");
49
+ var core_1 = require("../core");
50
+ var MIN_SUPPORTED_VERSION = [6, 0, 0, 828];
27
51
  function compareVersionTuple(a, b) {
28
52
  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;
53
+ for (var i = 0; i < Math.max(a.length, b.length); i++) {
54
+ var av = (_a = a[i]) !== null && _a !== void 0 ? _a : 0;
55
+ var bv = (_b = b[i]) !== null && _b !== void 0 ? _b : 0;
32
56
  if (av !== bv)
33
57
  return av - bv;
34
58
  }
35
59
  return 0;
36
60
  }
37
61
  function isSupportedVersion(versionDir) {
38
- const m = versionDir.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)/);
62
+ var m = versionDir.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)/);
39
63
  if (!m)
40
64
  return false;
41
- const current = m.slice(1).map(n => parseInt(n, 10));
65
+ var current = m.slice(1).map(function (n) { return parseInt(n, 10); });
42
66
  return compareVersionTuple(current, MIN_SUPPORTED_VERSION) >= 0;
43
67
  }
44
68
  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 [];
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ var simulatorInfos_1, simulatorInfosFromStderr_1, error_1;
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0:
74
+ _a.trys.push([0, 2, , 3]);
75
+ simulatorInfos_1 = '';
76
+ simulatorInfosFromStderr_1 = '';
77
+ return [4 /*yield*/, cli.run("\"".concat(emulator, "\""), {
78
+ args: ['--list'],
79
+ shell: true,
80
+ onStdout: function (msg) {
81
+ simulatorInfos_1 += msg;
82
+ },
83
+ onStderr: function (msg) {
84
+ simulatorInfosFromStderr_1 += msg;
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*/];
59
110
  }
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
- }
111
+ });
73
112
  });
74
113
  }
75
114
  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');
115
+ return __awaiter(this, void 0, void 0, function () {
116
+ var productInfoPath, content, info, error_2;
117
+ return __generator(this, function (_a) {
118
+ switch (_a.label) {
119
+ case 0:
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*/];
81
142
  }
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
- }
143
+ });
97
144
  });
98
145
  }
99
146
  function resolveDeviceManagerXml(env, devEcoVersion) {
100
- const candidates = [];
147
+ var candidates = [];
101
148
  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'));
149
+ var home = env.HOME || '';
150
+ candidates.push(path_1.default.join(home, 'Library', 'Application Support', 'Huawei', "DevEcoStudio".concat(devEcoVersion), 'options', 'deviceManager.xml'));
104
151
  }
105
152
  else if (process.platform === 'win32') {
106
- const appdata = env.APPDATA || '';
107
- candidates.push(path_1.default.join(appdata, 'Huawei', `DevEcoStudio${devEcoVersion}`, 'options', 'deviceManager.xml'));
153
+ var appdata = env.APPDATA || '';
154
+ candidates.push(path_1.default.join(appdata, 'Huawei', "DevEcoStudio".concat(devEcoVersion), 'options', 'deviceManager.xml'));
108
155
  }
109
156
  else {
110
157
  throw new core_1.DescriptiveError({
111
- whatHappened: `Unsupported operating system.`,
158
+ whatHappened: "Unsupported operating system.",
112
159
  whatCanUserDo: ['Please run the RNOH project on Windows or macOS.']
113
160
  });
114
161
  }
115
162
  return candidates;
116
163
  }
117
164
  function parseDeviceManagerXml(xmlContent) {
118
- const info = {};
119
- const optionRegex = /<option\b[^>]*?>/gi;
120
- let m;
165
+ var info = {};
166
+ var optionRegex = /<option\b[^>]*?>/gi;
167
+ var m;
121
168
  while ((m = optionRegex.exec(xmlContent))) {
122
- const tag = m[0];
123
- const nameMatch = tag.match(/\bname=["']([^"']+)["']/i);
169
+ var tag = m[0];
170
+ var nameMatch = tag.match(/\bname=["']([^"']+)["']/i);
124
171
  if (!nameMatch)
125
172
  continue;
126
- const valueMatch = tag.match(/\bvalue=["']([^"']+)["']/i);
173
+ var valueMatch = tag.match(/\bvalue=["']([^"']+)["']/i);
127
174
  if (!valueMatch)
128
175
  continue;
129
- const name = nameMatch[1];
130
- const value = valueMatch[1];
131
- if (name === 'imageDeployPath' && !info.imageRoot) {
176
+ var name_1 = nameMatch[1];
177
+ var value = valueMatch[1];
178
+ if (name_1 === 'imageDeployPath' && !info.imageRoot) {
132
179
  info.imageRoot = value;
133
180
  }
134
- else if (name === 'openharmonyDeployPath' && !info.instancePath) {
181
+ else if (name_1 === 'openharmonyDeployPath' && !info.instancePath) {
135
182
  info.instancePath = value;
136
183
  }
137
184
  if (info.imageRoot && info.instancePath)
@@ -140,8 +187,14 @@ function parseDeviceManagerXml(xmlContent) {
140
187
  return info;
141
188
  }
142
189
  function candidateEmulatorExecutables(devEcoStudioToolsPath) {
143
- const list = [];
144
- const add = (...segs) => list.push(devEcoStudioToolsPath.copyWithNewSegment(...segs).toString());
190
+ var list = [];
191
+ var add = function () {
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
+ };
145
198
  if (process.platform === 'win32') {
146
199
  add('emulator', 'Emulator.exe');
147
200
  }
@@ -151,161 +204,192 @@ function candidateEmulatorExecutables(devEcoStudioToolsPath) {
151
204
  return list;
152
205
  }
153
206
  function pickExisting(paths) {
154
- return paths.find(p => fs_extra_1.default.existsSync(p));
207
+ return paths.find(function (p) { return fs_extra_1.default.existsSync(p); });
155
208
  }
156
209
  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');
210
+ return __awaiter(this, void 0, void 0, function () {
211
+ var defaultInstanceCandidates, defaultImageCandidates, home, localAppData, xmlInfo, _i, _a, xmlPath, content, error_3, resolvedInstance, resolvedImageRoot;
212
+ return __generator(this, function (_b) {
213
+ switch (_b.label) {
214
+ case 0:
215
+ defaultInstanceCandidates = [];
216
+ defaultImageCandidates = [];
217
+ if (process.platform === 'darwin') {
218
+ home = env.HOME || '';
219
+ defaultInstanceCandidates.push(path_1.default.join(home, '.Huawei', 'Emulator', 'deployed'));
220
+ defaultImageCandidates.push(path_1.default.join(home, 'Library', 'Huawei', 'Sdk'));
221
+ }
222
+ else if (process.platform === 'win32') {
223
+ localAppData = env.LOCALAPPDATA || '';
224
+ defaultInstanceCandidates.push(path_1.default.join(localAppData, 'Huawei', 'Emulator', 'deployed'));
225
+ defaultImageCandidates.push(path_1.default.join(localAppData, 'Huawei', 'Sdk'));
226
+ }
227
+ else {
228
+ throw new core_1.DescriptiveError({
229
+ whatHappened: "Unsupported operating system.",
230
+ whatCanUserDo: ['Please run the RNOH project on Windows or macOS.']
231
+ });
232
+ }
233
+ xmlInfo = {};
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();
181
246
  xmlInfo = parseDeviceManagerXml(content);
182
247
  if (xmlInfo.instancePath || xmlInfo.imageRoot)
183
- break;
184
- }
185
- catch (error) {
248
+ return [3 /*break*/, 6];
249
+ return [3 /*break*/, 5];
250
+ case 4:
251
+ error_3 = _b.sent();
186
252
  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}`,
253
+ whatHappened: "Failed to read or parse device manager XML at ".concat(xmlPath, ": ").concat((error_3 === null || error_3 === void 0 ? void 0 : error_3.message) || error_3),
188
254
  whatCanUserDo: [
189
255
  'Verify that the DevEco Studio deviceManager.xml file exists and is readable.',
190
256
  'Check if DEVECO_SDK_HOME environment variable is set correctly.',
191
257
  'Ensure DevEco Studio has been launched at least once to generate configuration files.',
192
258
  'Check file permissions for the DevEco Studio configuration directory.'
193
259
  ],
194
- extraData: error,
260
+ extraData: error_3,
195
261
  });
196
- }
262
+ case 5:
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 }];
197
283
  }
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 };
284
+ });
216
285
  });
217
286
  }
218
287
  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
- }
288
+ return __awaiter(this, void 0, void 0, function () {
289
+ var devEcoStudioToolsPath, cli, logger, devEcoVersion, versionList, majorVersion, paths, emulatorExe, simulatorName, quoteIfNeeded, args, child;
290
+ return __generator(this, function (_a) {
291
+ switch (_a.label) {
292
+ case 0:
293
+ devEcoStudioToolsPath = opt.devEcoStudioToolsPath, cli = opt.cli, logger = opt.logger;
294
+ return [4 /*yield*/, getDevEcoVersion(devEcoStudioToolsPath)];
295
+ case 1:
296
+ devEcoVersion = _a.sent();
297
+ if (!devEcoVersion) {
298
+ throw new core_1.DescriptiveError({
299
+ whatHappened: "DevEco Studio version could not be obtained.",
300
+ whatCanUserDo: [
301
+ 'Verify DevEco Studio is properly installed and the tools path is correct.',
302
+ 'Check if product-info.json file exists in the DevEco Studio installation directory.',
303
+ 'Ensure you have the latest version of DevEco Studio installed.'
304
+ ]
305
+ });
306
+ }
307
+ if (!isSupportedVersion(devEcoVersion)) {
308
+ throw new core_1.DescriptiveError({
309
+ whatHappened: "Current DevEco SDK version (".concat(devEcoVersion, ") does not support launching the simulator via command line (requires >= ").concat(MIN_SUPPORTED_VERSION.join('.'), ")."),
310
+ whatCanUserDo: [
311
+ "Update DevEco Studio to version ".concat(MIN_SUPPORTED_VERSION.join('.'), " or higher."),
312
+ 'Check the official DevEco Studio website for the latest version.',
313
+ 'Launch the simulator manually from DevEco Studio IDE.'
314
+ ]
315
+ });
316
+ }
317
+ versionList = devEcoVersion.split('.');
318
+ majorVersion = "".concat(versionList[0], ".").concat(versionList[1]);
319
+ return [4 /*yield*/, resolveInstanceAndImageRoot(opt.env, majorVersion)];
320
+ case 2:
321
+ paths = _a.sent();
322
+ if (!paths) {
323
+ throw new core_1.DescriptiveError({
324
+ whatHappened: "Could not resolve simulator instance path or image root.",
325
+ whatCanUserDo: [
326
+ 'Open DevEco Studio and launch the simulator at least once to generate configuration files.',
327
+ 'Check if DEVECO_SDK_HOME environment variable is set correctly.',
328
+ 'Verify that the simulator has been properly configured in DevEco Studio.',
329
+ 'Ensure the default simulator paths exist in your system.'
330
+ ]
331
+ });
332
+ }
333
+ emulatorExe = pickExisting(candidateEmulatorExecutables(devEcoStudioToolsPath));
334
+ if (!emulatorExe) {
335
+ throw new core_1.DescriptiveError({
336
+ whatHappened: "Emulator executable not found in DevEco Studio installation.",
337
+ whatCanUserDo: [
338
+ 'Verify DevEco Studio installation is complete and not corrupted.',
339
+ 'Check if the emulator component is installed in DevEco Studio.',
340
+ 'Reinstall DevEco Studio if the emulator binary is missing.',
341
+ 'Ensure the DevEco Studio tools path is correctly configured.'
342
+ ]
343
+ });
344
+ }
345
+ return [4 /*yield*/, getCreatedSimulators(cli, emulatorExe)];
346
+ case 3:
347
+ simulatorName = _a.sent();
348
+ if (simulatorName.length <= 0) {
349
+ throw new core_1.DescriptiveError({
350
+ whatHappened: "No existing HarmonyOS simulator instance detected.",
351
+ whatCanUserDo: [
352
+ 'Create a simulator instance in DevEco Studio first.',
353
+ 'Open DevEco Studio Device Manager and create a new virtual device.',
354
+ 'Ensure the simulator instance is properly configured and available.',
355
+ 'Check if the emulator --list command returns any valid instances.'
356
+ ]
357
+ });
358
+ }
359
+ try {
360
+ quoteIfNeeded = function (p) {
361
+ return process.platform === 'win32' ? "\"".concat(p, "\"") : p;
362
+ };
363
+ args = [
364
+ '-hvd',
365
+ quoteIfNeeded(simulatorName[0].trim()),
366
+ '-path',
367
+ quoteIfNeeded(paths.instancePath),
368
+ '-imageRoot',
369
+ quoteIfNeeded(paths.imageRoot),
370
+ ];
371
+ child = (0, child_process_1.spawn)(quoteIfNeeded(emulatorExe), args, {
372
+ cwd: path_1.default.dirname(emulatorExe),
373
+ detached: true,
374
+ stdio: 'ignore',
375
+ shell: process.platform === 'win32',
376
+ });
377
+ child.unref();
378
+ logger.info(function () { return "Launching HarmonyOS simulator in background: ".concat(simulatorName[0]); });
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
+ });
310
394
  });
311
395
  }
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
+ };