@react-native-oh/react-native-harmony-cli 0.77.33 → 0.77.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 (192) hide show
  1. package/dist/assetResolver.js +43 -74
  2. package/dist/autolinking/Autolinking.js +178 -179
  3. package/dist/codegen/core/CodegenError.js +3 -23
  4. package/dist/codegen/core/EventUtils.js +3 -3
  5. package/dist/codegen/core/TypeAnnotationToTS.js +24 -28
  6. package/dist/codegen/core/UberSchema.js +55 -97
  7. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +28 -41
  8. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +27 -34
  9. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +25 -33
  10. package/dist/codegen/generators/CppComponentCodeGenerator.js +23 -28
  11. package/dist/codegen/generators/LibGlueCodeGenerator.js +26 -29
  12. package/dist/codegen/generators/NativeModuleCodeGenerator.js +25 -30
  13. package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
  14. package/dist/codegen/generators/UberGeneratorV1.js +24 -23
  15. package/dist/codegen/generators/UberGeneratorV2.js +34 -35
  16. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +50 -24
  17. package/dist/codegen/templates/BasePackageHTemplate.js +120 -21
  18. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +54 -8
  19. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +75 -27
  20. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +162 -29
  21. package/dist/codegen/templates/IndexTSTemplate.js +37 -17
  22. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +119 -24
  23. package/dist/codegen/templates/TurboModuleCppTemplate.js +38 -15
  24. package/dist/codegen/templates/TurboModuleHTemplate.js +32 -11
  25. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +52 -19
  26. package/dist/commands/bundle-harmony.js +118 -221
  27. package/dist/commands/clean-harmony.js +58 -63
  28. package/dist/commands/codegen-harmony.js +105 -165
  29. package/dist/commands/codegen-lib-harmony.js +76 -116
  30. package/dist/commands/init-harmony.js +151 -196
  31. package/dist/commands/init.js +537 -961
  32. package/dist/commands/link-harmony.js +35 -82
  33. package/dist/commands/run-harmony.js +372 -518
  34. package/dist/commands/verify-package-harmony.js +54 -117
  35. package/dist/core/AbsolutePath.js +33 -49
  36. package/dist/core/CodegenConfig.js +24 -22
  37. package/dist/core/DescriptiveError.js +18 -37
  38. package/dist/core/FileSystem.js +14 -18
  39. package/dist/core/OHPackageJSON5.js +17 -23
  40. package/dist/core/PackageJSON.js +26 -42
  41. package/dist/core/ProjectDependenciesManager.js +40 -92
  42. package/dist/core/ValidationError.js +2 -22
  43. package/dist/core/fs.js +10 -7
  44. package/dist/index.js +1 -1
  45. package/dist/init/templates/AppScopeAppJSON5Template.js +21 -8
  46. package/dist/init/templates/AppScopeStringVarTemplate.js +19 -8
  47. package/dist/init/templates/EntryIndexTemplate.js +56 -8
  48. package/dist/init/templates/EntryStringVarTemplate.js +27 -8
  49. package/dist/init/templates/HvigorConfigJson5Template.js +33 -8
  50. package/dist/init/templates/MetroConfigTemplate.js +38 -8
  51. package/dist/init/templates/OhPackageJson5Template.js +28 -8
  52. package/dist/init/templates/harmony/AppScope/app.json5 +10 -0
  53. package/dist/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
  54. package/dist/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  55. package/dist/init/templates/harmony/build-profile.json5 +36 -0
  56. package/dist/init/templates/harmony/codelinter.json +32 -0
  57. package/dist/init/templates/harmony/entry/build-profile.json5 +18 -0
  58. package/dist/init/templates/harmony/entry/gitignore +7 -0
  59. package/dist/init/templates/harmony/entry/hvigorfile.ts +13 -0
  60. package/dist/init/templates/harmony/entry/oh-package.json5 +9 -0
  61. package/dist/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
  62. package/dist/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
  63. package/dist/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
  64. package/dist/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
  65. package/dist/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
  66. package/dist/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
  67. package/dist/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
  68. package/dist/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  69. package/dist/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
  70. package/dist/init/templates/harmony/entry/src/main/module.json5 +65 -0
  71. package/dist/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
  72. package/dist/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
  73. package/dist/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  74. package/dist/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  75. package/dist/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
  76. package/dist/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  77. package/dist/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  78. package/dist/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
  79. package/dist/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
  80. package/dist/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
  81. package/dist/init/templates/harmony/gitignore +16 -0
  82. package/dist/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
  83. package/dist/init/templates/harmony/hvigorfile.ts +7 -0
  84. package/dist/io/CliExecutor.js +46 -98
  85. package/dist/io/Logger.js +40 -46
  86. package/dist/io/RealFS.js +43 -100
  87. package/dist/io/TarGz.js +11 -8
  88. package/dist/io/__fixtures__.js +79 -141
  89. package/dist/io/fsUtils.js +13 -12
  90. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +19 -47
  91. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +13 -41
  92. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +8 -38
  93. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +22 -54
  94. package/dist/package-verifier/verify-package.js +56 -133
  95. package/dist/simulator/LaunchSimulator.js +224 -301
  96. package/harmony/rnoh-hvigor-plugin-0.77.40.tgz +0 -0
  97. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0271b9dd +0 -0
  98. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/07ba0208 +0 -0
  99. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/082dd09d +0 -0
  100. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0a9e1b0b +0 -0
  101. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0c3d528a +0 -0
  102. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1014d3ff +0 -0
  103. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1184678c +0 -0
  104. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/12621366 +0 -0
  105. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/126d3e66 +0 -0
  106. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/19262852 +0 -0
  107. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/203fac53 +0 -0
  108. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/237b660a +0 -0
  109. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2528002d +0 -0
  110. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2587d041 +0 -0
  111. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2893bd11 +0 -0
  112. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2af6ff9d +0 -0
  113. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2bf31f33 +0 -0
  114. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/333648cc +0 -0
  115. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/386f6df0 +0 -0
  116. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/3b8c270e +0 -0
  117. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/3bcc34ba +0 -0
  118. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/444808bd +0 -0
  119. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/44a775e2 +0 -0
  120. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/46da3ccd +0 -0
  121. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/51f80e35 +0 -0
  122. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5203a2ca +0 -0
  123. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/52795646 +0 -0
  124. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/577f8208 +0 -0
  125. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5c2aafe7 +0 -0
  126. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5c69bcfe +0 -0
  127. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/62695b92 +0 -0
  128. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/62698102 +0 -0
  129. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6411ab00 +0 -0
  130. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6569ba92 +0 -0
  131. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/65e5133c +0 -0
  132. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/66029655 +0 -0
  133. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/69e85d0d +0 -0
  134. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6afcb99e +0 -0
  135. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6de07367 +0 -0
  136. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/72498307 +0 -0
  137. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7babd1de +0 -0
  138. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7fe56d21 +0 -0
  139. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/810cbd72 +0 -0
  140. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/812386d2 +0 -0
  141. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8448897d +0 -0
  142. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/84ab0a41 +0 -0
  143. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/853825e2 +0 -0
  144. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/862ad93a +0 -0
  145. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/86b14da6 +0 -0
  146. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/87f0fe62 +0 -0
  147. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/88ee8f74 +0 -0
  148. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8c5237c9 +0 -0
  149. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8c725800 +0 -0
  150. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8e83cbe1 +0 -0
  151. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8f4085b9 +0 -0
  152. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/931f0b2e +0 -0
  153. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/940c8f92 +0 -0
  154. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/968191a3 +0 -0
  155. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/970780c0 +0 -0
  156. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/98bc4394 +0 -0
  157. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/99a3b0b0 +0 -0
  158. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/9c0ffa6b +0 -0
  159. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/9d9b42c2 +0 -0
  160. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a04266ef +0 -0
  161. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a18f78c5 +0 -0
  162. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a642fb0e +0 -0
  163. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a97edf40 +0 -0
  164. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/aa672a20 +0 -0
  165. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ae25c61a +0 -0
  166. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b2bebae6 +0 -0
  167. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ba492422 +0 -0
  168. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/bd3e6c21 +0 -0
  169. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/be9e564e +0 -0
  170. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c342b18e +0 -0
  171. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c3993e7e +0 -0
  172. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c52ffd54 +0 -0
  173. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c7079ad4 +0 -0
  174. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c8eb01c1 +0 -0
  175. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/caee5d30 +0 -0
  176. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cf039161 +0 -0
  177. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d0377c40 +0 -0
  178. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d262bc85 +0 -0
  179. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d287cb5c +0 -0
  180. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d64bff57 +0 -0
  181. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d716a608 +0 -0
  182. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d751012b +0 -0
  183. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e0873711 +0 -0
  184. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e1fcf77b +0 -0
  185. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e8548d8a +0 -0
  186. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/eaedd71d +0 -0
  187. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/eca0019e +0 -0
  188. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f7189953 +0 -0
  189. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f75cb201 +0 -0
  190. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f888164b +0 -0
  191. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/fdb9eb5a +0 -0
  192. package/package.json +1 -1
@@ -6,17 +6,6 @@
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
- var __assign = (this && this.__assign) || function () {
10
- __assign = Object.assign || function(t) {
11
- for (var s, i = 1, n = arguments.length; i < n; i++) {
12
- s = arguments[i];
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
14
- t[p] = s[p];
15
- }
16
- return t;
17
- };
18
- return __assign.apply(this, arguments);
19
- };
20
9
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
21
10
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
11
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -26,167 +15,101 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
26
15
  step((generator = generator.apply(thisArg, _arguments || [])).next());
27
16
  });
28
17
  };
29
- var __generator = (this && this.__generator) || function (thisArg, body) {
30
- 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);
31
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
32
- function verb(n) { return function (v) { return step([n, v]); }; }
33
- function step(op) {
34
- if (f) throw new TypeError("Generator is already executing.");
35
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
36
- 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;
37
- if (y = 0, t) op = [op[0] & 2, t.value];
38
- switch (op[0]) {
39
- case 0: case 1: t = op; break;
40
- case 4: _.label++; return { value: op[1], done: false };
41
- case 5: _.label++; y = op[1]; op = [0]; continue;
42
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
43
- default:
44
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
45
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
46
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
47
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
48
- if (t[2]) _.ops.pop();
49
- _.trys.pop(); continue;
50
- }
51
- op = body.call(thisArg, _);
52
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
53
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
54
- }
55
- };
56
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
57
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
58
- if (ar || !(i in from)) {
59
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
60
- ar[i] = from[i];
61
- }
62
- }
63
- return to.concat(ar || Array.prototype.slice.call(from));
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
64
20
  };
65
21
  Object.defineProperty(exports, "__esModule", { value: true });
66
22
  exports.rnohInit = rnohInit;
67
- var node_path_1 = require("node:path");
68
- var node_os_1 = require("node:os");
69
- var commander_1 = require("commander");
70
- var inquirer_1 = require("inquirer");
71
- var chalk_1 = require("chalk");
72
- var fs_extra_1 = require("fs-extra");
73
- var json5_1 = require("json5");
74
- var cli_tools_1 = require("@react-native-community/cli-tools");
75
- var CliExecutor_1 = require("../io/CliExecutor");
76
- var AbsolutePath_1 = require("../core/AbsolutePath");
77
- var DescriptiveError_1 = require("../core/DescriptiveError");
78
- var VALID_APP_NAME_REG = /^[A-Za-z][A-Za-z0-9_]*[A-Za-z0-9]$/;
79
- var DEFAULT_PACKAGE_PREFIX = 'com.example.';
80
- var HARMONY_DIR = 'harmony';
81
- var JSON5_EXT = '.json5';
82
- var DEFAULT_ENCODING = 'utf8';
83
- var MODULE_DESC = 'module_desc';
84
- var ENTRY_ABILITY_DESC = 'EntryAbility_desc';
85
- var ENTRY_ABILITY_LABEL = 'EntryAbility_label';
86
- var REACT_NATIVE = 'react-native';
87
- var NODE_MODULES = 'node_modules';
88
- var STRING_TYPE = 'string';
89
- var PROJECT_NAME_INDEX = 0;
90
- var JSON_INDENTATION_LENGTH = 2;
91
- var GIT_EXE = 'git';
92
- var NODE_EXE = 'node';
93
- var NPM_EXE = 'npm';
94
- var APP_JSON = 'app.json';
95
- var APP_JSON5 = 'app.json5';
96
- var STRING_JSON = 'string.json';
97
- var PACKAGE_JSON = 'package.json';
98
- var TEMPLATE_CONFIG_JS = 'template.config.js';
99
- var METRO_CONFIG_JS = 'metro.config.js';
100
- var DEFAULT_TEMPLATE_PKG = '@react-native-oh/template';
101
- var REACT_NATIVE_OH_REACT_NATIVE_HARMONY = '@react-native-oh/react-native-harmony';
102
- var REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI = '@react-native-oh/react-native-harmony-cli';
23
+ const node_path_1 = __importDefault(require("node:path"));
24
+ const node_os_1 = __importDefault(require("node:os"));
25
+ const commander_1 = require("commander");
26
+ const inquirer_1 = __importDefault(require("inquirer"));
27
+ const chalk_1 = __importDefault(require("chalk"));
28
+ const fs_extra_1 = __importDefault(require("fs-extra"));
29
+ const json5_1 = __importDefault(require("json5"));
30
+ const cli_tools_1 = require("@react-native-community/cli-tools");
31
+ const CliExecutor_1 = require("../io/CliExecutor");
32
+ const AbsolutePath_1 = require("../core/AbsolutePath");
33
+ const DescriptiveError_1 = require("../core/DescriptiveError");
34
+ const VALID_APP_NAME_REG = /^[A-Za-z][A-Za-z0-9_]*[A-Za-z0-9]$/;
35
+ const DEFAULT_PACKAGE_PREFIX = 'com.example.';
36
+ const HARMONY_DIR = 'harmony';
37
+ const JSON5_EXT = '.json5';
38
+ const DEFAULT_ENCODING = 'utf8';
39
+ const MODULE_DESC = 'module_desc';
40
+ const ENTRY_ABILITY_DESC = 'EntryAbility_desc';
41
+ const ENTRY_ABILITY_LABEL = 'EntryAbility_label';
42
+ const REACT_NATIVE = 'react-native';
43
+ const NODE_MODULES = 'node_modules';
44
+ const STRING_TYPE = 'string';
45
+ const PROJECT_NAME_INDEX = 0;
46
+ const JSON_INDENTATION_LENGTH = 2;
47
+ const GIT_EXE = 'git';
48
+ const NODE_EXE = 'node';
49
+ const NPM_EXE = 'npm';
50
+ const APP_JSON = 'app.json';
51
+ const APP_JSON5 = 'app.json5';
52
+ const STRING_JSON = 'string.json';
53
+ const PACKAGE_JSON = 'package.json';
54
+ const TEMPLATE_CONFIG_JS = 'template.config.js';
55
+ const METRO_CONFIG_JS = 'metro.config.js';
56
+ const DEFAULT_TEMPLATE_PKG = '@react-native-oh/template';
57
+ const REACT_NATIVE_OH_REACT_NATIVE_HARMONY = '@react-native-oh/react-native-harmony';
58
+ const REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI = '@react-native-oh/react-native-harmony-cli';
103
59
  /**
104
60
  * Helper class for file operations (JSON and text file updates).
105
61
  */
106
- var FileOperationHelper = /** @class */ (function () {
107
- function FileOperationHelper() {
108
- }
109
- FileOperationHelper.updateJsonFile = function (filePath, updateFn, errorMessage) {
110
- return __awaiter(this, void 0, void 0, function () {
111
- var content, data, updatedData, outputContent, e_1;
112
- return __generator(this, function (_a) {
113
- switch (_a.label) {
114
- case 0: return [4 /*yield*/, fs_extra_1.default.pathExists(filePath)];
115
- case 1:
116
- if (!(_a.sent())) {
117
- return [2 /*return*/];
118
- }
119
- _a.label = 2;
120
- case 2:
121
- _a.trys.push([2, 5, , 6]);
122
- return [4 /*yield*/, fs_extra_1.default.readFile(filePath, DEFAULT_ENCODING)];
123
- case 3:
124
- content = _a.sent();
125
- data = json5_1.default.parse(content);
126
- updatedData = updateFn(data);
127
- outputContent = filePath.endsWith(JSON5_EXT)
128
- ? json5_1.default.stringify(updatedData, null, JSON_INDENTATION_LENGTH)
129
- : JSON.stringify(updatedData, null, JSON_INDENTATION_LENGTH);
130
- return [4 /*yield*/, fs_extra_1.default.writeFile(filePath, outputContent)];
131
- case 4:
132
- _a.sent();
133
- return [3 /*break*/, 6];
134
- case 5:
135
- e_1 = _a.sent();
136
- throw new DescriptiveError_1.DescriptiveError({
137
- whatHappened: errorMessage,
138
- whatCanUserDo: ['Please check if the file format is correct.'],
139
- extraData: e_1,
140
- });
141
- case 6: return [2 /*return*/];
142
- }
143
- });
62
+ class FileOperationHelper {
63
+ static updateJsonFile(filePath, updateFn, errorMessage) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ if (!(yield fs_extra_1.default.pathExists(filePath))) {
66
+ return;
67
+ }
68
+ try {
69
+ const content = yield fs_extra_1.default.readFile(filePath, DEFAULT_ENCODING);
70
+ const data = json5_1.default.parse(content);
71
+ const updatedData = updateFn(data);
72
+ const outputContent = filePath.endsWith(JSON5_EXT)
73
+ ? json5_1.default.stringify(updatedData, null, JSON_INDENTATION_LENGTH)
74
+ : JSON.stringify(updatedData, null, JSON_INDENTATION_LENGTH);
75
+ yield fs_extra_1.default.writeFile(filePath, outputContent);
76
+ }
77
+ catch (e) {
78
+ throw new DescriptiveError_1.DescriptiveError({
79
+ whatHappened: errorMessage,
80
+ whatCanUserDo: ['Please check if the file format is correct.'],
81
+ extraData: e,
82
+ });
83
+ }
144
84
  });
145
- };
146
- FileOperationHelper.updateTextFile = function (filePath, placeholder, replacement) {
147
- return __awaiter(this, void 0, void 0, function () {
148
- var content, e_2;
149
- return __generator(this, function (_a) {
150
- switch (_a.label) {
151
- case 0: return [4 /*yield*/, fs_extra_1.default.pathExists(filePath)];
152
- case 1:
153
- if (!(_a.sent())) {
154
- return [2 /*return*/];
155
- }
156
- _a.label = 2;
157
- case 2:
158
- _a.trys.push([2, 6, , 7]);
159
- return [4 /*yield*/, fs_extra_1.default.readFile(filePath, DEFAULT_ENCODING)];
160
- case 3:
161
- content = _a.sent();
162
- if (!content.includes(placeholder)) return [3 /*break*/, 5];
163
- content = content.replace(new RegExp(placeholder, 'g'), replacement);
164
- return [4 /*yield*/, fs_extra_1.default.writeFile(filePath, content, DEFAULT_ENCODING)];
165
- case 4:
166
- _a.sent();
167
- _a.label = 5;
168
- case 5: return [3 /*break*/, 7];
169
- case 6:
170
- e_2 = _a.sent();
171
- throw new DescriptiveError_1.DescriptiveError({
172
- whatHappened: "Failed to update ".concat(node_path_1.default.basename(filePath), "."),
173
- whatCanUserDo: ['Please check if the file is readable and writable.'],
174
- extraData: e_2,
175
- });
176
- case 7: return [2 /*return*/];
85
+ }
86
+ static updateTextFile(filePath, placeholder, replacement) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ if (!(yield fs_extra_1.default.pathExists(filePath))) {
89
+ return;
90
+ }
91
+ try {
92
+ let content = yield fs_extra_1.default.readFile(filePath, DEFAULT_ENCODING);
93
+ if (content.includes(placeholder)) {
94
+ content = content.replace(new RegExp(placeholder, 'g'), replacement);
95
+ yield fs_extra_1.default.writeFile(filePath, content, DEFAULT_ENCODING);
177
96
  }
178
- });
97
+ }
98
+ catch (e) {
99
+ throw new DescriptiveError_1.DescriptiveError({
100
+ whatHappened: `Failed to update ${node_path_1.default.basename(filePath)}.`,
101
+ whatCanUserDo: ['Please check if the file is readable and writable.'],
102
+ extraData: e,
103
+ });
104
+ }
179
105
  });
180
- };
181
- return FileOperationHelper;
182
- }());
106
+ }
107
+ }
183
108
  /**
184
109
  * Helper class for validation operations.
185
110
  */
186
- var ValidationHelper = /** @class */ (function () {
187
- function ValidationHelper() {
188
- }
189
- ValidationHelper.validateProjectName = function (projectName) {
111
+ class ValidationHelper {
112
+ static validateProjectName(projectName) {
190
113
  if (!projectName.trim()) {
191
114
  return 'Project name cannot be empty.';
192
115
  }
@@ -194,91 +117,60 @@ var ValidationHelper = /** @class */ (function () {
194
117
  return 'Project name must start with a letter and can only contain letters, numbers, _.';
195
118
  }
196
119
  return true;
197
- };
198
- ValidationHelper.validateOptions = function (options) {
120
+ }
121
+ static validateOptions(options) {
199
122
  if (options.version && options.template) {
200
123
  throw new DescriptiveError_1.DescriptiveError({
201
124
  whatHappened: 'Cannot specify both --version and --template.',
202
125
  whatCanUserDo: ['Please specify only one of --version or --template.'],
203
126
  });
204
127
  }
205
- };
206
- ValidationHelper.validateReactNativeVersion = function (destDir) {
207
- return __awaiter(this, void 0, void 0, function () {
208
- var packageJsonPath, packageJson, _a, _b, reactNativeVersion;
209
- var _c;
210
- return __generator(this, function (_d) {
211
- switch (_d.label) {
212
- case 0:
213
- packageJsonPath = node_path_1.default.join(destDir, PACKAGE_JSON);
214
- return [4 /*yield*/, fs_extra_1.default.pathExists(packageJsonPath)];
215
- case 1:
216
- if (!_d.sent()) return [3 /*break*/, 3];
217
- _b = (_a = JSON).parse;
218
- return [4 /*yield*/, fs_extra_1.default.readFile(packageJsonPath, DEFAULT_ENCODING)];
219
- case 2:
220
- packageJson = _b.apply(_a, [_d.sent()]);
221
- reactNativeVersion = (_c = packageJson.dependencies) === null || _c === void 0 ? void 0 : _c[REACT_NATIVE];
222
- if (!reactNativeVersion || !/^\^?0\.(72)|(77)\./.test(reactNativeVersion)) {
223
- throw new DescriptiveError_1.DescriptiveError({
224
- whatHappened: "Unsupported RN community template. Please ensure react-native version starts with \"0.77.\".",
225
- whatCanUserDo: ['Please use a template with react-native version 0.77.x.'],
226
- });
227
- }
228
- return [2 /*return*/, reactNativeVersion];
229
- case 3: return [2 /*return*/, "0.77"];
128
+ }
129
+ static validateReactNativeVersion(destDir) {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ var _a;
132
+ const packageJsonPath = node_path_1.default.join(destDir, PACKAGE_JSON);
133
+ if (yield fs_extra_1.default.pathExists(packageJsonPath)) {
134
+ const packageJson = JSON.parse(yield fs_extra_1.default.readFile(packageJsonPath, DEFAULT_ENCODING));
135
+ const reactNativeVersion = (_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a[REACT_NATIVE];
136
+ if (!reactNativeVersion || !/^\^?0\.(72)|(77)\./.test(reactNativeVersion)) {
137
+ throw new DescriptiveError_1.DescriptiveError({
138
+ whatHappened: `Unsupported RN community template. Please ensure react-native version starts with "0.77.".`,
139
+ whatCanUserDo: ['Please use a template with react-native version 0.77.x.'],
140
+ });
230
141
  }
231
- });
142
+ return reactNativeVersion;
143
+ }
144
+ return "0.77";
232
145
  });
233
- };
234
- return ValidationHelper;
235
- }());
146
+ }
147
+ }
236
148
  /**
237
149
  * Main entry point for the RNOH init command.
238
150
  * Initializes a new RNOH project with proper template and configuration.
239
151
  */
240
152
  function rnohInit() {
241
- return __awaiter(this, void 0, void 0, function () {
242
- var program;
243
- var _this = this;
244
- return __generator(this, function (_a) {
245
- switch (_a.label) {
246
- case 0:
247
- program = new commander_1.Command();
248
- program
249
- .command('init [projectName]')
250
- .description('Initialize a new RNOH project')
251
- .option('-v, --version <version>', 'Harmonized RN version')
252
- .option('-t, --template <template>', 'Template npm package')
253
- .action(function (projectName, options) { return __awaiter(_this, void 0, void 0, function () {
254
- var err_1;
255
- return __generator(this, function (_a) {
256
- switch (_a.label) {
257
- case 0:
258
- _a.trys.push([0, 2, , 3]);
259
- return [4 /*yield*/, runInit(projectName, options)];
260
- case 1:
261
- _a.sent();
262
- return [3 /*break*/, 3];
263
- case 2:
264
- err_1 = _a.sent();
265
- handleError(err_1);
266
- process.exit(1);
267
- return [3 /*break*/, 3];
268
- case 3: return [2 /*return*/];
269
- }
270
- });
271
- }); });
272
- return [4 /*yield*/, program.parseAsync(process.argv)];
273
- case 1:
274
- _a.sent();
275
- return [2 /*return*/];
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ const program = new commander_1.Command();
155
+ program
156
+ .command('init [projectName]')
157
+ .description('Initialize a new RNOH project')
158
+ .option('-v, --version <version>', 'Harmonized RN version')
159
+ .option('-t, --template <template>', 'Template npm package')
160
+ .action((projectName, options) => __awaiter(this, void 0, void 0, function* () {
161
+ try {
162
+ yield runInit(projectName, options);
276
163
  }
277
- });
164
+ catch (err) {
165
+ handleError(err);
166
+ process.exit(1);
167
+ }
168
+ }));
169
+ yield program.parseAsync(process.argv);
278
170
  });
279
171
  }
280
172
  function showWelcomeMessage(version) {
281
- var rnohLogoArray = [
173
+ const rnohLogoArray = [
282
174
  ' ',
283
175
  ' ____ _ ______ __ __ ',
284
176
  ' / __ \\/ | / / __ \\/ / / / ',
@@ -287,549 +179,348 @@ function showWelcomeMessage(version) {
287
179
  ' /_/ |_/_/ |_/\\____/_/ /_/ ',
288
180
  ' ',
289
181
  ];
290
- var versionInfo = version && version !== 'undefined'
291
- ? " Welcome to RNOH ".concat(version, "!")
182
+ const versionInfo = version && version !== 'undefined'
183
+ ? ` Welcome to RNOH ${version}!`
292
184
  : ' Welcome to RNOH!';
293
- cli_tools_1.logger.log("".concat(chalk_1.default.cyan(rnohLogoArray.join('\n')), "\n").concat(chalk_1.default.cyanBright.bold(versionInfo), "\n"));
185
+ cli_tools_1.logger.log(`${chalk_1.default.cyan(rnohLogoArray.join('\n'))}\n${chalk_1.default.cyanBright.bold(versionInfo)}\n`);
294
186
  }
295
187
  function runInit(projectName, options) {
296
- return __awaiter(this, void 0, void 0, function () {
297
- var packageName, destDir, tempDir, error_1;
298
- return __generator(this, function (_a) {
299
- switch (_a.label) {
300
- case 0: return [4 /*yield*/, getValidatedProjectName(projectName)];
301
- case 1:
302
- projectName = _a.sent();
303
- ValidationHelper.validateOptions(options);
304
- packageName = "".concat(DEFAULT_PACKAGE_PREFIX).concat(projectName);
305
- destDir = node_path_1.default.resolve(process.cwd(), projectName);
306
- return [4 /*yield*/, checkDestinationDirectory(destDir, projectName)];
307
- case 2:
308
- _a.sent();
309
- showWelcomeMessage(options.version);
310
- return [4 /*yield*/, createTempDir()];
311
- case 3:
312
- tempDir = _a.sent();
313
- _a.label = 4;
314
- case 4:
315
- _a.trys.push([4, 6, 8, 10]);
316
- return [4 /*yield*/, executeInitializationSteps(tempDir, destDir, projectName, packageName, options)];
317
- case 5:
318
- _a.sent();
319
- return [3 /*break*/, 10];
320
- case 6:
321
- error_1 = _a.sent();
322
- return [4 /*yield*/, cleanupOnError(destDir)];
323
- case 7:
324
- _a.sent();
325
- throw error_1;
326
- case 8: return [4 /*yield*/, cleanupTempDir(tempDir)];
327
- case 9:
328
- _a.sent();
329
- return [7 /*endfinally*/];
330
- case 10: return [2 /*return*/];
331
- }
332
- });
188
+ return __awaiter(this, void 0, void 0, function* () {
189
+ projectName = yield getValidatedProjectName(projectName);
190
+ ValidationHelper.validateOptions(options);
191
+ const packageName = `${DEFAULT_PACKAGE_PREFIX}${projectName}`;
192
+ const destDir = node_path_1.default.resolve(process.cwd(), projectName);
193
+ yield checkDestinationDirectory(destDir, projectName);
194
+ showWelcomeMessage(options.version);
195
+ const tempDir = yield createTempDir();
196
+ try {
197
+ yield executeInitializationSteps(tempDir, destDir, projectName, packageName, options);
198
+ }
199
+ catch (error) {
200
+ yield cleanupOnError(destDir);
201
+ throw error;
202
+ }
203
+ finally {
204
+ yield cleanupTempDir(tempDir);
205
+ }
333
206
  });
334
207
  }
335
208
  function getValidatedProjectName(projectName) {
336
- return __awaiter(this, void 0, void 0, function () {
337
- var name_1, validationResult;
338
- return __generator(this, function (_a) {
339
- switch (_a.label) {
340
- case 0:
341
- if (!!projectName) return [3 /*break*/, 2];
342
- return [4 /*yield*/, inquirer_1.default.prompt([
343
- {
344
- type: 'input',
345
- name: 'name',
346
- message: 'Please input your project name:',
347
- validate: ValidationHelper.validateProjectName,
348
- },
349
- ])];
350
- case 1:
351
- name_1 = (_a.sent()).name;
352
- return [2 /*return*/, name_1.trim()];
353
- case 2:
354
- validationResult = ValidationHelper.validateProjectName(projectName);
355
- if (validationResult !== true) {
356
- throw new DescriptiveError_1.DescriptiveError({
357
- whatHappened: 'Invalid project name.',
358
- whatCanUserDo: [validationResult],
359
- });
360
- }
361
- return [2 /*return*/, projectName];
362
- }
363
- });
209
+ return __awaiter(this, void 0, void 0, function* () {
210
+ if (!projectName) {
211
+ const { name } = yield inquirer_1.default.prompt([
212
+ {
213
+ type: 'input',
214
+ name: 'name',
215
+ message: 'Please input your project name:',
216
+ validate: ValidationHelper.validateProjectName,
217
+ },
218
+ ]);
219
+ return name.trim();
220
+ }
221
+ const validationResult = ValidationHelper.validateProjectName(projectName);
222
+ if (validationResult !== true) {
223
+ throw new DescriptiveError_1.DescriptiveError({
224
+ whatHappened: 'Invalid project name.',
225
+ whatCanUserDo: [validationResult],
226
+ });
227
+ }
228
+ return projectName;
364
229
  });
365
230
  }
366
231
  function checkDestinationDirectory(destDir, projectName) {
367
- return __awaiter(this, void 0, void 0, function () {
368
- var overwrite, err_2;
369
- return __generator(this, function (_a) {
370
- switch (_a.label) {
371
- case 0: return [4 /*yield*/, fs_extra_1.default.pathExists(destDir)];
372
- case 1:
373
- if (!_a.sent()) return [3 /*break*/, 6];
374
- return [4 /*yield*/, inquirer_1.default.prompt([
375
- {
376
- type: 'confirm',
377
- name: 'overwrite',
378
- message: "Directory '".concat(projectName, "' already exists. Do you want to overwrite it?"),
379
- default: false,
380
- },
381
- ])];
382
- case 2:
383
- overwrite = (_a.sent()).overwrite;
384
- if (!overwrite) {
385
- process.exit(0);
386
- }
387
- _a.label = 3;
388
- case 3:
389
- _a.trys.push([3, 5, , 6]);
390
- return [4 /*yield*/, fs_extra_1.default.remove(destDir)];
391
- case 4:
392
- _a.sent();
393
- return [3 /*break*/, 6];
394
- case 5:
395
- err_2 = _a.sent();
396
- throw new DescriptiveError_1.DescriptiveError({
397
- whatHappened: "Failed to remove existing directory ".concat(destDir),
398
- whatCanUserDo: ['Check permissions for the directory.', 'Ensure the directory is not in use.'],
399
- });
400
- case 6: return [2 /*return*/];
232
+ return __awaiter(this, void 0, void 0, function* () {
233
+ if (yield fs_extra_1.default.pathExists(destDir)) {
234
+ const { overwrite } = yield inquirer_1.default.prompt([
235
+ {
236
+ type: 'confirm',
237
+ name: 'overwrite',
238
+ message: `Directory '${projectName}' already exists. Do you want to overwrite it?`,
239
+ default: false,
240
+ },
241
+ ]);
242
+ if (!overwrite) {
243
+ process.exit(0);
401
244
  }
402
- });
245
+ try {
246
+ yield fs_extra_1.default.remove(destDir);
247
+ }
248
+ catch (err) {
249
+ throw new DescriptiveError_1.DescriptiveError({
250
+ whatHappened: `Failed to remove existing directory ${destDir}`,
251
+ whatCanUserDo: ['Check permissions for the directory.', 'Ensure the directory is not in use.'],
252
+ });
253
+ }
254
+ }
403
255
  });
404
256
  }
405
257
  function executeInitializationSteps(tempDir, destDir, projectName, packageName, options) {
406
- return __awaiter(this, void 0, void 0, function () {
407
- var loader, err_3, _a, templateConfig, templateRoot, isHarmonyTemplate, rnohTemplateConfig, rnohVersion, rnohCliVersion, rnVersion, err_4, updateConfig, err_5, err_6, isSuccess;
408
- var _b;
409
- return __generator(this, function (_c) {
410
- switch (_c.label) {
411
- case 0:
412
- loader = (0, cli_tools_1.getLoader)();
413
- loader.start("".concat(chalk_1.default.bold('Downloading template...')));
414
- _c.label = 1;
415
- case 1:
416
- _c.trys.push([1, 3, , 4]);
417
- return [4 /*yield*/, npmInitAndInstall(tempDir, options.template, options.version)];
418
- case 2:
419
- _c.sent();
420
- loader.succeed('Template downloaded successfully!');
421
- return [3 /*break*/, 4];
422
- case 3:
423
- err_3 = _c.sent();
424
- loader.fail('Failed to download template');
425
- if (err_3 instanceof DescriptiveError_1.DescriptiveError) {
426
- throw err_3;
427
- }
428
- throw new DescriptiveError_1.DescriptiveError({
429
- whatHappened: 'Template download failed',
430
- whatCanUserDo: ['Check your internet connection.', 'Ensure the template package exists.'],
431
- });
432
- case 4:
433
- loader.start("".concat(chalk_1.default.bold('Copying template...')));
434
- return [4 /*yield*/, getTemplateConfigFromPkg(tempDir)];
435
- case 5:
436
- _a = _c.sent(), templateConfig = _a.templateConfig, templateRoot = _a.templateRoot;
437
- isHarmonyTemplate = true;
438
- rnohTemplateConfig = undefined;
439
- rnohVersion = undefined;
440
- rnohCliVersion = undefined;
441
- _c.label = 6;
442
- case 6:
443
- _c.trys.push([6, 12, , 13]);
444
- return [4 /*yield*/, copyAndReplaceTemplate(templateConfig, templateRoot, destDir)];
445
- case 7:
446
- _c.sent();
447
- return [4 /*yield*/, ValidationHelper.validateReactNativeVersion(destDir)];
448
- case 8:
449
- rnVersion = _c.sent();
450
- return [4 /*yield*/, fs_extra_1.default.pathExists(node_path_1.default.join(destDir, HARMONY_DIR))];
451
- case 9:
452
- if (!!(_c.sent())) return [3 /*break*/, 11];
453
- isHarmonyTemplate = false;
454
- return [4 /*yield*/, handleMissingHarmonyDir(destDir, rnVersion)];
455
- case 10:
456
- (_b = _c.sent(), rnohTemplateConfig = _b.rnohTemplateConfig, rnohVersion = _b.rnohVersion, rnohCliVersion = _b.rnohCliVersion);
457
- _c.label = 11;
458
- case 11:
459
- loader.succeed('Template copied successfully!');
460
- return [3 /*break*/, 13];
461
- case 12:
462
- err_4 = _c.sent();
463
- loader.fail('Failed to copy template');
464
- if (err_4 instanceof DescriptiveError_1.DescriptiveError) {
465
- throw err_4;
466
- }
467
- throw new DescriptiveError_1.DescriptiveError({
468
- whatHappened: 'Template copy failed',
469
- whatCanUserDo: ['Ensure you have write permissions for the destination directory.'],
470
- });
471
- case 13:
472
- loader.start("".concat(chalk_1.default.bold('Processing template...')));
473
- _c.label = 14;
474
- case 14:
475
- _c.trys.push([14, 16, , 17]);
476
- updateConfig = {
477
- destDir: destDir,
478
- templateRoot: templateRoot,
479
- templateConfig: templateConfig,
480
- projectName: projectName,
481
- packageName: packageName,
482
- isHarmonyTemplate: isHarmonyTemplate,
483
- rnohVersion: rnohVersion,
484
- rnohCliVersion: rnohCliVersion,
485
- rnohTemplateConfig: rnohTemplateConfig,
486
- };
487
- return [4 /*yield*/, processTemplate(updateConfig)];
488
- case 15:
489
- _c.sent();
490
- loader.succeed('Template processed successfully!');
491
- return [3 /*break*/, 17];
492
- case 16:
493
- err_5 = _c.sent();
494
- loader.fail('Failed to process template');
495
- if (err_5 instanceof DescriptiveError_1.DescriptiveError) {
496
- throw err_5;
497
- }
498
- throw new DescriptiveError_1.DescriptiveError({
499
- whatHappened: 'Template processing failed',
500
- whatCanUserDo: ['Check if the template files are corrupted.'],
501
- });
502
- case 17:
503
- loader.start("".concat(chalk_1.default.bold('Installing dependencies...')));
504
- _c.label = 18;
505
- case 18:
506
- _c.trys.push([18, 20, , 21]);
507
- return [4 /*yield*/, runCliCommand(NPM_EXE, ['install', '--legacy-peer-deps'], destDir)];
508
- case 19:
509
- _c.sent();
510
- loader.succeed('Dependencies installed successfully!');
511
- return [3 /*break*/, 21];
512
- case 20:
513
- err_6 = _c.sent();
514
- loader.fail('Failed to install dependencies');
515
- if (err_6 instanceof DescriptiveError_1.DescriptiveError) {
516
- throw err_6;
517
- }
518
- throw new DescriptiveError_1.DescriptiveError({
519
- whatHappened: 'Dependency installation failed',
520
- whatCanUserDo: ['Check your internet connection.'],
521
- });
522
- case 21:
523
- loader.start("".concat(chalk_1.default.bold('Initializing git repository...')));
524
- return [4 /*yield*/, initGitRepo(destDir)];
525
- case 22:
526
- isSuccess = _c.sent();
527
- if (isSuccess) {
528
- loader.succeed('Git repository initialized successfully!');
529
- }
530
- else {
531
- loader.fail('Failed to initialize git repository.');
532
- }
533
- return [2 /*return*/];
258
+ return __awaiter(this, void 0, void 0, function* () {
259
+ const loader = (0, cli_tools_1.getLoader)();
260
+ loader.start(`${chalk_1.default.bold('Downloading template...')}`);
261
+ try {
262
+ yield npmInitAndInstall(tempDir, options.template, options.version);
263
+ loader.succeed('Template downloaded successfully!');
264
+ }
265
+ catch (err) {
266
+ loader.fail('Failed to download template');
267
+ if (err instanceof DescriptiveError_1.DescriptiveError) {
268
+ throw err;
534
269
  }
535
- });
270
+ throw new DescriptiveError_1.DescriptiveError({
271
+ whatHappened: 'Template download failed',
272
+ whatCanUserDo: ['Check your internet connection.', 'Ensure the template package exists.'],
273
+ });
274
+ }
275
+ loader.start(`${chalk_1.default.bold('Copying template...')}`);
276
+ const { templateConfig, templateRoot } = yield getTemplateConfigFromPkg(tempDir);
277
+ let isHarmonyTemplate = true;
278
+ let rnohTemplateConfig = undefined;
279
+ let rnohVersion = undefined;
280
+ let rnohCliVersion = undefined;
281
+ try {
282
+ yield copyAndReplaceTemplate(templateConfig, templateRoot, destDir);
283
+ const rnVersion = yield ValidationHelper.validateReactNativeVersion(destDir);
284
+ if (!(yield fs_extra_1.default.pathExists(node_path_1.default.join(destDir, HARMONY_DIR)))) {
285
+ isHarmonyTemplate = false;
286
+ ({ rnohTemplateConfig, rnohVersion, rnohCliVersion } = yield handleMissingHarmonyDir(destDir, rnVersion));
287
+ }
288
+ loader.succeed('Template copied successfully!');
289
+ }
290
+ catch (err) {
291
+ loader.fail('Failed to copy template');
292
+ if (err instanceof DescriptiveError_1.DescriptiveError) {
293
+ throw err;
294
+ }
295
+ throw new DescriptiveError_1.DescriptiveError({
296
+ whatHappened: 'Template copy failed',
297
+ whatCanUserDo: ['Ensure you have write permissions for the destination directory.'],
298
+ });
299
+ }
300
+ loader.start(`${chalk_1.default.bold('Processing template...')}`);
301
+ try {
302
+ const updateConfig = {
303
+ destDir,
304
+ templateRoot,
305
+ templateConfig,
306
+ projectName,
307
+ packageName,
308
+ isHarmonyTemplate,
309
+ rnohVersion,
310
+ rnohCliVersion,
311
+ rnohTemplateConfig,
312
+ };
313
+ yield processTemplate(updateConfig);
314
+ loader.succeed('Template processed successfully!');
315
+ }
316
+ catch (err) {
317
+ loader.fail('Failed to process template');
318
+ if (err instanceof DescriptiveError_1.DescriptiveError) {
319
+ throw err;
320
+ }
321
+ throw new DescriptiveError_1.DescriptiveError({
322
+ whatHappened: 'Template processing failed',
323
+ whatCanUserDo: ['Check if the template files are corrupted.'],
324
+ });
325
+ }
326
+ loader.start(`${chalk_1.default.bold('Installing dependencies...')}`);
327
+ try {
328
+ yield runCliCommand(NPM_EXE, ['install', '--legacy-peer-deps'], destDir);
329
+ loader.succeed('Dependencies installed successfully!');
330
+ }
331
+ catch (err) {
332
+ loader.fail('Failed to install dependencies');
333
+ if (err instanceof DescriptiveError_1.DescriptiveError) {
334
+ throw err;
335
+ }
336
+ throw new DescriptiveError_1.DescriptiveError({
337
+ whatHappened: 'Dependency installation failed',
338
+ whatCanUserDo: ['Check your internet connection.'],
339
+ });
340
+ }
341
+ loader.start(`${chalk_1.default.bold('Initializing git repository...')}`);
342
+ const isSuccess = yield initGitRepo(destDir);
343
+ if (isSuccess) {
344
+ loader.succeed('Git repository initialized successfully!');
345
+ }
346
+ else {
347
+ loader.fail('Failed to initialize git repository.');
348
+ }
536
349
  });
537
350
  }
538
351
  function createTempDir() {
539
- return __awaiter(this, void 0, void 0, function () {
540
- var tempDir;
541
- return __generator(this, function (_a) {
542
- switch (_a.label) {
543
- case 0:
544
- tempDir = node_path_1.default.join(node_os_1.default.tmpdir(), "rnoh-init-".concat(Date.now(), "-").concat(Math.random().toString(36).slice(2)));
545
- return [4 /*yield*/, fs_extra_1.default.ensureDir(tempDir)];
546
- case 1:
547
- _a.sent();
548
- return [2 /*return*/, tempDir];
549
- }
550
- });
352
+ return __awaiter(this, void 0, void 0, function* () {
353
+ const tempDir = node_path_1.default.join(node_os_1.default.tmpdir(), `rnoh-init-${Date.now()}-${Math.random().toString(36).slice(2)}`);
354
+ yield fs_extra_1.default.ensureDir(tempDir);
355
+ return tempDir;
551
356
  });
552
357
  }
553
358
  function npmInitAndInstall(tempDir, customTemplate, version) {
554
- return __awaiter(this, void 0, void 0, function () {
555
- var installTarget;
556
- return __generator(this, function (_a) {
557
- switch (_a.label) {
558
- case 0: return [4 /*yield*/, runCliCommand(NPM_EXE, ['init', '-y'], tempDir)];
559
- case 1:
560
- _a.sent();
561
- installTarget = customTemplate ? customTemplate : version ? "".concat(DEFAULT_TEMPLATE_PKG, "@").concat(version) : DEFAULT_TEMPLATE_PKG;
562
- return [4 /*yield*/, runCliCommand(NPM_EXE, ['install', installTarget], tempDir)];
563
- case 2:
564
- _a.sent();
565
- return [2 /*return*/];
566
- }
567
- });
359
+ return __awaiter(this, void 0, void 0, function* () {
360
+ yield runCliCommand(NPM_EXE, ['init', '-y'], tempDir);
361
+ const installTarget = customTemplate ? customTemplate : version ? `${DEFAULT_TEMPLATE_PKG}@${version}` : DEFAULT_TEMPLATE_PKG;
362
+ yield runCliCommand(NPM_EXE, ['install', installTarget], tempDir);
568
363
  });
569
364
  }
570
365
  function getTemplateConfigFromPkg(tempDir) {
571
- return __awaiter(this, void 0, void 0, function () {
572
- var pkgJsonPath, packageJson, _a, _b, dependencies, templateName, templateRoot, configPath, templateConfig;
573
- return __generator(this, function (_c) {
574
- switch (_c.label) {
575
- case 0:
576
- pkgJsonPath = node_path_1.default.join(tempDir, PACKAGE_JSON);
577
- _b = (_a = JSON).parse;
578
- return [4 /*yield*/, fs_extra_1.default.readFile(pkgJsonPath, DEFAULT_ENCODING)];
579
- case 1:
580
- packageJson = _b.apply(_a, [_c.sent()]);
581
- dependencies = packageJson.dependencies;
582
- templateName = Object.keys(dependencies)[0];
583
- templateRoot = node_path_1.default.join.apply(node_path_1.default, __spreadArray([tempDir, NODE_MODULES], templateName.split('/'), false));
584
- return [4 /*yield*/, fs_extra_1.default.pathExists(templateRoot)];
585
- case 2:
586
- if (!(_c.sent())) {
587
- throw new DescriptiveError_1.DescriptiveError({
588
- whatHappened: 'Cannot find installed template package.',
589
- whatCanUserDo: ['Check npm install output.'],
590
- });
591
- }
592
- configPath = node_path_1.default.join(templateRoot, TEMPLATE_CONFIG_JS);
593
- return [4 /*yield*/, fs_extra_1.default.pathExists(configPath)];
594
- case 3:
595
- if (!(_c.sent())) {
596
- throw new DescriptiveError_1.DescriptiveError({
597
- whatHappened: "".concat(TEMPLATE_CONFIG_JS, " not found in template package."),
598
- whatCanUserDo: ['Check the template package.'],
599
- });
600
- }
601
- templateConfig = require(configPath);
602
- validateTemplateConfig(templateConfig);
603
- return [2 /*return*/, { templateConfig: templateConfig, templateRoot: templateRoot }];
604
- }
605
- });
366
+ return __awaiter(this, void 0, void 0, function* () {
367
+ const pkgJsonPath = node_path_1.default.join(tempDir, PACKAGE_JSON);
368
+ const packageJson = JSON.parse(yield fs_extra_1.default.readFile(pkgJsonPath, DEFAULT_ENCODING));
369
+ const dependencies = packageJson.dependencies;
370
+ const templateName = Object.keys(dependencies)[0];
371
+ const templateRoot = node_path_1.default.join(tempDir, NODE_MODULES, ...templateName.split('/'));
372
+ if (!(yield fs_extra_1.default.pathExists(templateRoot))) {
373
+ throw new DescriptiveError_1.DescriptiveError({
374
+ whatHappened: 'Cannot find installed template package.',
375
+ whatCanUserDo: ['Check npm install output.'],
376
+ });
377
+ }
378
+ const configPath = node_path_1.default.join(templateRoot, TEMPLATE_CONFIG_JS);
379
+ if (!(yield fs_extra_1.default.pathExists(configPath))) {
380
+ throw new DescriptiveError_1.DescriptiveError({
381
+ whatHappened: `${TEMPLATE_CONFIG_JS} not found in template package.`,
382
+ whatCanUserDo: ['Check the template package.'],
383
+ });
384
+ }
385
+ const templateConfig = require(configPath);
386
+ validateTemplateConfig(templateConfig);
387
+ return { templateConfig, templateRoot };
606
388
  });
607
389
  }
608
390
  function validateTemplateConfig(templateConfig) {
609
391
  if (!templateConfig.placeholderName || !templateConfig.templateDir) {
610
392
  throw new DescriptiveError_1.DescriptiveError({
611
- whatHappened: "".concat(TEMPLATE_CONFIG_JS, " missing required fields (placeholderName, templateDir)."),
612
- whatCanUserDo: ["Check ".concat(TEMPLATE_CONFIG_JS, " format.")],
393
+ whatHappened: `${TEMPLATE_CONFIG_JS} missing required fields (placeholderName, templateDir).`,
394
+ whatCanUserDo: [`Check ${TEMPLATE_CONFIG_JS} format.`],
613
395
  });
614
396
  }
615
397
  if (typeof templateConfig.placeholderName !== STRING_TYPE || typeof templateConfig.templateDir !== STRING_TYPE) {
616
398
  throw new DescriptiveError_1.DescriptiveError({
617
- whatHappened: "".concat(TEMPLATE_CONFIG_JS, " fields must be strings."),
618
- whatCanUserDo: ["Check ".concat(TEMPLATE_CONFIG_JS, " format.")],
399
+ whatHappened: `${TEMPLATE_CONFIG_JS} fields must be strings.`,
400
+ whatCanUserDo: [`Check ${TEMPLATE_CONFIG_JS} format.`],
619
401
  });
620
402
  }
621
403
  }
622
404
  function copyAndReplaceTemplate(templateConfig, templateRoot, destDir) {
623
- return __awaiter(this, void 0, void 0, function () {
624
- var srcDir;
625
- return __generator(this, function (_a) {
626
- switch (_a.label) {
627
- case 0:
628
- srcDir = node_path_1.default.join(templateRoot, templateConfig.templateDir);
629
- return [4 /*yield*/, fs_extra_1.default.pathExists(srcDir)];
630
- case 1:
631
- if (!(_a.sent())) {
632
- throw new DescriptiveError_1.DescriptiveError({
633
- whatHappened: 'Template directory not found.',
634
- whatCanUserDo: ["Check templateDir in ".concat(TEMPLATE_CONFIG_JS, ".")],
635
- });
636
- }
637
- return [4 /*yield*/, fs_extra_1.default.copy(srcDir, destDir)];
638
- case 2:
639
- _a.sent();
640
- return [2 /*return*/];
641
- }
642
- });
405
+ return __awaiter(this, void 0, void 0, function* () {
406
+ const srcDir = node_path_1.default.join(templateRoot, templateConfig.templateDir);
407
+ if (!(yield fs_extra_1.default.pathExists(srcDir))) {
408
+ throw new DescriptiveError_1.DescriptiveError({
409
+ whatHappened: 'Template directory not found.',
410
+ whatCanUserDo: [`Check templateDir in ${TEMPLATE_CONFIG_JS}.`],
411
+ });
412
+ }
413
+ yield fs_extra_1.default.copy(srcDir, destDir);
643
414
  });
644
415
  }
645
416
  function updateRNConfigFiles(updateConfig) {
646
- return __awaiter(this, void 0, void 0, function () {
647
- var updates;
648
- return __generator(this, function (_a) {
649
- switch (_a.label) {
650
- case 0:
651
- updates = [
652
- FileOperationHelper.updateJsonFile(node_path_1.default.join(updateConfig.destDir, APP_JSON), function (data) { return (__assign(__assign({}, data), { name: updateConfig.projectName, displayName: updateConfig.projectName })); }, "Failed to update ".concat(APP_JSON, ".")),
653
- FileOperationHelper.updateJsonFile(node_path_1.default.join(updateConfig.destDir, PACKAGE_JSON), function (data) {
654
- var _a, _b;
655
- if (!updateConfig.isHarmonyTemplate) {
656
- data.dependencies = __assign(__assign({}, data.dependencies), (_a = {}, _a[REACT_NATIVE_OH_REACT_NATIVE_HARMONY] = updateConfig.rnohVersion, _a));
657
- data.devDependencies = __assign(__assign({}, data.devDependencies), (_b = {}, _b[REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI] = updateConfig.rnohCliVersion, _b));
658
- }
659
- return __assign(__assign({}, data), { name: updateConfig.packageName });
660
- }, "Failed to update ".concat(PACKAGE_JSON, ".")),
661
- ];
662
- return [4 /*yield*/, Promise.all(updates)];
663
- case 1:
664
- _a.sent();
665
- return [2 /*return*/];
666
- }
667
- });
417
+ return __awaiter(this, void 0, void 0, function* () {
418
+ const updates = [
419
+ FileOperationHelper.updateJsonFile(node_path_1.default.join(updateConfig.destDir, APP_JSON), (data) => (Object.assign(Object.assign({}, data), { name: updateConfig.projectName, displayName: updateConfig.projectName })), `Failed to update ${APP_JSON}.`),
420
+ FileOperationHelper.updateJsonFile(node_path_1.default.join(updateConfig.destDir, PACKAGE_JSON), (data) => {
421
+ if (!updateConfig.isHarmonyTemplate) {
422
+ data.dependencies = Object.assign(Object.assign({}, data.dependencies), { [REACT_NATIVE_OH_REACT_NATIVE_HARMONY]: updateConfig.rnohVersion });
423
+ data.devDependencies = Object.assign(Object.assign({}, data.devDependencies), { [REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI]: updateConfig.rnohCliVersion });
424
+ }
425
+ return Object.assign(Object.assign({}, data), { name: updateConfig.packageName });
426
+ }, `Failed to update ${PACKAGE_JSON}.`),
427
+ ];
428
+ yield Promise.all(updates);
668
429
  });
669
430
  }
670
431
  function renameDotFiles(destDir) {
671
- return __awaiter(this, void 0, void 0, function () {
672
- var dotMap, renameOperations;
673
- var _this = this;
674
- return __generator(this, function (_a) {
675
- switch (_a.label) {
676
- case 0:
677
- dotMap = {
678
- '_bundle': '.bundle',
679
- '_eslintrc.js': '.eslintrc.js',
680
- '_gitignore': '.gitignore',
681
- '_prettierrc.js': '.prettierrc.js',
682
- '_watchmanconfig': '.watchmanconfig',
683
- '_buckconfig': '.buckconfig',
684
- '_flowconfig': '.flowconfig',
685
- '_gitattributes': '.gitattributes',
686
- '_editorconfig': '.editorconfig',
687
- '_ruby-version': '.ruby-version',
688
- '_node-version': '.node-version',
689
- '_xcode.env': '.xcode.env',
690
- };
691
- renameOperations = Object.entries(dotMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
692
- var srcPath;
693
- var src = _b[0], dest = _b[1];
694
- return __generator(this, function (_c) {
695
- switch (_c.label) {
696
- case 0:
697
- srcPath = node_path_1.default.join(destDir, src);
698
- return [4 /*yield*/, fs_extra_1.default.pathExists(srcPath)];
699
- case 1:
700
- if (!_c.sent()) return [3 /*break*/, 3];
701
- return [4 /*yield*/, fs_extra_1.default.move(srcPath, node_path_1.default.join(destDir, dest), { overwrite: true })];
702
- case 2:
703
- _c.sent();
704
- _c.label = 3;
705
- case 3: return [2 /*return*/];
706
- }
707
- });
708
- }); });
709
- return [4 /*yield*/, Promise.all(renameOperations)];
710
- case 1:
711
- _a.sent();
712
- return [2 /*return*/];
432
+ return __awaiter(this, void 0, void 0, function* () {
433
+ const dotMap = {
434
+ '_bundle': '.bundle',
435
+ '_eslintrc.js': '.eslintrc.js',
436
+ '_gitignore': '.gitignore',
437
+ '_prettierrc.js': '.prettierrc.js',
438
+ '_watchmanconfig': '.watchmanconfig',
439
+ '_buckconfig': '.buckconfig',
440
+ '_flowconfig': '.flowconfig',
441
+ '_gitattributes': '.gitattributes',
442
+ '_editorconfig': '.editorconfig',
443
+ '_ruby-version': '.ruby-version',
444
+ '_node-version': '.node-version',
445
+ '_xcode.env': '.xcode.env',
446
+ };
447
+ const renameOperations = Object.entries(dotMap).map((_a) => __awaiter(this, [_a], void 0, function* ([src, dest]) {
448
+ const srcPath = node_path_1.default.join(destDir, src);
449
+ if (yield fs_extra_1.default.pathExists(srcPath)) {
450
+ yield fs_extra_1.default.move(srcPath, node_path_1.default.join(destDir, dest), { overwrite: true });
713
451
  }
714
- });
452
+ }));
453
+ yield Promise.all(renameOperations);
715
454
  });
716
455
  }
717
456
  function runPostInitScript(scriptPath, templateRoot, cwd, isHarmonyTemplate) {
718
- return __awaiter(this, void 0, void 0, function () {
719
- var absScriptPath, err_7;
720
- return __generator(this, function (_a) {
721
- switch (_a.label) {
722
- case 0:
723
- absScriptPath = node_path_1.default.join(templateRoot, scriptPath);
724
- return [4 /*yield*/, fs_extra_1.default.pathExists(absScriptPath)];
725
- case 1:
726
- if (!(_a.sent())) {
727
- throw new DescriptiveError_1.DescriptiveError({
728
- whatHappened: 'postInitScript not found.',
729
- whatCanUserDo: ["Check postInitScript path in ".concat(TEMPLATE_CONFIG_JS, ".")],
730
- });
731
- }
732
- if (!!isHarmonyTemplate) return [3 /*break*/, 6];
733
- _a.label = 2;
734
- case 2:
735
- _a.trys.push([2, 4, , 5]);
736
- return [4 /*yield*/, runCliCommand(NODE_EXE, [absScriptPath], cwd)];
737
- case 3:
738
- _a.sent();
739
- return [3 /*break*/, 5];
740
- case 4:
741
- err_7 = _a.sent();
742
- cli_tools_1.logger.error("Failed to execute postInitScript in RN community template, please execute manually.");
743
- return [3 /*break*/, 5];
744
- case 5: return [3 /*break*/, 8];
745
- case 6: return [4 /*yield*/, runCliCommand(NODE_EXE, [absScriptPath], cwd)];
746
- case 7:
747
- _a.sent();
748
- _a.label = 8;
749
- case 8: return [2 /*return*/];
457
+ return __awaiter(this, void 0, void 0, function* () {
458
+ const absScriptPath = node_path_1.default.join(templateRoot, scriptPath);
459
+ if (!(yield fs_extra_1.default.pathExists(absScriptPath))) {
460
+ throw new DescriptiveError_1.DescriptiveError({
461
+ whatHappened: 'postInitScript not found.',
462
+ whatCanUserDo: [`Check postInitScript path in ${TEMPLATE_CONFIG_JS}.`],
463
+ });
464
+ }
465
+ if (!isHarmonyTemplate) {
466
+ try {
467
+ yield runCliCommand(NODE_EXE, [absScriptPath], cwd);
750
468
  }
751
- });
469
+ catch (err) {
470
+ cli_tools_1.logger.error(`Failed to execute postInitScript in RN community template, please execute manually.`);
471
+ }
472
+ }
473
+ else {
474
+ yield runCliCommand(NODE_EXE, [absScriptPath], cwd);
475
+ }
752
476
  });
753
477
  }
754
478
  function runCliCommand(cmd_1, args_1, cwd_1) {
755
- return __awaiter(this, arguments, void 0, function (cmd, args, cwd, silent, stdOutFunc) {
756
- var cli, err_8;
757
- if (silent === void 0) { silent = true; }
758
- return __generator(this, function (_a) {
759
- switch (_a.label) {
760
- case 0:
761
- cli = new CliExecutor_1.RealCliExecutor();
762
- _a.label = 1;
763
- case 1:
764
- _a.trys.push([1, 3, , 4]);
765
- return [4 /*yield*/, cli.run(cmd, {
766
- args: args,
767
- cwd: new AbsolutePath_1.AbsolutePath(cwd),
768
- shell: true,
769
- onStdout: silent ? undefined : stdOutFunc ? function (data) { return stdOutFunc(data); } : function (data) { return cli_tools_1.logger.info(data); },
770
- onStderr: silent ? undefined : function (data) { return cli_tools_1.logger.error(data); },
771
- })];
772
- case 2:
773
- _a.sent();
774
- return [3 /*break*/, 4];
775
- case 3:
776
- err_8 = _a.sent();
777
- throw new DescriptiveError_1.DescriptiveError({
778
- whatHappened: "Failed to run command: ".concat(cmd, " ").concat(args.join(' ')),
779
- extraData: err_8,
780
- });
781
- case 4: return [2 /*return*/];
782
- }
783
- });
479
+ return __awaiter(this, arguments, void 0, function* (cmd, args, cwd, silent = true, stdOutFunc) {
480
+ const cli = new CliExecutor_1.RealCliExecutor();
481
+ try {
482
+ yield cli.run(cmd, {
483
+ args,
484
+ cwd: new AbsolutePath_1.AbsolutePath(cwd),
485
+ shell: true,
486
+ onStdout: silent ? undefined : stdOutFunc ? (data) => stdOutFunc(data) : (data) => cli_tools_1.logger.info(data),
487
+ onStderr: silent ? undefined : (data) => cli_tools_1.logger.error(data),
488
+ });
489
+ }
490
+ catch (err) {
491
+ throw new DescriptiveError_1.DescriptiveError({
492
+ whatHappened: `Failed to run command: ${cmd} ${args.join(' ')}`,
493
+ extraData: err,
494
+ });
495
+ }
784
496
  });
785
497
  }
786
498
  function initGitRepo(destDir) {
787
- return __awaiter(this, void 0, void 0, function () {
788
- var gitDir, error_2;
789
- return __generator(this, function (_a) {
790
- switch (_a.label) {
791
- case 0:
792
- gitDir = node_path_1.default.join(destDir, '.git');
793
- return [4 /*yield*/, fs_extra_1.default.pathExists(gitDir)];
794
- case 1:
795
- if (_a.sent()) {
796
- cli_tools_1.logger.warn('Git repository already exists, skipping git init.');
797
- return [2 /*return*/, false];
798
- }
799
- _a.label = 2;
800
- case 2:
801
- _a.trys.push([2, 6, , 10]);
802
- return [4 /*yield*/, runCliCommand(GIT_EXE, ['init'], destDir)];
803
- case 3:
804
- _a.sent();
805
- return [4 /*yield*/, runCliCommand(GIT_EXE, ['add', '.'], destDir)];
806
- case 4:
807
- _a.sent();
808
- return [4 /*yield*/, runCliCommand(GIT_EXE, ['commit', '-m', "\"Initial RNOH by ".concat(REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI, "\"")], destDir)];
809
- case 5:
810
- _a.sent();
811
- return [3 /*break*/, 10];
812
- case 6:
813
- error_2 = _a.sent();
814
- cli_tools_1.logger.warn('Failed to initialize git repository. You can initialize it manually later.');
815
- return [4 /*yield*/, fs_extra_1.default.pathExists(gitDir)];
816
- case 7:
817
- if (!_a.sent()) return [3 /*break*/, 9];
818
- return [4 /*yield*/, fs_extra_1.default.remove(gitDir)];
819
- case 8:
820
- _a.sent();
821
- _a.label = 9;
822
- case 9: return [2 /*return*/, false];
823
- case 10: return [2 /*return*/, true];
499
+ return __awaiter(this, void 0, void 0, function* () {
500
+ const gitDir = node_path_1.default.join(destDir, '.git');
501
+ if (yield fs_extra_1.default.pathExists(gitDir)) {
502
+ cli_tools_1.logger.warn('Git repository already exists, skipping git init.');
503
+ return false;
504
+ }
505
+ try {
506
+ yield runCliCommand(GIT_EXE, ['init'], destDir);
507
+ yield runCliCommand(GIT_EXE, ['add', '.'], destDir);
508
+ yield runCliCommand(GIT_EXE, ['commit', '-m', `"Initial RNOH by ${REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI}"`], destDir);
509
+ }
510
+ catch (error) {
511
+ cli_tools_1.logger.warn('Failed to initialize git repository. You can initialize it manually later.');
512
+ if (yield fs_extra_1.default.pathExists(gitDir)) {
513
+ yield fs_extra_1.default.remove(gitDir);
824
514
  }
825
- });
515
+ return false;
516
+ }
517
+ return true;
826
518
  });
827
519
  }
828
520
  function handleError(err) {
829
521
  if (err instanceof DescriptiveError_1.DescriptiveError) {
830
522
  cli_tools_1.logger.error(chalk_1.default.red(err.getMessage()));
831
- for (var _i = 0, _a = err.getSuggestions(); _i < _a.length; _i++) {
832
- var suggestion = _a[_i];
523
+ for (const suggestion of err.getSuggestions()) {
833
524
  cli_tools_1.logger.info(chalk_1.default.yellow('Tip: ' + suggestion));
834
525
  }
835
526
  if (err.getDetails()) {
@@ -837,291 +528,176 @@ function handleError(err) {
837
528
  }
838
529
  }
839
530
  else {
840
- var message = err instanceof Error ? err.message : String(err);
531
+ const message = err instanceof Error ? err.message : String(err);
841
532
  cli_tools_1.logger.error(chalk_1.default.red('Unexpected error: ' + message));
842
533
  }
843
534
  }
844
535
  function cleanupOnError(destDir) {
845
- return __awaiter(this, void 0, void 0, function () {
846
- return __generator(this, function (_a) {
847
- switch (_a.label) {
848
- case 0: return [4 /*yield*/, fs_extra_1.default.pathExists(destDir)];
849
- case 1:
850
- if (!_a.sent()) return [3 /*break*/, 3];
851
- return [4 /*yield*/, fs_extra_1.default.remove(destDir)];
852
- case 2:
853
- _a.sent();
854
- _a.label = 3;
855
- case 3: return [2 /*return*/];
856
- }
857
- });
536
+ return __awaiter(this, void 0, void 0, function* () {
537
+ if (yield fs_extra_1.default.pathExists(destDir)) {
538
+ yield fs_extra_1.default.remove(destDir);
539
+ }
858
540
  });
859
541
  }
860
542
  function cleanupTempDir(tempDir) {
861
- return __awaiter(this, void 0, void 0, function () {
862
- var cleanupError_1;
863
- return __generator(this, function (_a) {
864
- switch (_a.label) {
865
- case 0:
866
- _a.trys.push([0, 2, , 3]);
867
- return [4 /*yield*/, fs_extra_1.default.remove(tempDir)];
868
- case 1:
869
- _a.sent();
870
- return [3 /*break*/, 3];
871
- case 2:
872
- cleanupError_1 = _a.sent();
873
- cli_tools_1.logger.warn('Failed to clean up temporary directory:', tempDir);
874
- return [3 /*break*/, 3];
875
- case 3: return [2 /*return*/];
876
- }
877
- });
543
+ return __awaiter(this, void 0, void 0, function* () {
544
+ try {
545
+ yield fs_extra_1.default.remove(tempDir);
546
+ }
547
+ catch (cleanupError) {
548
+ cli_tools_1.logger.warn('Failed to clean up temporary directory:', tempDir);
549
+ }
878
550
  });
879
551
  }
880
552
  function getRNOHVersion(rnVersion) {
881
- return __awaiter(this, void 0, void 0, function () {
882
- var versionParts, majorMinorVersion, versionInfos, versions, matchingVersions;
883
- return __generator(this, function (_a) {
884
- switch (_a.label) {
885
- case 0:
886
- versionParts = rnVersion.split('.');
887
- majorMinorVersion = "".concat(versionParts[0], ".").concat(versionParts[1]);
888
- versionInfos = "";
889
- return [4 /*yield*/, runCliCommand(NPM_EXE, ['view', DEFAULT_TEMPLATE_PKG, 'versions', '--json'], process.cwd(), false, function (data) {
890
- versionInfos += data.toString();
891
- })];
892
- case 1:
893
- _a.sent();
894
- versions = JSON.parse(versionInfos);
895
- matchingVersions = versions.filter(function (v) { return v.startsWith(majorMinorVersion); });
896
- if (matchingVersions.length === 0) {
897
- throw new DescriptiveError_1.DescriptiveError({
898
- whatHappened: "No matching versions found for ".concat(DEFAULT_TEMPLATE_PKG, " with major version ").concat(majorMinorVersion, "."),
899
- whatCanUserDo: ['Please check the available versions of the template package.'],
900
- });
901
- }
902
- return [2 /*return*/, matchingVersions.pop()];
903
- }
553
+ return __awaiter(this, void 0, void 0, function* () {
554
+ const versionParts = rnVersion.split('.');
555
+ const majorMinorVersion = `${versionParts[0]}.${versionParts[1]}`;
556
+ let versionInfos = "";
557
+ yield runCliCommand(NPM_EXE, ['view', DEFAULT_TEMPLATE_PKG, 'versions', '--json'], process.cwd(), false, (data) => {
558
+ versionInfos += data.toString();
904
559
  });
560
+ const versions = JSON.parse(versionInfos);
561
+ const matchingVersions = versions.filter((v) => v.startsWith(majorMinorVersion));
562
+ if (matchingVersions.length === 0) {
563
+ throw new DescriptiveError_1.DescriptiveError({
564
+ whatHappened: `No matching versions found for ${DEFAULT_TEMPLATE_PKG} with major version ${majorMinorVersion}.`,
565
+ whatCanUserDo: ['Please check the available versions of the template package.'],
566
+ });
567
+ }
568
+ return matchingVersions.pop();
905
569
  });
906
570
  }
907
571
  function handleMissingHarmonyDir(destDir, rnVersion) {
908
- return __awaiter(this, void 0, void 0, function () {
909
- var lastestVersion, defaultTempDir, defaultTemplateConfig, sourceHarmonyDir, targetHarmonyDir, sourceMetroConfigPath, targetMetroConfigPath, pkgJsonPath, pkgContent, _a, _b, rnohVersion, rnohCliVersion, androidDir, iosDir, error_3;
910
- var _c, _d;
911
- return __generator(this, function (_e) {
912
- switch (_e.label) {
913
- case 0: return [4 /*yield*/, getRNOHVersion(rnVersion)];
914
- case 1:
915
- lastestVersion = _e.sent();
916
- return [4 /*yield*/, createTempDir()];
917
- case 2:
918
- defaultTempDir = _e.sent();
919
- _e.label = 3;
920
- case 3:
921
- _e.trys.push([3, 19, 20, 22]);
922
- return [4 /*yield*/, npmInitAndInstall(defaultTempDir, "".concat(DEFAULT_TEMPLATE_PKG, "@").concat(lastestVersion))];
923
- case 4:
924
- _e.sent();
925
- return [4 /*yield*/, getTemplateConfigFromPkg(defaultTempDir)];
926
- case 5:
927
- defaultTemplateConfig = _e.sent();
928
- sourceHarmonyDir = node_path_1.default.join(defaultTemplateConfig.templateRoot, defaultTemplateConfig.templateConfig.templateDir, HARMONY_DIR);
929
- targetHarmonyDir = node_path_1.default.join(destDir, HARMONY_DIR);
930
- return [4 /*yield*/, fs_extra_1.default.pathExists(sourceHarmonyDir)];
931
- case 6:
932
- if (!(_e.sent())) {
933
- throw new DescriptiveError_1.DescriptiveError({
934
- whatHappened: "Default template does not contain harmony directory at ".concat(sourceHarmonyDir),
935
- whatCanUserDo: ['Please use a template that contains harmony directory.', 'Check if the default template package is correct.'],
936
- });
937
- }
938
- return [4 /*yield*/, fs_extra_1.default.copy(sourceHarmonyDir, targetHarmonyDir)];
939
- case 7:
940
- _e.sent();
941
- sourceMetroConfigPath = node_path_1.default.join(defaultTemplateConfig.templateRoot, defaultTemplateConfig.templateConfig.templateDir, METRO_CONFIG_JS);
942
- targetMetroConfigPath = node_path_1.default.join(destDir, METRO_CONFIG_JS);
943
- return [4 /*yield*/, fs_extra_1.default.pathExists(sourceMetroConfigPath)];
944
- case 8:
945
- if (!_e.sent()) return [3 /*break*/, 10];
946
- return [4 /*yield*/, fs_extra_1.default.copyFile(sourceMetroConfigPath, targetMetroConfigPath)];
947
- case 9:
948
- _e.sent();
949
- return [3 /*break*/, 11];
950
- case 10: throw new DescriptiveError_1.DescriptiveError({
951
- whatHappened: "Default template does not contain ".concat(METRO_CONFIG_JS, " at ").concat(sourceMetroConfigPath),
952
- whatCanUserDo: ["Please use a template that contains ".concat(METRO_CONFIG_JS, "."), 'Check if the default template package is correct.'],
572
+ return __awaiter(this, void 0, void 0, function* () {
573
+ var _a, _b;
574
+ const lastestVersion = yield getRNOHVersion(rnVersion);
575
+ const defaultTempDir = yield createTempDir();
576
+ try {
577
+ yield npmInitAndInstall(defaultTempDir, `${DEFAULT_TEMPLATE_PKG}@${lastestVersion}`);
578
+ const defaultTemplateConfig = yield getTemplateConfigFromPkg(defaultTempDir);
579
+ const sourceHarmonyDir = node_path_1.default.join(defaultTemplateConfig.templateRoot, defaultTemplateConfig.templateConfig.templateDir, HARMONY_DIR);
580
+ const targetHarmonyDir = node_path_1.default.join(destDir, HARMONY_DIR);
581
+ if (!(yield fs_extra_1.default.pathExists(sourceHarmonyDir))) {
582
+ throw new DescriptiveError_1.DescriptiveError({
583
+ whatHappened: `Default template does not contain harmony directory at ${sourceHarmonyDir}`,
584
+ whatCanUserDo: ['Please use a template that contains harmony directory.', 'Check if the default template package is correct.'],
953
585
  });
954
- case 11:
955
- pkgJsonPath = node_path_1.default.join(defaultTemplateConfig.templateRoot, defaultTemplateConfig.templateConfig.templateDir, PACKAGE_JSON);
956
- _b = (_a = JSON).parse;
957
- return [4 /*yield*/, fs_extra_1.default.readFile(pkgJsonPath, DEFAULT_ENCODING)];
958
- case 12:
959
- pkgContent = _b.apply(_a, [_e.sent()]);
960
- rnohVersion = (_c = pkgContent.dependencies) === null || _c === void 0 ? void 0 : _c[REACT_NATIVE_OH_REACT_NATIVE_HARMONY];
961
- rnohCliVersion = (_d = pkgContent.devDependencies) === null || _d === void 0 ? void 0 : _d[REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI];
962
- androidDir = node_path_1.default.join(destDir, 'android');
963
- iosDir = node_path_1.default.join(destDir, 'ios');
964
- return [4 /*yield*/, fs_extra_1.default.pathExists(androidDir)];
965
- case 13:
966
- if (!_e.sent()) return [3 /*break*/, 15];
967
- return [4 /*yield*/, fs_extra_1.default.remove(androidDir)];
968
- case 14:
969
- _e.sent();
970
- _e.label = 15;
971
- case 15: return [4 /*yield*/, fs_extra_1.default.pathExists(iosDir)];
972
- case 16:
973
- if (!_e.sent()) return [3 /*break*/, 18];
974
- return [4 /*yield*/, fs_extra_1.default.remove(iosDir)];
975
- case 17:
976
- _e.sent();
977
- _e.label = 18;
978
- case 18: return [2 /*return*/, { rnohTemplateConfig: defaultTemplateConfig.templateConfig, rnohVersion: rnohVersion, rnohCliVersion: rnohCliVersion }];
979
- case 19:
980
- error_3 = _e.sent();
981
- if (error_3 instanceof DescriptiveError_1.DescriptiveError) {
982
- throw error_3;
983
- }
984
- throw new DescriptiveError_1.DescriptiveError({
985
- whatHappened: 'Failed to handle missing harmony directory from default template.',
986
- whatCanUserDo: [
987
- 'Check your internet connection.',
988
- 'Ensure you have write permissions for the destination directory.',
989
- 'Verify that the default template package exists and is accessible.',
990
- ],
991
- extraData: error_3,
992
- });
993
- case 20: return [4 /*yield*/, cleanupTempDir(defaultTempDir)];
994
- case 21:
995
- _e.sent();
996
- return [7 /*endfinally*/];
997
- case 22: return [2 /*return*/];
998
586
  }
999
- });
587
+ yield fs_extra_1.default.copy(sourceHarmonyDir, targetHarmonyDir);
588
+ const sourceMetroConfigPath = node_path_1.default.join(defaultTemplateConfig.templateRoot, defaultTemplateConfig.templateConfig.templateDir, METRO_CONFIG_JS);
589
+ const targetMetroConfigPath = node_path_1.default.join(destDir, METRO_CONFIG_JS);
590
+ if (yield fs_extra_1.default.pathExists(sourceMetroConfigPath)) {
591
+ yield fs_extra_1.default.copyFile(sourceMetroConfigPath, targetMetroConfigPath);
592
+ }
593
+ else {
594
+ throw new DescriptiveError_1.DescriptiveError({
595
+ whatHappened: `Default template does not contain ${METRO_CONFIG_JS} at ${sourceMetroConfigPath}`,
596
+ whatCanUserDo: [`Please use a template that contains ${METRO_CONFIG_JS}.`, 'Check if the default template package is correct.'],
597
+ });
598
+ }
599
+ const pkgJsonPath = node_path_1.default.join(defaultTemplateConfig.templateRoot, defaultTemplateConfig.templateConfig.templateDir, PACKAGE_JSON);
600
+ const pkgContent = JSON.parse(yield fs_extra_1.default.readFile(pkgJsonPath, DEFAULT_ENCODING));
601
+ const rnohVersion = (_a = pkgContent.dependencies) === null || _a === void 0 ? void 0 : _a[REACT_NATIVE_OH_REACT_NATIVE_HARMONY];
602
+ const rnohCliVersion = (_b = pkgContent.devDependencies) === null || _b === void 0 ? void 0 : _b[REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI];
603
+ const androidDir = node_path_1.default.join(destDir, 'android');
604
+ const iosDir = node_path_1.default.join(destDir, 'ios');
605
+ if (yield fs_extra_1.default.pathExists(androidDir)) {
606
+ yield fs_extra_1.default.remove(androidDir);
607
+ }
608
+ if (yield fs_extra_1.default.pathExists(iosDir)) {
609
+ yield fs_extra_1.default.remove(iosDir);
610
+ }
611
+ return { rnohTemplateConfig: defaultTemplateConfig.templateConfig, rnohVersion, rnohCliVersion };
612
+ }
613
+ catch (error) {
614
+ if (error instanceof DescriptiveError_1.DescriptiveError) {
615
+ throw error;
616
+ }
617
+ throw new DescriptiveError_1.DescriptiveError({
618
+ whatHappened: 'Failed to handle missing harmony directory from default template.',
619
+ whatCanUserDo: [
620
+ 'Check your internet connection.',
621
+ 'Ensure you have write permissions for the destination directory.',
622
+ 'Verify that the default template package exists and is accessible.',
623
+ ],
624
+ extraData: error,
625
+ });
626
+ }
627
+ finally {
628
+ yield cleanupTempDir(defaultTempDir);
629
+ }
1000
630
  });
1001
631
  }
1002
632
  function updateHarmonyFiles(updateConfig) {
1003
- return __awaiter(this, void 0, void 0, function () {
1004
- var harmonyDir, appScopeDir, entryDir, updateOperations;
1005
- return __generator(this, function (_a) {
1006
- switch (_a.label) {
1007
- case 0:
1008
- harmonyDir = node_path_1.default.join(updateConfig.destDir, HARMONY_DIR);
1009
- appScopeDir = node_path_1.default.join(harmonyDir, 'AppScope');
1010
- entryDir = node_path_1.default.join(harmonyDir, 'entry');
1011
- updateOperations = [
1012
- updateAppScopeStringJson(appScopeDir, updateConfig.projectName),
1013
- updateEntryIndexEts(entryDir, updateConfig),
1014
- updateAppScopeAppJson5(appScopeDir, updateConfig.packageName),
1015
- updateEntryStringJson(entryDir, updateConfig.projectName),
1016
- ];
1017
- return [4 /*yield*/, Promise.all(updateOperations)];
1018
- case 1:
1019
- _a.sent();
1020
- return [2 /*return*/];
1021
- }
1022
- });
633
+ return __awaiter(this, void 0, void 0, function* () {
634
+ const harmonyDir = node_path_1.default.join(updateConfig.destDir, HARMONY_DIR);
635
+ const appScopeDir = node_path_1.default.join(harmonyDir, 'AppScope');
636
+ const entryDir = node_path_1.default.join(harmonyDir, 'entry');
637
+ const updateOperations = [
638
+ updateAppScopeStringJson(appScopeDir, updateConfig.projectName),
639
+ updateEntryIndexEts(entryDir, updateConfig),
640
+ updateAppScopeAppJson5(appScopeDir, updateConfig.packageName),
641
+ updateEntryStringJson(entryDir, updateConfig.projectName),
642
+ ];
643
+ yield Promise.all(updateOperations);
1023
644
  });
1024
645
  }
1025
646
  function updateAppScopeStringJson(appScopeDir, projectName) {
1026
- return __awaiter(this, void 0, void 0, function () {
1027
- var appScopeStringJson;
1028
- return __generator(this, function (_a) {
1029
- switch (_a.label) {
1030
- case 0:
1031
- appScopeStringJson = node_path_1.default.join(appScopeDir, 'resources', 'base', 'element', STRING_JSON);
1032
- return [4 /*yield*/, FileOperationHelper.updateJsonFile(appScopeStringJson, function (data) {
1033
- if (Array.isArray(data.string) && data.string.length > 0) {
1034
- data.string[PROJECT_NAME_INDEX].value = projectName;
1035
- }
1036
- return data;
1037
- }, "Failed to update AppScope ".concat(STRING_JSON, "."))];
1038
- case 1:
1039
- _a.sent();
1040
- return [2 /*return*/];
647
+ return __awaiter(this, void 0, void 0, function* () {
648
+ const appScopeStringJson = node_path_1.default.join(appScopeDir, 'resources', 'base', 'element', STRING_JSON);
649
+ yield FileOperationHelper.updateJsonFile(appScopeStringJson, (data) => {
650
+ if (Array.isArray(data.string) && data.string.length > 0) {
651
+ data.string[PROJECT_NAME_INDEX].value = projectName;
1041
652
  }
1042
- });
653
+ return data;
654
+ }, `Failed to update AppScope ${STRING_JSON}.`);
1043
655
  });
1044
656
  }
1045
657
  function updateEntryIndexEts(entryDir, updateConfig) {
1046
- return __awaiter(this, void 0, void 0, function () {
1047
- var entryIndexEts, replacedText;
1048
- return __generator(this, function (_a) {
1049
- switch (_a.label) {
1050
- case 0:
1051
- entryIndexEts = node_path_1.default.join(entryDir, 'src', 'main', 'ets', 'pages', 'Index.ets');
1052
- replacedText = updateConfig.templateConfig.placeholderName;
1053
- if (!updateConfig.isHarmonyTemplate && updateConfig.rnohTemplateConfig) {
1054
- replacedText = updateConfig.rnohTemplateConfig.placeholderName;
1055
- }
1056
- return [4 /*yield*/, FileOperationHelper.updateTextFile(entryIndexEts, replacedText, updateConfig.projectName)];
1057
- case 1:
1058
- _a.sent();
1059
- return [2 /*return*/];
1060
- }
1061
- });
658
+ return __awaiter(this, void 0, void 0, function* () {
659
+ const entryIndexEts = node_path_1.default.join(entryDir, 'src', 'main', 'ets', 'pages', 'Index.ets');
660
+ let replacedText = updateConfig.templateConfig.placeholderName;
661
+ if (!updateConfig.isHarmonyTemplate && updateConfig.rnohTemplateConfig) {
662
+ replacedText = updateConfig.rnohTemplateConfig.placeholderName;
663
+ }
664
+ yield FileOperationHelper.updateTextFile(entryIndexEts, replacedText, updateConfig.projectName);
1062
665
  });
1063
666
  }
1064
667
  function updateAppScopeAppJson5(appScopeDir, packageName) {
1065
- return __awaiter(this, void 0, void 0, function () {
1066
- var appScopeAppJson5;
1067
- return __generator(this, function (_a) {
1068
- switch (_a.label) {
1069
- case 0:
1070
- appScopeAppJson5 = node_path_1.default.join(appScopeDir, APP_JSON5);
1071
- return [4 /*yield*/, FileOperationHelper.updateJsonFile(appScopeAppJson5, function (data) { return (__assign(__assign({}, data), { app: __assign(__assign({}, data.app), { bundleName: packageName }) })); }, "Failed to update AppScope ".concat(APP_JSON5, "."))];
1072
- case 1:
1073
- _a.sent();
1074
- return [2 /*return*/];
1075
- }
1076
- });
668
+ return __awaiter(this, void 0, void 0, function* () {
669
+ const appScopeAppJson5 = node_path_1.default.join(appScopeDir, APP_JSON5);
670
+ yield FileOperationHelper.updateJsonFile(appScopeAppJson5, (data) => (Object.assign(Object.assign({}, data), { app: Object.assign(Object.assign({}, data.app), { bundleName: packageName }) })), `Failed to update AppScope ${APP_JSON5}.`);
1077
671
  });
1078
672
  }
1079
673
  function updateEntryStringJson(entryDir, projectName) {
1080
- return __awaiter(this, void 0, void 0, function () {
1081
- var entryStringJson;
1082
- return __generator(this, function (_a) {
1083
- switch (_a.label) {
1084
- case 0:
1085
- entryStringJson = node_path_1.default.join(entryDir, 'src', 'main', 'resources', 'base', 'element', STRING_JSON);
1086
- return [4 /*yield*/, FileOperationHelper.updateJsonFile(entryStringJson, function (data) {
1087
- if (Array.isArray(data.string)) {
1088
- data.string.forEach(function (item) {
1089
- if (item.name === MODULE_DESC || item.name === ENTRY_ABILITY_DESC) {
1090
- item.value = '';
1091
- }
1092
- if (item.name === ENTRY_ABILITY_LABEL) {
1093
- item.value = projectName;
1094
- }
1095
- });
1096
- }
1097
- return data;
1098
- }, "Failed to update entry ".concat(STRING_JSON, "."))];
1099
- case 1:
1100
- _a.sent();
1101
- return [2 /*return*/];
674
+ return __awaiter(this, void 0, void 0, function* () {
675
+ const entryStringJson = node_path_1.default.join(entryDir, 'src', 'main', 'resources', 'base', 'element', STRING_JSON);
676
+ yield FileOperationHelper.updateJsonFile(entryStringJson, (data) => {
677
+ if (Array.isArray(data.string)) {
678
+ data.string.forEach((item) => {
679
+ if (item.name === MODULE_DESC || item.name === ENTRY_ABILITY_DESC) {
680
+ item.value = '';
681
+ }
682
+ if (item.name === ENTRY_ABILITY_LABEL) {
683
+ item.value = projectName;
684
+ }
685
+ });
1102
686
  }
1103
- });
687
+ return data;
688
+ }, `Failed to update entry ${STRING_JSON}.`);
1104
689
  });
1105
690
  }
1106
691
  function processTemplate(updateConfig) {
1107
- return __awaiter(this, void 0, void 0, function () {
1108
- return __generator(this, function (_a) {
1109
- switch (_a.label) {
1110
- case 0: return [4 /*yield*/, Promise.all([
1111
- updateRNConfigFiles(updateConfig),
1112
- updateHarmonyFiles(updateConfig),
1113
- renameDotFiles(updateConfig.destDir),
1114
- ])];
1115
- case 1:
1116
- _a.sent();
1117
- if (!updateConfig.templateConfig.postInitScript) return [3 /*break*/, 3];
1118
- return [4 /*yield*/, runPostInitScript(updateConfig.templateConfig.postInitScript, updateConfig.templateRoot, updateConfig.destDir, updateConfig.isHarmonyTemplate)];
1119
- case 2:
1120
- _a.sent();
1121
- _a.label = 3;
1122
- case 3: return [2 /*return*/];
1123
- }
1124
- });
692
+ return __awaiter(this, void 0, void 0, function* () {
693
+ yield Promise.all([
694
+ updateRNConfigFiles(updateConfig),
695
+ updateHarmonyFiles(updateConfig),
696
+ renameDotFiles(updateConfig.destDir),
697
+ ]);
698
+ if (updateConfig.templateConfig.postInitScript) {
699
+ yield runPostInitScript(updateConfig.templateConfig.postInitScript, updateConfig.templateRoot, updateConfig.destDir, updateConfig.isHarmonyTemplate);
700
+ }
1125
701
  });
1126
702
  }
1127
703
  rnohInit();