@react-native-oh/react-native-harmony-cli 0.0.30 → 0.77.18-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -4
  3. package/dist/assetResolver.js +105 -10
  4. package/dist/autolinking/Autolinking.js +21 -26
  5. package/dist/autolinking/index.js +0 -6
  6. package/dist/codegen/core/CodeGenerator.js +0 -6
  7. package/dist/codegen/core/CodegenError.js +0 -6
  8. package/dist/codegen/core/EventUtils.js +4 -13
  9. package/dist/codegen/core/TypeAnnotationToTS.js +3 -9
  10. package/dist/codegen/core/UberSchema.js +8 -21
  11. package/dist/codegen/core/index.js +0 -6
  12. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +2 -7
  13. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +3 -6
  14. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +3 -6
  15. package/dist/codegen/generators/CppComponentCodeGenerator.js +3 -6
  16. package/dist/codegen/generators/LibGlueCodeGenerator.js +2 -8
  17. package/dist/codegen/generators/NativeModuleCodeGenerator.js +1 -7
  18. package/dist/codegen/generators/SharedComponentCodeGenerator.js +0 -6
  19. package/dist/codegen/generators/UberGeneratorV1.js +0 -6
  20. package/dist/codegen/generators/UberGeneratorV2.js +0 -6
  21. package/dist/codegen/generators/index.js +0 -6
  22. package/dist/codegen/index.js +0 -6
  23. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +0 -6
  24. package/dist/codegen/templates/BasePackageHTemplate.js +12 -7
  25. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +1 -6
  26. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +15 -6
  27. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -6
  28. package/dist/codegen/templates/IndexTSTemplate.js +0 -6
  29. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +12 -7
  30. package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -6
  31. package/dist/codegen/templates/TurboModuleHTemplate.js +0 -6
  32. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -6
  33. package/dist/codegen/templates/index.js +0 -6
  34. package/dist/commands/bundle-harmony.js +133 -101
  35. package/dist/commands/clean-harmony.js +84 -0
  36. package/dist/commands/codegen-harmony.js +12 -22
  37. package/dist/commands/codegen-lib-harmony.js +15 -25
  38. package/dist/commands/index.js +3 -9
  39. package/dist/commands/init-harmony.js +226 -0
  40. package/dist/commands/init.js +703 -0
  41. package/dist/commands/link-harmony.js +12 -16
  42. package/dist/commands/run-harmony.js +438 -0
  43. package/dist/commands/types.js +2 -0
  44. package/dist/commands/verify-package-harmony.js +7 -11
  45. package/dist/core/AbsolutePath.js +3 -6
  46. package/dist/core/CodegenConfig.js +3 -11
  47. package/dist/core/DescriptiveError.js +7 -9
  48. package/dist/core/FileSystem.js +0 -6
  49. package/dist/core/OHPackageJSON5.js +0 -6
  50. package/dist/core/PackageJSON.js +4 -7
  51. package/dist/core/ProjectDependenciesManager.js +6 -14
  52. package/dist/core/ValidationError.js +0 -6
  53. package/dist/core/ValueObject.js +0 -6
  54. package/dist/core/fs.js +16 -10
  55. package/dist/core/index.js +0 -6
  56. package/dist/index.js +3 -9
  57. package/dist/init/templates/AppScopeAppJSON5Template.js +30 -0
  58. package/dist/init/templates/AppScopeStringVarTemplate.js +28 -0
  59. package/dist/init/templates/EntryIndexTemplate.js +65 -0
  60. package/dist/init/templates/EntryStringVarTemplate.js +38 -0
  61. package/dist/init/templates/HvigorConfigJson5Template.js +44 -0
  62. package/dist/init/templates/MetroConfigTemplate.js +47 -0
  63. package/dist/init/templates/OhPackageJson5Template.js +37 -0
  64. package/dist/init/templates/harmony/AppScope/app.json5 +10 -0
  65. package/dist/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
  66. package/dist/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  67. package/dist/init/templates/harmony/build-profile.json5 +36 -0
  68. package/dist/init/templates/harmony/codelinter.json +32 -0
  69. package/dist/init/templates/harmony/entry/build-profile.json5 +18 -0
  70. package/dist/init/templates/harmony/entry/gitignore +7 -0
  71. package/dist/init/templates/harmony/entry/hvigorfile.ts +13 -0
  72. package/dist/init/templates/harmony/entry/oh-package.json5 +9 -0
  73. package/dist/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
  74. package/dist/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
  75. package/dist/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
  76. package/dist/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
  77. package/dist/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
  78. package/dist/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
  79. package/dist/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
  80. package/dist/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  81. package/dist/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
  82. package/dist/init/templates/harmony/entry/src/main/module.json5 +58 -0
  83. package/dist/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
  84. package/dist/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
  85. package/dist/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  86. package/dist/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  87. package/dist/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
  88. package/dist/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  89. package/dist/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  90. package/dist/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
  91. package/dist/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
  92. package/dist/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
  93. package/dist/init/templates/harmony/gitignore +16 -0
  94. package/dist/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
  95. package/dist/init/templates/harmony/hvigorfile.ts +7 -0
  96. package/dist/init/templates/index.js +21 -0
  97. package/dist/io/CliExecutor.js +56 -29
  98. package/dist/io/Logger.js +71 -47
  99. package/dist/io/RealFS.js +10 -6
  100. package/dist/io/TarGz.js +3 -10
  101. package/dist/io/__fixtures__.js +8 -8
  102. package/dist/io/fsUtils.js +1 -8
  103. package/dist/io/index.js +1 -6
  104. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +1 -8
  105. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +1 -8
  106. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +1 -8
  107. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +1 -8
  108. package/dist/package-verifier/checks/index.js +0 -6
  109. package/dist/package-verifier/index.js +0 -6
  110. package/dist/package-verifier/types.js +0 -6
  111. package/dist/package-verifier/verify-package.js +5 -14
  112. package/harmony/rnoh-hvigor-plugin-0.77.18.tgz +0 -0
  113. package/jest.config.js +0 -7
  114. package/package.json +20 -16
  115. package/react-native.config.js +0 -7
  116. package/scripts/copy-template.js +18 -0
  117. package/src/assetResolver.ts +117 -11
  118. package/src/autolinking/Autolinking.test.ts +54 -18
  119. package/src/autolinking/Autolinking.ts +32 -31
  120. package/src/autolinking/index.ts +1 -8
  121. package/src/codegen/core/CodeGenerator.ts +0 -7
  122. package/src/codegen/core/CodegenError.ts +0 -7
  123. package/src/codegen/core/EventUtils.ts +3 -12
  124. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -7
  125. package/src/codegen/core/TypeAnnotationToTS.ts +3 -8
  126. package/src/codegen/core/UberSchema.ts +9 -22
  127. package/src/codegen/core/index.ts +0 -7
  128. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +5 -8
  129. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +3 -7
  130. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +3 -7
  131. package/src/codegen/generators/CppComponentCodeGenerator.ts +3 -7
  132. package/src/codegen/generators/LibGlueCodeGenerator.ts +2 -9
  133. package/src/codegen/generators/NativeModuleCodeGenerator.ts +1 -8
  134. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -7
  135. package/src/codegen/generators/UberGeneratorV1.ts +0 -7
  136. package/src/codegen/generators/UberGeneratorV2.ts +0 -7
  137. package/src/codegen/generators/index.ts +0 -7
  138. package/src/codegen/index.ts +0 -7
  139. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -7
  140. package/src/codegen/templates/BasePackageHTemplate.ts +13 -8
  141. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +1 -7
  142. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +24 -8
  143. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -7
  144. package/src/codegen/templates/IndexTSTemplate.ts +0 -7
  145. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +13 -8
  146. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -7
  147. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -7
  148. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -7
  149. package/src/codegen/templates/index.ts +0 -7
  150. package/src/commands/bundle-harmony.ts +178 -118
  151. package/src/commands/clean-harmony.ts +54 -0
  152. package/src/commands/codegen-harmony.ts +13 -25
  153. package/src/commands/codegen-lib-harmony.ts +16 -28
  154. package/src/commands/index.ts +3 -10
  155. package/src/commands/init-harmony.ts +299 -0
  156. package/src/commands/init.ts +755 -0
  157. package/src/commands/link-harmony.ts +14 -19
  158. package/src/commands/run-harmony.ts +478 -0
  159. package/src/commands/types.ts +14 -0
  160. package/src/commands/verify-package-harmony.ts +9 -12
  161. package/src/core/AbsolutePath.ts +4 -7
  162. package/src/core/CodegenConfig.ts +3 -12
  163. package/src/core/DescriptiveError.ts +8 -15
  164. package/src/core/FileSystem.ts +5 -8
  165. package/src/core/OHPackageJSON5.ts +0 -7
  166. package/src/core/PackageJSON.ts +4 -13
  167. package/src/core/ProjectDependenciesManager.ts +14 -22
  168. package/src/core/ValidationError.ts +0 -7
  169. package/src/core/ValueObject.ts +0 -7
  170. package/src/core/fs.ts +14 -8
  171. package/src/core/index.ts +0 -7
  172. package/src/index.ts +8 -15
  173. package/src/init/templates/AppScopeAppJSON5Template.ts +24 -0
  174. package/src/init/templates/AppScopeStringVarTemplate.ts +22 -0
  175. package/src/init/templates/EntryIndexTemplate.ts +59 -0
  176. package/src/init/templates/EntryStringVarTemplate.ts +31 -0
  177. package/src/init/templates/HvigorConfigJson5Template.ts +40 -0
  178. package/src/init/templates/MetroConfigTemplate.ts +41 -0
  179. package/src/init/templates/OhPackageJson5Template.ts +31 -0
  180. package/src/init/templates/harmony/AppScope/app.json5 +10 -0
  181. package/src/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
  182. package/src/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  183. package/src/init/templates/harmony/build-profile.json5 +36 -0
  184. package/src/init/templates/harmony/codelinter.json +32 -0
  185. package/src/init/templates/harmony/entry/build-profile.json5 +18 -0
  186. package/src/init/templates/harmony/entry/gitignore +7 -0
  187. package/src/init/templates/harmony/entry/hvigorfile.ts +13 -0
  188. package/src/init/templates/harmony/entry/oh-package.json5 +9 -0
  189. package/src/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
  190. package/src/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
  191. package/src/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
  192. package/src/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
  193. package/src/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
  194. package/src/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
  195. package/src/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
  196. package/src/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  197. package/src/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
  198. package/src/init/templates/harmony/entry/src/main/module.json5 +58 -0
  199. package/src/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
  200. package/src/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
  201. package/src/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  202. package/src/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  203. package/src/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
  204. package/src/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  205. package/src/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  206. package/src/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
  207. package/src/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
  208. package/src/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
  209. package/src/init/templates/harmony/gitignore +16 -0
  210. package/src/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
  211. package/src/init/templates/harmony/hvigorfile.ts +7 -0
  212. package/src/init/templates/index.ts +5 -0
  213. package/src/io/CliExecutor.ts +55 -40
  214. package/src/io/Logger.ts +77 -51
  215. package/src/io/RealFS.ts +15 -8
  216. package/src/io/TarGz.ts +1 -8
  217. package/src/io/__fixtures__.ts +15 -18
  218. package/src/io/fsUtils.ts +1 -7
  219. package/src/io/index.ts +1 -7
  220. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -7
  221. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -7
  222. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -7
  223. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -7
  224. package/src/package-verifier/checks/index.ts +0 -7
  225. package/src/package-verifier/index.ts +0 -7
  226. package/src/package-verifier/types.ts +0 -7
  227. package/src/package-verifier/verify-package.ts +4 -13
  228. package/tsconfig.build.json +2 -5
  229. package/tsconfig.json +4 -0
  230. package/dist/commands/create-metro-host-constants.js +0 -67
  231. package/dist/commands/pack-harmony.js +0 -106
  232. package/dist/commands/unpack-harmony.js +0 -191
  233. package/src/commands/create-metro-host-constants.ts +0 -55
  234. package/src/commands/pack-harmony.ts +0 -128
  235. package/src/commands/unpack-harmony.ts +0 -240
@@ -1,10 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE-MIT file in the root directory of this source tree.
7
- */
8
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
13
  };
20
14
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.createHarmonyDirExistsCheck = void 0;
15
+ exports.createHarmonyDirExistsCheck = createHarmonyDirExistsCheck;
22
16
  const node_fs_1 = __importDefault(require("node:fs"));
23
17
  function createHarmonyDirExistsCheck(packagePath, hasNativeCode) {
24
18
  return {
@@ -35,4 +29,3 @@ function createHarmonyDirExistsCheck(packagePath, hasNativeCode) {
35
29
  }),
36
30
  };
37
31
  }
38
- exports.createHarmonyDirExistsCheck = createHarmonyDirExistsCheck;
@@ -1,10 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE-MIT file in the root directory of this source tree.
7
- */
8
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -15,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15
9
  });
16
10
  };
17
11
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.createNpmAndOhPackageVersionsAreEqualCheck = void 0;
12
+ exports.createNpmAndOhPackageVersionsAreEqualCheck = createNpmAndOhPackageVersionsAreEqualCheck;
19
13
  function createNpmAndOhPackageVersionsAreEqualCheck(npmPackageVersion, ohPackageVersion) {
20
14
  return {
21
15
  checkIf: 'npm_and_oh_package_versions_are_equal',
@@ -29,4 +23,3 @@ function createNpmAndOhPackageVersionsAreEqualCheck(npmPackageVersion, ohPackage
29
23
  }),
30
24
  };
31
25
  }
32
- exports.createNpmAndOhPackageVersionsAreEqualCheck = createNpmAndOhPackageVersionsAreEqualCheck;
@@ -1,10 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE-MIT file in the root directory of this source tree.
7
- */
8
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -15,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15
9
  });
16
10
  };
17
11
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.createOhPackageNameFollowsNamingConventionCheck = void 0;
12
+ exports.createOhPackageNameFollowsNamingConventionCheck = createOhPackageNameFollowsNamingConventionCheck;
19
13
  function createOhPackageNameFollowsNamingConventionCheck(npmPackageName, ohPackageName) {
20
14
  const npmPackageNameInfo = getPackageNameInfo(npmPackageName);
21
15
  return {
@@ -42,7 +36,6 @@ function createOhPackageNameFollowsNamingConventionCheck(npmPackageName, ohPacka
42
36
  }),
43
37
  };
44
38
  }
45
- exports.createOhPackageNameFollowsNamingConventionCheck = createOhPackageNameFollowsNamingConventionCheck;
46
39
  function getPackageNameInfo(packageName) {
47
40
  if (packageName.startsWith('@') && packageName.includes('/')) {
48
41
  const [part1, part2] = packageName.split('/');
@@ -1,10 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE-MIT file in the root directory of this source tree.
7
- */
8
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
3
  if (k2 === undefined) k2 = k;
10
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1,10 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE-MIT file in the root directory of this source tree.
7
- */
8
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
3
  if (k2 === undefined) k2 = k;
10
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1,8 +1,2 @@
1
1
  "use strict";
2
- /**
3
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE-MIT file in the root directory of this source tree.
7
- */
8
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE-MIT file in the root directory of this source tree.
7
- */
8
2
  var __asyncValues = (this && this.__asyncValues) || function (o) {
9
3
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
10
4
  var m = o[Symbol.asyncIterator], i;
@@ -34,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
34
28
  return (mod && mod.__esModule) ? mod : { "default": mod };
35
29
  };
36
30
  Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.verifyRNOHPackage = void 0;
31
+ exports.verifyRNOHPackage = verifyRNOHPackage;
38
32
  const node_fs_1 = __importDefault(require("node:fs"));
39
33
  const tmp_1 = __importDefault(require("tmp"));
40
34
  const core_1 = require("../core");
@@ -53,12 +47,10 @@ function verifyRNOHPackage(_a) {
53
47
  if (!harPath) {
54
48
  throw new core_1.DescriptiveError({
55
49
  whatHappened: 'Attempted to verify har but no har was found',
56
- whatCanUserDo: {
57
- default: [
58
- 'Run this command without --no-harmony-code flag.',
59
- 'Create har files by running DevEco Studio > Build > Make Module (MODULE_NAME). The har file can be later found in MODULE_NAME/build/default/outputs/default/MODULE_NAME.har. Copy that file to the PACKAGE_ROOT/harmony directory.',
60
- ],
61
- },
50
+ whatCanUserDo: [
51
+ 'Run this command without --no-harmony-code flag.',
52
+ 'Create har files by running DevEco Studio > Build > Make Module (MODULE_NAME). The har file can be later found in MODULE_NAME/build/default/outputs/default/MODULE_NAME.har. Copy that file to the PACKAGE_ROOT/harmony directory.',
53
+ ],
62
54
  });
63
55
  }
64
56
  const tmpDirPath = new core_1.AbsolutePath(tmp_1.default.dirSync().name);
@@ -76,7 +68,6 @@ function verifyRNOHPackage(_a) {
76
68
  }
77
69
  });
78
70
  }
79
- exports.verifyRNOHPackage = verifyRNOHPackage;
80
71
  function runChecks(checks, checkNamesToSkip) {
81
72
  return __asyncGenerator(this, arguments, function* runChecks_1() {
82
73
  for (const { checkIf, run } of checks) {
package/jest.config.js CHANGED
@@ -1,10 +1,3 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
1
  /** @type {import('ts-jest').JestConfigWithTsJest} */
9
2
  module.exports = {
10
3
  preset: 'ts-jest',
package/package.json CHANGED
@@ -1,63 +1,67 @@
1
1
  {
2
2
  "name": "@react-native-oh/react-native-harmony-cli",
3
- "version": "0.0.30",
3
+ "version": "0.77.18-1",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
7
7
  "access": "public"
8
8
  },
9
9
  "scripts": {
10
- "build": "tsc --outDir dist -p tsconfig.build.json",
11
- "prepack": "npm run build",
10
+ "build": "tsc --outDir dist -p tsconfig.build.json && node ./scripts/copy-template.js",
11
+ "prepack": "npm run build && npm run _recreate-hvigor-plugin",
12
+ "_recreate-hvigor-plugin": "cd ../react-native-harmony-hvigor-plugin && npm i && npm run deploy && cd ../react-native-harmony-cli",
12
13
  "verify": "tsc --noEmit && npm run test",
13
14
  "test": "npm run build && jest",
14
15
  "test:codegen": "jest ./src/codegen/.* && npm run build && jest tests/codegen.*",
15
16
  "rn": "npm run build && react-native",
16
- "prepublishOnly": "npm run verify"
17
+ "dev": "tsc --outDir dist -p tsconfig.build.json --watch",
18
+ "prepublishOnly": "npm run build",
19
+ "deploy": "npm run verify && npm publish"
20
+ },
21
+ "bin": {
22
+ "rnoh-cli": "dist/commands/init.js"
17
23
  },
18
24
  "keywords": [],
19
25
  "author": "",
20
26
  "license": "MIT",
21
27
  "peerDependencies": {
22
- "metro": "*"
28
+ "metro": "^0.81.0"
23
29
  },
24
30
  "main": "dist/index.js",
25
31
  "devDependencies": {
32
+ "@react-native-community/cli": "^15.0.0",
26
33
  "@react-native-community/cli-types": "^11.3.0",
27
34
  "@types/adm-zip": "^0.5.5",
28
35
  "@types/fs-extra": "^11.0.1",
29
36
  "@types/jest": "^29.5.1",
30
- "@types/jszip": "^3.4.1",
31
37
  "@types/mustache": "^4.2.5",
32
38
  "@types/tar": "^6.1.5",
33
39
  "@types/tmp": "^0.2.3",
34
40
  "directory-tree": "^3.5.1",
35
41
  "execa": "npm:@esm2cjs/execa@^6.1.1-cjs.1",
36
42
  "jest": "^29.5.0",
37
- "react-native": "^0.72.0",
43
+ "react-native": "^0.77.1",
38
44
  "ts-jest": "^29.1.0",
39
- "ts-node": "^10.9.1",
40
45
  "typescript": "^5.0.4"
41
46
  },
42
47
  "dependencies": {
43
- "memfs": "^4.12.0",
44
48
  "@react-native-community/cli-tools": "^13.6.5",
45
- "@react-native/codegen": "0.74.0",
49
+ "@react-native/codegen": "0.77.1",
46
50
  "@tsconfig/recommended": "^1.0.2",
47
- "adm-zip": "^0.5.12",
48
51
  "case": "^1.6.3",
49
52
  "chalk": "^4",
53
+ "commander": "^14.0.0",
50
54
  "fs-extra": "^11.1.1",
51
- "glob": "^10.2.6",
52
- "ignore": "^5.2.4",
55
+ "inquirer": "^12.6.3",
53
56
  "json5": "^2.2.3",
57
+ "memfs": "4.12.0",
54
58
  "mustache": "^4.2.0",
55
59
  "tar": "^6.1.15",
56
60
  "tmp": "^0.2.1"
57
61
  },
58
- "homepage": "https://gitee.com/openharmony-sig/ohos_react_native",
62
+ "homepage": "https://gitcode.com/openharmony-sig/ohos_react_native",
59
63
  "repository": {
60
- "type": "gitee",
61
- "url": "https://gitee.com/openharmony-sig/ohos_react_native"
64
+ "type": "gitcode",
65
+ "url": "https://gitcode.com/openharmony-sig/ohos_react_native"
62
66
  }
63
67
  }
@@ -1,10 +1,3 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
1
  const { config: harmonyConfig } = require('./dist');
9
2
 
10
3
  /**
@@ -0,0 +1,18 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+
4
+ const templatesSrc = path.join(__dirname, '../src/init/templates/harmony');
5
+ const templatesDest = path.join(__dirname, '../dist/init/templates/harmony');
6
+ async function copyTemplate() {
7
+ try {
8
+ if (await fs.pathExists(templatesDest)) {
9
+ await fs.remove(templatesDest);
10
+ }
11
+ await fs.copy(templatesSrc, templatesDest);
12
+ console.log('Templates folder copied successfully!');
13
+ } catch (err) {
14
+ console.error('Error copying templates folder:', err);
15
+ }
16
+ }
17
+
18
+ copyTemplate();
@@ -4,25 +4,131 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE-MIT file in the root directory of this source tree.
6
6
  */
7
-
7
+ import fs from 'fs';
8
+ import pathUtils from 'path';
8
9
  import type { AssetData } from 'metro';
10
+ import { Logger } from './io';
11
+
12
+ type Path = string;
13
+ type CopiedFiles = Record<Path, Path>;
14
+
15
+ const ALLOWED_SCALES: number[] = [1, 2, 3, 4];
16
+
17
+ function filterAssetScales(
18
+ scales: readonly number[],
19
+ ): readonly number[] {
20
+ const result = scales.filter(scale => ALLOWED_SCALES.includes(scale));
21
+ if (result.length === 0 && scales.length > 0) {
22
+ // No matching scale found, but there are some available. Ideally we don't
23
+ // want to be in this situation and should throw, but for now as a fallback
24
+ // let's just use the closest larger image
25
+ const maxScale = ALLOWED_SCALES[ALLOWED_SCALES.length - 1];
26
+ for (const scale of scales) {
27
+ if (scale > maxScale) {
28
+ result.push(scale);
29
+ break;
30
+ }
31
+ }
32
+ // There is no larger scales available, use the largest we have
33
+ if (result.length === 0) {
34
+ result.push(scales[scales.length - 1]);
35
+ }
36
+ }
37
+ return result;
38
+ }
39
+
40
+ export async function copyAssets(
41
+ logger: Logger,
42
+ assetsData: readonly AssetData[],
43
+ assetsDest: Path
44
+ ): Promise<void> {
45
+ if (assetsDest == null) {
46
+ logger.warn((s) => 'Assets destination folder is not set, skipping...');
47
+ return;
48
+ }
49
+
50
+ const filesToCopy: CopiedFiles = {};
51
+ const addAssetToCopy = (asset: AssetData) => {
52
+ const validScales = filterAssetScales(asset.scales);
53
+ asset.scales.forEach((scale, idx) => {
54
+ if (!validScales.includes(scale)) {
55
+ return;
56
+ }
57
+ const src = asset.files[idx];
58
+ const dest = pathUtils.join(assetsDest, getAssetDestRelativePath(asset, scale));
59
+ filesToCopy[src] = dest;
60
+ });
61
+ };
62
+
63
+ assetsData.forEach(addAssetToCopy);
9
64
 
10
- export type Asset = AssetData;
65
+ return copyFiles(logger, filesToCopy);
66
+ }
11
67
 
12
- export function getAssetDestRelativePath(asset: Asset): string {
68
+ function getAssetDestRelativePath(asset: AssetData, scale: number = 1): string {
69
+ const suffix = scale === 1 ? '' : `@${scale}x`;
13
70
  const fileName = getResourceIdentifier(asset);
14
- return `${fileName}.${asset.type}`;
71
+ // Assets can have relative paths outside of the project root.
72
+ // Replace `../` with `_` to make sure they don't end up outside of
73
+ // the expected assets directory.
74
+ return `${fileName + suffix}.${asset.type}`.replace(/\.\.\//g, '_');
15
75
  }
16
76
 
17
- function getResourceIdentifier(asset: Asset): string {
77
+ function getResourceIdentifier(asset: AssetData): string {
18
78
  const folderPath = getBasePath(asset);
19
- return `${folderPath}/${asset.name}`.slice('assets/'.length);
79
+ return `${folderPath}/${asset.name}`.replace(/^assets\//, '');
80
+ }
81
+
82
+ function getBasePath(asset: AssetData): string {
83
+ const basePath = asset.httpServerLocation;
84
+ return basePath.startsWith('/') ? basePath.slice(1) : basePath;
20
85
  }
21
86
 
22
- function getBasePath(asset: Asset): string {
23
- let basePath = asset.httpServerLocation;
24
- if (basePath[0] === '/') {
25
- basePath = basePath.substr(1);
87
+ function copyFiles(logger: Logger, fileDestBySrc: CopiedFiles) {
88
+ const fileSources = Object.keys(fileDestBySrc);
89
+ if (fileSources.length === 0) {
90
+ return Promise.resolve();
26
91
  }
27
- return basePath;
92
+
93
+ const assetFilesCount = fileSources.length;
94
+ return new Promise<void>((resolve, reject) => {
95
+ const copyNext = (error?: Error) => {
96
+ if (error) {
97
+ reject(error);
98
+ return;
99
+ }
100
+ if (fileSources.length === 0) {
101
+ logger.info(
102
+ () =>
103
+ `Copied ${assetFilesCount} ${
104
+ assetFilesCount === 1 ? 'asset' : 'assets'
105
+ }`
106
+ );
107
+ resolve();
108
+ } else {
109
+ // fileSources.length === 0 is checked in previous branch, so this is string
110
+ const src = fileSources.shift()!;
111
+ const dest = fileDestBySrc[src];
112
+ copyFile(src, dest, copyNext);
113
+ }
114
+ };
115
+ copyNext();
116
+ });
117
+ }
118
+
119
+ function copyFile(
120
+ src: string,
121
+ dest: string,
122
+ onFinished: (error?: Error) => void
123
+ ): void {
124
+ const destDir = pathUtils.dirname(dest);
125
+ fs.mkdir(destDir, { recursive: true }, (err?) => {
126
+ if (err) {
127
+ onFinished(err);
128
+ return;
129
+ }
130
+ fs.createReadStream(src)
131
+ .pipe(fs.createWriteStream(dest))
132
+ .on('finish', onFinished);
133
+ });
28
134
  }
@@ -1,14 +1,8 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
1
  import { Autolinking, AutolinkingConfig } from './Autolinking';
9
2
  import { NestedDirectoryJSON } from 'memfs';
10
- import { AbsolutePath, DescriptiveError } from '../core';
3
+ import { AbsolutePath, DescriptiveError } from '../core/';
11
4
  import { MockedLogger, MemFS } from '../io/__fixtures__';
5
+ import pathUtils from "node:path"
12
6
 
13
7
  function createAutolinking({
14
8
  fsStructure,
@@ -98,7 +92,7 @@ it('should generate correct templates with scoped package default configuration'
98
92
  await runAutolinking();
99
93
 
100
94
  expect(
101
- memFS.readTextSync(new AbsolutePath('./harmony/oh-package.json5'))
95
+ memFS.readTextSync(new AbsolutePath('./harmony/oh-package.json5')).replace(/\\\\/g, '/')
102
96
  ).toBe(
103
97
  `
104
98
  {
@@ -162,7 +156,7 @@ std::vector<rnoh::Package::Shared> createRNOHPackages(const rnoh::Package::Conte
162
156
  # DO NOT modify it manually, your changes WILL be overwritten.
163
157
  cmake_minimum_required(VERSION 3.5)
164
158
 
165
- # @api
159
+ # @actor RNOH_APP
166
160
  function(autolink_libraries target)
167
161
  add_subdirectory("\${OH_MODULES_DIR}/@rnoh/rnoh--link-scoped/src/main/cpp" ./rnoh__rnoh__link_scoped)
168
162
 
@@ -210,9 +204,15 @@ it('should handle custom autolinking configuration', async () => {
210
204
  expect(memFS.readTextSync(output.etsRNOHPackagesFactoryPath)).toContain(
211
205
  'CustomEtsClass'
212
206
  );
207
+ expect(memFS.readTextSync(output.etsRNOHPackagesFactoryPath)).not.toContain(
208
+ 'CustomCppClass'
209
+ );
213
210
  expect(memFS.readTextSync(output.cppRNOHPackagesFactoryPath)).toContain(
214
211
  'CustomCppClass'
215
212
  );
213
+ expect(memFS.readTextSync(output.cppRNOHPackagesFactoryPath)).not.toContain(
214
+ 'CustomEtsClass'
215
+ );
216
216
  expect(memFS.readTextSync(output.cmakeAutolinkingPath)).toContain(
217
217
  'custom_cmake_target'
218
218
  );
@@ -323,14 +323,14 @@ it('should log updated files', async () => {
323
323
  const { logs } = await runAutolinking();
324
324
 
325
325
  const combinedLogs = logs.map((log) => log.msg).join('\n');
326
- expect(combinedLogs).toContain('harmony/entry/src/main/cpp/autolink.cmake');
327
- expect(combinedLogs).toContain(
328
- 'harmony/entry/src/main/ets/RNOHPackageFactory.ets'
326
+ expect(combinedLogs).toContain(pathUtils.normalize('harmony/entry/src/main/cpp/autolink.cmake'));
327
+ expect(combinedLogs).toContain(pathUtils.normalize(
328
+ 'harmony/entry/src/main/ets/RNOHPackageFactory.ets')
329
329
  );
330
- expect(combinedLogs).toContain(
331
- 'harmony/entry/src/main/cpp/RNOHPackageFactory.h'
330
+ expect(combinedLogs).toContain(pathUtils.normalize(
331
+ 'harmony/entry/src/main/cpp/RNOHPackageFactory.h')
332
332
  );
333
- expect(combinedLogs).toContain('harmony/oh-package.json5');
333
+ expect(combinedLogs).toContain(pathUtils.normalize('harmony/oh-package.json5'));
334
334
  });
335
335
 
336
336
  it('should log linked and skipped packages', async () => {
@@ -446,7 +446,6 @@ it('should link only specified packages', async () => {
446
446
  expect(combinedLogs).toContain('[skip] ignored-package');
447
447
  });
448
448
 
449
-
450
449
  it('should link by default only those packages that support autolinking', async () => {
451
450
  const { runAutolinking } = createAutolinking({
452
451
  fsStructure: {
@@ -480,4 +479,41 @@ it('should link by default only those packages that support autolinking', async
480
479
  const combinedLogs = logs.map((log) => log.msg).join('\n');
481
480
  expect(combinedLogs).toContain('[link] autolinkable-package');
482
481
  expect(combinedLogs).toContain('[skip] not-autolinkable-package');
483
- });
482
+ });
483
+
484
+ it('not delete packages with two hars', async () => {
485
+ const { runAutolinking, memFS } = createAutolinking({
486
+ fsStructure: {
487
+ ...baseFileStructure,
488
+ node_modules: {
489
+ '@rnoh': {
490
+ 'multiple-har': {
491
+ harmony: {
492
+ 'multiple_har.har': '',
493
+ 'some_other_har.har': '',
494
+ },
495
+ 'package.json': JSON.stringify({
496
+ name: '@rnoh/multiple-har',
497
+ harmony: {
498
+ autolinking: null,
499
+ },
500
+ }),
501
+ },
502
+ },
503
+ },
504
+ harmony: {
505
+ ...baseFileStructure.harmony,
506
+ 'oh-package.json5': `{
507
+ "dependencies": {
508
+ "@rnoh/multiple-har": "file:../node_modules/@rnoh/multiple-har/harmony/multiple_har.har",
509
+ }
510
+ }`,
511
+ },
512
+ },
513
+ });
514
+
515
+ const output = await runAutolinking();
516
+
517
+ const ohPackageContent = memFS.readTextSync(output.ohPackagePath);
518
+ expect(ohPackageContent).toContain('@rnoh/multiple-har');
519
+ });