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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -4
  3. package/dist/assetResolver.js +105 -10
  4. package/dist/autolinking/Autolinking.js +21 -26
  5. package/dist/autolinking/index.js +0 -6
  6. package/dist/codegen/core/CodeGenerator.js +0 -6
  7. package/dist/codegen/core/CodegenError.js +0 -6
  8. package/dist/codegen/core/EventUtils.js +4 -13
  9. package/dist/codegen/core/TypeAnnotationToTS.js +3 -9
  10. package/dist/codegen/core/UberSchema.js +8 -21
  11. package/dist/codegen/core/index.js +0 -6
  12. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +2 -7
  13. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +3 -6
  14. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +3 -6
  15. package/dist/codegen/generators/CppComponentCodeGenerator.js +3 -6
  16. package/dist/codegen/generators/LibGlueCodeGenerator.js +2 -8
  17. package/dist/codegen/generators/NativeModuleCodeGenerator.js +1 -7
  18. package/dist/codegen/generators/SharedComponentCodeGenerator.js +0 -6
  19. package/dist/codegen/generators/UberGeneratorV1.js +0 -6
  20. package/dist/codegen/generators/UberGeneratorV2.js +0 -6
  21. package/dist/codegen/generators/index.js +0 -6
  22. package/dist/codegen/index.js +0 -6
  23. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +0 -6
  24. package/dist/codegen/templates/BasePackageHTemplate.js +12 -7
  25. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +1 -6
  26. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +15 -6
  27. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -6
  28. package/dist/codegen/templates/IndexTSTemplate.js +0 -6
  29. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +12 -7
  30. package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -6
  31. package/dist/codegen/templates/TurboModuleHTemplate.js +0 -6
  32. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -6
  33. package/dist/codegen/templates/index.js +0 -6
  34. package/dist/commands/bundle-harmony.js +133 -101
  35. package/dist/commands/clean-harmony.js +84 -0
  36. package/dist/commands/codegen-harmony.js +12 -22
  37. package/dist/commands/codegen-lib-harmony.js +15 -25
  38. package/dist/commands/index.js +3 -9
  39. package/dist/commands/init-harmony.js +226 -0
  40. package/dist/commands/init.js +703 -0
  41. package/dist/commands/link-harmony.js +12 -16
  42. package/dist/commands/run-harmony.js +438 -0
  43. package/dist/commands/types.js +2 -0
  44. package/dist/commands/verify-package-harmony.js +7 -11
  45. package/dist/core/AbsolutePath.js +3 -6
  46. package/dist/core/CodegenConfig.js +3 -11
  47. package/dist/core/DescriptiveError.js +7 -9
  48. package/dist/core/FileSystem.js +0 -6
  49. package/dist/core/OHPackageJSON5.js +0 -6
  50. package/dist/core/PackageJSON.js +4 -7
  51. package/dist/core/ProjectDependenciesManager.js +6 -14
  52. package/dist/core/ValidationError.js +0 -6
  53. package/dist/core/ValueObject.js +0 -6
  54. package/dist/core/fs.js +16 -10
  55. package/dist/core/index.js +0 -6
  56. package/dist/index.js +3 -9
  57. package/dist/init/templates/AppScopeAppJSON5Template.js +30 -0
  58. package/dist/init/templates/AppScopeStringVarTemplate.js +28 -0
  59. package/dist/init/templates/EntryIndexTemplate.js +65 -0
  60. package/dist/init/templates/EntryStringVarTemplate.js +38 -0
  61. package/dist/init/templates/HvigorConfigJson5Template.js +44 -0
  62. package/dist/init/templates/MetroConfigTemplate.js +47 -0
  63. package/dist/init/templates/OhPackageJson5Template.js +37 -0
  64. package/dist/init/templates/harmony/AppScope/app.json5 +10 -0
  65. package/dist/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
  66. package/dist/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  67. package/dist/init/templates/harmony/build-profile.json5 +36 -0
  68. package/dist/init/templates/harmony/codelinter.json +32 -0
  69. package/dist/init/templates/harmony/entry/build-profile.json5 +18 -0
  70. package/dist/init/templates/harmony/entry/gitignore +7 -0
  71. package/dist/init/templates/harmony/entry/hvigorfile.ts +13 -0
  72. package/dist/init/templates/harmony/entry/oh-package.json5 +9 -0
  73. package/dist/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
  74. package/dist/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
  75. package/dist/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
  76. package/dist/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
  77. package/dist/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
  78. package/dist/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
  79. package/dist/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
  80. package/dist/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  81. package/dist/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
  82. package/dist/init/templates/harmony/entry/src/main/module.json5 +58 -0
  83. package/dist/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
  84. package/dist/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
  85. package/dist/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  86. package/dist/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  87. package/dist/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
  88. package/dist/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  89. package/dist/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  90. package/dist/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
  91. package/dist/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
  92. package/dist/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
  93. package/dist/init/templates/harmony/gitignore +16 -0
  94. package/dist/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
  95. package/dist/init/templates/harmony/hvigorfile.ts +7 -0
  96. package/dist/init/templates/index.js +21 -0
  97. package/dist/io/CliExecutor.js +56 -29
  98. package/dist/io/Logger.js +71 -47
  99. package/dist/io/RealFS.js +10 -6
  100. package/dist/io/TarGz.js +3 -10
  101. package/dist/io/__fixtures__.js +8 -8
  102. package/dist/io/fsUtils.js +1 -8
  103. package/dist/io/index.js +1 -6
  104. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +1 -8
  105. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +1 -8
  106. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +1 -8
  107. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +1 -8
  108. package/dist/package-verifier/checks/index.js +0 -6
  109. package/dist/package-verifier/index.js +0 -6
  110. package/dist/package-verifier/types.js +0 -6
  111. package/dist/package-verifier/verify-package.js +5 -14
  112. package/harmony/rnoh-hvigor-plugin-0.77.18.tgz +0 -0
  113. package/jest.config.js +0 -7
  114. package/package.json +20 -16
  115. package/react-native.config.js +0 -7
  116. package/scripts/copy-template.js +18 -0
  117. package/src/assetResolver.ts +117 -11
  118. package/src/autolinking/Autolinking.test.ts +54 -18
  119. package/src/autolinking/Autolinking.ts +32 -31
  120. package/src/autolinking/index.ts +1 -8
  121. package/src/codegen/core/CodeGenerator.ts +0 -7
  122. package/src/codegen/core/CodegenError.ts +0 -7
  123. package/src/codegen/core/EventUtils.ts +3 -12
  124. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -7
  125. package/src/codegen/core/TypeAnnotationToTS.ts +3 -8
  126. package/src/codegen/core/UberSchema.ts +9 -22
  127. package/src/codegen/core/index.ts +0 -7
  128. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +5 -8
  129. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +3 -7
  130. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +3 -7
  131. package/src/codegen/generators/CppComponentCodeGenerator.ts +3 -7
  132. package/src/codegen/generators/LibGlueCodeGenerator.ts +2 -9
  133. package/src/codegen/generators/NativeModuleCodeGenerator.ts +1 -8
  134. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -7
  135. package/src/codegen/generators/UberGeneratorV1.ts +0 -7
  136. package/src/codegen/generators/UberGeneratorV2.ts +0 -7
  137. package/src/codegen/generators/index.ts +0 -7
  138. package/src/codegen/index.ts +0 -7
  139. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -7
  140. package/src/codegen/templates/BasePackageHTemplate.ts +13 -8
  141. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +1 -7
  142. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +24 -8
  143. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -7
  144. package/src/codegen/templates/IndexTSTemplate.ts +0 -7
  145. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +13 -8
  146. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -7
  147. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -7
  148. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -7
  149. package/src/codegen/templates/index.ts +0 -7
  150. package/src/commands/bundle-harmony.ts +178 -118
  151. package/src/commands/clean-harmony.ts +54 -0
  152. package/src/commands/codegen-harmony.ts +13 -25
  153. package/src/commands/codegen-lib-harmony.ts +16 -28
  154. package/src/commands/index.ts +3 -10
  155. package/src/commands/init-harmony.ts +299 -0
  156. package/src/commands/init.ts +755 -0
  157. package/src/commands/link-harmony.ts +14 -19
  158. package/src/commands/run-harmony.ts +478 -0
  159. package/src/commands/types.ts +14 -0
  160. package/src/commands/verify-package-harmony.ts +9 -12
  161. package/src/core/AbsolutePath.ts +4 -7
  162. package/src/core/CodegenConfig.ts +3 -12
  163. package/src/core/DescriptiveError.ts +8 -15
  164. package/src/core/FileSystem.ts +5 -8
  165. package/src/core/OHPackageJSON5.ts +0 -7
  166. package/src/core/PackageJSON.ts +4 -13
  167. package/src/core/ProjectDependenciesManager.ts +14 -22
  168. package/src/core/ValidationError.ts +0 -7
  169. package/src/core/ValueObject.ts +0 -7
  170. package/src/core/fs.ts +14 -8
  171. package/src/core/index.ts +0 -7
  172. package/src/index.ts +8 -15
  173. package/src/init/templates/AppScopeAppJSON5Template.ts +24 -0
  174. package/src/init/templates/AppScopeStringVarTemplate.ts +22 -0
  175. package/src/init/templates/EntryIndexTemplate.ts +59 -0
  176. package/src/init/templates/EntryStringVarTemplate.ts +31 -0
  177. package/src/init/templates/HvigorConfigJson5Template.ts +40 -0
  178. package/src/init/templates/MetroConfigTemplate.ts +41 -0
  179. package/src/init/templates/OhPackageJson5Template.ts +31 -0
  180. package/src/init/templates/harmony/AppScope/app.json5 +10 -0
  181. package/src/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
  182. package/src/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  183. package/src/init/templates/harmony/build-profile.json5 +36 -0
  184. package/src/init/templates/harmony/codelinter.json +32 -0
  185. package/src/init/templates/harmony/entry/build-profile.json5 +18 -0
  186. package/src/init/templates/harmony/entry/gitignore +7 -0
  187. package/src/init/templates/harmony/entry/hvigorfile.ts +13 -0
  188. package/src/init/templates/harmony/entry/oh-package.json5 +9 -0
  189. package/src/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
  190. package/src/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
  191. package/src/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
  192. package/src/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
  193. package/src/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
  194. package/src/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
  195. package/src/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
  196. package/src/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  197. package/src/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
  198. package/src/init/templates/harmony/entry/src/main/module.json5 +58 -0
  199. package/src/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
  200. package/src/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
  201. package/src/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  202. package/src/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  203. package/src/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
  204. package/src/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  205. package/src/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  206. package/src/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
  207. package/src/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
  208. package/src/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
  209. package/src/init/templates/harmony/gitignore +16 -0
  210. package/src/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
  211. package/src/init/templates/harmony/hvigorfile.ts +7 -0
  212. package/src/init/templates/index.ts +5 -0
  213. package/src/io/CliExecutor.ts +55 -40
  214. package/src/io/Logger.ts +77 -51
  215. package/src/io/RealFS.ts +15 -8
  216. package/src/io/TarGz.ts +1 -8
  217. package/src/io/__fixtures__.ts +15 -18
  218. package/src/io/fsUtils.ts +1 -7
  219. package/src/io/index.ts +1 -7
  220. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -7
  221. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -7
  222. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -7
  223. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -7
  224. package/src/package-verifier/checks/index.ts +0 -7
  225. package/src/package-verifier/index.ts +0 -7
  226. package/src/package-verifier/types.ts +0 -7
  227. package/src/package-verifier/verify-package.ts +4 -13
  228. package/tsconfig.build.json +2 -5
  229. package/tsconfig.json +4 -0
  230. package/dist/commands/create-metro-host-constants.js +0 -67
  231. package/dist/commands/pack-harmony.js +0 -106
  232. package/dist/commands/unpack-harmony.js +0 -191
  233. package/src/commands/create-metro-host-constants.ts +0 -55
  234. package/src/commands/pack-harmony.ts +0 -128
  235. package/src/commands/unpack-harmony.ts +0 -240
@@ -1,10 +1,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 { AbsolutePath } from './AbsolutePath';
9
2
  import pathUtils from 'node:path';
10
3
 
@@ -12,6 +5,10 @@ export abstract class Dirent {
12
5
  abstract isDirectory(): boolean;
13
6
 
14
7
  abstract get name(): string;
8
+
9
+ abstract get path(): AbsolutePath;
10
+
11
+ abstract isSymbolicLink(): boolean;
15
12
  }
16
13
 
17
14
  export abstract class FS {
@@ -54,4 +51,4 @@ export abstract class FS {
54
51
  }
55
52
  return results;
56
53
  }
57
- }
54
+ }
@@ -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 json5 from 'json5';
9
2
  import fs from 'node:fs';
10
3
  import { AbsolutePath } from './AbsolutePath';
@@ -1,9 +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
1
  import { AbsolutePath } from './AbsolutePath';
8
2
  import { CodegenConfig, RawCodegenConfig } from './CodegenConfig';
9
3
  import { DescriptiveError } from './DescriptiveError';
@@ -26,12 +20,10 @@ export class PackageJSON {
26
20
  if (!fs.existsSync(packageJSONPath)) {
27
21
  throw new DescriptiveError({
28
22
  whatHappened: "Couldn't find 'package.json'",
29
- whatCanUserDo: {
30
- default: [
31
- 'Check if the path to project root is correct',
32
- 'Try changing working directory to project root',
33
- ],
34
- },
23
+ whatCanUserDo: [
24
+ 'Check if the path to project root is correct',
25
+ 'Try changing working directory to project root',
26
+ ],
35
27
  extraData: packageJSONPath.getValue(),
36
28
  });
37
29
  }
@@ -44,7 +36,6 @@ export class PackageJSON {
44
36
  } catch (err) {
45
37
  throw new DescriptiveError({
46
38
  whatHappened: "Couldn't parse package.json",
47
- whatCanUserDo: {},
48
39
  extraData: { packageJSONPath, err },
49
40
  });
50
41
  }
@@ -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 { AbsolutePath } from './AbsolutePath';
9
2
  import { PackageJSON } from './PackageJSON';
10
3
  import { FS } from '../core';
@@ -14,7 +7,7 @@ export class ProjectDependency {
14
7
  private fs: FS,
15
8
  private packageRootPath: AbsolutePath,
16
9
  private projectRootPath: AbsolutePath
17
- ) {}
10
+ ) { }
18
11
 
19
12
  getRootPath() {
20
13
  return this.packageRootPath;
@@ -24,21 +17,20 @@ export class ProjectDependency {
24
17
  return this.readPackageJSON().getCodegenConfigs();
25
18
  }
26
19
 
27
- getHarFilePath(): AbsolutePath | null {
20
+ getHarFilePaths(): AbsolutePath[] {
28
21
  const packageHarmonyPath =
29
22
  this.packageRootPath.copyWithNewSegment('harmony');
30
- if (!this.fs.existsSync(packageHarmonyPath)) {
31
- return null;
32
- }
33
-
34
- const harFilePaths = this.fs.findFilePathsWithExtensions(
35
- packageHarmonyPath,
36
- ['har']
37
- );
38
- if (harFilePaths.length !== 1) {
39
- return null;
23
+ if (this.fs.existsSync(packageHarmonyPath)) {
24
+ return this.fs.findFilePathsWithExtensions(
25
+ packageHarmonyPath,
26
+ ['har']
27
+ );
28
+ } else {
29
+ return this.fs.findFilePathsWithExtensions(
30
+ this.packageRootPath,
31
+ ['har']
32
+ );
40
33
  }
41
- return harFilePaths[0];
42
34
  }
43
35
 
44
36
  readPackageJSON() {
@@ -51,7 +43,7 @@ export class ProjectDependency {
51
43
  }
52
44
 
53
45
  export class ProjectDependenciesManager {
54
- constructor(private fs: FS, private projectRootPath: AbsolutePath) {}
46
+ constructor(private fs: FS, private projectRootPath: AbsolutePath) { }
55
47
 
56
48
  async forEachAsync(
57
49
  cb: (dependency: ProjectDependency) => Promise<void> | void
@@ -70,7 +62,7 @@ export class ProjectDependenciesManager {
70
62
  return;
71
63
  }
72
64
  for (let dirent of this.fs.readDirentsSync(directoryPath)) {
73
- if (dirent.isDirectory()) {
65
+ if (dirent.isDirectory() || dirent.isSymbolicLink()) {
74
66
  if (dirent.name.startsWith('.')) {
75
67
  continue;
76
68
  } else if (dirent.name.startsWith('@')) {
@@ -1,8 +1 @@
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 class ValidationError extends Error {}
@@ -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
  /** https://en.wikipedia.org/wiki/Value_object */
9
2
  export interface ValueObject {}
package/src/core/fs.ts CHANGED
@@ -1,10 +1,3 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
1
  import fs from 'node:fs';
9
2
  import { AbsolutePath } from './AbsolutePath';
10
3
  import { DescriptiveError } from './DescriptiveError';
@@ -23,7 +16,7 @@ export function maybeRemoveFilesInDirectory(path: AbsolutePath): void {
23
16
  throw new DescriptiveError({
24
17
  whatHappened:
25
18
  "Tried to remove all files from a path that doesn't point to a directory",
26
- whatCanUserDo: { default: [`Verify path: ${path.getValue()}`] },
19
+ whatCanUserDo: [`Verify path: ${path.getValue()}`],
27
20
  });
28
21
  }
29
22
  const fileOrDirNames = fs.readdirSync(path.getValue());
@@ -36,3 +29,16 @@ export function maybeRemoveFilesInDirectory(path: AbsolutePath): void {
36
29
  }
37
30
  });
38
31
  }
32
+
33
+ export function maybeReadFile(path: AbsolutePath): string | null {
34
+ if (!fs.existsSync(path.getValue())) {
35
+ return null;
36
+ }
37
+ if (!fs.lstatSync(path.getValue()).isFile()) {
38
+ throw new DescriptiveError({
39
+ whatHappened: "Tried to read a path that doesn't point to a file",
40
+ whatCanUserDo: [`Verify path: ${path.getValue()}`],
41
+ });
42
+ }
43
+ return fs.readFileSync(path.getValue(), 'utf-8');
44
+ }
package/src/core/index.ts CHANGED
@@ -1,10 +1,3 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
1
  export * from './AbsolutePath';
9
2
  export * from './ValidationError';
10
3
  export * from './DescriptiveError';
package/src/index.ts CHANGED
@@ -1,31 +1,24 @@
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 { Config } from '@react-native-community/cli-types';
1
+ import { Config, Command } from '@react-native-community/cli-types';
9
2
  import {
10
3
  commandBundleHarmony,
11
- commandPackHarmony,
12
- commandUnpackHarmony,
13
- commandCreateMetroConstantsHarmony,
14
4
  commandCodegenHarmony,
15
5
  commandVerifyPackageHarmony,
16
6
  commandCodegenLibHarmony,
17
7
  commandLinkHarmony,
8
+ commandRunHarmony,
9
+ commandInitHarmony,
10
+ commandCleanHarmony,
18
11
  } from './commands';
19
12
 
20
13
  export const config = {
21
14
  commands: [
22
15
  commandBundleHarmony,
23
- commandPackHarmony,
24
- commandUnpackHarmony,
25
- commandCreateMetroConstantsHarmony,
26
16
  commandCodegenHarmony,
27
17
  commandVerifyPackageHarmony,
28
18
  commandCodegenLibHarmony,
29
19
  commandLinkHarmony,
30
- ],
20
+ commandRunHarmony,
21
+ commandInitHarmony,
22
+ commandCleanHarmony
23
+ ] as Command[],
31
24
  } satisfies Partial<Config>;
@@ -0,0 +1,24 @@
1
+ import mustache from 'mustache';
2
+
3
+ const TEMPLATE = `
4
+ {
5
+ "app": {
6
+ "bundleName": "{{bundleName}}",
7
+ "vendor": "example",
8
+ "versionCode": 1000000,
9
+ "versionName": "1.0.0",
10
+ "icon": "$media:app_icon",
11
+ "label": "$string:app_name",
12
+ }
13
+ }
14
+ `;
15
+
16
+ export class AppScopeAppJSON5Template {
17
+ constructor(private bundleName: string) {}
18
+
19
+ build(): string {
20
+ return mustache.render(TEMPLATE.trimStart(), {
21
+ bundleName: this.bundleName,
22
+ });
23
+ }
24
+ }
@@ -0,0 +1,22 @@
1
+ import mustache from 'mustache';
2
+
3
+ const TEMPLATE = `
4
+ {
5
+ "string": [
6
+ {
7
+ "name": "app_name",
8
+ "value": "{{name}}"
9
+ }
10
+ ]
11
+ }
12
+ `;
13
+
14
+ export class AppScopeStringVarTemplate {
15
+ constructor(private name: string) {}
16
+
17
+ build(): string {
18
+ return mustache.render(TEMPLATE.trimStart(), {
19
+ name: this.name,
20
+ });
21
+ }
22
+ }
@@ -0,0 +1,59 @@
1
+ import mustache from 'mustache';
2
+
3
+ const TEMPLATE = `
4
+ import {
5
+ AnyJSBundleProvider,
6
+ MetroJSBundleProvider,
7
+ RNApp,
8
+ RNOHErrorDialog,
9
+ ResourceJSBundleProvider,
10
+ RNOHCoreContext
11
+ } from '@rnoh/react-native-openharmony';
12
+ import { getRNOHPackages } from '../PackageProvider';
13
+
14
+ @Entry
15
+ @Component
16
+ struct Index {
17
+ @StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
18
+
19
+ build() {
20
+ Column() {
21
+ if (this.rnohCoreContext) {
22
+ if (this.rnohCoreContext?.isDebugModeEnabled) {
23
+ RNOHErrorDialog({ ctx: this.rnohCoreContext })
24
+ }
25
+ RNApp({
26
+ rnInstanceConfig: {
27
+ name: "{{name}}",
28
+ createRNPackages: getRNOHPackages,
29
+ fontResourceByFontFamily: {},
30
+ enableDebugger: this.rnohCoreContext?.isDebugModeEnabled,
31
+ },
32
+ appKey: "{{name}}",
33
+ jsBundleProvider: this.rnohCoreContext?.isDebugModeEnabled ?
34
+ new AnyJSBundleProvider([
35
+ new MetroJSBundleProvider(),
36
+ new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
37
+ ]) :
38
+ /**
39
+ * NOTE: The HBC format is recommended for Hermes in a production environment. HBC provides better performance and loading times.
40
+ */
41
+ new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
42
+ })
43
+ }
44
+ }
45
+ .height('100%')
46
+ .width('100%')
47
+ }
48
+ }
49
+ `;
50
+
51
+ export class EntryIndexTemplate {
52
+ constructor(private name: string) {}
53
+
54
+ build(): string {
55
+ return mustache.render(TEMPLATE.trimStart(), {
56
+ name: this.name,
57
+ });
58
+ }
59
+ }
@@ -0,0 +1,31 @@
1
+ import mustache from 'mustache';
2
+
3
+ const TEMPLATE = `
4
+ {
5
+ "string": [
6
+ {
7
+ "name": "module_desc",
8
+ "value": "{{description}}"
9
+ },
10
+ {
11
+ "name": "EntryAbility_desc",
12
+ "value": "{{description}}"
13
+ },
14
+ {
15
+ "name": "EntryAbility_label",
16
+ "value": "{{name}}"
17
+ }
18
+ ]
19
+ }
20
+ `;
21
+
22
+ export class EntryStringVarTemplate {
23
+ constructor(private name: string, private description: string) {}
24
+
25
+ build(): string {
26
+ return mustache.render(TEMPLATE.trimStart(), {
27
+ name: this.name,
28
+ description: this.description,
29
+ });
30
+ }
31
+ }
@@ -0,0 +1,40 @@
1
+ import mustache from 'mustache';
2
+
3
+ const TEMPLATE = `
4
+ {
5
+ "modelVersion": "5.0.0",
6
+ "dependencies": {
7
+ "@rnoh/hvigor-plugin": "../../node_modules/{{{rnohCliNpmPackageName}}}/harmony/{{{rnohHvigorPluginFilename}}}", // <PROJECT_ROOT>/node_modules/<RNOH_CLI>/harmony/rnoh-hvigor-plugin-X.X.X.tgz
8
+ },
9
+ "execution": {
10
+ // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */
11
+ // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */
12
+ // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */
13
+ // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */
14
+ // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */
15
+ },
16
+ "logging": {
17
+ // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
18
+ },
19
+ "debugging": {
20
+ // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */
21
+ },
22
+ "nodeOptions": {
23
+ // "maxOldSpaceSize": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */
24
+ }
25
+ }
26
+ `;
27
+
28
+ export class HvigorConfigJson5Template {
29
+ constructor(
30
+ private rnohCliNpmPackageName: string,
31
+ private rnohHvigorPluginFilename: string
32
+ ) {}
33
+
34
+ build(): string {
35
+ return mustache.render(TEMPLATE.trimStart(), {
36
+ rnohCliNpmPackageName: this.rnohCliNpmPackageName,
37
+ rnohHvigorPluginFilename: this.rnohHvigorPluginFilename,
38
+ });
39
+ }
40
+ }
@@ -0,0 +1,41 @@
1
+ import mustache from 'mustache';
2
+
3
+ const TEMPLATE = `
4
+ const {mergeConfig, getDefaultConfig} = require('@react-native/metro-config');
5
+ const {
6
+ createHarmonyMetroConfig,
7
+ } = require('{{{reactNativeHarmonyPackageName}}}/metro.config');
8
+
9
+ /**
10
+ * @type {import("metro-config").MetroConfig}
11
+ */
12
+ const config = {
13
+ transformer: {
14
+ getTransformOptions: async () => ({
15
+ transform: {
16
+ experimentalImportSupport: false,
17
+ inlineRequires: true,
18
+ },
19
+ }),
20
+ },
21
+ };
22
+
23
+ module.exports = mergeConfig(
24
+ getDefaultConfig(__dirname),
25
+ createHarmonyMetroConfig({
26
+ reactNativeHarmonyPackageName: '{{{reactNativeHarmonyPackageName}}}',
27
+ }),
28
+ config,
29
+ );
30
+
31
+ `;
32
+
33
+ export class MetroConfigTemplate {
34
+ constructor(private reactNativeHarmonyPackageName: string) {}
35
+
36
+ build(): string {
37
+ return mustache.render(TEMPLATE.trimStart(), {
38
+ reactNativeHarmonyPackageName: this.reactNativeHarmonyPackageName,
39
+ });
40
+ }
41
+ }
@@ -0,0 +1,31 @@
1
+ import mustache from 'mustache';
2
+
3
+ const TEMPLATE = `
4
+ {
5
+ name: "example-name",
6
+ description: "example description",
7
+ version: "1.0.0",
8
+ modelVersion: "5.0.0",
9
+ license: "ISC",
10
+ repository: {},
11
+ dependencies: {
12
+ "@rnoh/react-native-openharmony": "file:../node_modules/{{{rnohNpmPackageName}}}/react_native_openharmony.har",
13
+ },
14
+ devDependencies: {
15
+ "@ohos/hypium": "1.0.6",
16
+ },
17
+ overrides: {
18
+ "@rnoh/react-native-openharmony": "file:../node_modules/{{{rnohNpmPackageName}}}/react_native_openharmony.har",
19
+ },
20
+ }
21
+ `;
22
+
23
+ export class OhPackageJson5Template {
24
+ constructor(private rnohNpmPackageName: string) {}
25
+
26
+ build(): string {
27
+ return mustache.render(TEMPLATE.trimStart(), {
28
+ rnohNpmPackageName: this.rnohNpmPackageName,
29
+ });
30
+ }
31
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "app": {
3
+ "bundleName": "com.example",
4
+ "vendor": "example",
5
+ "versionCode": 1000000,
6
+ "versionName": "1.0.0",
7
+ "icon": "$media:app_icon",
8
+ "label": "$string:app_name",
9
+ }
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "app_name",
5
+ "value": "example"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ app: {
3
+ products: [
4
+ {
5
+ name: 'default',
6
+ signingConfig: 'default',
7
+ compatibleSdkVersion: '5.0.0(12)',
8
+ runtimeOS: 'HarmonyOS',
9
+ buildOption: {
10
+ nativeCompiler: 'BiSheng'
11
+ }
12
+ },
13
+ ],
14
+ buildModeSet: [
15
+ {
16
+ name: 'debug',
17
+ },
18
+ {
19
+ name: 'release',
20
+ },
21
+ ],
22
+ signingConfigs: [],
23
+ },
24
+ modules: [
25
+ {
26
+ name: 'entry',
27
+ srcPath: './entry',
28
+ targets: [
29
+ {
30
+ name: 'default',
31
+ applyToProducts: ['default'],
32
+ },
33
+ ],
34
+ },
35
+ ],
36
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "files": ["**/*.ts", "**/*.ets"],
3
+ "ignore": [
4
+ "**/ohosTest/**/*",
5
+ "**/node_modules/**/*",
6
+ "**/hvigorfile.ts",
7
+ "**/node_modules/**/*",
8
+ "**/oh_modules/**/*",
9
+ "**/build/**/*",
10
+ "**/.preview/**/*"
11
+ ],
12
+ "plugins": ["@typescript-eslint"],
13
+ "ruleSet": [],
14
+ "rules": {
15
+ "@typescript-eslint/await-thenable": "warn",
16
+ "@typescript-eslint/consistent-type-imports": "warn",
17
+ "@typescript-eslint/explicit-function-return-type": "warn",
18
+ "@typescript-eslint/explicit-module-boundary-types": "warn",
19
+ "@typescript-eslint/no-dynamic-delete": "warn",
20
+ "@typescript-eslint/no-explicit-any": "warn",
21
+ "@typescript-eslint/no-for-in-array": "warn",
22
+ "@typescript-eslint/no-this-alias": "warn",
23
+ "@typescript-eslint/no-unnecessary-type-constraint": "warn",
24
+ "@typescript-eslint/no-unsafe-argument": "warn",
25
+ "@typescript-eslint/no-unsafe-assignment": "warn",
26
+ "@typescript-eslint/no-unsafe-call": "warn",
27
+ "@typescript-eslint/no-unsafe-member-access": "warn",
28
+ "@typescript-eslint/no-unsafe-return": "warn",
29
+ "@typescript-eslint/prefer-literal-enum-member": "warn"
30
+ },
31
+ "overrides": []
32
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "apiType": 'stageMode',
3
+ "buildOption": {
4
+ "externalNativeOptions": {
5
+ "path": "./src/main/cpp/CMakeLists.txt",
6
+ "arguments": "",
7
+ },
8
+ },
9
+ "targets": [
10
+ {
11
+ "name": "default",
12
+ "runtimeOS": "HarmonyOS"
13
+ },
14
+ {
15
+ "name": "ohosTest",
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,7 @@
1
+ /node_modules
2
+ /.preview
3
+ /build
4
+ /.cxx
5
+ package-lock.json
6
+ /oh_modules
7
+ /assets
@@ -0,0 +1,13 @@
1
+ import { hapTasks } from '@ohos/hvigor-ohos-plugin';
2
+ import { createRNOHModulePlugin } from '@rnoh/hvigor-plugin';
3
+
4
+ export default {
5
+ system: hapTasks,
6
+ plugins: [
7
+ createRNOHModulePlugin({
8
+ codegen: {
9
+ rnohModulePath: './oh_modules/@rnoh/react-native-openharmony',
10
+ },
11
+ }),
12
+ ],
13
+ };
@@ -0,0 +1,9 @@
1
+ {
2
+ "license": "ISC",
3
+ "devDependencies": {},
4
+ "name": "entry",
5
+ "description": "example description",
6
+ "version": "1.0.0",
7
+ "dependencies": {
8
+ }
9
+ }