@react-native-oh/react-native-harmony-cli 0.77.22 → 0.77.33

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 (200) hide show
  1. package/dist/assetResolver.js +74 -43
  2. package/dist/autolinking/Autolinking.js +179 -178
  3. package/dist/codegen/core/CodegenError.js +23 -3
  4. package/dist/codegen/core/EventUtils.js +3 -3
  5. package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
  6. package/dist/codegen/core/UberSchema.js +97 -55
  7. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +41 -28
  8. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
  9. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
  10. package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
  11. package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
  12. package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
  13. package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
  14. package/dist/codegen/generators/UberGeneratorV1.js +24 -18
  15. package/dist/codegen/generators/UberGeneratorV2.js +36 -28
  16. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
  17. package/dist/codegen/templates/BasePackageHTemplate.js +21 -120
  18. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -54
  19. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
  20. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
  21. package/dist/codegen/templates/IndexTSTemplate.js +17 -37
  22. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -119
  23. package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
  24. package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
  25. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
  26. package/dist/commands/bundle-harmony.js +221 -118
  27. package/dist/commands/clean-harmony.js +63 -58
  28. package/dist/commands/codegen-harmony.js +175 -104
  29. package/dist/commands/codegen-lib-harmony.js +116 -76
  30. package/dist/commands/init-harmony.js +196 -151
  31. package/dist/commands/init.js +961 -537
  32. package/dist/commands/link-harmony.js +82 -35
  33. package/dist/commands/run-harmony.js +518 -374
  34. package/dist/commands/verify-package-harmony.js +117 -54
  35. package/dist/core/AbsolutePath.js +49 -33
  36. package/dist/core/CodegenConfig.js +22 -24
  37. package/dist/core/DescriptiveError.js +37 -18
  38. package/dist/core/FileSystem.js +18 -14
  39. package/dist/core/OHPackageJSON5.js +23 -17
  40. package/dist/core/PackageJSON.js +42 -26
  41. package/dist/core/ProjectDependenciesManager.js +92 -40
  42. package/dist/core/ValidationError.js +22 -2
  43. package/dist/core/fs.js +7 -10
  44. package/dist/index.js +1 -1
  45. package/dist/init/templates/AppScopeAppJSON5Template.js +8 -21
  46. package/dist/init/templates/AppScopeStringVarTemplate.js +8 -19
  47. package/dist/init/templates/EntryIndexTemplate.js +8 -56
  48. package/dist/init/templates/EntryStringVarTemplate.js +8 -27
  49. package/dist/init/templates/HvigorConfigJson5Template.js +8 -33
  50. package/dist/init/templates/MetroConfigTemplate.js +8 -38
  51. package/dist/init/templates/OhPackageJson5Template.js +8 -28
  52. package/dist/io/CliExecutor.js +98 -46
  53. package/dist/io/Logger.js +46 -40
  54. package/dist/io/RealFS.js +100 -43
  55. package/dist/io/TarGz.js +8 -11
  56. package/dist/io/__fixtures__.js +141 -79
  57. package/dist/io/fsUtils.js +12 -13
  58. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
  59. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
  60. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
  61. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
  62. package/dist/package-verifier/verify-package.js +133 -56
  63. package/dist/simulator/LaunchSimulator.js +301 -217
  64. package/package.json +2 -11
  65. package/scripts/sync-hvigor.js +27 -0
  66. package/src/autolinking/Autolinking.ts +1 -1
  67. package/src/codegen/generators/UberGeneratorV1.ts +7 -2
  68. package/src/codegen/generators/UberGeneratorV2.ts +6 -1
  69. package/src/commands/codegen-harmony.ts +17 -7
  70. package/src/commands/run-harmony.ts +0 -2
  71. package/src/simulator/LaunchSimulator.ts +9 -2
  72. package/dist/init/templates/harmony/AppScope/app.json5 +0 -10
  73. package/dist/init/templates/harmony/AppScope/resources/base/element/string.json +0 -8
  74. package/dist/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  75. package/dist/init/templates/harmony/build-profile.json5 +0 -36
  76. package/dist/init/templates/harmony/codelinter.json +0 -32
  77. package/dist/init/templates/harmony/entry/build-profile.json5 +0 -18
  78. package/dist/init/templates/harmony/entry/gitignore +0 -7
  79. package/dist/init/templates/harmony/entry/hvigorfile.ts +0 -13
  80. package/dist/init/templates/harmony/entry/oh-package.json5 +0 -9
  81. package/dist/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +0 -27
  82. package/dist/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +0 -13
  83. package/dist/init/templates/harmony/entry/src/main/cpp/gitignore +0 -4
  84. package/dist/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +0 -8
  85. package/dist/init/templates/harmony/entry/src/main/ets/codegen/gitignore +0 -2
  86. package/dist/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +0 -11
  87. package/dist/init/templates/harmony/entry/src/main/ets/gitignore +0 -1
  88. package/dist/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  89. package/dist/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +0 -16
  90. package/dist/init/templates/harmony/entry/src/main/module.json5 +0 -65
  91. package/dist/init/templates/harmony/entry/src/main/resources/base/element/color.json +0 -8
  92. package/dist/init/templates/harmony/entry/src/main/resources/base/element/string.json +0 -16
  93. package/dist/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  94. package/dist/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  95. package/dist/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +0 -7
  96. package/dist/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  97. package/dist/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +0 -5
  98. package/dist/init/templates/harmony/entry/src/main/resources/gitignore +0 -1
  99. package/dist/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +0 -2
  100. package/dist/init/templates/harmony/entry/src/ohosTest/module.json5 +0 -13
  101. package/dist/init/templates/harmony/gitignore +0 -16
  102. package/dist/init/templates/harmony/hvigor/hvigor-config.json5 +0 -22
  103. package/dist/init/templates/harmony/hvigorfile.ts +0 -7
  104. package/harmony/rnoh-hvigor-plugin-0.77.22.tgz +0 -0
  105. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/02febc14 +0 -0
  106. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0429e5b7 +0 -0
  107. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/05339e68 +0 -0
  108. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/070be2fe +0 -0
  109. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/07851ff1 +0 -0
  110. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/12e10c06 +0 -0
  111. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/12e1d696 +0 -0
  112. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/14950087 +0 -0
  113. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/15e87372 +0 -0
  114. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/19e6ecbe +0 -0
  115. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1aac0ac4 +0 -0
  116. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1b8db102 +0 -0
  117. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1c181646 +0 -0
  118. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/203e747c +0 -0
  119. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/21ba4c08 +0 -0
  120. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/259939e5 +0 -0
  121. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/288ba98c +0 -0
  122. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2a45461c +0 -0
  123. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2d773091 +0 -0
  124. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2eda89fc +0 -0
  125. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2f584eca +0 -0
  126. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/35b495ca +0 -0
  127. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/36478aed +0 -0
  128. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/3844e772 +0 -0
  129. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/3ee777f4 +0 -0
  130. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/471ac436 +0 -0
  131. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4a91abcc +0 -0
  132. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4d1a5094 +0 -0
  133. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4d3ef38f +0 -0
  134. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4daf5855 +0 -0
  135. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4ef0389f +0 -0
  136. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4f72da28 +0 -0
  137. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/59d3e924 +0 -0
  138. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5a8edfaa +0 -0
  139. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5d28a510 +0 -0
  140. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/61a6391d +0 -0
  141. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/65921a14 +0 -0
  142. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6624e7fc +0 -0
  143. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/66d28144 +0 -0
  144. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6aceb8d2 +0 -0
  145. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/702393d3 +0 -0
  146. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/714f932b +0 -0
  147. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/73f9d4a6 +0 -0
  148. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/78d3adae +0 -0
  149. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7b6564b8 +0 -0
  150. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7c7c3e6e +0 -0
  151. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7cbc9b6a +0 -0
  152. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7dd579e0 +0 -0
  153. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7e0b7d06 +0 -0
  154. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7e153eef +0 -0
  155. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7ee84fd7 +0 -0
  156. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7f5146a4 +0 -0
  157. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/844e633a +0 -0
  158. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8a1af22c +0 -0
  159. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/90a1680d +0 -0
  160. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a15fb79a +0 -0
  161. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ac288a8a +0 -0
  162. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ad7a66b4 +0 -0
  163. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/aee8805e +0 -0
  164. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b0487ec8 +0 -0
  165. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b10e16d2 +0 -0
  166. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b32d42ac +0 -0
  167. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b7d8f35c +0 -0
  168. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b96748af +0 -0
  169. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/bedb2fea +0 -0
  170. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c01ad640 +0 -0
  171. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c0472cf5 +0 -0
  172. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c102ed0f +0 -0
  173. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c1a91819 +0 -0
  174. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c243857a +0 -0
  175. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c407792f +0 -0
  176. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c4459bee +0 -0
  177. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c72a4dcd +0 -0
  178. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c83537a9 +0 -0
  179. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c88f7498 +0 -0
  180. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c8d04070 +0 -0
  181. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cc44d6f1 +0 -0
  182. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d4d913f6 +0 -0
  183. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/da97f202 +0 -0
  184. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/dc965522 +0 -0
  185. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/dff6f700 +0 -0
  186. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e507c001 +0 -0
  187. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e52f3f2d +0 -0
  188. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e5c3890d +0 -0
  189. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e720074d +0 -0
  190. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e7656fa7 +0 -0
  191. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e80bcaac +0 -0
  192. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e8e7900e +0 -0
  193. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ee8993f9 +0 -0
  194. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ef8cf362 +0 -0
  195. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f1405b1d +0 -0
  196. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f20f0e0d +0 -0
  197. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f2586978 +0 -0
  198. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f53cd716 +0 -0
  199. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/fe71f6bb +0 -0
  200. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/febfc20b +0 -0
@@ -14,24 +14,57 @@ 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
+ }
43
+ };
44
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
45
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
46
+ if (ar || !(i in from)) {
47
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
48
+ ar[i] = from[i];
49
+ }
50
+ }
51
+ return to.concat(ar || Array.prototype.slice.call(from));
19
52
  };
20
53
  Object.defineProperty(exports, "__esModule", { value: true });
21
54
  exports.commandRunHarmony = void 0;
22
- const core_1 = require("../core");
23
- const io_1 = require("../io");
24
- const CliExecutor_1 = require("../io/CliExecutor");
25
- const fs_extra_1 = __importDefault(require("fs-extra"));
26
- const node_crypto_1 = __importDefault(require("node:crypto"));
27
- const json5_1 = __importDefault(require("json5"));
28
- const inquirer_1 = __importDefault(require("inquirer"));
29
- const path_1 = __importDefault(require("path"));
30
- const cli_tools_1 = require("@react-native-community/cli-tools");
31
- const simulator_1 = require("../simulator");
32
- const COMMAND_NAME = 'run-harmony';
33
- const LOOPBACK_IP = '127.0.0.1';
34
- const DEFAULT_SIMULATOR_NAME = `${LOOPBACK_IP}:5555`;
55
+ var core_1 = require("../core");
56
+ var io_1 = require("../io");
57
+ var CliExecutor_1 = require("../io/CliExecutor");
58
+ var fs_extra_1 = require("fs-extra");
59
+ var node_crypto_1 = require("node:crypto");
60
+ var json5_1 = require("json5");
61
+ var inquirer_1 = require("inquirer");
62
+ var path_1 = require("path");
63
+ var cli_tools_1 = require("@react-native-community/cli-tools");
64
+ var simulator_1 = require("../simulator");
65
+ var COMMAND_NAME = 'run-harmony';
66
+ var LOOPBACK_IP = '127.0.0.1';
67
+ var DEFAULT_SIMULATOR_NAME = "".concat(LOOPBACK_IP, ":5555");
35
68
  exports.commandRunHarmony = {
36
69
  name: COMMAND_NAME,
37
70
  description: 'Builds your app and starts it on your phone.',
@@ -76,387 +109,498 @@ exports.commandRunHarmony = {
76
109
  description: 'Do not launch packager while running the app.',
77
110
  },
78
111
  ],
79
- func: (_argv, _config, rawArgs) => __awaiter(void 0, void 0, void 0, function* () {
80
- const logger = new io_1.Logger();
81
- try {
82
- const DEVECO_SDK_HOME = process.env.DEVECO_SDK_HOME;
83
- if (!DEVECO_SDK_HOME) {
84
- throw new core_1.DescriptiveError({
85
- whatHappened: 'DEVECO_SDK_HOME environment variable is not set',
86
- whatCanUserDo: [
87
- process.platform === 'darwin'
88
- ? 'On MacOS, the contents directory is typically located at: /Applications/DevEco-Studio.app/Contents/sdk. Set this path as the value of DEVECO_SDK_HOME'
89
- : "Locate the installation directory of DevEco Studio, and set its 'sdk' subdirectory as the value of DEVECO_SDK_HOME environment variable.",
90
- ],
91
- });
92
- }
93
- const fs = new io_1.RealFS();
94
- const sdkPath = new core_1.AbsolutePath(DEVECO_SDK_HOME);
95
- const sdkDirectoryNames = fs
96
- .readDirentsSync(sdkPath)
97
- .flatMap((dirent) => {
98
- if (dirent.isDirectory()) {
99
- return [dirent.name];
100
- }
101
- else {
102
- return [];
103
- }
104
- });
105
- if (sdkDirectoryNames.length === 0) {
106
- throw new core_1.DescriptiveError({
107
- whatHappened: `${sdkPath.toString()} has no directories`,
108
- unexpected: true,
109
- });
110
- }
111
- const sdkToolchainsPath = sdkPath.copyWithNewSegment(sdkDirectoryNames[0], 'openharmony', 'toolchains');
112
- const cli = new CliExecutor_1.RealCliExecutor();
113
- const harmonyProjectPath = new core_1.AbsolutePath(rawArgs.harmonyProjectPath);
114
- const productName = rawArgs.product;
115
- const buildMode = rawArgs.buildMode;
116
- const moduleName = rawArgs.module;
117
- const abilityName = rawArgs.ability;
118
- let simulatorName = rawArgs.simulator;
119
- const defaultPort = rawArgs.port;
120
- const packager = rawArgs.packager;
121
- const devEcoStudioToolsPath = new core_1.AbsolutePath(DEVECO_SDK_HOME).copyWithNewSegment('..', 'tools');
122
- if (!fs.existsSync(devEcoStudioToolsPath)) {
123
- throw new core_1.DescriptiveError({
124
- whatHappened: `${devEcoStudioToolsPath.toString()} doesn't exist`,
125
- });
126
- }
127
- const bundleName = json5_1.default.parse(fs.readTextSync(harmonyProjectPath.copyWithNewSegment('AppScope', 'app.json5'))).app.bundleName;
128
- let currentPort = defaultPort;
129
- if (packager) {
130
- const root = _config.root || '.';
131
- const reactNativePath = _config.reactNativePath || path_1.default.dirname(require.resolve('react-native', { paths: [root] }));
132
- const { port: newPort, startPackager } = yield (0, cli_tools_1.findDevServerPort)(defaultPort, root);
133
- if (newPort !== 8081) {
134
- yield trySetMetroPort(harmonyProjectPath.copyWithNewSegment('entry', 'src', 'main', 'ets', 'pages', 'Index.ets').toString(), newPort);
135
- }
136
- if (startPackager) {
137
- (0, cli_tools_1.startServerInNewWindow)(newPort, root, reactNativePath, (0, cli_tools_1.getDefaultUserTerminal)());
138
- }
139
- currentPort = newPort;
140
- }
141
- const selectDevice = (deviceAndSimulatorInfos) => __awaiter(void 0, void 0, void 0, function* () {
142
- const lines = deviceAndSimulatorInfos.trim().split('\n');
143
- const availableDevices = lines.map((line) => {
144
- const parts = line.split(/\s+/);
145
- return {
146
- name: parts[0],
147
- method: parts[1],
148
- state: parts[2],
149
- locate: parts[3],
150
- connectTool: parts[4]
151
- };
152
- });
153
- if (simulatorName !== 'undefined') {
154
- const isRequestedDeviceAvailable = availableDevices.some((deviceOrSimulator) => deviceOrSimulator.name === simulatorName);
155
- if (!isRequestedDeviceAvailable) {
112
+ func: function (_argv, _config, rawArgs) { return __awaiter(void 0, void 0, void 0, function () {
113
+ var logger, DEVECO_SDK_HOME, fs_1, sdkPath, sdkDirectoryNames, sdkToolchainsPath_1, cli_1, harmonyProjectPath_1, productName_1, buildMode_1, moduleName_1, abilityName_1, simulatorName_1, defaultPort, packager, devEcoStudioToolsPath_1, bundleName_1, currentPort_1, root, reactNativePath, _a, newPort, startPackager, selectDevice, deviceAndSimulatorInfo, deviceOrSimulatorName_1, runJob, err_1;
114
+ return __generator(this, function (_b) {
115
+ switch (_b.label) {
116
+ case 0:
117
+ logger = new io_1.Logger();
118
+ _b.label = 1;
119
+ case 1:
120
+ _b.trys.push([1, 11, , 12]);
121
+ DEVECO_SDK_HOME = process.env.DEVECO_SDK_HOME;
122
+ if (!DEVECO_SDK_HOME) {
156
123
  throw new core_1.DescriptiveError({
157
- whatHappened: `Simulator with name "${simulatorName}" not found.`,
124
+ whatHappened: 'DEVECO_SDK_HOME environment variable is not set',
158
125
  whatCanUserDo: [
159
- 'Please confirm whether the entered simulator name has been activated.',
160
- ]
126
+ process.platform === 'darwin'
127
+ ? 'On MacOS, the contents directory is typically located at: /Applications/DevEco-Studio.app/Contents/sdk. Set this path as the value of DEVECO_SDK_HOME'
128
+ : "Locate the installation directory of DevEco Studio, and set its 'sdk' subdirectory as the value of DEVECO_SDK_HOME environment variable.",
129
+ ],
161
130
  });
162
131
  }
163
- return simulatorName;
164
- }
165
- const connectedDevices = availableDevices.filter((deviceOrSimulator) => deviceOrSimulator.state === 'Connected');
166
- if (connectedDevices.length === 1) {
167
- return connectedDevices[0].name;
168
- }
169
- if (connectedDevices.length > 1) {
170
- const answers = yield inquirer_1.default.prompt([
171
- {
172
- type: 'list',
173
- name: 'selectedDeviceIndex',
174
- message: 'Please select a device:',
175
- choices: connectedDevices.map((deviceOrSimulator, index) => `${index + 1}. ${deviceOrSimulator.name}`)
132
+ fs_1 = new io_1.RealFS();
133
+ sdkPath = new core_1.AbsolutePath(DEVECO_SDK_HOME);
134
+ sdkDirectoryNames = fs_1
135
+ .readDirentsSync(sdkPath)
136
+ .flatMap(function (dirent) {
137
+ if (dirent.isDirectory()) {
138
+ return [dirent.name];
139
+ }
140
+ else {
141
+ return [];
176
142
  }
177
- ]);
178
- return connectedDevices[parseInt(answers.selectedDeviceIndex) - 1].name;
179
- }
180
- try {
181
- yield (0, simulator_1.launchHarmonySimulator)({
182
- devEcoStudioToolsPath,
183
- sdkToolchainsPath,
184
- cli,
185
- logger,
186
- env: process.env,
187
143
  });
188
- simulatorName = DEFAULT_SIMULATOR_NAME;
189
- return simulatorName;
190
- }
191
- catch (e) {
192
- if (e instanceof core_1.DescriptiveError) {
144
+ if (sdkDirectoryNames.length === 0) {
193
145
  throw new core_1.DescriptiveError({
194
- whatHappened: `${e.getMessage()} \n No devices are connected. Failed to auto-launch simulator.`,
195
- whatCanUserDo: [...e.getSuggestions()],
196
- extraData: e.getRawData().extraData,
146
+ whatHappened: "".concat(sdkPath.toString(), " has no directories"),
147
+ unexpected: true,
197
148
  });
198
149
  }
199
- throw new core_1.DescriptiveError({
200
- whatHappened: `No devices are connected in the current environment (auto-launch attempt failed).`,
201
- whatCanUserDo: [
202
- 'Connect a HarmonyOS device via USB or start the simulator manually.',
203
- 'Re-run the command after a device is listed by: hdc list targets -v',
204
- ],
205
- extraData: e,
206
- });
207
- }
208
- });
209
- const deviceAndSimulatorInfo = yield cli.run(sdkToolchainsPath.copyWithNewSegment('hdc').toString(), {
210
- args: ['list', 'targets', '-v'],
211
- cwd: harmonyProjectPath,
212
- });
213
- const deviceOrSimulatorName = yield selectDevice(deviceAndSimulatorInfo);
214
- if (deviceOrSimulatorName.includes(`${LOOPBACK_IP}:`)) {
215
- simulatorName = deviceOrSimulatorName;
216
- }
217
- const runJob = (name, job) => __awaiter(void 0, void 0, void 0, function* () {
218
- const stop = logger.start((s) => s.bold(name));
219
- logger.info((s) => s.bold(`${name} started`));
220
- try {
221
- yield job();
222
- logger.succeed((s) => s.bold(`${name} finished`));
223
- }
224
- catch (err) {
225
- if (err instanceof core_1.DescriptiveError) {
226
- throw err;
227
- }
228
- throw new core_1.DescriptiveError({
229
- whatHappened: `${name} failed`,
230
- extraData: err,
231
- });
232
- }
233
- finally {
234
- stop();
235
- }
236
- });
237
- yield runJob('[1/3] installing dependencies', () => __awaiter(void 0, void 0, void 0, function* () {
238
- let ohpmPath = devEcoStudioToolsPath
239
- .copyWithNewSegment('ohpm', 'bin', 'ohpm');
240
- if (process.platform === 'win32') {
241
- ohpmPath = devEcoStudioToolsPath
242
- .copyWithNewSegment('ohpm', 'bin', 'ohpm.bat');
243
- }
244
- yield cli.run(`"${ohpmPath.toString()}"`, {
245
- args: [
246
- 'install',
247
- '--all',
248
- '--strict_ssl',
249
- 'true',
250
- ],
251
- cwd: harmonyProjectPath,
252
- shell: true,
253
- onArgsStringified: (commandWithArgs) => {
254
- logger.debug((s) => s.bold(s.gray(commandWithArgs)));
255
- },
256
- onStdout: (msg) => {
257
- logger.debug((s) => s.gray(msg.trimEnd()));
258
- },
259
- onStderr(msg) {
260
- logger.debug(() => msg.trimEnd());
261
- },
262
- });
263
- }));
264
- yield runJob('[2/3] building app', () => __awaiter(void 0, void 0, void 0, function* () {
265
- let nodePath = devEcoStudioToolsPath
266
- .copyWithNewSegment('node', 'bin', 'node');
267
- if (!fs.existsSync(nodePath)) {
268
- nodePath = devEcoStudioToolsPath.copyWithNewSegment('node', 'node');
269
- }
270
- let hvigorPathRaw = devEcoStudioToolsPath.copyWithNewSegment('hvigor', 'bin', 'hvigorw.js').toString();
271
- const hvigorPath = `"${hvigorPathRaw}"`;
272
- yield cli.run(`"${nodePath.toString()}"`, {
273
- args: [
274
- hvigorPath,
275
- `-p`,
276
- `module=${moduleName}@default`,
277
- `-p`,
278
- `product=${productName}`,
279
- `-p`,
280
- `buildMode=${buildMode}`,
281
- `-p`,
282
- `requiredDeviceType=phone`,
283
- `assembleHap`,
284
- ],
285
- cwd: harmonyProjectPath,
286
- shell: true,
287
- onArgsStringified: (commandWithArgs) => {
288
- logger.debug((s) => s.bold(s.gray(commandWithArgs)));
289
- },
290
- onStdout: (msg) => {
291
- logger.debug((s) => s.gray(msg.trimEnd()));
292
- },
293
- onStderr(msg) {
294
- logger.debug(() => msg.trimEnd());
295
- },
296
- });
297
- }));
298
- yield runJob('[3/3] installing and opening app', () => __awaiter(void 0, void 0, void 0, function* () {
299
- const tmpDirName = generateRandomString();
300
- const ohosTmpDirPath = `data/local/tmp/${tmpDirName}`;
301
- const exec = (command, args) => __awaiter(void 0, void 0, void 0, function* () {
302
- const result = yield cli.run(command, {
303
- args: args,
304
- shell: true,
305
- onArgsStringified: (commandWithArgs) => logger.debug((s) => s.bold(s.gray(commandWithArgs))),
306
- });
307
- if (result.startsWith('[Fail]')) {
308
- throw new core_1.DescriptiveError({ whatHappened: result });
309
- }
310
- if (result) {
311
- logger.debug((s) => s.gray(result.trimEnd() + '\n'));
150
+ sdkToolchainsPath_1 = sdkPath.copyWithNewSegment(sdkDirectoryNames[0], 'openharmony', 'toolchains');
151
+ cli_1 = new CliExecutor_1.RealCliExecutor();
152
+ harmonyProjectPath_1 = new core_1.AbsolutePath(rawArgs.harmonyProjectPath);
153
+ productName_1 = rawArgs.product;
154
+ buildMode_1 = rawArgs.buildMode;
155
+ moduleName_1 = rawArgs.module;
156
+ abilityName_1 = rawArgs.ability;
157
+ simulatorName_1 = rawArgs.simulator;
158
+ defaultPort = rawArgs.port;
159
+ packager = rawArgs.packager;
160
+ devEcoStudioToolsPath_1 = new core_1.AbsolutePath(DEVECO_SDK_HOME).copyWithNewSegment('..', 'tools');
161
+ if (!fs_1.existsSync(devEcoStudioToolsPath_1)) {
162
+ throw new core_1.DescriptiveError({
163
+ whatHappened: "".concat(devEcoStudioToolsPath_1.toString(), " doesn't exist"),
164
+ });
312
165
  }
313
- else {
314
- logger.debug(() => '');
166
+ bundleName_1 = json5_1.default.parse(fs_1.readTextSync(harmonyProjectPath_1.copyWithNewSegment('AppScope', 'app.json5'))).app.bundleName;
167
+ currentPort_1 = defaultPort;
168
+ if (!packager) return [3 /*break*/, 5];
169
+ root = _config.root || '.';
170
+ reactNativePath = _config.reactNativePath || path_1.default.dirname(require.resolve('react-native', { paths: [root] }));
171
+ return [4 /*yield*/, (0, cli_tools_1.findDevServerPort)(defaultPort, root)];
172
+ case 2:
173
+ _a = _b.sent(), newPort = _a.port, startPackager = _a.startPackager;
174
+ if (!(newPort !== 8081)) return [3 /*break*/, 4];
175
+ return [4 /*yield*/, trySetMetroPort(harmonyProjectPath_1.copyWithNewSegment('entry', 'src', 'main', 'ets', 'pages', 'Index.ets').toString(), newPort)];
176
+ case 3:
177
+ _b.sent();
178
+ _b.label = 4;
179
+ case 4:
180
+ if (startPackager) {
181
+ (0, cli_tools_1.startServerInNewWindow)(newPort, root, reactNativePath, (0, cli_tools_1.getDefaultUserTerminal)());
315
182
  }
316
- return result;
317
- });
318
- const hdcPathStrRaw = sdkToolchainsPath
319
- .copyWithNewSegment('hdc')
320
- .toString();
321
- const hdcPathStr = `"${hdcPathStrRaw.toString()}"`;
322
- const tryRemoveForwardPorting = () => __awaiter(void 0, void 0, void 0, function* () {
323
- let fportInfo = '';
324
- yield cli.run(hdcPathStrRaw, {
325
- args: ['fport', 'ls'],
326
- cwd: harmonyProjectPath,
327
- onStdout: (msg) => {
328
- fportInfo += msg;
329
- },
330
- onStderr: (msg) => {
331
- logger.debug((s) => s.gray(msg.trimEnd()));
332
- },
333
- });
334
- if (fportInfo.includes(`tcp:${currentPort} tcp:${currentPort}`)) {
335
- yield exec(hdcPathStr, [
336
- 'fport',
337
- 'rm',
338
- `tcp:${currentPort}`,
339
- `tcp:${currentPort}`
340
- ]);
341
- }
342
- });
343
- yield exec(hdcPathStr, ['-t', deviceOrSimulatorName, 'shell', 'aa', 'force-stop', bundleName]);
344
- try {
345
- yield exec(hdcPathStr, ['-t', deviceOrSimulatorName, 'shell', 'mkdir', ohosTmpDirPath]);
346
- let hapName = `${moduleName}-default-signed.hap`;
347
- if (simulatorName !== 'undefined') {
348
- hapName = `${moduleName}-default-unsigned.hap`;
183
+ currentPort_1 = newPort;
184
+ _b.label = 5;
185
+ case 5:
186
+ selectDevice = function (deviceAndSimulatorInfos) { return __awaiter(void 0, void 0, void 0, function () {
187
+ var lines, availableDevices, isRequestedDeviceAvailable, connectedDevices, answers, e_1;
188
+ return __generator(this, function (_a) {
189
+ switch (_a.label) {
190
+ case 0:
191
+ lines = deviceAndSimulatorInfos.trim().split('\n');
192
+ availableDevices = lines.map(function (line) {
193
+ var parts = line.split(/\s+/);
194
+ return {
195
+ name: parts[0],
196
+ method: parts[1],
197
+ state: parts[2],
198
+ locate: parts[3],
199
+ connectTool: parts[4]
200
+ };
201
+ });
202
+ if (simulatorName_1 !== 'undefined') {
203
+ isRequestedDeviceAvailable = availableDevices.some(function (deviceOrSimulator) { return deviceOrSimulator.name === simulatorName_1; });
204
+ if (!isRequestedDeviceAvailable) {
205
+ throw new core_1.DescriptiveError({
206
+ whatHappened: "Simulator with name \"".concat(simulatorName_1, "\" not found."),
207
+ whatCanUserDo: [
208
+ 'Please confirm whether the entered simulator name has been activated.',
209
+ ]
210
+ });
211
+ }
212
+ return [2 /*return*/, simulatorName_1];
213
+ }
214
+ connectedDevices = availableDevices.filter(function (deviceOrSimulator) { return deviceOrSimulator.state === 'Connected'; });
215
+ if (connectedDevices.length === 1) {
216
+ return [2 /*return*/, connectedDevices[0].name];
217
+ }
218
+ if (!(connectedDevices.length > 1)) return [3 /*break*/, 2];
219
+ return [4 /*yield*/, inquirer_1.default.prompt([
220
+ {
221
+ type: 'list',
222
+ name: 'selectedDeviceIndex',
223
+ message: 'Please select a device:',
224
+ choices: connectedDevices.map(function (deviceOrSimulator, index) { return "".concat(index + 1, ". ").concat(deviceOrSimulator.name); })
225
+ }
226
+ ])];
227
+ case 1:
228
+ answers = _a.sent();
229
+ return [2 /*return*/, connectedDevices[parseInt(answers.selectedDeviceIndex) - 1].name];
230
+ case 2:
231
+ _a.trys.push([2, 4, , 5]);
232
+ return [4 /*yield*/, (0, simulator_1.launchHarmonySimulator)({
233
+ devEcoStudioToolsPath: devEcoStudioToolsPath_1,
234
+ sdkToolchainsPath: sdkToolchainsPath_1,
235
+ cli: cli_1,
236
+ logger: logger,
237
+ env: process.env,
238
+ })];
239
+ case 3:
240
+ _a.sent();
241
+ simulatorName_1 = DEFAULT_SIMULATOR_NAME;
242
+ return [2 /*return*/, simulatorName_1];
243
+ case 4:
244
+ e_1 = _a.sent();
245
+ if (e_1 instanceof core_1.DescriptiveError) {
246
+ throw new core_1.DescriptiveError({
247
+ whatHappened: "".concat(e_1.getMessage(), " \n No devices are connected. Failed to auto-launch simulator."),
248
+ whatCanUserDo: __spreadArray([], e_1.getSuggestions(), true),
249
+ extraData: e_1.getRawData().extraData,
250
+ });
251
+ }
252
+ throw new core_1.DescriptiveError({
253
+ whatHappened: "No devices are connected in the current environment (auto-launch attempt failed).",
254
+ whatCanUserDo: [
255
+ 'Connect a HarmonyOS device via USB or start the simulator manually.',
256
+ 'Re-run the command after a device is listed by: hdc list targets -v',
257
+ ],
258
+ extraData: e_1,
259
+ });
260
+ case 5: return [2 /*return*/];
261
+ }
262
+ });
263
+ }); };
264
+ return [4 /*yield*/, cli_1.run(sdkToolchainsPath_1.copyWithNewSegment('hdc').toString(), {
265
+ args: ['list', 'targets', '-v'],
266
+ cwd: harmonyProjectPath_1,
267
+ })];
268
+ case 6:
269
+ deviceAndSimulatorInfo = _b.sent();
270
+ return [4 /*yield*/, selectDevice(deviceAndSimulatorInfo)];
271
+ case 7:
272
+ deviceOrSimulatorName_1 = _b.sent();
273
+ if (deviceOrSimulatorName_1.includes("".concat(LOOPBACK_IP, ":"))) {
274
+ simulatorName_1 = deviceOrSimulatorName_1;
349
275
  }
350
- yield exec(hdcPathStr, [
351
- '-t',
352
- deviceOrSimulatorName,
353
- 'file',
354
- 'send',
355
- harmonyProjectPath
356
- .copyWithNewSegment(moduleName, 'build', 'default', 'outputs', 'default', hapName)
357
- .toString(),
358
- ohosTmpDirPath,
359
- ]);
360
- const installationResult = yield exec(hdcPathStr, [
361
- '-t',
362
- deviceOrSimulatorName,
363
- 'shell',
364
- 'bm',
365
- 'install',
366
- '-p',
367
- ohosTmpDirPath,
368
- ]);
369
- if (installationResult.includes('failed to install')) {
370
- throw new core_1.DescriptiveError({
371
- whatHappened: 'Installation failed.',
372
- whatCanUserDo: [
373
- `If an application with the same bundle name is already installed, try uninstalling it:\n${hdcPathStr} shell bm uninstall -n ${bundleName}`,
374
- ],
276
+ runJob = function (name, job) { return __awaiter(void 0, void 0, void 0, function () {
277
+ var stop, err_2;
278
+ return __generator(this, function (_a) {
279
+ switch (_a.label) {
280
+ case 0:
281
+ stop = logger.start(function (s) { return s.bold(name); });
282
+ logger.info(function (s) { return s.bold("".concat(name, " started")); });
283
+ _a.label = 1;
284
+ case 1:
285
+ _a.trys.push([1, 3, 4, 5]);
286
+ return [4 /*yield*/, job()];
287
+ case 2:
288
+ _a.sent();
289
+ logger.succeed(function (s) { return s.bold("".concat(name, " finished")); });
290
+ return [3 /*break*/, 5];
291
+ case 3:
292
+ err_2 = _a.sent();
293
+ if (err_2 instanceof core_1.DescriptiveError) {
294
+ throw err_2;
295
+ }
296
+ throw new core_1.DescriptiveError({
297
+ whatHappened: "".concat(name, " failed"),
298
+ extraData: err_2,
299
+ });
300
+ case 4:
301
+ stop();
302
+ return [7 /*endfinally*/];
303
+ case 5: return [2 /*return*/];
304
+ }
375
305
  });
306
+ }); };
307
+ return [4 /*yield*/, runJob('[1/3] installing dependencies', function () { return __awaiter(void 0, void 0, void 0, function () {
308
+ var ohpmPath;
309
+ return __generator(this, function (_a) {
310
+ switch (_a.label) {
311
+ case 0:
312
+ ohpmPath = devEcoStudioToolsPath_1
313
+ .copyWithNewSegment('ohpm', 'bin', 'ohpm');
314
+ if (process.platform === 'win32') {
315
+ ohpmPath = devEcoStudioToolsPath_1
316
+ .copyWithNewSegment('ohpm', 'bin', 'ohpm.bat');
317
+ }
318
+ return [4 /*yield*/, cli_1.run("\"".concat(ohpmPath.toString(), "\""), {
319
+ args: [
320
+ 'install',
321
+ '--all',
322
+ ],
323
+ cwd: harmonyProjectPath_1,
324
+ shell: true,
325
+ onArgsStringified: function (commandWithArgs) {
326
+ logger.debug(function (s) { return s.bold(s.gray(commandWithArgs)); });
327
+ },
328
+ onStdout: function (msg) {
329
+ logger.debug(function (s) { return s.gray(msg.trimEnd()); });
330
+ },
331
+ onStderr: function (msg) {
332
+ logger.debug(function () { return msg.trimEnd(); });
333
+ },
334
+ })];
335
+ case 1:
336
+ _a.sent();
337
+ return [2 /*return*/];
338
+ }
339
+ });
340
+ }); })];
341
+ case 8:
342
+ _b.sent();
343
+ return [4 /*yield*/, runJob('[2/3] building app', function () { return __awaiter(void 0, void 0, void 0, function () {
344
+ var nodePath, hvigorPathRaw, hvigorPath;
345
+ return __generator(this, function (_a) {
346
+ switch (_a.label) {
347
+ case 0:
348
+ nodePath = devEcoStudioToolsPath_1
349
+ .copyWithNewSegment('node', 'bin', 'node');
350
+ if (!fs_1.existsSync(nodePath)) {
351
+ nodePath = devEcoStudioToolsPath_1.copyWithNewSegment('node', 'node');
352
+ }
353
+ hvigorPathRaw = devEcoStudioToolsPath_1.copyWithNewSegment('hvigor', 'bin', 'hvigorw.js').toString();
354
+ hvigorPath = "\"".concat(hvigorPathRaw, "\"");
355
+ return [4 /*yield*/, cli_1.run("\"".concat(nodePath.toString(), "\""), {
356
+ args: [
357
+ hvigorPath,
358
+ "-p",
359
+ "module=".concat(moduleName_1, "@default"),
360
+ "-p",
361
+ "product=".concat(productName_1),
362
+ "-p",
363
+ "buildMode=".concat(buildMode_1),
364
+ "-p",
365
+ "requiredDeviceType=phone",
366
+ "assembleHap",
367
+ ],
368
+ cwd: harmonyProjectPath_1,
369
+ shell: true,
370
+ onArgsStringified: function (commandWithArgs) {
371
+ logger.debug(function (s) { return s.bold(s.gray(commandWithArgs)); });
372
+ },
373
+ onStdout: function (msg) {
374
+ logger.debug(function (s) { return s.gray(msg.trimEnd()); });
375
+ },
376
+ onStderr: function (msg) {
377
+ logger.debug(function () { return msg.trimEnd(); });
378
+ },
379
+ })];
380
+ case 1:
381
+ _a.sent();
382
+ return [2 /*return*/];
383
+ }
384
+ });
385
+ }); })];
386
+ case 9:
387
+ _b.sent();
388
+ return [4 /*yield*/, runJob('[3/3] installing and opening app', function () { return __awaiter(void 0, void 0, void 0, function () {
389
+ var tmpDirName, ohosTmpDirPath, exec, hdcPathStrRaw, hdcPathStr, tryRemoveForwardPorting, hapName, installationResult;
390
+ return __generator(this, function (_a) {
391
+ switch (_a.label) {
392
+ case 0:
393
+ tmpDirName = generateRandomString();
394
+ ohosTmpDirPath = "data/local/tmp/".concat(tmpDirName);
395
+ exec = function (command, args) { return __awaiter(void 0, void 0, void 0, function () {
396
+ var result;
397
+ return __generator(this, function (_a) {
398
+ switch (_a.label) {
399
+ case 0: return [4 /*yield*/, cli_1.run(command, {
400
+ args: args,
401
+ shell: true,
402
+ onArgsStringified: function (commandWithArgs) {
403
+ return logger.debug(function (s) { return s.bold(s.gray(commandWithArgs)); });
404
+ },
405
+ })];
406
+ case 1:
407
+ result = _a.sent();
408
+ if (result.startsWith('[Fail]')) {
409
+ throw new core_1.DescriptiveError({ whatHappened: result });
410
+ }
411
+ if (result) {
412
+ logger.debug(function (s) { return s.gray(result.trimEnd() + '\n'); });
413
+ }
414
+ else {
415
+ logger.debug(function () { return ''; });
416
+ }
417
+ return [2 /*return*/, result];
418
+ }
419
+ });
420
+ }); };
421
+ hdcPathStrRaw = sdkToolchainsPath_1
422
+ .copyWithNewSegment('hdc')
423
+ .toString();
424
+ hdcPathStr = "\"".concat(hdcPathStrRaw.toString(), "\"");
425
+ tryRemoveForwardPorting = function () { return __awaiter(void 0, void 0, void 0, function () {
426
+ var fportInfo;
427
+ return __generator(this, function (_a) {
428
+ switch (_a.label) {
429
+ case 0:
430
+ fportInfo = '';
431
+ return [4 /*yield*/, cli_1.run(hdcPathStrRaw, {
432
+ args: ['fport', 'ls'],
433
+ cwd: harmonyProjectPath_1,
434
+ onStdout: function (msg) {
435
+ fportInfo += msg;
436
+ },
437
+ onStderr: function (msg) {
438
+ logger.debug(function (s) { return s.gray(msg.trimEnd()); });
439
+ },
440
+ })];
441
+ case 1:
442
+ _a.sent();
443
+ if (!fportInfo.includes("tcp:".concat(currentPort_1, " tcp:").concat(currentPort_1))) return [3 /*break*/, 3];
444
+ return [4 /*yield*/, exec(hdcPathStr, [
445
+ 'fport',
446
+ 'rm',
447
+ "tcp:".concat(currentPort_1),
448
+ "tcp:".concat(currentPort_1)
449
+ ])];
450
+ case 2:
451
+ _a.sent();
452
+ _a.label = 3;
453
+ case 3: return [2 /*return*/];
454
+ }
455
+ });
456
+ }); };
457
+ return [4 /*yield*/, exec(hdcPathStr, ['-t', deviceOrSimulatorName_1, 'shell', 'aa', 'force-stop', bundleName_1])];
458
+ case 1:
459
+ _a.sent();
460
+ _a.label = 2;
461
+ case 2:
462
+ _a.trys.push([2, , 6, 8]);
463
+ return [4 /*yield*/, exec(hdcPathStr, ['-t', deviceOrSimulatorName_1, 'shell', 'mkdir', ohosTmpDirPath])];
464
+ case 3:
465
+ _a.sent();
466
+ hapName = "".concat(moduleName_1, "-default-signed.hap");
467
+ if (simulatorName_1 !== 'undefined') {
468
+ hapName = "".concat(moduleName_1, "-default-unsigned.hap");
469
+ }
470
+ return [4 /*yield*/, exec(hdcPathStr, [
471
+ '-t',
472
+ deviceOrSimulatorName_1,
473
+ 'file',
474
+ 'send',
475
+ harmonyProjectPath_1
476
+ .copyWithNewSegment(moduleName_1, 'build', 'default', 'outputs', 'default', hapName)
477
+ .toString(),
478
+ ohosTmpDirPath,
479
+ ])];
480
+ case 4:
481
+ _a.sent();
482
+ return [4 /*yield*/, exec(hdcPathStr, [
483
+ '-t',
484
+ deviceOrSimulatorName_1,
485
+ 'shell',
486
+ 'bm',
487
+ 'install',
488
+ '-p',
489
+ ohosTmpDirPath,
490
+ ])];
491
+ case 5:
492
+ installationResult = _a.sent();
493
+ if (installationResult.includes('failed to install')) {
494
+ throw new core_1.DescriptiveError({
495
+ whatHappened: 'Installation failed.',
496
+ whatCanUserDo: [
497
+ "If an application with the same bundle name is already installed, try uninstalling it:\n".concat(hdcPathStr, " shell bm uninstall -n ").concat(bundleName_1),
498
+ ],
499
+ });
500
+ }
501
+ return [3 /*break*/, 8];
502
+ case 6: return [4 /*yield*/, exec(hdcPathStr, ['-t', deviceOrSimulatorName_1, 'shell', 'rm', '-rf', ohosTmpDirPath])];
503
+ case 7:
504
+ _a.sent();
505
+ return [7 /*endfinally*/];
506
+ case 8: return [4 /*yield*/, exec(hdcPathStr, [
507
+ '-t',
508
+ deviceOrSimulatorName_1,
509
+ 'shell',
510
+ 'aa',
511
+ 'start',
512
+ '-a',
513
+ abilityName_1,
514
+ '-b',
515
+ bundleName_1,
516
+ ])];
517
+ case 9:
518
+ _a.sent();
519
+ return [4 /*yield*/, tryRemoveForwardPorting()];
520
+ case 10:
521
+ _a.sent();
522
+ return [4 /*yield*/, exec(hdcPathStr, [
523
+ '-t',
524
+ deviceOrSimulatorName_1,
525
+ 'rport',
526
+ "tcp:".concat(currentPort_1),
527
+ "tcp:".concat(currentPort_1)
528
+ ])];
529
+ case 11:
530
+ _a.sent();
531
+ return [2 /*return*/];
532
+ }
533
+ });
534
+ }); })];
535
+ case 10:
536
+ _b.sent();
537
+ return [3 /*break*/, 12];
538
+ case 11:
539
+ err_1 = _b.sent();
540
+ if (err_1 instanceof core_1.DescriptiveError) {
541
+ logger.descriptiveError(new core_1.DescriptiveError({
542
+ whatHappened: err_1.getMessage(),
543
+ whatCanUserDo: __spreadArray(__spreadArray([], err_1.getSuggestions(), true), [
544
+ 'Try building and running the app from DevEco studio.',
545
+ ], false),
546
+ extraData: err_1.getRawData().extraData,
547
+ }));
376
548
  }
377
- }
378
- finally {
379
- yield exec(hdcPathStr, ['-t', deviceOrSimulatorName, 'shell', 'rm', '-rf', ohosTmpDirPath]);
380
- }
381
- yield exec(hdcPathStr, [
382
- '-t',
383
- deviceOrSimulatorName,
384
- 'shell',
385
- 'aa',
386
- 'start',
387
- '-a',
388
- abilityName,
389
- '-b',
390
- bundleName,
391
- ]);
392
- yield tryRemoveForwardPorting();
393
- yield exec(hdcPathStr, [
394
- '-t',
395
- deviceOrSimulatorName,
396
- 'rport',
397
- `tcp:${currentPort}`,
398
- `tcp:${currentPort}`
399
- ]);
400
- }));
401
- }
402
- catch (err) {
403
- if (err instanceof core_1.DescriptiveError) {
404
- logger.descriptiveError(new core_1.DescriptiveError({
405
- whatHappened: err.getMessage(),
406
- whatCanUserDo: [
407
- ...err.getSuggestions(),
408
- 'Try building and running the app from DevEco studio.',
409
- ],
410
- extraData: err.getRawData().extraData,
411
- }));
412
- }
413
- else {
414
- throw err;
549
+ else {
550
+ throw err_1;
551
+ }
552
+ return [3 /*break*/, 12];
553
+ case 12: return [2 /*return*/];
415
554
  }
416
- }
417
- }),
555
+ });
556
+ }); },
418
557
  };
419
- function generateRandomString(length = 32) {
420
- const chars = '0123456789abcdefghijklmnopqrstuvwxyz';
421
- let result = '';
422
- const randomValues = new Uint8Array(length);
558
+ function generateRandomString(length) {
559
+ if (length === void 0) { length = 32; }
560
+ var chars = '0123456789abcdefghijklmnopqrstuvwxyz';
561
+ var result = '';
562
+ var randomValues = new Uint8Array(length);
423
563
  node_crypto_1.default.getRandomValues(randomValues);
424
- for (let i = 0; i < length; i++) {
425
- const randomIndex = randomValues[i] % chars.length;
564
+ for (var i = 0; i < length; i++) {
565
+ var randomIndex = randomValues[i] % chars.length;
426
566
  result += chars[randomIndex];
427
567
  }
428
568
  return result;
429
569
  }
430
570
  function trySetMetroPort(filePath, port) {
431
- return __awaiter(this, void 0, void 0, function* () {
432
- let content = yield fs_extra_1.default.readFile(filePath, 'utf-8');
433
- const reFromServerIp = /MetroJSBundleProvider\.fromServerIp\(\s*"([^"]+)"\s*,\s*(\d+)\s*\)/;
434
- if (reFromServerIp.test(content)) {
435
- content = content.replace(reFromServerIp, (_match, host) => {
436
- return `MetroJSBundleProvider.fromServerIp("${host}", ${port})`;
437
- });
438
- yield fs_extra_1.default.writeFile(filePath, content, 'utf-8');
439
- return;
440
- }
441
- const reNewProvider = /new\s+MetroJSBundleProvider\s*\(\s*\)/;
442
- if (reNewProvider.test(content)) {
443
- content = content.replace(reNewProvider, () => {
444
- return `MetroJSBundleProvider.fromServerIp("localhost", ${port}),\n new MetroJSBundleProvider()`;
445
- });
446
- yield fs_extra_1.default.writeFile(filePath, content, 'utf-8');
447
- return;
448
- }
449
- throw new core_1.DescriptiveError({
450
- whatHappened: `Unable to set the specified port [${port}] for the Metro server automatically.`,
451
- whatCanUserDo: [
452
- `Please manually add "MetroJSBundleProvider.fromServerIp("localhost", ${port})" in the "new AnyJSBundleProvider" section of your ${filePath} file.
453
- e.g:
454
- new AnyJSBundleProvider([
455
- MetroJSBundleProvider.fromServerIp("localhost", ${port}),
456
- new MetroJSBundleProvider(),
457
- new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
458
- ])`
459
- ],
571
+ return __awaiter(this, void 0, void 0, function () {
572
+ var content, reFromServerIp, reNewProvider;
573
+ return __generator(this, function (_a) {
574
+ switch (_a.label) {
575
+ case 0: return [4 /*yield*/, fs_extra_1.default.readFile(filePath, 'utf-8')];
576
+ case 1:
577
+ content = _a.sent();
578
+ reFromServerIp = /MetroJSBundleProvider\.fromServerIp\(\s*"([^"]+)"\s*,\s*(\d+)\s*\)/;
579
+ if (!reFromServerIp.test(content)) return [3 /*break*/, 3];
580
+ content = content.replace(reFromServerIp, function (_match, host) {
581
+ return "MetroJSBundleProvider.fromServerIp(\"".concat(host, "\", ").concat(port, ")");
582
+ });
583
+ return [4 /*yield*/, fs_extra_1.default.writeFile(filePath, content, 'utf-8')];
584
+ case 2:
585
+ _a.sent();
586
+ return [2 /*return*/];
587
+ case 3:
588
+ reNewProvider = /new\s+MetroJSBundleProvider\s*\(\s*\)/;
589
+ if (!reNewProvider.test(content)) return [3 /*break*/, 5];
590
+ content = content.replace(reNewProvider, function () {
591
+ return "MetroJSBundleProvider.fromServerIp(\"localhost\", ".concat(port, "),\n new MetroJSBundleProvider()");
592
+ });
593
+ return [4 /*yield*/, fs_extra_1.default.writeFile(filePath, content, 'utf-8')];
594
+ case 4:
595
+ _a.sent();
596
+ return [2 /*return*/];
597
+ case 5: throw new core_1.DescriptiveError({
598
+ whatHappened: "Unable to set the specified port [".concat(port, "] for the Metro server automatically."),
599
+ whatCanUserDo: [
600
+ "Please manually add \"MetroJSBundleProvider.fromServerIp(\"localhost\", ".concat(port, ")\" in the \"new AnyJSBundleProvider\" section of your ").concat(filePath, " file.\ne.g:\n new AnyJSBundleProvider([\n MetroJSBundleProvider.fromServerIp(\"localhost\", ").concat(port, "),\n new MetroJSBundleProvider(),\n new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),\n ])")
601
+ ],
602
+ });
603
+ }
460
604
  });
461
605
  });
462
606
  }