@react-native-oh/react-native-harmony-cli 0.0.27 → 0.0.28

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 (140) hide show
  1. package/README.md +12 -0
  2. package/dist/assetResolver.js +6 -0
  3. package/dist/autolinking/Autolinking.js +275 -0
  4. package/dist/autolinking/index.js +23 -0
  5. package/dist/codegen/core/CodeGenerator.js +6 -0
  6. package/dist/codegen/core/CodegenError.js +6 -0
  7. package/dist/codegen/core/EventUtils.js +6 -0
  8. package/dist/codegen/core/TypeAnnotationToTS.js +6 -0
  9. package/dist/codegen/core/UberSchema.js +9 -3
  10. package/dist/codegen/core/index.js +6 -0
  11. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +6 -0
  12. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +6 -0
  13. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +6 -0
  14. package/dist/codegen/generators/CppComponentCodeGenerator.js +6 -0
  15. package/dist/codegen/generators/LibGlueCodeGenerator.js +6 -0
  16. package/dist/codegen/generators/NativeModuleCodeGenerator.js +6 -0
  17. package/dist/codegen/generators/SharedComponentCodeGenerator.js +6 -0
  18. package/dist/codegen/generators/UberGeneratorV1.js +6 -0
  19. package/dist/codegen/generators/UberGeneratorV2.js +6 -0
  20. package/dist/codegen/generators/index.js +6 -0
  21. package/dist/codegen/index.js +6 -0
  22. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +6 -0
  23. package/dist/codegen/templates/BasePackageHTemplate.js +6 -0
  24. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +6 -0
  25. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +6 -0
  26. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +6 -0
  27. package/dist/codegen/templates/IndexTSTemplate.js +6 -0
  28. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +6 -0
  29. package/dist/codegen/templates/TurboModuleCppTemplate.js +6 -0
  30. package/dist/codegen/templates/TurboModuleHTemplate.js +6 -0
  31. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +6 -0
  32. package/dist/codegen/templates/index.js +6 -0
  33. package/dist/commands/bundle-harmony.js +6 -0
  34. package/dist/commands/codegen-harmony.js +16 -10
  35. package/dist/commands/codegen-lib-harmony.js +6 -0
  36. package/dist/commands/create-metro-host-constants.js +6 -0
  37. package/dist/commands/index.js +7 -0
  38. package/dist/commands/link-harmony.js +97 -0
  39. package/dist/commands/pack-harmony.js +6 -0
  40. package/dist/commands/unpack-harmony.js +10 -3
  41. package/dist/commands/verify-package-harmony.js +6 -0
  42. package/dist/core/AbsolutePath.js +12 -0
  43. package/dist/core/CodegenConfig.js +6 -0
  44. package/dist/core/DescriptiveError.js +6 -0
  45. package/dist/core/FileSystem.js +33 -0
  46. package/dist/core/OHPackageJSON5.js +6 -0
  47. package/dist/core/PackageJSON.js +15 -7
  48. package/dist/core/ProjectDependenciesManager.js +31 -18
  49. package/dist/core/ValidationError.js +6 -0
  50. package/dist/core/ValueObject.js +6 -0
  51. package/dist/core/fs.js +6 -0
  52. package/dist/core/index.js +7 -0
  53. package/dist/index.js +7 -0
  54. package/dist/io/CliExecutor.js +35 -0
  55. package/dist/io/Logger.js +9 -0
  56. package/dist/io/RealFS.js +68 -0
  57. package/dist/io/TarGz.js +6 -0
  58. package/dist/io/__fixtures__.js +127 -0
  59. package/dist/io/fsUtils.js +20 -6
  60. package/dist/io/index.js +7 -0
  61. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +6 -0
  62. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +6 -0
  63. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +6 -0
  64. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +6 -0
  65. package/dist/package-verifier/checks/index.js +6 -0
  66. package/dist/package-verifier/index.js +6 -0
  67. package/dist/package-verifier/types.js +6 -0
  68. package/dist/package-verifier/verify-package.js +7 -1
  69. package/jest.config.js +7 -0
  70. package/package.json +8 -2
  71. package/react-native.config.js +7 -0
  72. package/src/assetResolver.ts +7 -0
  73. package/src/autolinking/Autolinking.test.ts +483 -0
  74. package/src/autolinking/Autolinking.ts +384 -0
  75. package/src/autolinking/index.ts +8 -0
  76. package/src/codegen/core/CodeGenerator.ts +7 -0
  77. package/src/codegen/core/CodegenError.ts +7 -0
  78. package/src/codegen/core/EventUtils.ts +7 -0
  79. package/src/codegen/core/TypeAnnotationToTS.test.ts +7 -0
  80. package/src/codegen/core/TypeAnnotationToTS.ts +7 -0
  81. package/src/codegen/core/UberSchema.ts +11 -1
  82. package/src/codegen/core/index.ts +7 -0
  83. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +7 -0
  84. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +7 -0
  85. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +7 -0
  86. package/src/codegen/generators/CppComponentCodeGenerator.ts +7 -0
  87. package/src/codegen/generators/LibGlueCodeGenerator.ts +7 -0
  88. package/src/codegen/generators/NativeModuleCodeGenerator.ts +7 -0
  89. package/src/codegen/generators/SharedComponentCodeGenerator.ts +7 -0
  90. package/src/codegen/generators/UberGeneratorV1.ts +7 -0
  91. package/src/codegen/generators/UberGeneratorV2.ts +7 -0
  92. package/src/codegen/generators/index.ts +7 -0
  93. package/src/codegen/index.ts +7 -0
  94. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +7 -0
  95. package/src/codegen/templates/BasePackageHTemplate.ts +7 -0
  96. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +7 -0
  97. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +7 -0
  98. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +7 -0
  99. package/src/codegen/templates/IndexTSTemplate.ts +7 -0
  100. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +7 -0
  101. package/src/codegen/templates/TurboModuleCppTemplate.ts +7 -0
  102. package/src/codegen/templates/TurboModuleHTemplate.ts +7 -0
  103. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +7 -0
  104. package/src/codegen/templates/index.ts +7 -0
  105. package/src/commands/bundle-harmony.ts +8 -1
  106. package/src/commands/codegen-harmony.ts +19 -6
  107. package/src/commands/codegen-lib-harmony.ts +7 -0
  108. package/src/commands/create-metro-host-constants.ts +7 -0
  109. package/src/commands/index.ts +8 -0
  110. package/src/commands/link-harmony.ts +102 -0
  111. package/src/commands/pack-harmony.ts +7 -0
  112. package/src/commands/unpack-harmony.ts +12 -3
  113. package/src/commands/verify-package-harmony.ts +7 -0
  114. package/src/core/AbsolutePath.ts +16 -0
  115. package/src/core/CodegenConfig.ts +7 -0
  116. package/src/core/DescriptiveError.ts +7 -0
  117. package/src/core/FileSystem.ts +57 -0
  118. package/src/core/OHPackageJSON5.ts +7 -0
  119. package/src/core/PackageJSON.ts +40 -8
  120. package/src/core/ProjectDependenciesManager.ts +40 -14
  121. package/src/core/ValidationError.ts +7 -0
  122. package/src/core/ValueObject.ts +7 -0
  123. package/src/core/fs.ts +7 -0
  124. package/src/core/index.ts +8 -0
  125. package/src/index.ts +9 -0
  126. package/src/io/CliExecutor.ts +47 -0
  127. package/src/io/Logger.ts +11 -0
  128. package/src/io/RealFS.ts +62 -0
  129. package/src/io/TarGz.ts +7 -0
  130. package/src/io/__fixtures__.ts +135 -0
  131. package/src/io/fsUtils.ts +26 -6
  132. package/src/io/index.ts +8 -0
  133. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +7 -0
  134. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +7 -0
  135. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +7 -0
  136. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +7 -0
  137. package/src/package-verifier/checks/index.ts +7 -0
  138. package/src/package-verifier/index.ts +7 -0
  139. package/src/package-verifier/types.ts +7 -0
  140. package/src/package-verifier/verify-package.ts +9 -1
@@ -0,0 +1,384 @@
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 JSON5 from 'json5';
9
+ import {
10
+ AbsolutePath,
11
+ ProjectDependenciesManager,
12
+ FS,
13
+ DescriptiveError,
14
+ } from '../core';
15
+ import Mustache from 'mustache';
16
+ import Case from 'case';
17
+ import { Logger } from '../io';
18
+
19
+ type Version = string;
20
+ type DependencySpecifier = `file:${string}` | Version;
21
+
22
+ export type AutolinkingConfig = {
23
+ harmonyProjectPath: AbsolutePath;
24
+ nodeModulesPath: AbsolutePath;
25
+ ohPackagePathRelativeToHarmony: string;
26
+ etsRNOHPackagesFactoryPathRelativeToHarmony: string;
27
+ cppRNOHPackagesFactoryPathRelativeToHarmony: string;
28
+ cmakeAutolinkPathRelativeToHarmony: string;
29
+ excludedNpmPackageNames: Set<string>;
30
+ includedNpmPackageNames: Set<string>;
31
+ };
32
+
33
+ type AutolinkableLibrary = {
34
+ npmPackageName: string;
35
+ harFilePathRelativeToHarmony: string;
36
+ etsRNOHPackageClassName?: string;
37
+ cppRNOHPackageClassName?: string;
38
+ cmakeLibraryTargetName?: string;
39
+ ohPackageName?: string;
40
+ };
41
+
42
+ type AutolinkingInput = {
43
+ projectRootPath: AbsolutePath;
44
+ etsRNOHPackagesFactoryPath: AbsolutePath;
45
+ cppRNOHPackagesFactoryPath: AbsolutePath;
46
+ cmakeAutolinkingPath: AbsolutePath;
47
+ ohPackagePathAndContent: [AbsolutePath, string];
48
+ autolinkableLibraries: AutolinkableLibrary[];
49
+ nodeModuleHarFilePathsRelativeToHarmony: string[];
50
+ skippedLibraryNpmPackageNames: string[];
51
+ };
52
+
53
+ type AutolinkingOutput = {
54
+ linkedLibraryNpmPackageNames: string[];
55
+ skippedLibraryNpmPackageNames: string[];
56
+ projectRootPath: AbsolutePath;
57
+ etsRNOHPackagesFactoryPathAndContent: [AbsolutePath, string];
58
+ cppRNOHPackagesFactoryPathAndContent: [AbsolutePath, string];
59
+ cmakeAutolinkingPathAndContent: [AbsolutePath, string];
60
+ ohPackagePathAndContent: [AbsolutePath, string];
61
+ };
62
+
63
+ const ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = `
64
+ /*
65
+ * This file was generated by RNOH autolinking.
66
+ * DO NOT modify it manually, your changes WILL be overwritten.
67
+ */
68
+ import type { RNPackageContext, RNOHPackage } from '@rnoh/react-native-openharmony';
69
+ {{#libraries}}
70
+ import {{etsRNOHPackageClassName}} from '{{{ohPackageName}}}';
71
+ {{/libraries}}
72
+
73
+ export function createRNOHPackages(ctx: RNPackageContext): RNOHPackage[] {
74
+ return [
75
+ {{#libraries}}
76
+ new {{etsRNOHPackageClassName}}(ctx),
77
+ {{/libraries}}
78
+ ];
79
+ }
80
+ `.trimStart();
81
+
82
+ const CPP_RNOH_PACKAGES_FACTORY_TEMPLATE = `
83
+ /*
84
+ * This file was generated by RNOH autolinking.
85
+ * DO NOT modify it manually, your changes WILL be overwritten.
86
+ */
87
+ // clang-format off
88
+ #pragma once
89
+ #include "RNOH/Package.h"
90
+ {{#libraries}}
91
+ #include "{{etsRNOHPackageClassName}}.h"
92
+ {{/libraries}}
93
+
94
+ std::vector<rnoh::Package::Shared> createRNOHPackages(const rnoh::Package::Context &ctx) {
95
+ return {
96
+ {{#libraries}}
97
+ std::make_shared<rnoh::{{cppRNOHPackageClassName}}>(ctx),
98
+ {{/libraries}}
99
+ };
100
+ }
101
+ `.trimStart();
102
+
103
+ const CMAKE_AUTOLINKING_TEMPLATE = `
104
+ # This file was generated by RNOH autolinking.
105
+ # DO NOT modify it manually, your changes WILL be overwritten.
106
+ cmake_minimum_required(VERSION 3.5)
107
+
108
+ # @api
109
+ function(autolink_libraries target)
110
+ {{#libraries}}
111
+ add_subdirectory("\${OH_MODULES_DIR}/{{{ohPackageName}}}/src/main/cpp" ./{{cmakeLibraryTargetName}})
112
+ {{/libraries}}
113
+
114
+ set(AUTOLINKED_LIBRARIES
115
+ {{#libraries}}
116
+ {{cmakeLibraryTargetName}}
117
+ {{/libraries}}
118
+ )
119
+
120
+ foreach(lib \${AUTOLINKED_LIBRARIES})
121
+ target_link_libraries(\${target} PUBLIC \${lib})
122
+ endforeach()
123
+ endfunction()
124
+ `.trimStart();
125
+
126
+ export class Autolinking {
127
+ constructor(private fs: FS, private logger: Logger) {}
128
+
129
+ async prepareInput(config: AutolinkingConfig): Promise<AutolinkingInput> {
130
+ if (
131
+ config.includedNpmPackageNames.size > 0 &&
132
+ config.excludedNpmPackageNames.size > 0
133
+ ) {
134
+ throw new DescriptiveError({
135
+ whatHappened: 'Tried to exclude and include npm packages.',
136
+ whatCanUserDo: {
137
+ default: ['Include or exclude npm packages, but not both.'],
138
+ },
139
+ extraData: {
140
+ includedNpmPackageNamesCount: config.includedNpmPackageNames.size,
141
+ excludedNpmPackageNamesCount: config.excludedNpmPackageNames.size,
142
+ includedNpmPackageNames: config.includedNpmPackageNames,
143
+ excludedNpmPackageNames: config.excludedNpmPackageNames,
144
+ },
145
+ });
146
+ }
147
+ const harmonyProjectPath =
148
+ config.harmonyProjectPath ?? new AbsolutePath('./');
149
+ const nodeModuleHarPaths: AbsolutePath[] = [];
150
+ const autolinkableLibraries: AutolinkableLibrary[] = [];
151
+ const projectRootPath = config.nodeModulesPath.copyWithNewSegment('..');
152
+ const skippedLibraryNpmPackageNames: string[] = [];
153
+ await new ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync(
154
+ (dependency) => {
155
+ const harFilePath = dependency.getHarFilePath();
156
+ if (!harFilePath) {
157
+ return;
158
+ }
159
+ nodeModuleHarPaths.push(harFilePath);
160
+ const packageJson = dependency.readPackageJSON();
161
+ const providedAutolinkingConfig = packageJson.harmony?.autolinking;
162
+
163
+ if (
164
+ providedAutolinkingConfig === undefined ||
165
+ providedAutolinkingConfig === null ||
166
+ (config.excludedNpmPackageNames.has(packageJson.name) &&
167
+ config.excludedNpmPackageNames.size > 0) ||
168
+ (!config.includedNpmPackageNames.has(packageJson.name) &&
169
+ config.includedNpmPackageNames.size > 0)
170
+ ) {
171
+ skippedLibraryNpmPackageNames.push(packageJson.name);
172
+ return;
173
+ }
174
+ const autolinkingConfig =
175
+ providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
176
+ autolinkableLibraries.push({
177
+ npmPackageName: packageJson.name,
178
+ etsRNOHPackageClassName: autolinkingConfig?.etsPackageClassName,
179
+ cppRNOHPackageClassName: autolinkingConfig?.cppPackageClassName,
180
+ cmakeLibraryTargetName: autolinkingConfig?.cmakeLibraryTargetName,
181
+ ohPackageName: autolinkingConfig?.ohPackageName,
182
+ harFilePathRelativeToHarmony: harFilePath
183
+ .relativeTo(harmonyProjectPath)
184
+ .toString(),
185
+ });
186
+ }
187
+ );
188
+ const ohPackagePath = harmonyProjectPath.copyWithNewSegment(
189
+ config.ohPackagePathRelativeToHarmony
190
+ );
191
+ const ohPackageContent = await this.fs.readText(ohPackagePath);
192
+ const cppRNOHPackagesFactoryPath = harmonyProjectPath.copyWithNewSegment(
193
+ config.cppRNOHPackagesFactoryPathRelativeToHarmony
194
+ );
195
+ const cmakeAutolinkingPath = harmonyProjectPath.copyWithNewSegment(
196
+ config.cmakeAutolinkPathRelativeToHarmony
197
+ );
198
+ return {
199
+ projectRootPath,
200
+ skippedLibraryNpmPackageNames,
201
+ etsRNOHPackagesFactoryPath: harmonyProjectPath.copyWithNewSegment(
202
+ config.etsRNOHPackagesFactoryPathRelativeToHarmony
203
+ ),
204
+ cppRNOHPackagesFactoryPath,
205
+ cmakeAutolinkingPath: cmakeAutolinkingPath,
206
+ ohPackagePathAndContent: [ohPackagePath, ohPackageContent],
207
+ autolinkableLibraries,
208
+ nodeModuleHarFilePathsRelativeToHarmony: nodeModuleHarPaths.map((p) =>
209
+ p.relativeTo(harmonyProjectPath).toString()
210
+ ),
211
+ };
212
+ }
213
+
214
+ evaluate(input: AutolinkingInput): AutolinkingOutput {
215
+ const autolinkableLibraries: Required<AutolinkableLibrary>[] =
216
+ input.autolinkableLibraries.map((lib) => {
217
+ return {
218
+ ...lib,
219
+ etsRNOHPackageClassName:
220
+ lib.etsRNOHPackageClassName ??
221
+ this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName),
222
+ cppRNOHPackageClassName:
223
+ lib.cppRNOHPackageClassName ??
224
+ this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName),
225
+ cmakeLibraryTargetName:
226
+ lib.cmakeLibraryTargetName ??
227
+ this.npmPackageNameToCMakeLibraryTargetName(lib.npmPackageName),
228
+ ohPackageName:
229
+ lib.ohPackageName ??
230
+ this.npmPackageNameToOHPackageName(lib.npmPackageName),
231
+ };
232
+ });
233
+ autolinkableLibraries.sort((a, b) => {
234
+ if (a.npmPackageName < b.npmPackageName) return -1;
235
+ if (a.npmPackageName > b.npmPackageName) return 1;
236
+ return 0;
237
+ });
238
+ const ohPackage = JSON5.parse(input.ohPackagePathAndContent[1]);
239
+ const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map(
240
+ (lib) => lib.harFilePathRelativeToHarmony
241
+ );
242
+ const unmanagedNativeDependencySpecifierByName: Record<
243
+ string,
244
+ DependencySpecifier
245
+ > = {};
246
+ Object.entries<DependencySpecifier>(ohPackage.dependencies).forEach(
247
+ ([name, dependencySpecifier]) => {
248
+ if (!dependencySpecifier.includes('file:')) {
249
+ unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
250
+ } else {
251
+ const harFilePathRelativeToHarmony = dependencySpecifier.replace(
252
+ 'file:',
253
+ ''
254
+ );
255
+ if (
256
+ !autolinkableHarFilePathsRelativeToHarmony.includes(
257
+ harFilePathRelativeToHarmony
258
+ ) &&
259
+ input.nodeModuleHarFilePathsRelativeToHarmony.includes(
260
+ harFilePathRelativeToHarmony
261
+ )
262
+ ) {
263
+ unmanagedNativeDependencySpecifierByName[name] =
264
+ dependencySpecifier;
265
+ }
266
+ }
267
+ }
268
+ );
269
+ const managedNativeDependencySpecifierByName: Record<string, string> = {};
270
+ for (const library of autolinkableLibraries) {
271
+ managedNativeDependencySpecifierByName[library.ohPackageName] =
272
+ 'file:' + library.harFilePathRelativeToHarmony;
273
+ }
274
+ return {
275
+ skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
276
+ linkedLibraryNpmPackageNames: autolinkableLibraries.map(
277
+ (lib) => lib.npmPackageName
278
+ ),
279
+ projectRootPath: input.projectRootPath,
280
+ cppRNOHPackagesFactoryPathAndContent: [
281
+ input.cppRNOHPackagesFactoryPath,
282
+ Mustache.render(CPP_RNOH_PACKAGES_FACTORY_TEMPLATE, {
283
+ libraries: autolinkableLibraries,
284
+ }),
285
+ ],
286
+ etsRNOHPackagesFactoryPathAndContent: [
287
+ input.etsRNOHPackagesFactoryPath,
288
+ Mustache.render(ETS_RNOH_PACKAGES_FACTORY_TEMPLATE, {
289
+ libraries: autolinkableLibraries,
290
+ }),
291
+ ],
292
+ cmakeAutolinkingPathAndContent: [
293
+ input.cmakeAutolinkingPath,
294
+ Mustache.render(CMAKE_AUTOLINKING_TEMPLATE, {
295
+ libraries: autolinkableLibraries,
296
+ }),
297
+ ],
298
+ ohPackagePathAndContent: [
299
+ input.ohPackagePathAndContent[0],
300
+ JSON5.stringify(
301
+ {
302
+ ...ohPackage,
303
+ dependencies: {
304
+ ...unmanagedNativeDependencySpecifierByName,
305
+ ...managedNativeDependencySpecifierByName,
306
+ },
307
+ },
308
+ { space: 2, quote: '"' }
309
+ ) + '\n',
310
+ ],
311
+ };
312
+ }
313
+
314
+ private npmPackageNameToRNOHPackageClassName(fullNpmPackageName: string) {
315
+ if (fullNpmPackageName.startsWith('@')) {
316
+ const [scopeName, packageName] = fullNpmPackageName
317
+ .replace('@', '')
318
+ .split('/');
319
+ return Case.pascal(scopeName) + Case.pascal(packageName) + 'Package';
320
+ }
321
+ return Case.pascal(fullNpmPackageName) + 'Package';
322
+ }
323
+
324
+ private npmPackageNameToCMakeLibraryTargetName(fullNpmPackageName: string) {
325
+ if (fullNpmPackageName.startsWith('@')) {
326
+ const [scopeName, packageName] = fullNpmPackageName
327
+ .replace('@', '')
328
+ .split('/');
329
+ return 'rnoh__' + Case.snake(scopeName) + '__' + Case.snake(packageName);
330
+ }
331
+ return 'rnoh__' + Case.snake(fullNpmPackageName);
332
+ }
333
+
334
+ private npmPackageNameToOHPackageName(fullNpmPackageName: string): string {
335
+ if (fullNpmPackageName.startsWith('@')) {
336
+ const [scopeName, packageName] = fullNpmPackageName
337
+ .replace('@', '')
338
+ .split('/');
339
+ return '@rnoh/' + Case.kebab(scopeName) + '--' + Case.kebab(packageName);
340
+ }
341
+ return '@rnoh/' + Case.kebab(fullNpmPackageName);
342
+ }
343
+
344
+ saveAndLogOutput(output: AutolinkingOutput) {
345
+ const pathAndContentPairs: [AbsolutePath, string][] = [];
346
+ pathAndContentPairs.push(output.etsRNOHPackagesFactoryPathAndContent);
347
+ pathAndContentPairs.push(output.cppRNOHPackagesFactoryPathAndContent);
348
+ pathAndContentPairs.push(output.cmakeAutolinkingPathAndContent);
349
+ pathAndContentPairs.push(output.ohPackagePathAndContent);
350
+ pathAndContentPairs.forEach(([path, content]) => {
351
+ this.fs.writeTextSync(path, content);
352
+ });
353
+ output.linkedLibraryNpmPackageNames.forEach((npmPackageName) => {
354
+ this.logger.info(
355
+ (styles) => `[${styles.green(styles.bold('link'))}] ${npmPackageName}`
356
+ );
357
+ });
358
+ output.skippedLibraryNpmPackageNames.forEach((npmPackageName) => {
359
+ this.logger.warn(
360
+ (styles) => `[${styles.yellow(styles.bold('skip'))}] ${npmPackageName}`
361
+ );
362
+ });
363
+ this.logger.info(() => '');
364
+ const sortedPathsRelativeToRoot = pathAndContentPairs
365
+ .map(([path]) => path.relativeTo(output.projectRootPath).toString())
366
+ .sort();
367
+ sortedPathsRelativeToRoot.forEach((pathStr) => {
368
+ this.logger.info((styles) => styles.gray(`• ${pathStr}`));
369
+ });
370
+ this.logger.info(() => '');
371
+ this.logger.info(
372
+ (styles) =>
373
+ `updated ${styles.green(
374
+ styles.bold(sortedPathsRelativeToRoot.length)
375
+ )} file(s), linked ${styles.green(
376
+ styles.bold(output.linkedLibraryNpmPackageNames.length)
377
+ )} libraries, skipped ${styles.yellow(
378
+ styles.bold(output.skippedLibraryNpmPackageNames.length)
379
+ )} libraries`,
380
+ { prefix: true }
381
+ );
382
+ this.logger.info(() => '');
383
+ }
384
+ }
@@ -0,0 +1,8 @@
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
+ export * from './Autolinking';
@@ -1,3 +1,10 @@
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
8
  import { AbsolutePath } from '../../core';
2
9
  import { SpecSchema } from './UberSchema';
3
10
 
@@ -1,3 +1,10 @@
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
8
  import { DescriptiveError } from '../../core';
2
9
 
3
10
  export class CodegenError extends DescriptiveError {}
@@ -1,3 +1,10 @@
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
8
  import { CodegenError } from './CodegenError';
2
9
 
3
10
  export function createEventNameFromEventHandlerName(
@@ -1,3 +1,10 @@
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
8
  import { TypeAnnotationToTS, TypeAnnotation } from './TypeAnnotationToTS';
2
9
 
3
10
  function convert(typeAnnotation: TypeAnnotation) {
@@ -1,3 +1,10 @@
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
8
  import {
2
9
  BooleanTypeAnnotation,
3
10
  DoubleTypeAnnotation,
@@ -1,3 +1,10 @@
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
8
  import {
2
9
  ComponentSchema,
3
10
  NativeModuleSchema,
@@ -9,6 +16,7 @@ import {
9
16
  PackageJSON,
10
17
  ProjectDependenciesManager,
11
18
  CodegenConfig,
19
+ FS
12
20
  } from '../../core';
13
21
  // @ts-expect-error
14
22
  import extractUberSchemaFromSpecFilePaths_ from '@react-native/codegen/lib/cli/combine/combine-js-to-schema.js';
@@ -58,6 +66,7 @@ export class UberSchema implements ValueObject {
58
66
  }
59
67
 
60
68
  static async fromProject(
69
+ fs: FS,
61
70
  projectRootPath: AbsolutePath,
62
71
  onShouldAcceptCodegenConfig?: (
63
72
  codegenVersion: number,
@@ -67,6 +76,7 @@ export class UberSchema implements ValueObject {
67
76
  const onShouldAcceptCodegenConfig_ =
68
77
  onShouldAcceptCodegenConfig ?? ((x: number) => true);
69
78
  const packageJSON = PackageJSON.fromProjectRootPath(
79
+ fs,
70
80
  projectRootPath,
71
81
  projectRootPath
72
82
  );
@@ -82,7 +92,7 @@ export class UberSchema implements ValueObject {
82
92
  acceptedCodegenConfigs.push(codegenConfig);
83
93
  }
84
94
  }
85
- await new ProjectDependenciesManager(projectRootPath).forEachAsync(
95
+ await new ProjectDependenciesManager(fs, projectRootPath).forEachAsync(
86
96
  (dependency) => {
87
97
  const codegenConfigs = dependency.getCodegenConfigs();
88
98
  for (const codegenConfig of codegenConfigs) {
@@ -1,3 +1,10 @@
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
8
  export * from './CodeGenerator';
2
9
  export * from './UberSchema';
3
10
  export * from './CodegenError';
@@ -1,3 +1,10 @@
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
8
  import Case from 'case';
2
9
  import { AbsolutePath } from '../../core';
3
10
  import { CodeGenerator } from '../core';
@@ -1,3 +1,10 @@
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
8
  import { AbsolutePath } from '../../core';
2
9
  import {
3
10
  CodegenError,
@@ -1,3 +1,10 @@
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
8
  import { AbsolutePath } from '../../core';
2
9
  import {
3
10
  TypeAnnotationToTS,
@@ -1,3 +1,10 @@
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
8
  import { AbsolutePath } from '../../core';
2
9
  import { CodeGenerator, UberSchema } from '../core';
3
10
  import {
@@ -1,3 +1,10 @@
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
8
  import Case from 'case';
2
9
  import { AbsolutePath } from '../../core';
3
10
  import { CodeGenerator } from '../core';
@@ -1,3 +1,10 @@
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
8
  import { AbsolutePath } from '../../core';
2
9
  import type { SpecCodeGenerator } from '../core';
3
10
  import {
@@ -1,3 +1,10 @@
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
8
  import RNCodegen from '@react-native/codegen/lib/generators/RNCodegen';
2
9
  import { AbsolutePath } from '../../core';
3
10
  import { CodeGenerator, UberSchema } from '../core';
@@ -1,3 +1,10 @@
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
8
  import { AbsolutePath } from '../../core';
2
9
  import {
3
10
  CodeGenerator,
@@ -1,3 +1,10 @@
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
8
  import { AbsolutePath } from '../../core';
2
9
  import { CodeGenerator } from '../core';
3
10
  import {
@@ -1,3 +1,10 @@
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
8
  export * from './NativeModuleCodeGenerator';
2
9
  export * from './AppBuildTimeGlueCodeGenerator';
3
10
  export * from './ArkTSComponentCodeGeneratorArkTS';
@@ -1,2 +1,9 @@
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
8
  export * from './core';
2
9
  export * from './generators';
@@ -1,3 +1,10 @@
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
8
  import mustache from 'mustache';
2
9
  import Case from 'case';
3
10
  import { TypeAnnotation } from '../core';
@@ -1,3 +1,10 @@
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
8
  import mustache from 'mustache';
2
9
 
3
10
  const TEMPLATE = `
@@ -1,3 +1,10 @@
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
8
  import mustache from 'mustache';
2
9
 
3
10
  const TEMPLATE = `
@@ -1,3 +1,10 @@
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
8
  import mustache from 'mustache';
2
9
 
3
10
  const TEMPLATE = `