@react-native-oh/react-native-harmony-cli 0.0.36 → 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 (229) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -4
  3. package/dist/autolinking/Autolinking.js +13 -16
  4. package/dist/autolinking/index.js +0 -6
  5. package/dist/codegen/core/CodeGenerator.js +0 -6
  6. package/dist/codegen/core/CodegenError.js +0 -6
  7. package/dist/codegen/core/EventUtils.js +0 -6
  8. package/dist/codegen/core/TypeAnnotationToTS.js +0 -6
  9. package/dist/codegen/core/UberSchema.js +2 -11
  10. package/dist/codegen/core/index.js +0 -6
  11. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +2 -7
  12. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +0 -6
  13. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +0 -6
  14. package/dist/codegen/generators/CppComponentCodeGenerator.js +0 -6
  15. package/dist/codegen/generators/LibGlueCodeGenerator.js +2 -8
  16. package/dist/codegen/generators/NativeModuleCodeGenerator.js +1 -7
  17. package/dist/codegen/generators/SharedComponentCodeGenerator.js +0 -6
  18. package/dist/codegen/generators/UberGeneratorV1.js +0 -6
  19. package/dist/codegen/generators/UberGeneratorV2.js +0 -6
  20. package/dist/codegen/generators/index.js +0 -6
  21. package/dist/codegen/index.js +0 -6
  22. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +0 -6
  23. package/dist/codegen/templates/BasePackageHTemplate.js +12 -7
  24. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +1 -6
  25. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +0 -6
  26. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -6
  27. package/dist/codegen/templates/IndexTSTemplate.js +0 -6
  28. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +12 -7
  29. package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -6
  30. package/dist/codegen/templates/TurboModuleHTemplate.js +0 -6
  31. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -6
  32. package/dist/codegen/templates/index.js +0 -6
  33. package/dist/commands/bundle-harmony.js +131 -36
  34. package/dist/commands/clean-harmony.js +84 -0
  35. package/dist/commands/codegen-harmony.js +0 -6
  36. package/dist/commands/codegen-lib-harmony.js +6 -12
  37. package/dist/commands/index.js +2 -9
  38. package/dist/commands/init-harmony.js +226 -0
  39. package/dist/commands/init.js +0 -0
  40. package/dist/commands/link-harmony.js +12 -16
  41. package/dist/commands/types.js +0 -6
  42. package/dist/commands/verify-package-harmony.js +6 -10
  43. package/dist/core/AbsolutePath.js +3 -6
  44. package/dist/core/CodegenConfig.js +0 -6
  45. package/dist/core/DescriptiveError.js +0 -6
  46. package/dist/core/FileSystem.js +0 -6
  47. package/dist/core/OHPackageJSON5.js +0 -6
  48. package/dist/core/ProjectDependenciesManager.js +6 -14
  49. package/dist/core/ValidationError.js +0 -6
  50. package/dist/core/ValueObject.js +0 -6
  51. package/dist/core/fs.js +13 -6
  52. package/dist/core/index.js +0 -6
  53. package/dist/index.js +2 -9
  54. package/dist/init/templates/AppScopeAppJSON5Template.js +30 -0
  55. package/dist/init/templates/AppScopeStringVarTemplate.js +28 -0
  56. package/dist/init/templates/EntryIndexTemplate.js +65 -0
  57. package/dist/init/templates/EntryStringVarTemplate.js +38 -0
  58. package/dist/init/templates/HvigorConfigJson5Template.js +44 -0
  59. package/dist/init/templates/MetroConfigTemplate.js +47 -0
  60. package/dist/init/templates/OhPackageJson5Template.js +37 -0
  61. package/dist/init/templates/harmony/AppScope/app.json5 +10 -0
  62. package/dist/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
  63. package/dist/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  64. package/dist/init/templates/harmony/build-profile.json5 +36 -0
  65. package/dist/init/templates/harmony/codelinter.json +32 -0
  66. package/dist/init/templates/harmony/entry/build-profile.json5 +18 -0
  67. package/dist/init/templates/harmony/entry/gitignore +7 -0
  68. package/dist/init/templates/harmony/entry/hvigorfile.ts +13 -0
  69. package/dist/init/templates/harmony/entry/oh-package.json5 +9 -0
  70. package/dist/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
  71. package/dist/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
  72. package/dist/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
  73. package/dist/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
  74. package/dist/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
  75. package/dist/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
  76. package/dist/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
  77. package/dist/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  78. package/dist/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
  79. package/dist/init/templates/harmony/entry/src/main/module.json5 +58 -0
  80. package/dist/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
  81. package/dist/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
  82. package/dist/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  83. package/dist/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  84. package/dist/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
  85. package/dist/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  86. package/dist/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  87. package/dist/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
  88. package/dist/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
  89. package/dist/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
  90. package/dist/init/templates/harmony/gitignore +16 -0
  91. package/dist/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
  92. package/dist/init/templates/harmony/hvigorfile.ts +7 -0
  93. package/dist/init/templates/index.js +21 -0
  94. package/dist/io/CliExecutor.js +0 -6
  95. package/dist/io/Logger.js +0 -6
  96. package/dist/io/RealFS.js +10 -6
  97. package/dist/io/TarGz.js +2 -8
  98. package/dist/io/__fixtures__.js +0 -6
  99. package/dist/io/fsUtils.js +0 -6
  100. package/dist/io/index.js +1 -6
  101. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +0 -6
  102. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +0 -6
  103. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +0 -6
  104. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +0 -6
  105. package/dist/package-verifier/checks/index.js +0 -6
  106. package/dist/package-verifier/index.js +0 -6
  107. package/dist/package-verifier/types.js +0 -6
  108. package/dist/package-verifier/verify-package.js +1 -7
  109. package/harmony/rnoh-hvigor-plugin-0.77.18.tgz +0 -0
  110. package/jest.config.js +0 -7
  111. package/package.json +15 -18
  112. package/react-native.config.js +0 -7
  113. package/scripts/copy-template.js +18 -0
  114. package/src/autolinking/Autolinking.test.ts +54 -18
  115. package/src/autolinking/Autolinking.ts +23 -20
  116. package/src/autolinking/index.ts +1 -8
  117. package/src/codegen/core/CodeGenerator.ts +0 -7
  118. package/src/codegen/core/CodegenError.ts +0 -7
  119. package/src/codegen/core/EventUtils.ts +0 -7
  120. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -7
  121. package/src/codegen/core/TypeAnnotationToTS.ts +3 -8
  122. package/src/codegen/core/UberSchema.ts +3 -12
  123. package/src/codegen/core/index.ts +0 -7
  124. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +5 -8
  125. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -7
  126. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -7
  127. package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -7
  128. package/src/codegen/generators/LibGlueCodeGenerator.ts +2 -9
  129. package/src/codegen/generators/NativeModuleCodeGenerator.ts +1 -8
  130. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -7
  131. package/src/codegen/generators/UberGeneratorV1.ts +0 -7
  132. package/src/codegen/generators/UberGeneratorV2.ts +0 -7
  133. package/src/codegen/generators/index.ts +0 -7
  134. package/src/codegen/index.ts +0 -7
  135. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -7
  136. package/src/codegen/templates/BasePackageHTemplate.ts +13 -8
  137. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +1 -7
  138. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -7
  139. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -7
  140. package/src/codegen/templates/IndexTSTemplate.ts +0 -7
  141. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +13 -8
  142. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -7
  143. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -7
  144. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -7
  145. package/src/codegen/templates/index.ts +0 -7
  146. package/src/commands/bundle-harmony.ts +174 -39
  147. package/src/commands/clean-harmony.ts +54 -0
  148. package/src/commands/codegen-harmony.ts +0 -7
  149. package/src/commands/codegen-lib-harmony.ts +6 -13
  150. package/src/commands/index.ts +2 -10
  151. package/src/commands/init-harmony.ts +299 -0
  152. package/src/commands/link-harmony.ts +13 -18
  153. package/src/commands/types.ts +0 -7
  154. package/src/commands/verify-package-harmony.ts +7 -10
  155. package/src/core/AbsolutePath.ts +4 -7
  156. package/src/core/CodegenConfig.ts +0 -7
  157. package/src/core/DescriptiveError.ts +0 -7
  158. package/src/core/FileSystem.ts +5 -8
  159. package/src/core/OHPackageJSON5.ts +0 -7
  160. package/src/core/PackageJSON.ts +0 -6
  161. package/src/core/ProjectDependenciesManager.ts +14 -22
  162. package/src/core/ValidationError.ts +0 -7
  163. package/src/core/ValueObject.ts +0 -7
  164. package/src/core/fs.ts +13 -7
  165. package/src/core/index.ts +0 -7
  166. package/src/index.ts +4 -13
  167. package/src/init/templates/AppScopeAppJSON5Template.ts +24 -0
  168. package/src/init/templates/AppScopeStringVarTemplate.ts +22 -0
  169. package/src/init/templates/EntryIndexTemplate.ts +59 -0
  170. package/src/init/templates/EntryStringVarTemplate.ts +31 -0
  171. package/src/init/templates/HvigorConfigJson5Template.ts +40 -0
  172. package/src/init/templates/MetroConfigTemplate.ts +41 -0
  173. package/src/init/templates/OhPackageJson5Template.ts +31 -0
  174. package/src/init/templates/harmony/AppScope/app.json5 +10 -0
  175. package/src/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
  176. package/src/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  177. package/src/init/templates/harmony/build-profile.json5 +36 -0
  178. package/src/init/templates/harmony/codelinter.json +32 -0
  179. package/src/init/templates/harmony/entry/build-profile.json5 +18 -0
  180. package/src/init/templates/harmony/entry/gitignore +7 -0
  181. package/src/init/templates/harmony/entry/hvigorfile.ts +13 -0
  182. package/src/init/templates/harmony/entry/oh-package.json5 +9 -0
  183. package/src/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
  184. package/src/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
  185. package/src/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
  186. package/src/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
  187. package/src/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
  188. package/src/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
  189. package/src/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
  190. package/src/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  191. package/src/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
  192. package/src/init/templates/harmony/entry/src/main/module.json5 +58 -0
  193. package/src/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
  194. package/src/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
  195. package/src/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  196. package/src/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  197. package/src/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
  198. package/src/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  199. package/src/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  200. package/src/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
  201. package/src/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
  202. package/src/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
  203. package/src/init/templates/harmony/gitignore +16 -0
  204. package/src/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
  205. package/src/init/templates/harmony/hvigorfile.ts +7 -0
  206. package/src/init/templates/index.ts +5 -0
  207. package/src/io/CliExecutor.ts +1 -8
  208. package/src/io/Logger.ts +0 -7
  209. package/src/io/RealFS.ts +15 -8
  210. package/src/io/TarGz.ts +1 -8
  211. package/src/io/__fixtures__.ts +1 -8
  212. package/src/io/fsUtils.ts +1 -7
  213. package/src/io/index.ts +1 -7
  214. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -7
  215. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -7
  216. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -7
  217. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -7
  218. package/src/package-verifier/checks/index.ts +0 -7
  219. package/src/package-verifier/index.ts +0 -7
  220. package/src/package-verifier/types.ts +0 -7
  221. package/src/package-verifier/verify-package.ts +0 -7
  222. package/tsconfig.build.json +2 -5
  223. package/tsconfig.json +4 -0
  224. package/dist/commands/create-metro-host-constants.js +0 -67
  225. package/dist/commands/pack-harmony.js +0 -106
  226. package/dist/commands/unpack-harmony.js +0 -189
  227. package/src/commands/create-metro-host-constants.ts +0 -55
  228. package/src/commands/pack-harmony.ts +0 -128
  229. package/src/commands/unpack-harmony.ts +0 -238
@@ -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
  import mustache from 'mustache';
9
2
  import Case from 'case';
10
3
  import { TypeAnnotation } from '../core';
@@ -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
  import mustache from 'mustache';
9
2
 
10
3
  const TEMPLATE = `
@@ -46,16 +39,26 @@ class {{name}}EventEmitRequestHandler : public EventEmitRequestHandler {
46
39
  public:
47
40
  void handleEvent(Context const &ctx) override {
48
41
  auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
42
+ auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
43
+
49
44
  if (eventEmitter == nullptr) {
50
45
  return;
51
46
  }
52
47
 
48
+ std::vector<std::string> supportedComponentNames = {
49
+ {{#arkTSComponents}}
50
+ "{{name}}",
51
+ {{/arkTSComponents}}
52
+ };
53
+
53
54
  std::vector<std::string> supportedEventNames = {
54
55
  {{#arkTSEvents}}
55
56
  "{{name}}",
56
57
  {{/arkTSEvents}}
57
58
  };
58
- if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
59
+
60
+ if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
61
+ std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
59
62
  eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
60
63
  }
61
64
  }
@@ -103,6 +106,7 @@ type GeneratedPackageTurboModule = {
103
106
  type GeneratedPackageComponent = {
104
107
  name: string;
105
108
  libraryCppName: string;
109
+ isArkTSComponent: boolean;
106
110
  };
107
111
 
108
112
  type ArkTSEvent = {
@@ -138,6 +142,7 @@ export class BasePackageHTemplate {
138
142
  name: this.name,
139
143
  turboModules: this.turboModules,
140
144
  components: this.components,
145
+ arkTSComponents: this.components.filter((component) => component.isArkTSComponent),
141
146
  arkTSEvents: this.arkTSEvents,
142
147
  libraries: Array.from(this.libraryCppNames).map((name) => ({
143
148
  name,
@@ -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
  import mustache from 'mustache';
9
2
 
10
3
  const TEMPLATE = `
@@ -26,6 +19,7 @@ const TEMPLATE = `
26
19
  namespace facebook {
27
20
  namespace react {
28
21
 
22
+ // RNOH patch
29
23
  constexpr char {{name}}ComponentName[] = "{{name}}";
30
24
 
31
25
  class {{name}}Props : public ViewProps {
@@ -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
  import mustache from 'mustache';
9
2
 
10
3
  const TEMPLATE = `
@@ -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
  import mustache from 'mustache';
9
2
 
10
3
  const TEMPLATE = `
@@ -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
  import mustache from 'mustache';
9
2
 
10
3
  const TEMPLATE = `
@@ -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
  import mustache from 'mustache';
9
2
 
10
3
  const TEMPLATE = `
@@ -49,16 +42,26 @@ class GeneratedEventEmitRequestHandler : public EventEmitRequestHandler {
49
42
  public:
50
43
  void handleEvent(Context const &ctx) override {
51
44
  auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
45
+ auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
46
+
52
47
  if (eventEmitter == nullptr) {
53
48
  return;
54
49
  }
55
50
 
51
+ std::vector<std::string> supportedComponentNames = {
52
+ {{#arkTSComponents}}
53
+ "{{name}}",
54
+ {{/arkTSComponents}}
55
+ };
56
+
56
57
  std::vector<std::string> supportedEventNames = {
57
58
  {{#supportedEvents}}
58
59
  "{{name}}",
59
60
  {{/supportedEvents}}
60
61
  };
61
- if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
62
+
63
+ if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
64
+ std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
62
65
  eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
63
66
  }
64
67
  }
@@ -105,6 +108,7 @@ type RNOHGeneratedPackageTurboModule = {
105
108
  type RNOHGeneratedPackageComponent = {
106
109
  name: string;
107
110
  supportedEventNames: string[];
111
+ isArkTSComponent: boolean;
108
112
  };
109
113
 
110
114
  export class RNOHGeneratedPackageHTemplate {
@@ -130,6 +134,7 @@ export class RNOHGeneratedPackageHTemplate {
130
134
  return mustache.render(TEMPLATE.trimStart(), {
131
135
  turboModules: this.turboModules,
132
136
  components: this.components,
137
+ arkTSComponents: this.components.filter((component) => component.isArkTSComponent),
133
138
  supportedEvents: this.supportedEventNames.map((eventName) => ({
134
139
  name: eventName,
135
140
  })),
@@ -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
  import mustache from 'mustache';
9
2
 
10
3
  const TEMPLATE = `
@@ -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
  import mustache from 'mustache';
9
2
 
10
3
  const TEMPLATE = `
@@ -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
  import mustache from 'mustache';
9
2
 
10
3
  const TEMPLATE = `
@@ -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
  export * from './TurboModuleHTemplate';
9
2
  export * from './TurboModuleCppTemplate';
10
3
  export * from './RNOHGeneratedPackageHTemplate';
@@ -1,28 +1,38 @@
1
- /**
2
- * Copyright (c) 2024-2025 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 { Command } from './types';
9
- import fs from 'fs';
2
+ import fs from 'node:fs';
3
+ import os from 'os';
10
4
  import fse from 'fs-extra';
11
5
  import Metro from 'metro';
12
6
  import { RunBuildOptions as BuildOptions } from 'metro';
13
7
  import MetroServer from 'metro/src/Server';
14
8
  import pathUtils from 'path';
15
9
  import { copyAssets } from '../assetResolver';
16
- import { ConfigT as MetroConfig } from 'metro-config';
10
+ import { execSync } from 'child_process';
17
11
  import { Logger } from '../io';
12
+ import { DescriptiveError } from '../core';
13
+ import { randomUUID } from 'node:crypto';
14
+
15
+ type MetroConfig = Awaited<ReturnType<typeof Metro.loadConfig>>;
18
16
 
19
- const ARK_RESOURCE_PATH = './harmony/entry/src/main/resources/rawfile';
20
- const ASSETS_DEFAULT_DEST_PATH =
21
- './harmony/entry/src/main/resources/rawfile/assets';
17
+ const HERMESC_BIN_PATH = {
18
+ darwin: pathUtils.normalize('osx-bin/hermesc'),
19
+ linux: pathUtils.normalize('linux64-bin/hermesc'),
20
+ win32: pathUtils.normalize('win64-bin/hermesc.exe'),
21
+ };
22
+ const HERMESC_PATH_PREFIX = pathUtils.normalize(
23
+ './node_modules/react-native/sdks/hermesc/'
24
+ );
25
+ const HARMONY_RESOURCE_PATH = pathUtils.normalize(
26
+ './harmony/entry/src/main/resources/rawfile'
27
+ );
28
+ const ASSETS_DEFAULT_DEST_PATH = pathUtils.normalize(
29
+ './harmony/entry/src/main/resources/rawfile/assets'
30
+ );
22
31
 
23
32
  type AssetData = Metro.AssetData;
24
33
  type Bundle = { code: string; map: string };
25
34
  type Path = string;
35
+ type OSType = 'darwin' | 'linux' | 'win32';
26
36
 
27
37
  export const commandBundleHarmony: Command = {
28
38
  name: 'bundle-harmony',
@@ -40,58 +50,131 @@ export const commandBundleHarmony: Command = {
40
50
  description:
41
51
  'Path to the root JS file, either absolute or relative to JS root',
42
52
  default: 'index.js',
53
+ parse: (val: string) => pathUtils.normalize(val),
54
+ },
55
+ {
56
+ name: '--reset-cache',
57
+ description: 'Removes cached files',
58
+ default: false,
43
59
  },
44
60
  {
45
61
  name: '--config <path>',
46
62
  description: 'Path to the Metro configuration file',
63
+ parse: (val: string) => pathUtils.normalize(val),
47
64
  },
48
65
  {
49
66
  name: '--bundle-output <path>',
67
+ description: `File path where to store the resulting bundle (default: "${HARMONY_RESOURCE_PATH}${pathUtils.sep}bundle.harmony.js")`,
68
+ parse: (val: string) => pathUtils.normalize(val),
69
+ },
70
+ {
71
+ name: '--js-engine <string>',
50
72
  description:
51
- 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
52
- default: ARK_RESOURCE_PATH + '/bundle.harmony.js',
73
+ 'JavaScript engine used to run the bundle. Supported engines: "hermes" and "any" (default: "any"). Setting this option to "hermes" will generate a HBC bundle instead of a JS bundle.',
74
+ default: 'any',
75
+ parse: (val: string) => {
76
+ if (val !== 'any' && val !== 'hermes') {
77
+ throw new Error(
78
+ `Only "any" and "hermes" are supported as JavaScript engines, but "${val}" was provided`
79
+ );
80
+ }
81
+ return val;
82
+ },
53
83
  },
54
84
  {
55
85
  name: '--assets-dest <path>',
56
86
  description:
57
87
  'Directory name where to store assets referenced in the bundle',
58
88
  default: ASSETS_DEFAULT_DEST_PATH,
89
+ parse: (val: string) => pathUtils.normalize(val),
59
90
  },
60
91
  {
61
92
  name: '--sourcemap-output <path>',
62
93
  description:
63
94
  'File name where to store the resulting source map, ex. /tmp/groups.map',
95
+ parse: (val: string) => pathUtils.normalize(val),
64
96
  },
65
97
  {
66
98
  name: '--minify [boolean]',
67
99
  description: 'Allows overriding whether bundle is minified',
68
100
  parse: (val: string) => val !== 'false',
69
101
  },
102
+ {
103
+ name: '--hermesc-dir <path>',
104
+ description:
105
+ 'Path to hermesc directory. Relevant when --js-engine set to "hermes".',
106
+ default: HERMESC_PATH_PREFIX,
107
+ parse: (val: string) => pathUtils.normalize(val),
108
+ },
109
+ {
110
+ name: '--hermesc-options <string...>',
111
+ description:
112
+ 'Additional options to pass to hermesc when generating HBC bundle. Example: --hermesc-options O g reuse-prop-cache. Relevant when --js-engine set to "hermes".',
113
+ parse: (val, prev) => (prev ? [...prev, val] : [val]),
114
+ },
70
115
  ],
71
116
  func: async (argv, config, args: any) => {
72
117
  const logger = new Logger();
73
- const buildOptions: BuildOptions = {
74
- entry: args.entryFile,
75
- platform: 'harmony',
76
- minify: args.minify !== undefined ? args.minify : !args.dev,
77
- dev: args.dev,
78
- sourceMap: args.sourcemapOutput,
79
- sourceMapUrl: args.sourcemapOutput,
80
- };
81
- const metroConfig = await loadMetroConfig(args.config);
82
- const bundle = await createBundle(metroConfig, buildOptions);
83
- await saveBundle(bundle, args.bundleOutput, args.sourcemapOutput);
84
- const assets = await retrieveAssetsData(metroConfig, buildOptions);
85
- copyAssets(logger, assets, args.assetsDest);
118
+ try {
119
+ const defaultBundleName =
120
+ args.jsEngine === 'hermes' ? 'hermes_bundle.hbc' : 'bundle.harmony.js';
121
+ const bundleOutput: string =
122
+ args.bundleOutput ??
123
+ `${HARMONY_RESOURCE_PATH}${pathUtils.sep}${defaultBundleName}`;
124
+ const shouldGenerateHbcBundle = bundleOutput
125
+ .toLowerCase()
126
+ .endsWith('hbc');
127
+ await fse.ensureDir(pathUtils.dirname(bundleOutput));
128
+ const assetsDest: Path = args.assetsDest;
129
+ await fse.ensureDir(assetsDest);
130
+ const buildOptions: BuildOptions = {
131
+ entry: args.entryFile,
132
+ platform: 'harmony',
133
+ minify: args.minify !== undefined ? args.minify : !args.dev,
134
+ dev: args.dev,
135
+ sourceMap: args.sourcemapOutput,
136
+ sourceMapUrl: args.sourcemapOutput,
137
+ };
138
+ const metroConfig = await loadMetroConfig({
139
+ config: args.config,
140
+ resetCache: args.resetCache,
141
+ });
142
+
143
+ const bundle = await createBundle(metroConfig, buildOptions);
144
+ const assets = await retrieveAssetsData(metroConfig, buildOptions);
145
+
146
+ if (shouldGenerateHbcBundle) {
147
+ await saveHbcBundle(
148
+ logger,
149
+ bundle.code,
150
+ bundleOutput,
151
+ args.hermescDir,
152
+ args.hermescOptions
153
+ );
154
+ } else {
155
+ await saveJSBundle(logger, bundle, bundleOutput);
156
+ }
157
+ maybeSaveSourceMap(logger, bundle, args.sourcemapOutput);
158
+ await copyAssets(logger, assets, assetsDest);
159
+ } catch (err) {
160
+ if (err instanceof DescriptiveError) {
161
+ logger.descriptiveError(err);
162
+ return;
163
+ } else {
164
+ throw err;
165
+ }
166
+ }
86
167
  },
87
168
  };
88
169
 
89
- async function loadMetroConfig(
90
- configPath: Path | undefined
91
- ): Promise<MetroConfig> {
92
- return configPath
93
- ? await Metro.loadConfig({ config: configPath })
94
- : await Metro.loadConfig();
170
+ async function loadMetroConfig(options: {
171
+ config: Path | undefined;
172
+ resetCache: boolean;
173
+ }): Promise<MetroConfig> {
174
+ if (!options.config) {
175
+ delete options.config;
176
+ }
177
+ return await Metro.loadConfig(options);
95
178
  }
96
179
 
97
180
  async function createBundle(
@@ -103,17 +186,68 @@ async function createBundle(
103
186
  return (await Metro.runBuild(metroConfig, buildOptions)) as unknown as Bundle;
104
187
  }
105
188
 
106
- async function saveBundle(
107
- bundle: Bundle,
189
+ async function saveHbcBundle(
190
+ logger: Logger,
191
+ bundleCode: string,
108
192
  bundleOutput: Path,
109
- sourceMapOutput: Path | undefined
193
+ hermescPath: string,
194
+ hermescOptions: string[] | undefined
195
+ ) {
196
+ if (
197
+ process.platform !== 'darwin' &&
198
+ process.platform !== 'linux' &&
199
+ process.platform !== 'win32'
200
+ ) {
201
+ throw new Error(`Unsupported platform ${process.platform} (⊙︿⊙)`);
202
+ }
203
+ const resolvedHermescPath = pathUtils.resolve(
204
+ hermescPath,
205
+ HERMESC_BIN_PATH[process.platform as OSType]
206
+ );
207
+
208
+ if (!fs.existsSync(resolvedHermescPath)) {
209
+ throw new DescriptiveError({
210
+ whatHappened: `Couldn't find hermesc at ${resolvedHermescPath}`,
211
+ whatCanUserDo: [
212
+ 'Find hermesc dir and provide it by using --hermesc-dir argument. hermesc dir should be in react-native package.',
213
+ ],
214
+ });
215
+ }
216
+
217
+ const tmpBundlePath = `${os.tmpdir()}${pathUtils.sep}b-${randomUUID()}.harmony.js`;
218
+ await fse.writeFile(tmpBundlePath, bundleCode);
219
+ const hbcFilePath = bundleOutput.endsWith('.hbc')
220
+ ? bundleOutput
221
+ : pathUtils.join(pathUtils.dirname(bundleOutput), 'hermes_bundle.hbc');
222
+ const hermescOptionsString =
223
+ hermescOptions?.map((e) => `-${e}`).join(' ') || '';
224
+ execSync(
225
+ `${resolvedHermescPath} ${hermescOptionsString} --emit-binary -out ${hbcFilePath} ${tmpBundlePath}`,
226
+ {
227
+ stdio: 'inherit',
228
+ }
229
+ );
230
+ fs.unlinkSync(tmpBundlePath);
231
+ logger.info((s) => `Created ${hbcFilePath}`);
232
+ }
233
+
234
+ async function saveJSBundle(
235
+ logger: Logger,
236
+ bundle: Bundle,
237
+ bundleOutput: Path
110
238
  ) {
111
- await fse.ensureDir(pathUtils.dirname(bundleOutput));
112
239
  fs.writeFileSync(bundleOutput, bundle.code);
113
- console.log(`[CREATED] ${bundleOutput}`);
240
+ logger.info((s) => `Created ${bundleOutput}`);
241
+ }
242
+
243
+ function maybeSaveSourceMap(
244
+ logger: Logger,
245
+ bundle: Bundle,
246
+ sourceMapOutput: Path | undefined
247
+ ) {
114
248
  if (sourceMapOutput) {
115
249
  fs.writeFileSync(sourceMapOutput, bundle.map);
116
- console.log(`[CREATED] ${sourceMapOutput}`);
250
+ logger.info((s) => `Created ${sourceMapOutput}`);
117
251
  }
118
252
  }
119
253
 
@@ -127,6 +261,7 @@ async function retrieveAssetsData(
127
261
  ...MetroServer.DEFAULT_BUNDLE_OPTIONS,
128
262
  ...buildOptions,
129
263
  entryFile: buildOptions.entry,
264
+ bundleType: 'todo',
130
265
  });
131
266
  } finally {
132
267
  metroServer.end();
@@ -0,0 +1,54 @@
1
+ import { AbsolutePath, maybeReadFile } from '../core';
2
+ import { Command } from './types';
3
+ import JSON5 from 'json5';
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import os from 'node:os';
7
+ import * as crypto from 'node:crypto';
8
+
9
+ const COMMAND_NAME = 'clean-harmony';
10
+ export const commandCleanHarmony: Command = {
11
+ name: COMMAND_NAME,
12
+ description: 'Remove cached files in the OpenHarmony project.',
13
+ options: [
14
+ {
15
+ name: "--harmony-project-path <path>",
16
+ description: "Specifies the root of your OpenHarmony project.",
17
+ default: "./harmony"
18
+ }
19
+ ],
20
+ func: async (_argv, _config, rawArgs: any) => {
21
+ const harmonyProjectPath = new AbsolutePath(rawArgs.harmonyProjectPath);
22
+ const md5Path = crypto.createHash("md5").update(harmonyProjectPath.getValue()).digest("hex");
23
+ const hvigorCachePath = new AbsolutePath(path.join(os.homedir(), ".hvigor", "project_caches", md5Path));
24
+
25
+ if (fs.existsSync(hvigorCachePath.getValue())) {
26
+ fs.rmSync(hvigorCachePath.getValue(), { recursive: true, force: true });
27
+ }
28
+
29
+ const buildProfilePath = harmonyProjectPath.copyWithNewSegment('build-profile.json5');
30
+ const buildProfileContent = maybeReadFile(buildProfilePath);
31
+
32
+ if (buildProfileContent) {
33
+ const buildProfile = JSON5.parse(buildProfileContent);
34
+
35
+ if (Array.isArray(buildProfile.modules)) {
36
+ buildProfile.modules.forEach((module: any) => {
37
+ if (module && module.srcPath) {
38
+ const modulePath = harmonyProjectPath.copyWithNewSegment(module.srcPath);
39
+ const cxxPath = modulePath.copyWithNewSegment('.cxx');
40
+ const buildPath = modulePath.copyWithNewSegment('build');
41
+
42
+ if (fs.existsSync(cxxPath.getValue())) {
43
+ fs.rmSync(cxxPath.getValue(), { recursive: true, force: true });
44
+ }
45
+
46
+ if (fs.existsSync(buildPath.getValue())) {
47
+ fs.rmSync(buildPath.getValue(), { recursive: true, force: true });
48
+ }
49
+ }
50
+ });
51
+ }
52
+ }
53
+ }
54
+ };
@@ -1,10 +1,3 @@
1
- /**
2
- * Copyright (c) 2024-2025 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 pathUtils from 'node:path';
9
2
  import Case from 'case';
10
3
  import { Command } from './types';
@@ -1,10 +1,3 @@
1
- /**
2
- * Copyright (c) 2024-2025 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 { Command } from './types';
9
2
  import {
10
3
  AbsolutePath,
@@ -37,22 +30,22 @@ export const commandCodegenLibHarmony: Command = {
37
30
  'Name of your React Native library. This value is processed and used as a directory name for C++ files to reduce the chances of conflicts between libraries.',
38
31
  },
39
32
  {
40
- name: '--turbo-modules-spec-paths [path]',
33
+ name: '--turbo-modules-spec-paths [path...]',
41
34
  description:
42
35
  'Path or paths to Turbo Module spec files. Each path can point to a spec file or a directory containing spec files.',
43
- parse: (val: string) => val.split(' '),
36
+ parse: (val, prev) => (prev ? [...prev, val] : [val]),
44
37
  },
45
38
  {
46
- name: '--arkts-components-spec-paths [path]',
39
+ name: '--arkts-components-spec-paths [path...]',
47
40
  description:
48
41
  'Path or paths to component spec files used to generate code for components to be implemented on the ArkTS side. Each path can point to a spec file or a directory containing spec files.',
49
- parse: (val: string) => val.split(' '),
42
+ parse: (val, prev) => (prev ? [...prev, val] : [val]),
50
43
  },
51
44
  {
52
- name: '--cpp-components-spec-paths [path]',
45
+ name: '--cpp-components-spec-paths [path...]',
53
46
  description:
54
47
  'Path or paths to component spec files used to generate code for components to be implemented on the C++ side. Each path can point to a spec file or a directory containing spec files.',
55
- parse: (val: string) => val.split(' '),
48
+ parse: (val, prev) => (prev ? [...prev, val] : [val]),
56
49
  },
57
50
  {
58
51
  name: '--cpp-output-path <path>',
@@ -1,16 +1,8 @@
1
- /**
2
- * Copyright (c) 2024-2025 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
  export * from './bundle-harmony';
9
- export * from './pack-harmony';
10
- export * from './unpack-harmony';
11
- export * from './create-metro-host-constants';
12
2
  export * from './codegen-harmony';
13
3
  export * from './verify-package-harmony';
14
4
  export * from './codegen-lib-harmony';
15
5
  export * from './link-harmony';
16
6
  export * from './run-harmony';
7
+ export * from './init-harmony';
8
+ export * from './clean-harmony';