@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
package/src/io/index.ts CHANGED
@@ -1,11 +1,5 @@
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 './Logger';
9
2
  export * from './fsUtils';
10
3
  export * from './TarGz';
11
4
  export * from './RealFS';
5
+ export * from './CliExecutor';
@@ -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 fs from 'node:fs';
9
2
  import { AbsolutePath } from '../../core';
10
3
  import { Check } from '../types';
@@ -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 fs from 'node:fs';
9
2
  import { AbsolutePath } from '../../core';
10
3
  import { Check } from '../types';
@@ -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 { Check } from '../types';
9
2
 
10
3
  export function createNpmAndOhPackageVersionsAreEqualCheck(
@@ -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 { Check } from '../types';
9
2
 
10
3
  export function createOhPackageNameFollowsNamingConventionCheck(
@@ -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 './HarmonyDirExistsCheck';
9
2
  export * from './HarmonyDirContainsOnlyHarsCheck';
10
3
  export * from './NpmAnAndOhPackageVersionsAreEqual';
@@ -1,9 +1,2 @@
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 './types';
9
2
  export * from './verify-package';
@@ -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 type CheckStatus = 'pass' | 'fail' | 'skip';
9
2
 
10
3
  export type Check = {
@@ -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 fs from 'node:fs';
9
2
  import tmp from 'tmp';
10
3
  import {
@@ -60,12 +53,10 @@ export async function* verifyRNOHPackage({
60
53
  if (!harPath) {
61
54
  throw new DescriptiveError({
62
55
  whatHappened: 'Attempted to verify har but no har was found',
63
- whatCanUserDo: {
64
- default: [
65
- 'Run this command without --no-harmony-code flag.',
66
- '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.',
67
- ],
68
- },
56
+ whatCanUserDo: [
57
+ 'Run this command without --no-harmony-code flag.',
58
+ '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.',
59
+ ],
69
60
  });
70
61
  }
71
62
  const tmpDirPath = new AbsolutePath(tmp.dirSync().name);
@@ -1,7 +1,4 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
- "exclude": [
4
- "tests",
5
- "**/*.test.ts",
6
- ]
7
- }
3
+ "exclude": ["tests", "**/*.test.ts", "src/init/templates/harmony", "dist"]
4
+ }
package/tsconfig.json CHANGED
@@ -1,3 +1,7 @@
1
1
  {
2
2
  "extends": "@tsconfig/recommended/tsconfig.json",
3
+ "exclude": [
4
+ "src/init/templates/harmony",
5
+ "dist"
6
+ ]
3
7
  }
@@ -1,67 +0,0 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.commandCreateMetroConstantsHarmony = void 0;
22
- const node_os_1 = __importDefault(require("node:os"));
23
- const node_fs_1 = __importDefault(require("node:fs"));
24
- const node_path_1 = __importDefault(require("node:path"));
25
- exports.commandCreateMetroConstantsHarmony = {
26
- name: 'create-metro-host-constants-harmony',
27
- description: 'Creates a Typescript file that exports constant with IP of the host machine. That IP is later used to connect to the Metro server from a physical device.',
28
- options: [
29
- {
30
- name: '--output <string>',
31
- description: 'Output file',
32
- default: './harmony/entry/src/main/ets/codegen/MetroHostConstants.ts',
33
- },
34
- ],
35
- func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
36
- createMetroHostConstants(node_path_1.default.resolve(args.output));
37
- }),
38
- };
39
- function createMetroHostConstants(outputPath) {
40
- const networkInterfacesByName = node_os_1.default.networkInterfaces();
41
- const getIP = () => {
42
- var _a;
43
- for (let name of Object.keys(networkInterfacesByName)) {
44
- for (let net of (_a = networkInterfacesByName[name]) !== null && _a !== void 0 ? _a : []) {
45
- // skip over non-ipv4 and internal (i.e. 127.0.0.1) addresses
46
- if (net.family === 'IPv4' && !net.internal) {
47
- return net.address;
48
- }
49
- }
50
- }
51
- return;
52
- };
53
- const ip = getIP();
54
- const tsCode = [
55
- '// This file is autogenerated. Do not modify it manually.',
56
- '',
57
- `export const METRO_SERVER_IP = '${ip}';\n`,
58
- ];
59
- node_fs_1.default.writeFile(outputPath, tsCode.join('\n'), (err) => {
60
- if (err) {
61
- console.error(`Error writing to ${outputPath}:`, err);
62
- }
63
- else {
64
- console.log(`Created file at ${outputPath}`);
65
- }
66
- });
67
- }
@@ -1,106 +0,0 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.commandPackHarmony = void 0;
22
- const glob_1 = require("glob");
23
- const path_1 = __importDefault(require("path"));
24
- const tar_1 = __importDefault(require("tar"));
25
- const fs_1 = __importDefault(require("fs"));
26
- const core_1 = require("../core");
27
- const ignore_1 = __importDefault(require("ignore"));
28
- const json5_1 = __importDefault(require("json5"));
29
- exports.commandPackHarmony = {
30
- name: 'pack-harmony',
31
- description: 'Pack native code. Used for package development.',
32
- options: [
33
- {
34
- name: '--oh-module-path <string>',
35
- description: 'Path to the OH module',
36
- },
37
- {
38
- name: '--harmony-dir-path <string>',
39
- description: 'Path to the harmony dir',
40
- },
41
- {
42
- name: '--package-json-path <string>',
43
- description: 'Path to the package.json',
44
- },
45
- ],
46
- func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
47
- try {
48
- yield pack(path_1.default.resolve(args.harmonyDirPath), path_1.default.resolve(args.ohModulePath), path_1.default.resolve(args.packageJsonPath));
49
- }
50
- catch (err) {
51
- if (err instanceof core_1.ValidationError) {
52
- console.error('[ERROR]', err.message);
53
- process.exit(1);
54
- }
55
- else {
56
- throw err;
57
- }
58
- }
59
- }),
60
- };
61
- function pack(harmonyDirPath, ohModuleDirPath, packageJSONPath) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- syncVersions(packageJSONPath, path_1.default.join(ohModuleDirPath, 'oh-package.json5'));
64
- if (!fs_1.default.existsSync(harmonyDirPath)) {
65
- fs_1.default.mkdirSync(harmonyDirPath, { recursive: true });
66
- }
67
- yield createTGZFromDir(ohModuleDirPath, path_1.default.join(harmonyDirPath, `${path_1.default.parse(ohModuleDirPath).name}.tar.gz`));
68
- yield createTGZFromDir(harmonyDirPath, path_1.default.join(path_1.default.dirname(harmonyDirPath), 'harmony.tar.gz'));
69
- });
70
- }
71
- function syncVersions(packageJSONFilePath, ohPackageJSONFilePath) {
72
- const packageJSONFileContent = JSON.parse(fs_1.default.readFileSync(packageJSONFilePath, { encoding: 'utf-8' }));
73
- if (fs_1.default.existsSync(ohPackageJSONFilePath)) {
74
- const ohPackageJSONFileContent = json5_1.default.parse(fs_1.default.readFileSync(ohPackageJSONFilePath, { encoding: 'utf-8' }));
75
- ohPackageJSONFileContent['version'] = packageJSONFileContent['version'];
76
- fs_1.default.writeFileSync(ohPackageJSONFilePath, json5_1.default.stringify(ohPackageJSONFileContent, null, 2));
77
- }
78
- }
79
- function createTGZFromDir(dirPath, outputFilePath) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- const ig = getIgnoreUtil(path_1.default.join(dirPath, '.tarignore'));
82
- const filesToInclude = (0, glob_1.globSync)('**', {
83
- cwd: dirPath,
84
- nodir: true,
85
- }).filter((path) => !ig.ignores(path));
86
- yield createArchive(outputFilePath, dirPath, filesToInclude);
87
- });
88
- }
89
- function getIgnoreUtil(tarignorePath) {
90
- if (!fs_1.default.existsSync(tarignorePath)) {
91
- return (0, ignore_1.default)();
92
- }
93
- return (0, ignore_1.default)().add(fs_1.default.readFileSync(tarignorePath).toString());
94
- }
95
- function createArchive(outputFilePath, packageDirPath, filesToInclude) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- if (filesToInclude.length === 0) {
98
- throw new core_1.ValidationError('Nothing to pack');
99
- }
100
- yield tar_1.default.c({
101
- gzip: true,
102
- file: outputFilePath,
103
- cwd: packageDirPath,
104
- }, filesToInclude);
105
- });
106
- }
@@ -1,191 +0,0 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.commandUnpackHarmony = void 0;
22
- const io_1 = require("../io");
23
- const path_1 = __importDefault(require("path"));
24
- const fs_1 = __importDefault(require("fs"));
25
- const zlib_1 = __importDefault(require("zlib"));
26
- const tar_1 = __importDefault(require("tar"));
27
- const json5_1 = __importDefault(require("json5"));
28
- const core_1 = require("../core");
29
- exports.commandUnpackHarmony = {
30
- name: 'unpack-harmony',
31
- description: 'Unpacks native code.',
32
- options: [
33
- {
34
- name: '--project-root-path <path>',
35
- description: 'Relative path to package root',
36
- default: '.',
37
- },
38
- {
39
- name: '--output-dir <string>',
40
- description: 'Output directory to which OH modules should be unpacked to',
41
- default: './harmony/rnoh_modules',
42
- },
43
- ],
44
- func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
45
- try {
46
- yield unpack(new core_1.AbsolutePath(args.projectRootPath), new core_1.AbsolutePath(args.outputDir));
47
- }
48
- catch (err) {
49
- if (err instanceof core_1.ValidationError) {
50
- console.error('[ERROR]', err.message);
51
- process.exit(1);
52
- }
53
- else {
54
- throw err;
55
- }
56
- }
57
- }),
58
- };
59
- function unpack(projectRootPath, outputDirPath) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- const logger = new io_1.Logger();
62
- const fs = new io_1.RealFS();
63
- const projectDependenciesManager = new core_1.ProjectDependenciesManager(fs, projectRootPath);
64
- logger.info((styles) => styles.bold(`Unpacking RNOH modules`), {
65
- prefix: true,
66
- });
67
- let unpackedArchivesCount = 0;
68
- let skippedArchivesCount = 0;
69
- yield projectDependenciesManager.forEachAsync((dependency) => __awaiter(this, void 0, void 0, function* () {
70
- const packageJSON = dependency.readPackageJSON();
71
- const harmonyArchivePath = dependency
72
- .getRootPath()
73
- .copyWithNewSegment('harmony.tar.gz');
74
- const pkgHarmonyDirPath = dependency
75
- .getRootPath()
76
- .copyWithNewSegment('harmony');
77
- const harmonyTarGzPathStr = dependency
78
- .getRootPath()
79
- .copyWithNewSegment('harmony.tar.gz')
80
- .relativeTo(projectRootPath)
81
- .getValue();
82
- if (packageJSON.version &&
83
- shouldUnpack(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, packageJSON.version)) {
84
- if (!fs.existsSync(pkgHarmonyDirPath)) {
85
- /**
86
- * After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
87
- */
88
- logger.info((styles) => `[${styles.cyan('unpacking')}] ${styles.gray(harmonyTarGzPathStr)}`);
89
- yield unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
90
- unpackedArchivesCount++;
91
- }
92
- else {
93
- skippedArchivesCount++;
94
- logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(harmonyTarGzPathStr)}`);
95
- }
96
- const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
97
- for (const ohModuleInfo of ohModulesInfo) {
98
- const moduleArchivePathStr = dependency
99
- .getRootPath()
100
- .copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
101
- .relativeTo(projectRootPath)
102
- .getValue();
103
- logger.info((styles) => `[${styles.cyan('unpacking')}] ${styles.gray(moduleArchivePathStr)}`);
104
- unpackedArchivesCount++;
105
- yield unpackTarGz(ohModuleInfo.archivePath, ohModuleInfo.computedModulePath);
106
- }
107
- }
108
- else {
109
- if (fs.existsSync(harmonyArchivePath)) {
110
- skippedArchivesCount++;
111
- logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(harmonyTarGzPathStr)}`);
112
- }
113
- const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
114
- for (const ohModuleInfo of ohModulesInfo) {
115
- const moduleArchivePathStr = dependency
116
- .getRootPath()
117
- .copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
118
- .relativeTo(projectRootPath)
119
- .getValue();
120
- skippedArchivesCount++;
121
- logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(moduleArchivePathStr)}`);
122
- }
123
- }
124
- }));
125
- logger.info((styles) => `\nUnpacked: ${styles.cyan(unpackedArchivesCount)}, Skipped: ${styles.yellow(skippedArchivesCount)}`);
126
- });
127
- }
128
- function shouldUnpack(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, nodePackageVersion) {
129
- if (!fs_1.default.existsSync(harmonyArchivePath.getValue()))
130
- return false;
131
- if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue()))
132
- return true;
133
- const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
134
- for (const ohModuleInfo of ohModulesInfo) {
135
- if (!fs_1.default.existsSync(ohModuleInfo.computedModulePath.getValue()) ||
136
- getOhPackageVersion(ohModuleInfo.computedModulePath) !==
137
- nodePackageVersion) {
138
- return true;
139
- }
140
- }
141
- return false;
142
- }
143
- function getOhPackageVersion(modulePath) {
144
- const ohPackagePath = modulePath.copyWithNewSegment('oh-package.json5');
145
- if (!fs_1.default.existsSync(ohPackagePath.getValue()))
146
- return null;
147
- const content = fs_1.default.readFileSync(ohPackagePath.getValue(), {
148
- encoding: 'utf-8',
149
- });
150
- return json5_1.default.parse(content)['version'];
151
- }
152
- function getOhModulesInfo(pkgHarmonyDirPath, outputDirPath) {
153
- const results = [];
154
- if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue()))
155
- return [];
156
- const names = fs_1.default.readdirSync(pkgHarmonyDirPath.getValue());
157
- for (const name of names) {
158
- if (name.endsWith('.tar.gz')) {
159
- const archivePath = pkgHarmonyDirPath.copyWithNewSegment(name);
160
- const computedModuleName = path_1.default
161
- .parse(archivePath.getValue())
162
- .name.split('.')[0];
163
- const computedModulePath = outputDirPath.copyWithNewSegment(computedModuleName);
164
- results.push({
165
- archivePath,
166
- archiveFileName: name,
167
- computedModulePath,
168
- computedModuleName,
169
- });
170
- }
171
- }
172
- return results;
173
- }
174
- function unpackTarGz(archivePath, outputDirPath) {
175
- if (!fs_1.default.existsSync(outputDirPath.getValue())) {
176
- fs_1.default.mkdirSync(outputDirPath.getValue(), { recursive: true });
177
- }
178
- const readStream = fs_1.default.createReadStream(archivePath.getValue());
179
- const writeStream = tar_1.default.extract({
180
- cwd: outputDirPath.getValue(),
181
- });
182
- readStream.pipe(zlib_1.default.createGunzip()).pipe(writeStream);
183
- return new Promise((resolve, reject) => {
184
- writeStream.on('finish', () => {
185
- resolve(undefined);
186
- });
187
- writeStream.on('error', (err) => {
188
- reject(err);
189
- });
190
- });
191
- }
@@ -1,55 +0,0 @@
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
- import { Command } from '@react-native-community/cli-types';
9
- import os from 'node:os';
10
- import fs from 'node:fs';
11
- import pathUtils from 'node:path';
12
-
13
- export const commandCreateMetroConstantsHarmony: Command = {
14
- name: 'create-metro-host-constants-harmony',
15
- description:
16
- 'Creates a Typescript file that exports constant with IP of the host machine. That IP is later used to connect to the Metro server from a physical device.',
17
- options: [
18
- {
19
- name: '--output <string>',
20
- description: 'Output file',
21
- default: './harmony/entry/src/main/ets/codegen/MetroHostConstants.ts',
22
- },
23
- ],
24
- func: async (argv, config, args: any) => {
25
- createMetroHostConstants(pathUtils.resolve(args.output));
26
- },
27
- };
28
-
29
- function createMetroHostConstants(outputPath: string): void {
30
- const networkInterfacesByName = os.networkInterfaces();
31
- const getIP = () => {
32
- for (let name of Object.keys(networkInterfacesByName)) {
33
- for (let net of networkInterfacesByName[name] ?? []) {
34
- // skip over non-ipv4 and internal (i.e. 127.0.0.1) addresses
35
- if (net.family === 'IPv4' && !net.internal) {
36
- return net.address;
37
- }
38
- }
39
- }
40
- return;
41
- };
42
- const ip = getIP();
43
- const tsCode = [
44
- '// This file is autogenerated. Do not modify it manually.',
45
- '',
46
- `export const METRO_SERVER_IP = '${ip}';\n`,
47
- ];
48
- fs.writeFile(outputPath, tsCode.join('\n'), (err) => {
49
- if (err) {
50
- console.error(`Error writing to ${outputPath}:`, err);
51
- } else {
52
- console.log(`Created file at ${outputPath}`);
53
- }
54
- });
55
- }