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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -4
  3. package/dist/autolinking/Autolinking.js +13 -16
  4. package/dist/autolinking/index.js +0 -6
  5. package/dist/codegen/core/CodeGenerator.js +0 -6
  6. package/dist/codegen/core/CodegenError.js +0 -6
  7. package/dist/codegen/core/EventUtils.js +0 -6
  8. package/dist/codegen/core/TypeAnnotationToTS.js +0 -6
  9. package/dist/codegen/core/UberSchema.js +2 -11
  10. package/dist/codegen/core/index.js +0 -6
  11. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +2 -7
  12. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +0 -6
  13. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +0 -6
  14. package/dist/codegen/generators/CppComponentCodeGenerator.js +0 -6
  15. package/dist/codegen/generators/LibGlueCodeGenerator.js +2 -8
  16. package/dist/codegen/generators/NativeModuleCodeGenerator.js +1 -7
  17. package/dist/codegen/generators/SharedComponentCodeGenerator.js +0 -6
  18. package/dist/codegen/generators/UberGeneratorV1.js +0 -6
  19. package/dist/codegen/generators/UberGeneratorV2.js +0 -6
  20. package/dist/codegen/generators/index.js +0 -6
  21. package/dist/codegen/index.js +0 -6
  22. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +0 -6
  23. package/dist/codegen/templates/BasePackageHTemplate.js +12 -7
  24. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +1 -6
  25. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +0 -6
  26. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -6
  27. package/dist/codegen/templates/IndexTSTemplate.js +0 -6
  28. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +12 -7
  29. package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -6
  30. package/dist/codegen/templates/TurboModuleHTemplate.js +0 -6
  31. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -6
  32. package/dist/codegen/templates/index.js +0 -6
  33. package/dist/commands/bundle-harmony.js +131 -36
  34. package/dist/commands/clean-harmony.js +84 -0
  35. package/dist/commands/codegen-harmony.js +0 -6
  36. package/dist/commands/codegen-lib-harmony.js +6 -12
  37. package/dist/commands/index.js +2 -9
  38. package/dist/commands/init-harmony.js +226 -0
  39. package/dist/commands/init.js +0 -0
  40. package/dist/commands/link-harmony.js +12 -16
  41. package/dist/commands/types.js +0 -6
  42. package/dist/commands/verify-package-harmony.js +6 -10
  43. package/dist/core/AbsolutePath.js +3 -6
  44. package/dist/core/CodegenConfig.js +0 -6
  45. package/dist/core/DescriptiveError.js +0 -6
  46. package/dist/core/FileSystem.js +0 -6
  47. package/dist/core/OHPackageJSON5.js +0 -6
  48. package/dist/core/ProjectDependenciesManager.js +6 -14
  49. package/dist/core/ValidationError.js +0 -6
  50. package/dist/core/ValueObject.js +0 -6
  51. package/dist/core/fs.js +13 -6
  52. package/dist/core/index.js +0 -6
  53. package/dist/index.js +2 -9
  54. package/dist/init/templates/AppScopeAppJSON5Template.js +30 -0
  55. package/dist/init/templates/AppScopeStringVarTemplate.js +28 -0
  56. package/dist/init/templates/EntryIndexTemplate.js +65 -0
  57. package/dist/init/templates/EntryStringVarTemplate.js +38 -0
  58. package/dist/init/templates/HvigorConfigJson5Template.js +44 -0
  59. package/dist/init/templates/MetroConfigTemplate.js +47 -0
  60. package/dist/init/templates/OhPackageJson5Template.js +37 -0
  61. package/dist/init/templates/harmony/AppScope/app.json5 +10 -0
  62. package/dist/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
  63. package/dist/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  64. package/dist/init/templates/harmony/build-profile.json5 +36 -0
  65. package/dist/init/templates/harmony/codelinter.json +32 -0
  66. package/dist/init/templates/harmony/entry/build-profile.json5 +18 -0
  67. package/dist/init/templates/harmony/entry/gitignore +7 -0
  68. package/dist/init/templates/harmony/entry/hvigorfile.ts +13 -0
  69. package/dist/init/templates/harmony/entry/oh-package.json5 +9 -0
  70. package/dist/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
  71. package/dist/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
  72. package/dist/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
  73. package/dist/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
  74. package/dist/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
  75. package/dist/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
  76. package/dist/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
  77. package/dist/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  78. package/dist/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
  79. package/dist/init/templates/harmony/entry/src/main/module.json5 +58 -0
  80. package/dist/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
  81. package/dist/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
  82. package/dist/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  83. package/dist/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  84. package/dist/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
  85. package/dist/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  86. package/dist/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  87. package/dist/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
  88. package/dist/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
  89. package/dist/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
  90. package/dist/init/templates/harmony/gitignore +16 -0
  91. package/dist/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
  92. package/dist/init/templates/harmony/hvigorfile.ts +7 -0
  93. package/dist/init/templates/index.js +21 -0
  94. package/dist/io/CliExecutor.js +0 -6
  95. package/dist/io/Logger.js +0 -6
  96. package/dist/io/RealFS.js +10 -6
  97. package/dist/io/TarGz.js +2 -8
  98. package/dist/io/__fixtures__.js +0 -6
  99. package/dist/io/fsUtils.js +0 -6
  100. package/dist/io/index.js +1 -6
  101. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +0 -6
  102. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +0 -6
  103. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +0 -6
  104. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +0 -6
  105. package/dist/package-verifier/checks/index.js +0 -6
  106. package/dist/package-verifier/index.js +0 -6
  107. package/dist/package-verifier/types.js +0 -6
  108. package/dist/package-verifier/verify-package.js +1 -7
  109. package/harmony/rnoh-hvigor-plugin-0.77.18.tgz +0 -0
  110. package/jest.config.js +0 -7
  111. package/package.json +15 -18
  112. package/react-native.config.js +0 -7
  113. package/scripts/copy-template.js +18 -0
  114. package/src/autolinking/Autolinking.test.ts +54 -18
  115. package/src/autolinking/Autolinking.ts +23 -20
  116. package/src/autolinking/index.ts +1 -8
  117. package/src/codegen/core/CodeGenerator.ts +0 -7
  118. package/src/codegen/core/CodegenError.ts +0 -7
  119. package/src/codegen/core/EventUtils.ts +0 -7
  120. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -7
  121. package/src/codegen/core/TypeAnnotationToTS.ts +3 -8
  122. package/src/codegen/core/UberSchema.ts +3 -12
  123. package/src/codegen/core/index.ts +0 -7
  124. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +5 -8
  125. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -7
  126. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -7
  127. package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -7
  128. package/src/codegen/generators/LibGlueCodeGenerator.ts +2 -9
  129. package/src/codegen/generators/NativeModuleCodeGenerator.ts +1 -8
  130. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -7
  131. package/src/codegen/generators/UberGeneratorV1.ts +0 -7
  132. package/src/codegen/generators/UberGeneratorV2.ts +0 -7
  133. package/src/codegen/generators/index.ts +0 -7
  134. package/src/codegen/index.ts +0 -7
  135. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -7
  136. package/src/codegen/templates/BasePackageHTemplate.ts +13 -8
  137. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +1 -7
  138. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -7
  139. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -7
  140. package/src/codegen/templates/IndexTSTemplate.ts +0 -7
  141. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +13 -8
  142. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -7
  143. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -7
  144. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -7
  145. package/src/codegen/templates/index.ts +0 -7
  146. package/src/commands/bundle-harmony.ts +174 -39
  147. package/src/commands/clean-harmony.ts +54 -0
  148. package/src/commands/codegen-harmony.ts +0 -7
  149. package/src/commands/codegen-lib-harmony.ts +6 -13
  150. package/src/commands/index.ts +2 -10
  151. package/src/commands/init-harmony.ts +299 -0
  152. package/src/commands/link-harmony.ts +13 -18
  153. package/src/commands/types.ts +0 -7
  154. package/src/commands/verify-package-harmony.ts +7 -10
  155. package/src/core/AbsolutePath.ts +4 -7
  156. package/src/core/CodegenConfig.ts +0 -7
  157. package/src/core/DescriptiveError.ts +0 -7
  158. package/src/core/FileSystem.ts +5 -8
  159. package/src/core/OHPackageJSON5.ts +0 -7
  160. package/src/core/PackageJSON.ts +0 -6
  161. package/src/core/ProjectDependenciesManager.ts +14 -22
  162. package/src/core/ValidationError.ts +0 -7
  163. package/src/core/ValueObject.ts +0 -7
  164. package/src/core/fs.ts +13 -7
  165. package/src/core/index.ts +0 -7
  166. package/src/index.ts +4 -13
  167. package/src/init/templates/AppScopeAppJSON5Template.ts +24 -0
  168. package/src/init/templates/AppScopeStringVarTemplate.ts +22 -0
  169. package/src/init/templates/EntryIndexTemplate.ts +59 -0
  170. package/src/init/templates/EntryStringVarTemplate.ts +31 -0
  171. package/src/init/templates/HvigorConfigJson5Template.ts +40 -0
  172. package/src/init/templates/MetroConfigTemplate.ts +41 -0
  173. package/src/init/templates/OhPackageJson5Template.ts +31 -0
  174. package/src/init/templates/harmony/AppScope/app.json5 +10 -0
  175. package/src/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
  176. package/src/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  177. package/src/init/templates/harmony/build-profile.json5 +36 -0
  178. package/src/init/templates/harmony/codelinter.json +32 -0
  179. package/src/init/templates/harmony/entry/build-profile.json5 +18 -0
  180. package/src/init/templates/harmony/entry/gitignore +7 -0
  181. package/src/init/templates/harmony/entry/hvigorfile.ts +13 -0
  182. package/src/init/templates/harmony/entry/oh-package.json5 +9 -0
  183. package/src/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
  184. package/src/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
  185. package/src/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
  186. package/src/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
  187. package/src/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
  188. package/src/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
  189. package/src/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
  190. package/src/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  191. package/src/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
  192. package/src/init/templates/harmony/entry/src/main/module.json5 +58 -0
  193. package/src/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
  194. package/src/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
  195. package/src/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  196. package/src/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  197. package/src/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
  198. package/src/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  199. package/src/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  200. package/src/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
  201. package/src/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
  202. package/src/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
  203. package/src/init/templates/harmony/gitignore +16 -0
  204. package/src/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
  205. package/src/init/templates/harmony/hvigorfile.ts +7 -0
  206. package/src/init/templates/index.ts +5 -0
  207. package/src/io/CliExecutor.ts +1 -8
  208. package/src/io/Logger.ts +0 -7
  209. package/src/io/RealFS.ts +15 -8
  210. package/src/io/TarGz.ts +1 -8
  211. package/src/io/__fixtures__.ts +1 -8
  212. package/src/io/fsUtils.ts +1 -7
  213. package/src/io/index.ts +1 -7
  214. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -7
  215. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -7
  216. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -7
  217. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -7
  218. package/src/package-verifier/checks/index.ts +0 -7
  219. package/src/package-verifier/index.ts +0 -7
  220. package/src/package-verifier/types.ts +0 -7
  221. package/src/package-verifier/verify-package.ts +0 -7
  222. package/tsconfig.build.json +2 -5
  223. package/tsconfig.json +4 -0
  224. package/dist/commands/create-metro-host-constants.js +0 -67
  225. package/dist/commands/pack-harmony.js +0 -106
  226. package/dist/commands/unpack-harmony.js +0 -189
  227. package/src/commands/create-metro-host-constants.ts +0 -55
  228. package/src/commands/pack-harmony.ts +0 -128
  229. package/src/commands/unpack-harmony.ts +0 -238
@@ -0,0 +1,299 @@
1
+ import { Command } from './types';
2
+ import { Logger, RealFS } from '../io';
3
+ import {
4
+ MetroConfigTemplate,
5
+ EntryStringVarTemplate,
6
+ EntryIndexTemplate,
7
+ OhPackageJson5Template,
8
+ HvigorConfigJson5Template,
9
+ } from '../init/templates';
10
+ import { AbsolutePath, DescriptiveError, PackageJSON } from '../core';
11
+ import { copy as dirCopy, ensureDir } from 'fs-extra';
12
+ import { AppScopeStringVarTemplate } from '../init/templates/AppScopeStringVarTemplate';
13
+ import { AppScopeAppJSON5Template } from '../init/templates/AppScopeAppJSON5Template';
14
+
15
+ const COMMAND_NAME = 'init-harmony';
16
+ const BUNDLE_NAME_PATTERN = /^[a-zA-Z][0-9a-zA-Z_.]+$/;
17
+
18
+ export const commandInitHarmony: Command = {
19
+ name: COMMAND_NAME,
20
+ description: 'Initializes a new RNOH project.',
21
+ options: [
22
+ {
23
+ name: '--bundle-name <string>',
24
+ description: `Required. The native app bundle name. It must match ${BUNDLE_NAME_PATTERN} pattern and include three segments separated by a dot (.).`,
25
+ },
26
+ {
27
+ name: '--project-root-path [path]',
28
+ description: 'Relative path to the project root',
29
+ default: '.',
30
+ },
31
+ {
32
+ name: '--app-name [string]',
33
+ description:
34
+ 'The native app name. Defaults to the name property in package.json',
35
+ default: undefined,
36
+ },
37
+ {
38
+ name: '--rnoh-npm-package-name [string]',
39
+ description: 'Name of the react-native-harmony package.',
40
+ default: '@react-native-oh/react-native-harmony',
41
+ },
42
+ {
43
+ name: '--rnoh-cli-npm-package-name [string]',
44
+ description: 'Name of the react-native-harmony-cli package.',
45
+ default: '@react-native-oh/react-native-harmony-cli',
46
+ },
47
+ ],
48
+ func: async (_argv, _config, rawArgs: any) => {
49
+ const fs = new RealFS();
50
+ const logger = new Logger();
51
+ try {
52
+ // input preparation and validation
53
+ if (!rawArgs.bundleName) {
54
+ throw new DescriptiveError({
55
+ whatHappened: "--bundle-name argument wasn't provided",
56
+ whatCanUserDo: ['Please provide --bundle-name argument'],
57
+ });
58
+ }
59
+ const projectRootPath = new AbsolutePath(rawArgs.projectRootPath);
60
+ const harmonyDirPath = projectRootPath.copyWithNewSegment('harmony');
61
+
62
+ if (fs.existsSync(harmonyDirPath)) {
63
+ throw new DescriptiveError({
64
+ whatHappened: 'The "harmony" directory is already initialized',
65
+ whatCanUserDo: ["Remove the 'harmony' directory."],
66
+ });
67
+ }
68
+ const rnohNpmPackageName: string = rawArgs.rnohNpmPackageName;
69
+ const rnohNpmPackagePath = projectRootPath.copyWithNewSegment(
70
+ 'node_modules',
71
+ rnohNpmPackageName
72
+ );
73
+ if (!fs.existsSync(rnohNpmPackagePath)) {
74
+ throw new DescriptiveError({
75
+ whatHappened: `${rnohNpmPackagePath
76
+ .relativeTo(projectRootPath)
77
+ .toString()} does not exist. This command requires that 'react-native-harmony' NPM package is already installed.`,
78
+ whatCanUserDo: [
79
+ 'Install react-native-harmony and try again.',
80
+ 'Provide --rnoh-npm-package-name if the default value is incorrect.',
81
+ ],
82
+ });
83
+ }
84
+ const rnohCliNpmPackageName: string = rawArgs.rnohCliNpmPackageName;
85
+ const rnohCliNpmPackagePath = projectRootPath.copyWithNewSegment(
86
+ 'node_modules',
87
+ rnohCliNpmPackageName
88
+ );
89
+ if (!fs.existsSync(rnohCliNpmPackagePath)) {
90
+ throw new DescriptiveError({
91
+ whatHappened: `${rnohCliNpmPackagePath
92
+ .relativeTo(projectRootPath)
93
+ .toString()} does not exist. This command requires that 'react-native-cli-harmony' NPM package is already installed.`,
94
+ whatCanUserDo: [
95
+ 'Install react-native-harmony-cli and try again.',
96
+ 'Provide --rnoh-cli-npm-package-name if the default value is incorrect.',
97
+ ],
98
+ });
99
+ }
100
+ const rnohHvigorPluginPath = findRNOHHvigorPluginPath(
101
+ fs,
102
+ rnohCliNpmPackagePath.copyWithNewSegment('harmony')
103
+ );
104
+ if (rnohHvigorPluginPath === null) {
105
+ throw new DescriptiveError({
106
+ whatHappened: `Couldn't find RNOH hvigor plugin in ${rnohHvigorPluginPath}. This CLI package seems to be incompatible with RNOH.`,
107
+ whatCanUserDo: ['Try using different RNOH or CLI version.'],
108
+ });
109
+ }
110
+ const packageJSON = PackageJSON.fromProjectRootPath(
111
+ fs,
112
+ projectRootPath,
113
+ projectRootPath
114
+ );
115
+
116
+ const appName = rawArgs.appName ?? packageJSON.name;
117
+ const bundleName = rawArgs.bundleName;
118
+ if (!isBundleNameValid(bundleName)) {
119
+ throw new DescriptiveError({
120
+ whatHappened: 'Bundle name validation failed',
121
+ whatCanUserDo: [
122
+ `Provide a different project name or provide a bundle name explicitly. Bundle name should have three parts separated by dot e.g. com.org.project and it should match the following regex pattern: ${BUNDLE_NAME_PATTERN}`,
123
+ ],
124
+ });
125
+ }
126
+
127
+ const harmonyTemplateDirPath = new AbsolutePath(
128
+ __dirname
129
+ ).copyWithNewSegment('..', 'init', 'templates', 'harmony');
130
+ await ensureDir(harmonyDirPath.toString());
131
+
132
+ // processing
133
+ const metroConfigPath =
134
+ projectRootPath.copyWithNewSegment('metro.config.js');
135
+ const metroConfigContent = new MetroConfigTemplate(
136
+ rnohNpmPackageName
137
+ ).build();
138
+ const dynamicTemplateContentByPath = new Map<AbsolutePath, string>([
139
+ [
140
+ harmonyDirPath.copyWithNewSegment('oh-package.json5'),
141
+ new OhPackageJson5Template(rnohNpmPackageName).build(),
142
+ ],
143
+ [
144
+ harmonyDirPath.copyWithNewSegment('hvigor', 'hvigor-config.json5'),
145
+ new HvigorConfigJson5Template(
146
+ rnohCliNpmPackageName,
147
+ rnohHvigorPluginPath!.getBasename()
148
+ ).build(),
149
+ ],
150
+ [
151
+ harmonyDirPath.copyWithNewSegment(
152
+ 'entry',
153
+ 'src',
154
+ 'main',
155
+ 'resources',
156
+ 'base',
157
+ 'element',
158
+ 'string.json'
159
+ ),
160
+ new EntryStringVarTemplate(appName, '').build(),
161
+ ],
162
+ [
163
+ harmonyDirPath.copyWithNewSegment(
164
+ 'entry',
165
+ 'src',
166
+ 'main',
167
+ 'ets',
168
+ 'pages',
169
+ 'Index.ets'
170
+ ),
171
+ new EntryIndexTemplate(appName).build(),
172
+ ],
173
+ [
174
+ harmonyDirPath.copyWithNewSegment(
175
+ 'AppScope',
176
+ 'resources',
177
+ 'base',
178
+ 'element',
179
+ 'string.json'
180
+ ),
181
+ new AppScopeStringVarTemplate(appName).build(),
182
+ ],
183
+ [
184
+ harmonyDirPath.copyWithNewSegment('AppScope', 'app.json5'),
185
+ new AppScopeAppJSON5Template(bundleName).build(),
186
+ ],
187
+ ]);
188
+
189
+ // output
190
+ if (fs.existsSync(metroConfigPath)) {
191
+ if (fs.existsSync(projectRootPath.copyWithNewSegment('.git'))) {
192
+ logger.warn((s) => `Overwritten "${s.bold('./metro.config.js')}"`);
193
+ fs.writeTextSync(metroConfigPath, metroConfigContent);
194
+ } else {
195
+ logger.warn(
196
+ (s) =>
197
+ `Skipped overriding "${s.bold(
198
+ './metro.config.js'
199
+ )}" due to lack of .git. Override "${s.bold(
200
+ './metro.config.js'
201
+ )}" manually.`
202
+ );
203
+ console.log(metroConfigContent);
204
+ }
205
+ } else {
206
+ fs.writeTextSync(metroConfigPath, metroConfigContent);
207
+ }
208
+
209
+ await dirCopy(
210
+ harmonyTemplateDirPath.toString(),
211
+ harmonyDirPath.toString()
212
+ );
213
+ renameGitignoreFiles(fs, harmonyDirPath);
214
+ logger.succeed((s) => `Created "${s.bold('./harmony')}" directory`);
215
+ dynamicTemplateContentByPath.forEach((content, path) => {
216
+ fs.writeTextSync(path, content);
217
+ });
218
+
219
+ const buildProfileTemplateComment = "build-profile.json5 can contain signingConfigs which are unique for each developer, therefore that file is ignored by Git. Create a build-profile.json5 based on this template after cloning this repository to be able to open this project in DevEco Studio.";
220
+
221
+ const buildProfilePath = harmonyDirPath.copyWithNewSegment('build-profile.json5');
222
+ const buildProfileContent = fs.readTextSync(buildProfilePath);
223
+ const contentLines = buildProfileContent.split('\n');
224
+ contentLines.splice(1, 0, " // " + buildProfileTemplateComment);
225
+ const buildProfileTemplateContent = contentLines.join('\n');
226
+
227
+ fs.writeTextSync(
228
+ harmonyDirPath.copyWithNewSegment('build-profile.template.json5'),
229
+ buildProfileTemplateContent
230
+ );
231
+
232
+ logger.info((s) =>
233
+ [
234
+ s.bold('Run on a physical device:'),
235
+ s.gray('1. Run `npm start` to start the Metro server.'),
236
+ s.gray(
237
+ '2. Open `./harmony` project in DevEco Studio and wait for background jobs to finish.'
238
+ ),
239
+ s.gray(
240
+ '3. Press the user icon in top right corner, and then press "Sign in" button.'
241
+ ),
242
+ s.gray('4. Connect the device.'),
243
+ s.gray(
244
+ '5. Go to File > Project Structure > Signing Configs and mark "Automatically generate signature", and then press OK.'
245
+ ),
246
+ s.gray("6. Select 'entry' run configuration (top right corner)."),
247
+ s.gray("7. Press the `Debug 'entry'` button (top right corner)."),
248
+ ].join('\n')
249
+ );
250
+ } catch (err) {
251
+ if (err instanceof DescriptiveError && !err.isUnexpected()) {
252
+ logger.descriptiveError(err);
253
+ return;
254
+ }
255
+ throw err;
256
+ }
257
+ },
258
+ };
259
+
260
+ function findRNOHHvigorPluginPath(
261
+ fs: RealFS,
262
+ dirPath: AbsolutePath
263
+ ): AbsolutePath | null {
264
+ for (let dirent of fs.readDirentsSync(dirPath)) {
265
+ if (dirent.isDirectory() || !dirent.name.startsWith('rnoh-hvigor-plugin')) {
266
+ continue;
267
+ }
268
+ return dirent.path;
269
+ }
270
+ return null;
271
+ }
272
+
273
+ /**
274
+ * In the template directory, gitignore files don't start with a dot.
275
+ * After copying the template, those files need to be renamed.
276
+ */
277
+ function renameGitignoreFiles(fs: RealFS, dirPath: AbsolutePath) {
278
+ try {
279
+ for (const dirent of fs.readDirentsSync(dirPath)) {
280
+ if (dirent.isDirectory()) {
281
+ renameGitignoreFiles(fs, dirent.path);
282
+ } else if (!dirent.isDirectory() && dirent.name === 'gitignore') {
283
+ const newFilePath = dirPath.copyWithNewSegment('.gitignore');
284
+ fs.renameSync(dirent.path, newFilePath);
285
+ }
286
+ }
287
+ } catch (error) {
288
+ throw new DescriptiveError({
289
+ whatHappened: 'Encounter an error when processing .gitignore files',
290
+ extraData: error,
291
+ });
292
+ }
293
+ }
294
+
295
+ function isBundleNameValid(bundleName: string): boolean {
296
+ return (
297
+ BUNDLE_NAME_PATTERN.test(bundleName) && bundleName.split('.').length === 3
298
+ );
299
+ }
@@ -1,10 +1,3 @@
1
- /**
2
- * Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
1
  import { Command } from './types';
9
2
  import { AbsolutePath, DescriptiveError } from '../core';
10
3
  import { Logger, RealFS } from '../io';
@@ -53,14 +46,16 @@ export const commandLinkHarmony: Command = {
53
46
  default: './oh-package.json5',
54
47
  },
55
48
  {
56
- name: '--exclude-npm-packages [string]',
49
+ name: '--exclude-npm-packages [string...]',
57
50
  description:
58
- "Lists npm package names to be excluded from the autolinking process, separated by semicolons. By default every library is included. Can't be used with --included-npm-packages.",
51
+ "Lists npm package names to be excluded from the autolinking process. By default every library is included. Can't be used with --included-npm-packages.",
52
+ parse: (val, prev) => (prev ? [...prev, val] : [val]),
59
53
  },
60
54
  {
61
- name: '--include-npm-packages [string]',
55
+ name: '--include-npm-packages [string...]',
62
56
  description:
63
- "Lists npm package names to be included from the autolinking process, separated by semicolons. By default every library is included. Can't be used with --excluded-npm-packages.",
57
+ "Lists npm package names to be included from the autolinking process. By default every library is included. Can't be used with --excluded-npm-packages.",
58
+ parse: (val, prev) => (prev ? [...prev, val] : [val]),
64
59
  },
65
60
  ],
66
61
  func: async (_argv, _config, rawArgs: any) => {
@@ -79,14 +74,14 @@ export const commandLinkHarmony: Command = {
79
74
  rawArgs.etsRnohPackagesFactoryPathRelativeToHarmony,
80
75
  ohPackagePathRelativeToHarmony: rawArgs.ohPackagePathRelativeToHarmony,
81
76
  excludedNpmPackageNames: new Set(
82
- rawArgs.excludeNpmPackages
83
- ? (rawArgs.excludeNpmPackages ?? '').split(';')
84
- : undefined
77
+ rawArgs.excludeNpmPackages?.length === 1
78
+ ? rawArgs.excludeNpmPackages[0].split(';')
79
+ : rawArgs.excludeNpmPackages
85
80
  ),
86
81
  includedNpmPackageNames: new Set(
87
- rawArgs.includeNpmPackages
88
- ? (rawArgs.includeNpmPackages ?? '').split(';')
89
- : undefined
82
+ rawArgs.includeNpmPackages?.length === 1
83
+ ? rawArgs.includeNpmPackages[0].split(';')
84
+ : rawArgs.includeNpmPackages
90
85
  ),
91
86
  });
92
87
  const result = autolinking.evaluate(config);
@@ -99,4 +94,4 @@ export const commandLinkHarmony: Command = {
99
94
  throw err;
100
95
  }
101
96
  },
102
- };
97
+ };
@@ -1,10 +1,3 @@
1
- /**
2
- * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
1
  import { Command as CLICommand } from '@react-native-community/cli-types';
9
2
 
10
3
  // RNOH patch: The parse function in the Command.options type is missing an extra argument in @react-native-community/cli-types.
@@ -1,10 +1,3 @@
1
- /**
2
- * Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
1
  import { Command } from './types';
9
2
  import { getLoader, Loader } from '@react-native-community/cli-tools';
10
3
  import chalk from 'chalk';
@@ -25,8 +18,9 @@ export const commandVerifyPackageHarmony: Command = {
25
18
  description: 'Disable har verification',
26
19
  },
27
20
  {
28
- name: '--skip-checks <string>',
29
- description: 'Disable certain checks by their names separated by ";"',
21
+ name: '--skip-checks <string...>',
22
+ description: 'Disable certain checks by their names',
23
+ parse: (val, prev) => (prev ? [...prev, val] : [val]),
30
24
  },
31
25
  ],
32
26
  func: async (argv, config, rawArgs: any) => {
@@ -88,7 +82,10 @@ function validateArgs(args: any): Args {
88
82
  return {
89
83
  packagePath: new AbsolutePath(args.packagePath),
90
84
  hasHarmonyCode: args.harmonyCode,
91
- checkNamesToSkip: ((args.skipChecks ?? '') as string).split(';'),
85
+ checkNamesToSkip:
86
+ args.skipChecks.length === 1
87
+ ? args.skipChecks[0].split(';')
88
+ : args.skipChecks,
92
89
  };
93
90
  }
94
91
 
@@ -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 pathUtils from 'node:path';
9
2
  import { ValueObject } from './ValueObject';
10
3
 
@@ -39,6 +32,10 @@ export class AbsolutePath implements ValueObject {
39
32
  return null;
40
33
  }
41
34
 
35
+ getBasename(): string {
36
+ return pathUtils.basename(this.value);
37
+ }
38
+
42
39
  getDirectoryPath(): AbsolutePath {
43
40
  const dirPath = pathUtils.extname(this.value)
44
41
  ? pathUtils.dirname(this.value)
@@ -1,10 +1,3 @@
1
- /**
2
- * Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
1
  import fs from 'node:fs';
9
2
  import { AbsolutePath } from './AbsolutePath';
10
3
  import { findFilePathsWithExtensions } from '../io';
@@ -1,10 +1,3 @@
1
- /**
2
- * Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
1
  export class DescriptiveError extends Error {
9
2
  constructor(
10
3
  private data:
@@ -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-2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
1
  import { AbsolutePath } from './AbsolutePath';
8
2
  import { CodegenConfig, RawCodegenConfig } from './CodegenConfig';
9
3
  import { DescriptiveError } from './DescriptiveError';
@@ -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-2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
1
  import fs from 'node:fs';
9
2
  import { AbsolutePath } from './AbsolutePath';
10
3
  import { DescriptiveError } from './DescriptiveError';
@@ -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,33 +1,24 @@
1
- /**
2
- * Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
1
  import { 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,
18
8
  commandRunHarmony,
9
+ commandInitHarmony,
10
+ commandCleanHarmony,
19
11
  } from './commands';
20
12
 
21
13
  export const config = {
22
14
  commands: [
23
15
  commandBundleHarmony,
24
- commandPackHarmony,
25
- commandUnpackHarmony,
26
- commandCreateMetroConstantsHarmony,
27
16
  commandCodegenHarmony,
28
17
  commandVerifyPackageHarmony,
29
18
  commandCodegenLibHarmony,
30
19
  commandLinkHarmony,
31
20
  commandRunHarmony,
21
+ commandInitHarmony,
22
+ commandCleanHarmony
32
23
  ] as Command[],
33
24
  } satisfies Partial<Config>;