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

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 (234) 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/jest.config.js +0 -7
  113. package/package.json +20 -16
  114. package/react-native.config.js +0 -7
  115. package/scripts/copy-template.js +18 -0
  116. package/src/assetResolver.ts +117 -11
  117. package/src/autolinking/Autolinking.test.ts +54 -18
  118. package/src/autolinking/Autolinking.ts +32 -31
  119. package/src/autolinking/index.ts +1 -8
  120. package/src/codegen/core/CodeGenerator.ts +0 -7
  121. package/src/codegen/core/CodegenError.ts +0 -7
  122. package/src/codegen/core/EventUtils.ts +3 -12
  123. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -7
  124. package/src/codegen/core/TypeAnnotationToTS.ts +3 -8
  125. package/src/codegen/core/UberSchema.ts +9 -22
  126. package/src/codegen/core/index.ts +0 -7
  127. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +5 -8
  128. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +3 -7
  129. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +3 -7
  130. package/src/codegen/generators/CppComponentCodeGenerator.ts +3 -7
  131. package/src/codegen/generators/LibGlueCodeGenerator.ts +2 -9
  132. package/src/codegen/generators/NativeModuleCodeGenerator.ts +1 -8
  133. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -7
  134. package/src/codegen/generators/UberGeneratorV1.ts +0 -7
  135. package/src/codegen/generators/UberGeneratorV2.ts +0 -7
  136. package/src/codegen/generators/index.ts +0 -7
  137. package/src/codegen/index.ts +0 -7
  138. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -7
  139. package/src/codegen/templates/BasePackageHTemplate.ts +13 -8
  140. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +1 -7
  141. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +24 -8
  142. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -7
  143. package/src/codegen/templates/IndexTSTemplate.ts +0 -7
  144. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +13 -8
  145. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -7
  146. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -7
  147. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -7
  148. package/src/codegen/templates/index.ts +0 -7
  149. package/src/commands/bundle-harmony.ts +178 -118
  150. package/src/commands/clean-harmony.ts +54 -0
  151. package/src/commands/codegen-harmony.ts +13 -25
  152. package/src/commands/codegen-lib-harmony.ts +16 -28
  153. package/src/commands/index.ts +3 -10
  154. package/src/commands/init-harmony.ts +299 -0
  155. package/src/commands/init.ts +755 -0
  156. package/src/commands/link-harmony.ts +14 -19
  157. package/src/commands/run-harmony.ts +478 -0
  158. package/src/commands/types.ts +14 -0
  159. package/src/commands/verify-package-harmony.ts +9 -12
  160. package/src/core/AbsolutePath.ts +4 -7
  161. package/src/core/CodegenConfig.ts +3 -12
  162. package/src/core/DescriptiveError.ts +8 -15
  163. package/src/core/FileSystem.ts +5 -8
  164. package/src/core/OHPackageJSON5.ts +0 -7
  165. package/src/core/PackageJSON.ts +4 -13
  166. package/src/core/ProjectDependenciesManager.ts +14 -22
  167. package/src/core/ValidationError.ts +0 -7
  168. package/src/core/ValueObject.ts +0 -7
  169. package/src/core/fs.ts +14 -8
  170. package/src/core/index.ts +0 -7
  171. package/src/index.ts +8 -15
  172. package/src/init/templates/AppScopeAppJSON5Template.ts +24 -0
  173. package/src/init/templates/AppScopeStringVarTemplate.ts +22 -0
  174. package/src/init/templates/EntryIndexTemplate.ts +59 -0
  175. package/src/init/templates/EntryStringVarTemplate.ts +31 -0
  176. package/src/init/templates/HvigorConfigJson5Template.ts +40 -0
  177. package/src/init/templates/MetroConfigTemplate.ts +41 -0
  178. package/src/init/templates/OhPackageJson5Template.ts +31 -0
  179. package/src/init/templates/harmony/AppScope/app.json5 +10 -0
  180. package/src/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
  181. package/src/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  182. package/src/init/templates/harmony/build-profile.json5 +36 -0
  183. package/src/init/templates/harmony/codelinter.json +32 -0
  184. package/src/init/templates/harmony/entry/build-profile.json5 +18 -0
  185. package/src/init/templates/harmony/entry/gitignore +7 -0
  186. package/src/init/templates/harmony/entry/hvigorfile.ts +13 -0
  187. package/src/init/templates/harmony/entry/oh-package.json5 +9 -0
  188. package/src/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
  189. package/src/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
  190. package/src/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
  191. package/src/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
  192. package/src/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
  193. package/src/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
  194. package/src/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
  195. package/src/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  196. package/src/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
  197. package/src/init/templates/harmony/entry/src/main/module.json5 +58 -0
  198. package/src/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
  199. package/src/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
  200. package/src/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  201. package/src/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  202. package/src/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
  203. package/src/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  204. package/src/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  205. package/src/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
  206. package/src/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
  207. package/src/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
  208. package/src/init/templates/harmony/gitignore +16 -0
  209. package/src/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
  210. package/src/init/templates/harmony/hvigorfile.ts +7 -0
  211. package/src/init/templates/index.ts +5 -0
  212. package/src/io/CliExecutor.ts +55 -40
  213. package/src/io/Logger.ts +77 -51
  214. package/src/io/RealFS.ts +15 -8
  215. package/src/io/TarGz.ts +1 -8
  216. package/src/io/__fixtures__.ts +15 -18
  217. package/src/io/fsUtils.ts +1 -7
  218. package/src/io/index.ts +1 -7
  219. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -7
  220. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -7
  221. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -7
  222. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -7
  223. package/src/package-verifier/checks/index.ts +0 -7
  224. package/src/package-verifier/index.ts +0 -7
  225. package/src/package-verifier/types.ts +0 -7
  226. package/src/package-verifier/verify-package.ts +4 -13
  227. package/tsconfig.build.json +2 -5
  228. package/tsconfig.json +4 -0
  229. package/dist/commands/create-metro-host-constants.js +0 -67
  230. package/dist/commands/pack-harmony.js +0 -106
  231. package/dist/commands/unpack-harmony.js +0 -191
  232. package/src/commands/create-metro-host-constants.ts +0 -55
  233. package/src/commands/pack-harmony.ts +0 -128
  234. 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 __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 __importDefault = (this && this.__importDefault) || function (mod) {
9
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
9
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
@@ -50,16 +44,26 @@ class {{name}}EventEmitRequestHandler : public EventEmitRequestHandler {
50
44
  public:
51
45
  void handleEvent(Context const &ctx) override {
52
46
  auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
47
+ auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
48
+
53
49
  if (eventEmitter == nullptr) {
54
50
  return;
55
51
  }
56
52
 
53
+ std::vector<std::string> supportedComponentNames = {
54
+ {{#arkTSComponents}}
55
+ "{{name}}",
56
+ {{/arkTSComponents}}
57
+ };
58
+
57
59
  std::vector<std::string> supportedEventNames = {
58
60
  {{#arkTSEvents}}
59
61
  "{{name}}",
60
62
  {{/arkTSEvents}}
61
63
  };
62
- if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
64
+
65
+ if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
66
+ std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
63
67
  eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
64
68
  }
65
69
  }
@@ -126,6 +130,7 @@ class BasePackageHTemplate {
126
130
  name: this.name,
127
131
  turboModules: this.turboModules,
128
132
  components: this.components,
133
+ arkTSComponents: this.components.filter((component) => component.isArkTSComponent),
129
134
  arkTSEvents: this.arkTSEvents,
130
135
  libraries: Array.from(this.libraryCppNames).map((name) => ({
131
136
  name,
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
9
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
@@ -30,6 +24,7 @@ const TEMPLATE = `
30
24
  namespace facebook {
31
25
  namespace react {
32
26
 
27
+ // RNOH patch
33
28
  constexpr char {{name}}ComponentName[] = "{{name}}";
34
29
 
35
30
  class {{name}}Props : public ViewProps {
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
9
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
@@ -32,6 +26,14 @@ class {{name}}JSIBinder : public ViewComponentJSIBinder {
32
26
  return object;
33
27
  }
34
28
 
29
+ facebook::jsi::Object createCommands(facebook::jsi::Runtime &rt) override {
30
+ auto commands = ViewComponentJSIBinder::createCommands(rt);
31
+ {{#commands}}
32
+ commands.setProperty(rt, "{{name}}", "{{name}}");
33
+ {{/commands}}
34
+ return commands;
35
+ }
36
+
35
37
  facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
36
38
  facebook::jsi::Object events(rt);
37
39
  {{#bubblingEvents}}
@@ -55,11 +57,15 @@ class ComponentJSIBinderHTemplate {
55
57
  this.name = name;
56
58
  this.codegenNoticeLines = codegenNoticeLines;
57
59
  this.props = [];
60
+ this.commands = [];
58
61
  this.events = [];
59
62
  }
60
63
  addProp(prop) {
61
64
  this.props.push(prop);
62
65
  }
66
+ addCommand(command) {
67
+ this.commands.push(command);
68
+ }
63
69
  addEvent(event) {
64
70
  this.events.push(event);
65
71
  }
@@ -73,6 +79,9 @@ class ComponentJSIBinderHTemplate {
73
79
  name: prop.name,
74
80
  type: prop.isObject ? '"Object"' : 'true',
75
81
  })),
82
+ commands: this.commands.map((command) => ({
83
+ name: command.name,
84
+ })),
76
85
  bubblingEvents: this.events
77
86
  .filter((event) => event.type === 'bubble')
78
87
  .map((event) => ({
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
9
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
9
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
9
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
@@ -53,16 +47,26 @@ class GeneratedEventEmitRequestHandler : public EventEmitRequestHandler {
53
47
  public:
54
48
  void handleEvent(Context const &ctx) override {
55
49
  auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
50
+ auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
51
+
56
52
  if (eventEmitter == nullptr) {
57
53
  return;
58
54
  }
59
55
 
56
+ std::vector<std::string> supportedComponentNames = {
57
+ {{#arkTSComponents}}
58
+ "{{name}}",
59
+ {{/arkTSComponents}}
60
+ };
61
+
60
62
  std::vector<std::string> supportedEventNames = {
61
63
  {{#supportedEvents}}
62
64
  "{{name}}",
63
65
  {{/supportedEvents}}
64
66
  };
65
- if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
67
+
68
+ if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
69
+ std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
66
70
  eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
67
71
  }
68
72
  }
@@ -121,6 +125,7 @@ class RNOHGeneratedPackageHTemplate {
121
125
  return mustache_1.default.render(TEMPLATE.trimStart(), {
122
126
  turboModules: this.turboModules,
123
127
  components: this.components,
128
+ arkTSComponents: this.components.filter((component) => component.isArkTSComponent),
124
129
  supportedEvents: this.supportedEventNames.map((eventName) => ({
125
130
  name: eventName,
126
131
  })),
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
9
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
9
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
9
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
@@ -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 __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) {
@@ -19,14 +13,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
13
  };
20
14
  Object.defineProperty(exports, "__esModule", { value: true });
21
15
  exports.commandBundleHarmony = void 0;
22
- const fs_1 = __importDefault(require("fs"));
16
+ const node_fs_1 = __importDefault(require("node:fs"));
17
+ const os_1 = __importDefault(require("os"));
23
18
  const fs_extra_1 = __importDefault(require("fs-extra"));
24
19
  const metro_1 = __importDefault(require("metro"));
25
20
  const Server_1 = __importDefault(require("metro/src/Server"));
26
21
  const path_1 = __importDefault(require("path"));
27
22
  const assetResolver_1 = require("../assetResolver");
28
- const ARK_RESOURCE_PATH = './harmony/entry/src/main/resources/rawfile';
29
- const ASSETS_DEFAULT_DEST_PATH = './harmony/entry/src/main/resources/rawfile/assets';
23
+ const child_process_1 = require("child_process");
24
+ const io_1 = require("../io");
25
+ const core_1 = require("../core");
26
+ const node_crypto_1 = require("node:crypto");
27
+ const HERMESC_BIN_PATH = {
28
+ darwin: path_1.default.normalize('osx-bin/hermesc'),
29
+ linux: path_1.default.normalize('linux64-bin/hermesc'),
30
+ win32: path_1.default.normalize('win64-bin/hermesc.exe'),
31
+ };
32
+ const HERMESC_PATH_PREFIX = path_1.default.normalize('./node_modules/react-native/sdks/hermesc/');
33
+ const HARMONY_RESOURCE_PATH = path_1.default.normalize('./harmony/entry/src/main/resources/rawfile');
34
+ const ASSETS_DEFAULT_DEST_PATH = path_1.default.normalize('./harmony/entry/src/main/resources/rawfile/assets');
30
35
  exports.commandBundleHarmony = {
31
36
  name: 'bundle-harmony',
32
37
  description: 'Creates JS bundle, creates a special cpp header containing the JS code, copies assets directory to the project.',
@@ -41,52 +46,114 @@ exports.commandBundleHarmony = {
41
46
  name: '--entry-file <path>',
42
47
  description: 'Path to the root JS file, either absolute or relative to JS root',
43
48
  default: 'index.js',
49
+ parse: (val) => path_1.default.normalize(val),
50
+ },
51
+ {
52
+ name: '--reset-cache',
53
+ description: 'Removes cached files',
54
+ default: false,
44
55
  },
45
56
  {
46
57
  name: '--config <path>',
47
58
  description: 'Path to the Metro configuration file',
59
+ parse: (val) => path_1.default.normalize(val),
48
60
  },
49
61
  {
50
62
  name: '--bundle-output <path>',
51
- description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
52
- default: ARK_RESOURCE_PATH + '/bundle.harmony.js',
63
+ description: `File path where to store the resulting bundle (default: "${HARMONY_RESOURCE_PATH}${path_1.default.sep}bundle.harmony.js")`,
64
+ parse: (val) => path_1.default.normalize(val),
65
+ },
66
+ {
67
+ name: '--js-engine <string>',
68
+ description: '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.',
69
+ default: 'any',
70
+ parse: (val) => {
71
+ if (val !== 'any' && val !== 'hermes') {
72
+ throw new Error(`Only "any" and "hermes" are supported as JavaScript engines, but "${val}" was provided`);
73
+ }
74
+ return val;
75
+ },
53
76
  },
54
77
  {
55
78
  name: '--assets-dest <path>',
56
79
  description: 'Directory name where to store assets referenced in the bundle',
57
80
  default: ASSETS_DEFAULT_DEST_PATH,
81
+ parse: (val) => path_1.default.normalize(val),
58
82
  },
59
83
  {
60
84
  name: '--sourcemap-output <path>',
61
85
  description: 'File name where to store the resulting source map, ex. /tmp/groups.map',
86
+ parse: (val) => path_1.default.normalize(val),
62
87
  },
63
88
  {
64
89
  name: '--minify [boolean]',
65
90
  description: 'Allows overriding whether bundle is minified',
66
91
  parse: (val) => val !== 'false',
67
92
  },
93
+ {
94
+ name: '--hermesc-dir <path>',
95
+ description: 'Path to hermesc directory. Relevant when --js-engine set to "hermes".',
96
+ default: HERMESC_PATH_PREFIX,
97
+ parse: (val) => path_1.default.normalize(val),
98
+ },
99
+ {
100
+ name: '--hermesc-options <string...>',
101
+ description: '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".',
102
+ parse: (val, prev) => (prev ? [...prev, val] : [val]),
103
+ },
68
104
  ],
69
105
  func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
70
- const buildOptions = {
71
- entry: args.entryFile,
72
- platform: 'harmony',
73
- minify: args.minify !== undefined ? args.minify : !args.dev,
74
- dev: args.dev,
75
- sourceMap: args.sourcemapOutput,
76
- sourceMapUrl: args.sourcemapOutput,
77
- };
78
- const metroConfig = yield loadMetroConfig(args.config);
79
- const bundle = yield createBundle(metroConfig, buildOptions);
80
- yield saveBundle(bundle, args.bundleOutput, args.sourcemapOutput);
81
- const assets = yield retrieveAssetsData(metroConfig, buildOptions);
82
- copyAssets(assets, args.assetsDest);
106
+ var _a;
107
+ const logger = new io_1.Logger();
108
+ try {
109
+ const defaultBundleName = args.jsEngine === 'hermes' ? 'hermes_bundle.hbc' : 'bundle.harmony.js';
110
+ const bundleOutput = (_a = args.bundleOutput) !== null && _a !== void 0 ? _a : `${HARMONY_RESOURCE_PATH}${path_1.default.sep}${defaultBundleName}`;
111
+ const shouldGenerateHbcBundle = bundleOutput
112
+ .toLowerCase()
113
+ .endsWith('hbc');
114
+ yield fs_extra_1.default.ensureDir(path_1.default.dirname(bundleOutput));
115
+ const assetsDest = args.assetsDest;
116
+ yield fs_extra_1.default.ensureDir(assetsDest);
117
+ const buildOptions = {
118
+ entry: args.entryFile,
119
+ platform: 'harmony',
120
+ minify: args.minify !== undefined ? args.minify : !args.dev,
121
+ dev: args.dev,
122
+ sourceMap: args.sourcemapOutput,
123
+ sourceMapUrl: args.sourcemapOutput,
124
+ };
125
+ const metroConfig = yield loadMetroConfig({
126
+ config: args.config,
127
+ resetCache: args.resetCache,
128
+ });
129
+ const bundle = yield createBundle(metroConfig, buildOptions);
130
+ const assets = yield retrieveAssetsData(metroConfig, buildOptions);
131
+ if (shouldGenerateHbcBundle) {
132
+ yield saveHbcBundle(logger, bundle.code, bundleOutput, args.hermescDir, args.hermescOptions);
133
+ }
134
+ else {
135
+ yield saveJSBundle(logger, bundle, bundleOutput);
136
+ }
137
+ maybeSaveSourceMap(logger, bundle, args.sourcemapOutput);
138
+ yield (0, assetResolver_1.copyAssets)(logger, assets, assetsDest);
139
+ }
140
+ catch (err) {
141
+ if (err instanceof core_1.DescriptiveError) {
142
+ logger.descriptiveError(err);
143
+ return;
144
+ }
145
+ else {
146
+ throw err;
147
+ }
148
+ }
83
149
  }),
84
150
  };
85
- function loadMetroConfig(configPath) {
151
+ function loadMetroConfig(options) {
86
152
  return __awaiter(this, void 0, void 0, function* () {
87
- return configPath
88
- ? yield metro_1.default.loadConfig({ config: configPath })
89
- : yield metro_1.default.loadConfig();
153
+ if (!options.config) {
154
+ delete options.config;
155
+ }
156
+ return yield metro_1.default.loadConfig(options);
90
157
  });
91
158
  }
92
159
  function createBundle(metroConfig, buildOptions) {
@@ -96,90 +163,55 @@ function createBundle(metroConfig, buildOptions) {
96
163
  return (yield metro_1.default.runBuild(metroConfig, buildOptions));
97
164
  });
98
165
  }
99
- function saveBundle(bundle, bundleOutput, sourceMapOutput) {
166
+ function saveHbcBundle(logger, bundleCode, bundleOutput, hermescPath, hermescOptions) {
100
167
  return __awaiter(this, void 0, void 0, function* () {
101
- yield fs_extra_1.default.ensureDir(path_1.default.dirname(bundleOutput));
102
- fs_1.default.writeFileSync(bundleOutput, bundle.code);
103
- console.log(`[CREATED] ${bundleOutput}`);
104
- if (sourceMapOutput) {
105
- fs_1.default.writeFileSync(sourceMapOutput, bundle.map);
106
- console.log(`[CREATED] ${sourceMapOutput}`);
168
+ if (process.platform !== 'darwin' &&
169
+ process.platform !== 'linux' &&
170
+ process.platform !== 'win32') {
171
+ throw new Error(`Unsupported platform ${process.platform} (⊙︿⊙)`);
172
+ }
173
+ const resolvedHermescPath = path_1.default.resolve(hermescPath, HERMESC_BIN_PATH[process.platform]);
174
+ if (!node_fs_1.default.existsSync(resolvedHermescPath)) {
175
+ throw new core_1.DescriptiveError({
176
+ whatHappened: `Couldn't find hermesc at ${resolvedHermescPath}`,
177
+ whatCanUserDo: [
178
+ 'Find hermesc dir and provide it by using --hermesc-dir argument. hermesc dir should be in react-native package.',
179
+ ],
180
+ });
107
181
  }
182
+ const tmpBundlePath = `${os_1.default.tmpdir()}${path_1.default.sep}b-${(0, node_crypto_1.randomUUID)()}.harmony.js`;
183
+ yield fs_extra_1.default.writeFile(tmpBundlePath, bundleCode);
184
+ const hbcFilePath = bundleOutput.endsWith('.hbc')
185
+ ? bundleOutput
186
+ : path_1.default.join(path_1.default.dirname(bundleOutput), 'hermes_bundle.hbc');
187
+ const hermescOptionsString = (hermescOptions === null || hermescOptions === void 0 ? void 0 : hermescOptions.map((e) => `-${e}`).join(' ')) || '';
188
+ (0, child_process_1.execSync)(`${resolvedHermescPath} ${hermescOptionsString} --emit-binary -out ${hbcFilePath} ${tmpBundlePath}`, {
189
+ stdio: 'inherit',
190
+ });
191
+ node_fs_1.default.unlinkSync(tmpBundlePath);
192
+ logger.info((s) => `Created ${hbcFilePath}`);
108
193
  });
109
194
  }
195
+ function saveJSBundle(logger, bundle, bundleOutput) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ node_fs_1.default.writeFileSync(bundleOutput, bundle.code);
198
+ logger.info((s) => `Created ${bundleOutput}`);
199
+ });
200
+ }
201
+ function maybeSaveSourceMap(logger, bundle, sourceMapOutput) {
202
+ if (sourceMapOutput) {
203
+ node_fs_1.default.writeFileSync(sourceMapOutput, bundle.map);
204
+ logger.info((s) => `Created ${sourceMapOutput}`);
205
+ }
206
+ }
110
207
  function retrieveAssetsData(metroConfig, buildOptions) {
111
208
  return __awaiter(this, void 0, void 0, function* () {
112
209
  const metroServer = new Server_1.default(metroConfig);
113
210
  try {
114
- return yield metroServer.getAssets(Object.assign(Object.assign(Object.assign({}, Server_1.default.DEFAULT_BUNDLE_OPTIONS), buildOptions), { entryFile: buildOptions.entry }));
211
+ return yield metroServer.getAssets(Object.assign(Object.assign(Object.assign({}, Server_1.default.DEFAULT_BUNDLE_OPTIONS), buildOptions), { entryFile: buildOptions.entry, bundleType: 'todo' }));
115
212
  }
116
213
  finally {
117
214
  metroServer.end();
118
215
  }
119
216
  });
120
217
  }
121
- function copyAssets(assetsData, assetsDest) {
122
- return __awaiter(this, void 0, void 0, function* () {
123
- if (assetsDest == null) {
124
- console.warn('Assets destination folder is not set, skipping...');
125
- return;
126
- }
127
- yield fs_extra_1.default.ensureDir(assetsDest);
128
- const fileDestBySrc = {};
129
- for (const asset of assetsData) {
130
- const idx = getHighestQualityFileIdx(asset);
131
- fileDestBySrc[asset.files[idx]] = path_1.default.join(assetsDest, (0, assetResolver_1.getAssetDestRelativePath)(asset));
132
- }
133
- return copyFiles(fileDestBySrc);
134
- });
135
- }
136
- function getHighestQualityFileIdx(assetData) {
137
- let result = 0;
138
- let maxScale = -1;
139
- for (let idx = 0; idx < assetData.scales.length; idx++) {
140
- const scale = assetData.scales[idx];
141
- if (scale > maxScale) {
142
- maxScale = scale;
143
- result = idx;
144
- }
145
- }
146
- return result;
147
- }
148
- function copyFiles(fileDestBySrc) {
149
- const fileSources = Object.keys(fileDestBySrc);
150
- if (fileSources.length === 0) {
151
- return Promise.resolve();
152
- }
153
- console.info(`Copying ${fileSources.length} asset files`);
154
- return new Promise((resolve, reject) => {
155
- const copyNext = (error) => {
156
- if (error) {
157
- reject(error);
158
- return;
159
- }
160
- if (fileSources.length === 0) {
161
- console.info('Done copying assets');
162
- resolve();
163
- }
164
- else {
165
- // fileSources.length === 0 is checked in previous branch, so this is string
166
- const src = fileSources.shift();
167
- const dest = fileDestBySrc[src];
168
- copyFile(src, dest, copyNext);
169
- }
170
- };
171
- copyNext();
172
- });
173
- }
174
- function copyFile(src, dest, onFinished) {
175
- const destDir = path_1.default.dirname(dest);
176
- fs_1.default.mkdir(destDir, { recursive: true }, (err) => {
177
- if (err) {
178
- onFinished(err);
179
- return;
180
- }
181
- fs_1.default.createReadStream(src)
182
- .pipe(fs_1.default.createWriteStream(dest))
183
- .on('finish', onFinished);
184
- });
185
- }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.commandCleanHarmony = void 0;
39
+ const core_1 = require("../core");
40
+ const json5_1 = __importDefault(require("json5"));
41
+ const node_fs_1 = __importDefault(require("node:fs"));
42
+ const node_path_1 = __importDefault(require("node:path"));
43
+ const node_os_1 = __importDefault(require("node:os"));
44
+ const crypto = __importStar(require("node:crypto"));
45
+ const COMMAND_NAME = 'clean-harmony';
46
+ exports.commandCleanHarmony = {
47
+ name: COMMAND_NAME,
48
+ description: 'Remove cached files in the OpenHarmony project.',
49
+ options: [
50
+ {
51
+ name: "--harmony-project-path <path>",
52
+ description: "Specifies the root of your OpenHarmony project.",
53
+ default: "./harmony"
54
+ }
55
+ ],
56
+ func: (_argv, _config, rawArgs) => __awaiter(void 0, void 0, void 0, function* () {
57
+ const harmonyProjectPath = new core_1.AbsolutePath(rawArgs.harmonyProjectPath);
58
+ const md5Path = crypto.createHash("md5").update(harmonyProjectPath.getValue()).digest("hex");
59
+ const hvigorCachePath = new core_1.AbsolutePath(node_path_1.default.join(node_os_1.default.homedir(), ".hvigor", "project_caches", md5Path));
60
+ if (node_fs_1.default.existsSync(hvigorCachePath.getValue())) {
61
+ node_fs_1.default.rmSync(hvigorCachePath.getValue(), { recursive: true, force: true });
62
+ }
63
+ const buildProfilePath = harmonyProjectPath.copyWithNewSegment('build-profile.json5');
64
+ const buildProfileContent = (0, core_1.maybeReadFile)(buildProfilePath);
65
+ if (buildProfileContent) {
66
+ const buildProfile = json5_1.default.parse(buildProfileContent);
67
+ if (Array.isArray(buildProfile.modules)) {
68
+ buildProfile.modules.forEach((module) => {
69
+ if (module && module.srcPath) {
70
+ const modulePath = harmonyProjectPath.copyWithNewSegment(module.srcPath);
71
+ const cxxPath = modulePath.copyWithNewSegment('.cxx');
72
+ const buildPath = modulePath.copyWithNewSegment('build');
73
+ if (node_fs_1.default.existsSync(cxxPath.getValue())) {
74
+ node_fs_1.default.rmSync(cxxPath.getValue(), { recursive: true, force: true });
75
+ }
76
+ if (node_fs_1.default.existsSync(buildPath.getValue())) {
77
+ node_fs_1.default.rmSync(buildPath.getValue(), { recursive: true, force: true });
78
+ }
79
+ }
80
+ });
81
+ }
82
+ }
83
+ })
84
+ };