@react-native-oh/react-native-harmony-cli 0.0.36 → 0.0.40

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 (137) hide show
  1. package/README.md +11 -11
  2. package/dist/assetResolver.js +74 -43
  3. package/dist/autolinking/Autolinking.js +183 -179
  4. package/dist/codegen/core/CodegenError.js +23 -3
  5. package/dist/codegen/core/EventUtils.js +3 -3
  6. package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
  7. package/dist/codegen/core/UberSchema.js +96 -57
  8. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +42 -28
  9. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
  10. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
  11. package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
  12. package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
  13. package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
  14. package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
  15. package/dist/codegen/generators/UberGeneratorV1.js +24 -18
  16. package/dist/codegen/generators/UberGeneratorV2.js +36 -28
  17. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
  18. package/dist/codegen/templates/BasePackageHTemplate.js +21 -109
  19. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -53
  20. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
  21. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
  22. package/dist/codegen/templates/IndexTSTemplate.js +17 -37
  23. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -108
  24. package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
  25. package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
  26. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
  27. package/dist/commands/bundle-harmony.js +138 -53
  28. package/dist/commands/codegen-harmony.js +175 -104
  29. package/dist/commands/codegen-lib-harmony.js +116 -76
  30. package/dist/commands/create-metro-host-constants.js +47 -18
  31. package/dist/commands/init.js +961 -537
  32. package/dist/commands/link-harmony.js +71 -33
  33. package/dist/commands/pack-harmony.js +108 -47
  34. package/dist/commands/run-harmony.js +520 -352
  35. package/dist/commands/unpack-harmony.js +198 -105
  36. package/dist/commands/verify-package-harmony.js +108 -54
  37. package/dist/core/AbsolutePath.js +47 -31
  38. package/dist/core/CodegenConfig.js +22 -24
  39. package/dist/core/DescriptiveError.js +37 -18
  40. package/dist/core/FileSystem.js +18 -14
  41. package/dist/core/OHPackageJSON5.js +23 -17
  42. package/dist/core/PackageJSON.js +42 -26
  43. package/dist/core/ProjectDependenciesManager.js +96 -46
  44. package/dist/core/ValidationError.js +22 -2
  45. package/dist/core/fs.js +6 -9
  46. package/dist/index.js +1 -1
  47. package/dist/io/CliExecutor.js +98 -46
  48. package/dist/io/Logger.js +46 -40
  49. package/dist/io/RealFS.js +88 -35
  50. package/dist/io/TarGz.js +8 -11
  51. package/dist/io/__fixtures__.js +141 -79
  52. package/dist/io/fsUtils.js +12 -13
  53. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
  54. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
  55. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
  56. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
  57. package/dist/package-verifier/verify-package.js +132 -55
  58. package/dist/simulator/LaunchSimulator.js +395 -0
  59. package/dist/simulator/index.js +23 -0
  60. package/jest.config.js +12 -12
  61. package/package.json +78 -70
  62. package/react-native.config.js +17 -17
  63. package/tsconfig.build.json +6 -6
  64. package/tsconfig.json +2 -2
  65. package/.prettierrc +0 -6
  66. package/src/assetResolver.ts +0 -134
  67. package/src/autolinking/Autolinking.test.ts +0 -483
  68. package/src/autolinking/Autolinking.ts +0 -382
  69. package/src/autolinking/index.ts +0 -8
  70. package/src/codegen/core/CodeGenerator.ts +0 -16
  71. package/src/codegen/core/CodegenError.ts +0 -10
  72. package/src/codegen/core/EventUtils.ts +0 -23
  73. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
  74. package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
  75. package/src/codegen/core/UberSchema.ts +0 -152
  76. package/src/codegen/core/index.ts +0 -12
  77. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -120
  78. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
  79. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
  80. package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
  81. package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
  82. package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
  83. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
  84. package/src/codegen/generators/UberGeneratorV1.ts +0 -75
  85. package/src/codegen/generators/UberGeneratorV2.ts +0 -114
  86. package/src/codegen/generators/index.ts +0 -15
  87. package/src/codegen/index.ts +0 -9
  88. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
  89. package/src/codegen/templates/BasePackageHTemplate.ts +0 -147
  90. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
  91. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
  92. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
  93. package/src/codegen/templates/IndexTSTemplate.ts +0 -62
  94. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -138
  95. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
  96. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
  97. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
  98. package/src/codegen/templates/index.ts +0 -16
  99. package/src/commands/bundle-harmony.ts +0 -134
  100. package/src/commands/codegen-harmony.ts +0 -297
  101. package/src/commands/codegen-lib-harmony.ts +0 -389
  102. package/src/commands/create-metro-host-constants.ts +0 -55
  103. package/src/commands/index.ts +0 -16
  104. package/src/commands/init.ts +0 -755
  105. package/src/commands/link-harmony.ts +0 -102
  106. package/src/commands/pack-harmony.ts +0 -128
  107. package/src/commands/run-harmony.ts +0 -478
  108. package/src/commands/types.ts +0 -21
  109. package/src/commands/unpack-harmony.ts +0 -238
  110. package/src/commands/verify-package-harmony.ts +0 -113
  111. package/src/core/AbsolutePath.ts +0 -66
  112. package/src/core/CodegenConfig.ts +0 -67
  113. package/src/core/DescriptiveError.ts +0 -68
  114. package/src/core/FileSystem.ts +0 -57
  115. package/src/core/OHPackageJSON5.ts +0 -30
  116. package/src/core/PackageJSON.ts +0 -104
  117. package/src/core/ProjectDependenciesManager.ts +0 -103
  118. package/src/core/ValidationError.ts +0 -8
  119. package/src/core/ValueObject.ts +0 -9
  120. package/src/core/fs.ts +0 -38
  121. package/src/core/index.ts +0 -17
  122. package/src/index.ts +0 -33
  123. package/src/io/CliExecutor.ts +0 -69
  124. package/src/io/Logger.ts +0 -112
  125. package/src/io/RealFS.ts +0 -62
  126. package/src/io/TarGz.ts +0 -33
  127. package/src/io/__fixtures__.ts +0 -139
  128. package/src/io/fsUtils.ts +0 -44
  129. package/src/io/index.ts +0 -11
  130. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
  131. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
  132. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
  133. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
  134. package/src/package-verifier/checks/index.ts +0 -11
  135. package/src/package-verifier/index.ts +0 -9
  136. package/src/package-verifier/types.ts +0 -19
  137. package/src/package-verifier/verify-package.ts +0 -123
@@ -1,382 +0,0 @@
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
- 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: ['Include or exclude npm packages, but not both.'],
137
-
138
- extraData: {
139
- includedNpmPackageNamesCount: config.includedNpmPackageNames.size,
140
- excludedNpmPackageNamesCount: config.excludedNpmPackageNames.size,
141
- includedNpmPackageNames: config.includedNpmPackageNames,
142
- excludedNpmPackageNames: config.excludedNpmPackageNames,
143
- },
144
- });
145
- }
146
- const harmonyProjectPath =
147
- config.harmonyProjectPath ?? new AbsolutePath('./');
148
- const nodeModuleHarPaths: AbsolutePath[] = [];
149
- const autolinkableLibraries: AutolinkableLibrary[] = [];
150
- const projectRootPath = config.nodeModulesPath.copyWithNewSegment('..');
151
- const skippedLibraryNpmPackageNames: string[] = [];
152
- await new ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync(
153
- (dependency) => {
154
- const harFilePath = dependency.getHarFilePath();
155
- if (!harFilePath) {
156
- return;
157
- }
158
- nodeModuleHarPaths.push(harFilePath);
159
- const packageJson = dependency.readPackageJSON();
160
- const providedAutolinkingConfig = packageJson.harmony?.autolinking;
161
-
162
- if (
163
- providedAutolinkingConfig === undefined ||
164
- providedAutolinkingConfig === null ||
165
- (config.excludedNpmPackageNames.has(packageJson.name) &&
166
- config.excludedNpmPackageNames.size > 0) ||
167
- (!config.includedNpmPackageNames.has(packageJson.name) &&
168
- config.includedNpmPackageNames.size > 0)
169
- ) {
170
- skippedLibraryNpmPackageNames.push(packageJson.name);
171
- return;
172
- }
173
- const autolinkingConfig =
174
- providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
175
- autolinkableLibraries.push({
176
- npmPackageName: packageJson.name,
177
- etsRNOHPackageClassName: autolinkingConfig?.etsPackageClassName,
178
- cppRNOHPackageClassName: autolinkingConfig?.cppPackageClassName,
179
- cmakeLibraryTargetName: autolinkingConfig?.cmakeLibraryTargetName,
180
- ohPackageName: autolinkingConfig?.ohPackageName,
181
- harFilePathRelativeToHarmony: harFilePath
182
- .relativeTo(harmonyProjectPath)
183
- .toString(),
184
- });
185
- }
186
- );
187
- const ohPackagePath = harmonyProjectPath.copyWithNewSegment(
188
- config.ohPackagePathRelativeToHarmony
189
- );
190
- const ohPackageContent = await this.fs.readText(ohPackagePath);
191
- const cppRNOHPackagesFactoryPath = harmonyProjectPath.copyWithNewSegment(
192
- config.cppRNOHPackagesFactoryPathRelativeToHarmony
193
- );
194
- const cmakeAutolinkingPath = harmonyProjectPath.copyWithNewSegment(
195
- config.cmakeAutolinkPathRelativeToHarmony
196
- );
197
- return {
198
- projectRootPath,
199
- skippedLibraryNpmPackageNames,
200
- etsRNOHPackagesFactoryPath: harmonyProjectPath.copyWithNewSegment(
201
- config.etsRNOHPackagesFactoryPathRelativeToHarmony
202
- ),
203
- cppRNOHPackagesFactoryPath,
204
- cmakeAutolinkingPath: cmakeAutolinkingPath,
205
- ohPackagePathAndContent: [ohPackagePath, ohPackageContent],
206
- autolinkableLibraries,
207
- nodeModuleHarFilePathsRelativeToHarmony: nodeModuleHarPaths.map((p) =>
208
- p.relativeTo(harmonyProjectPath).toString()
209
- ),
210
- };
211
- }
212
-
213
- evaluate(input: AutolinkingInput): AutolinkingOutput {
214
- const autolinkableLibraries: Required<AutolinkableLibrary>[] =
215
- input.autolinkableLibraries.map((lib) => {
216
- return {
217
- ...lib,
218
- etsRNOHPackageClassName:
219
- lib.etsRNOHPackageClassName ??
220
- this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName),
221
- cppRNOHPackageClassName:
222
- lib.cppRNOHPackageClassName ??
223
- this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName),
224
- cmakeLibraryTargetName:
225
- lib.cmakeLibraryTargetName ??
226
- this.npmPackageNameToCMakeLibraryTargetName(lib.npmPackageName),
227
- ohPackageName:
228
- lib.ohPackageName ??
229
- this.npmPackageNameToOHPackageName(lib.npmPackageName),
230
- };
231
- });
232
- autolinkableLibraries.sort((a, b) => {
233
- if (a.npmPackageName < b.npmPackageName) return -1;
234
- if (a.npmPackageName > b.npmPackageName) return 1;
235
- return 0;
236
- });
237
- const ohPackage = JSON5.parse(input.ohPackagePathAndContent[1]);
238
- const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map(
239
- (lib) => lib.harFilePathRelativeToHarmony
240
- );
241
- const unmanagedNativeDependencySpecifierByName: Record<
242
- string,
243
- DependencySpecifier
244
- > = {};
245
- Object.entries<DependencySpecifier>(ohPackage.dependencies).forEach(
246
- ([name, dependencySpecifier]) => {
247
- if (!dependencySpecifier.includes('file:')) {
248
- unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
249
- } else {
250
- const harFilePathRelativeToHarmony = dependencySpecifier.replace(
251
- 'file:',
252
- ''
253
- );
254
- if (
255
- !autolinkableHarFilePathsRelativeToHarmony.includes(
256
- harFilePathRelativeToHarmony
257
- ) &&
258
- input.nodeModuleHarFilePathsRelativeToHarmony.includes(
259
- harFilePathRelativeToHarmony
260
- )
261
- ) {
262
- unmanagedNativeDependencySpecifierByName[name] =
263
- dependencySpecifier;
264
- }
265
- }
266
- }
267
- );
268
- const managedNativeDependencySpecifierByName: Record<string, string> = {};
269
- for (const library of autolinkableLibraries) {
270
- managedNativeDependencySpecifierByName[library.ohPackageName] =
271
- 'file:' + library.harFilePathRelativeToHarmony;
272
- }
273
- return {
274
- skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
275
- linkedLibraryNpmPackageNames: autolinkableLibraries.map(
276
- (lib) => lib.npmPackageName
277
- ),
278
- projectRootPath: input.projectRootPath,
279
- cppRNOHPackagesFactoryPathAndContent: [
280
- input.cppRNOHPackagesFactoryPath,
281
- Mustache.render(CPP_RNOH_PACKAGES_FACTORY_TEMPLATE, {
282
- libraries: autolinkableLibraries,
283
- }),
284
- ],
285
- etsRNOHPackagesFactoryPathAndContent: [
286
- input.etsRNOHPackagesFactoryPath,
287
- Mustache.render(ETS_RNOH_PACKAGES_FACTORY_TEMPLATE, {
288
- libraries: autolinkableLibraries,
289
- }),
290
- ],
291
- cmakeAutolinkingPathAndContent: [
292
- input.cmakeAutolinkingPath,
293
- Mustache.render(CMAKE_AUTOLINKING_TEMPLATE, {
294
- libraries: autolinkableLibraries,
295
- }),
296
- ],
297
- ohPackagePathAndContent: [
298
- input.ohPackagePathAndContent[0],
299
- JSON5.stringify(
300
- {
301
- ...ohPackage,
302
- dependencies: {
303
- ...unmanagedNativeDependencySpecifierByName,
304
- ...managedNativeDependencySpecifierByName,
305
- },
306
- },
307
- { space: 2, quote: '"' }
308
- ) + '\n',
309
- ],
310
- };
311
- }
312
-
313
- private npmPackageNameToRNOHPackageClassName(fullNpmPackageName: string) {
314
- if (fullNpmPackageName.startsWith('@')) {
315
- const [scopeName, packageName] = fullNpmPackageName
316
- .replace('@', '')
317
- .split('/');
318
- return Case.pascal(scopeName) + Case.pascal(packageName) + 'Package';
319
- }
320
- return Case.pascal(fullNpmPackageName) + 'Package';
321
- }
322
-
323
- private npmPackageNameToCMakeLibraryTargetName(fullNpmPackageName: string) {
324
- if (fullNpmPackageName.startsWith('@')) {
325
- const [scopeName, packageName] = fullNpmPackageName
326
- .replace('@', '')
327
- .split('/');
328
- return 'rnoh__' + Case.snake(scopeName) + '__' + Case.snake(packageName);
329
- }
330
- return 'rnoh__' + Case.snake(fullNpmPackageName);
331
- }
332
-
333
- private npmPackageNameToOHPackageName(fullNpmPackageName: string): string {
334
- if (fullNpmPackageName.startsWith('@')) {
335
- const [scopeName, packageName] = fullNpmPackageName
336
- .replace('@', '')
337
- .split('/');
338
- return '@rnoh/' + Case.kebab(scopeName) + '--' + Case.kebab(packageName);
339
- }
340
- return '@rnoh/' + Case.kebab(fullNpmPackageName);
341
- }
342
-
343
- saveAndLogOutput(output: AutolinkingOutput) {
344
- const pathAndContentPairs: [AbsolutePath, string][] = [];
345
- pathAndContentPairs.push(output.etsRNOHPackagesFactoryPathAndContent);
346
- pathAndContentPairs.push(output.cppRNOHPackagesFactoryPathAndContent);
347
- pathAndContentPairs.push(output.cmakeAutolinkingPathAndContent);
348
- pathAndContentPairs.push(output.ohPackagePathAndContent);
349
- pathAndContentPairs.forEach(([path, content]) => {
350
- this.fs.writeTextSync(path, content);
351
- });
352
- output.linkedLibraryNpmPackageNames.forEach((npmPackageName) => {
353
- this.logger.debug(
354
- (styles) => `[${styles.green(styles.bold('link'))}] ${npmPackageName}`
355
- );
356
- });
357
- output.skippedLibraryNpmPackageNames.forEach((npmPackageName) => {
358
- this.logger.debug(
359
- (styles) => `[${styles.yellow(styles.bold('skip'))}] ${npmPackageName}`
360
- );
361
- });
362
- this.logger.debug(() => '');
363
- const sortedPathsRelativeToRoot = pathAndContentPairs
364
- .map(([path]) => path.relativeTo(output.projectRootPath).toString())
365
- .sort();
366
- sortedPathsRelativeToRoot.forEach((pathStr) => {
367
- this.logger.debug((styles) => styles.gray(`• ${pathStr}`));
368
- });
369
- this.logger.debug(() => '');
370
- this.logger.info(
371
- (styles) =>
372
- `updated ${styles.green(
373
- styles.bold(sortedPathsRelativeToRoot.length)
374
- )} file(s), linked ${styles.green(
375
- styles.bold(output.linkedLibraryNpmPackageNames.length)
376
- )} libraries, skipped ${styles.yellow(
377
- styles.bold(output.skippedLibraryNpmPackageNames.length)
378
- )} libraries`
379
- );
380
- this.logger.debug(() => '');
381
- }
382
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- export * from './Autolinking';
@@ -1,16 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import { AbsolutePath } from '../../core';
9
- import { SpecSchema } from './UberSchema';
10
-
11
- type FileContent = string;
12
- export interface CodeGenerator<T> {
13
- generate(data: T): Map<AbsolutePath, FileContent>;
14
- }
15
-
16
- export interface SpecCodeGenerator extends CodeGenerator<SpecSchema> {}
@@ -1,10 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import { DescriptiveError } from '../../core';
9
-
10
- export class CodegenError extends DescriptiveError {}
@@ -1,23 +0,0 @@
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
- import { CodegenError } from './CodegenError';
9
-
10
- export function createEventNameFromEventHandlerName(
11
- eventHandlerName: string
12
- ): string {
13
- const eventName = eventHandlerName.replace('on', '');
14
- if (eventName.length === 0) {
15
- throw new CodegenError({
16
- whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
17
- whatCanUserDo: [
18
- 'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
19
- ],
20
- });
21
- }
22
- return eventName.charAt(0).toLowerCase() + eventName.slice(1);
23
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import { TypeAnnotationToTS, TypeAnnotation } from './TypeAnnotationToTS';
9
-
10
- function convert(typeAnnotation: TypeAnnotation) {
11
- return new TypeAnnotationToTS().convert(typeAnnotation);
12
- }
13
-
14
- it('should convert boolean prop correctly', () => {
15
- const result = convert({
16
- type: 'BooleanTypeAnnotation',
17
- });
18
-
19
- expect(result).toBe('boolean');
20
- });
21
-
22
- it('should convert string prop correctly', () => {
23
- const result = convert({
24
- type: 'StringTypeAnnotation',
25
- });
26
-
27
- expect(result).toBe('string');
28
- });
29
-
30
- it('should convert double prop correctly', () => {
31
- const result = convert({
32
- type: 'DoubleTypeAnnotation',
33
- });
34
-
35
- expect(result).toBe('number');
36
- });
37
-
38
- it('should convert float prop correctly', () => {
39
- const result = convert({
40
- type: 'FloatTypeAnnotation',
41
- });
42
-
43
- expect(result).toBe('number');
44
- });
45
-
46
- it('should convert object prop correctly', () => {
47
- const result = convert({
48
- type: 'ObjectTypeAnnotation',
49
- properties: [
50
- {
51
- typeAnnotation: { type: 'BooleanTypeAnnotation' },
52
- name: 'booleanTest',
53
- optional: false,
54
- },
55
- {
56
- typeAnnotation: { type: 'ObjectTypeAnnotation', properties: [] },
57
- name: 'objectTest',
58
- optional: true,
59
- },
60
- ],
61
- });
62
-
63
- expect(result).toBe('{booleanTest: boolean, objectTest?: {}}');
64
- });
65
-
66
- it('should convert array correctly', () => {
67
- const result = convert({
68
- type: 'ObjectTypeAnnotation',
69
- properties: [
70
- {
71
- typeAnnotation: {
72
- type: 'ArrayTypeAnnotation',
73
- elementType: { type: 'StringTypeAnnotation' },
74
- },
75
- name: 'arrayTest',
76
- optional: false,
77
- },
78
- ],
79
- });
80
-
81
- expect(result).toBe('{arrayTest: string[]}');
82
- });