@react-native-oh/react-native-harmony-cli 0.0.26-9 → 0.0.27

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 (51) hide show
  1. package/dist/codegen/core/UberSchema.js +3 -0
  2. package/dist/codegen/generators/{GlueCodeGenerator.js → AppBuildTimeGlueCodeGenerator.js} +11 -10
  3. package/dist/codegen/generators/{ComponentCodeGeneratorArkTS.js → ArkTSComponentCodeGeneratorArkTS.js} +8 -6
  4. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +74 -0
  5. package/dist/codegen/generators/{ComponentCodeGeneratorCAPI.js → CppComponentCodeGenerator.js} +10 -33
  6. package/dist/codegen/generators/LibGlueCodeGenerator.js +50 -0
  7. package/dist/codegen/generators/NativeModuleCodeGenerator.js +6 -5
  8. package/dist/codegen/generators/SharedComponentCodeGenerator.js +34 -0
  9. package/dist/codegen/generators/UberGeneratorV1.js +7 -6
  10. package/dist/codegen/generators/UberGeneratorV2.js +25 -14
  11. package/dist/codegen/generators/index.js +5 -3
  12. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +9 -7
  13. package/dist/codegen/templates/{GeneratedPackageHTemplate.js → BasePackageHTemplate.js} +40 -11
  14. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +2 -1
  15. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +9 -11
  16. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +11 -8
  17. package/dist/codegen/templates/IndexTSTemplate.js +12 -9
  18. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +1 -0
  19. package/dist/codegen/templates/TurboModuleCppTemplate.js +10 -10
  20. package/dist/codegen/templates/TurboModuleHTemplate.js +10 -10
  21. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +11 -10
  22. package/dist/commands/codegen-harmony.js +11 -5
  23. package/dist/commands/codegen-lib-harmony.js +253 -0
  24. package/dist/commands/index.js +1 -0
  25. package/dist/index.js +1 -0
  26. package/package.json +1 -1
  27. package/src/codegen/core/UberSchema.ts +4 -0
  28. package/src/codegen/generators/{GlueCodeGenerator.ts → AppBuildTimeGlueCodeGenerator.ts} +13 -9
  29. package/src/codegen/generators/{ComponentCodeGeneratorArkTS.ts → ArkTSComponentCodeGeneratorArkTS.ts} +11 -5
  30. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +112 -0
  31. package/src/codegen/generators/{ComponentCodeGeneratorCAPI.ts → CppComponentCodeGenerator.ts} +14 -43
  32. package/src/codegen/generators/LibGlueCodeGenerator.ts +91 -0
  33. package/src/codegen/generators/NativeModuleCodeGenerator.ts +7 -5
  34. package/src/codegen/generators/SharedComponentCodeGenerator.ts +50 -0
  35. package/src/codegen/generators/UberGeneratorV1.ts +12 -8
  36. package/src/codegen/generators/UberGeneratorV2.ts +32 -16
  37. package/src/codegen/generators/index.ts +5 -3
  38. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +12 -7
  39. package/src/codegen/templates/{GeneratedPackageHTemplate.ts → BasePackageHTemplate.ts} +45 -12
  40. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +2 -1
  41. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +8 -10
  42. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +13 -8
  43. package/src/codegen/templates/IndexTSTemplate.ts +11 -9
  44. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +1 -0
  45. package/src/codegen/templates/TurboModuleCppTemplate.ts +9 -9
  46. package/src/codegen/templates/TurboModuleHTemplate.ts +9 -9
  47. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +13 -9
  48. package/src/commands/codegen-harmony.ts +24 -7
  49. package/src/commands/codegen-lib-harmony.ts +387 -0
  50. package/src/commands/index.ts +1 -0
  51. package/src/index.ts +2 -0
@@ -12,14 +12,16 @@ import {
12
12
  ComponentJSIBinderHTemplate,
13
13
  ComponentUtilsTSTemplate,
14
14
  } from '../templates';
15
- import { GlueCodeComponentDataV1 } from './GlueCodeGenerator';
15
+ import { GlueCodeComponentDataV1 } from './AppBuildTimeGlueCodeGenerator';
16
16
 
17
- export class ComponentCodeGeneratorArkTS implements SpecCodeGenerator {
17
+ export class ArkTSComponentCodeGeneratorArkTS implements SpecCodeGenerator {
18
18
  private glueCodeDataItems: GlueCodeComponentDataV1[] = [];
19
19
 
20
20
  constructor(
21
21
  private cppOutputPath: AbsolutePath,
22
- private tsOutputPath: AbsolutePath
22
+ private tsOutputPath: AbsolutePath,
23
+ private codegenNoticeLines: string[],
24
+ private rnohImport: string
23
25
  ) {}
24
26
 
25
27
  getGlueCodeData(): GlueCodeComponentDataV1[] {
@@ -41,9 +43,13 @@ export class ComponentCodeGeneratorArkTS implements SpecCodeGenerator {
41
43
  );
42
44
  const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(
43
45
  name,
44
- 1
46
+ this.codegenNoticeLines
47
+ );
48
+ const componentUtilsTSTemplate = new ComponentUtilsTSTemplate(
49
+ name,
50
+ this.codegenNoticeLines,
51
+ this.rnohImport
45
52
  );
46
- const componentUtilsTSTemplate = new ComponentUtilsTSTemplate(name);
47
53
 
48
54
  shape.props.forEach((prop) => {
49
55
  componentJSIBinderHTemplate.addProp({
@@ -0,0 +1,112 @@
1
+ import { AbsolutePath } from '../../core';
2
+ import {
3
+ TypeAnnotationToTS,
4
+ createEventNameFromEventHandlerName,
5
+ getStringifiedTSDefaultValueFromPropTypeAnnotation,
6
+ } from '../core';
7
+ import type { CodeGenerator, UberSchema } from '../core';
8
+ import {
9
+ ComponentJSIBinderHTemplate,
10
+ ComponentUtilsTSTemplate,
11
+ } from '../templates';
12
+ import { ArkTSComponentLibGlueCodeData } from './LibGlueCodeGenerator';
13
+
14
+ /**
15
+ * Generates component code for ArkTS components used in C-API architecture.
16
+ */
17
+ export class ArkTSComponentCodeGeneratorCAPI
18
+ implements CodeGenerator<UberSchema>
19
+ {
20
+ private glueCodeDataItems: ArkTSComponentLibGlueCodeData[] = [];
21
+
22
+ constructor(
23
+ private cppOutputPath: AbsolutePath,
24
+ private tsOutputPath: AbsolutePath,
25
+ private codegenNoticeLines: string[],
26
+ private rnohImport: string
27
+ ) {}
28
+
29
+ getLibGlueCodeData(): ArkTSComponentLibGlueCodeData[] {
30
+ return this.glueCodeDataItems;
31
+ }
32
+
33
+ generate(uberSchema: UberSchema): Map<AbsolutePath, string> {
34
+ const typeAnnotationToTS = new TypeAnnotationToTS();
35
+ const result = new Map<AbsolutePath, string>();
36
+ const componentSpecSchemas =
37
+ uberSchema.findAllSpecSchemasByType('Component');
38
+
39
+ for (const componentSpecSchema of componentSpecSchemas) {
40
+ Object.entries(componentSpecSchema.components).map(([name, shape]) => {
41
+ const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(
42
+ name,
43
+ this.codegenNoticeLines
44
+ );
45
+ const componentUtilsTSTemplate = new ComponentUtilsTSTemplate(
46
+ name,
47
+ this.codegenNoticeLines,
48
+ this.rnohImport
49
+ );
50
+ shape.props.forEach((prop) => {
51
+ componentJSIBinderHTemplate.addProp({
52
+ name: prop.name,
53
+ isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
54
+ });
55
+
56
+ componentUtilsTSTemplate.addProp({
57
+ name: prop.name,
58
+ tsType: typeAnnotationToTS.convert(prop.typeAnnotation),
59
+ defaultValue: getStringifiedTSDefaultValueFromPropTypeAnnotation(
60
+ prop.typeAnnotation
61
+ ),
62
+ isOptional: prop.optional,
63
+ });
64
+ });
65
+ shape.commands.forEach((command) => {
66
+ componentUtilsTSTemplate.addCommand({
67
+ name: command.name,
68
+ argsTSType:
69
+ '[' +
70
+ command.typeAnnotation.params
71
+ .map(
72
+ (param) =>
73
+ typeAnnotationToTS.convert(param.typeAnnotation) +
74
+ (param.optional ? '?' : '')
75
+ )
76
+ .join(', ') +
77
+ ']',
78
+ });
79
+ });
80
+
81
+ shape.events.forEach((event) => {
82
+ componentUtilsTSTemplate.addEvent({
83
+ name: createEventNameFromEventHandlerName(event.name),
84
+ payloadTSType: event.typeAnnotation.argument
85
+ ? typeAnnotationToTS.convert(event.typeAnnotation.argument)
86
+ : 'undefined',
87
+ });
88
+ componentJSIBinderHTemplate.addEvent({
89
+ type: event.bubblingType,
90
+ eventHandlerName: event.name,
91
+ });
92
+ });
93
+ result.set(
94
+ this.cppOutputPath.copyWithNewSegment(`${name}JSIBinder.h`),
95
+ componentJSIBinderHTemplate.build()
96
+ );
97
+ result.set(
98
+ this.tsOutputPath.copyWithNewSegment(`${name}.ts`),
99
+ componentUtilsTSTemplate.build()
100
+ );
101
+ this.glueCodeDataItems.push({
102
+ componentName: name,
103
+ eventNames: shape.events.map((event) =>
104
+ createEventNameFromEventHandlerName(event.name)
105
+ ),
106
+ });
107
+ });
108
+ }
109
+
110
+ return result;
111
+ }
112
+ }
@@ -1,30 +1,22 @@
1
- import RNCodegen from '@react-native/codegen/lib/generators/RNCodegen';
2
1
  import { AbsolutePath } from '../../core';
3
2
  import { CodeGenerator, UberSchema } from '../core';
4
3
  import {
5
4
  BaseComponentInstanceHTemplate,
6
5
  ComponentJSIBinderHTemplate,
7
6
  } from '../templates';
8
- import { GlueCodeComponentDataV2 } from './GlueCodeGenerator';
7
+ import { GlueCodeComponentDataV2 } from './AppBuildTimeGlueCodeGenerator';
9
8
 
10
- /**
11
- * NPM package that extends RNOH capabilities.
12
- */
13
9
  export type LibraryData = {
14
- /**
15
- * C++ directory name which is used in #include statements
16
- */
17
- name: string;
10
+ libraryCppName: string;
18
11
  uberSchema: UberSchema;
19
12
  };
20
13
 
21
- export class ComponentCodeGeneratorCAPI implements CodeGenerator<LibraryData> {
14
+ export class CppComponentCodeGenerator implements CodeGenerator<LibraryData> {
22
15
  private glueCodeComponentsData: GlueCodeComponentDataV2[] = [];
23
16
 
24
17
  constructor(
25
- /// "shared" — platform independent code that can be shared between platforms
26
- private onGetSharedOutputPath: (filename: string) => AbsolutePath,
27
- private onGetRNOHOutputPath: (filename: string) => AbsolutePath
18
+ private onGetRNOHOutputPath: (filename: string) => AbsolutePath,
19
+ private codegenNoticeLines: string[]
28
20
  ) {}
29
21
 
30
22
  getGlueCodeData() {
@@ -32,46 +24,25 @@ export class ComponentCodeGeneratorCAPI implements CodeGenerator<LibraryData> {
32
24
  }
33
25
 
34
26
  generate({
35
- name: libraryName,
27
+ libraryCppName,
36
28
  uberSchema,
37
29
  }: LibraryData): Map<AbsolutePath, string> {
38
30
  const fileContentByPath = new Map<AbsolutePath, string>();
39
- const generatorFns = [
40
- RNCodegen.allGenerators.generatePropsH,
41
- RNCodegen.allGenerators.generatePropsCpp,
42
- RNCodegen.allGenerators.generateEventEmitterH,
43
- RNCodegen.allGenerators.generateEventEmitterCpp,
44
- RNCodegen.allGenerators.generateComponentDescriptorH,
45
- RNCodegen.allGenerators.generateStateH,
46
- RNCodegen.allGenerators.generateStateCpp,
47
- RNCodegen.allGenerators.generateShadowNodeH,
48
- RNCodegen.allGenerators.generateShadowNodeCpp,
49
- ];
50
- generatorFns.forEach((generate) => {
51
- const filesOutput = generate(
52
- libraryName,
53
- uberSchema.getValue(),
54
- 'UNUSED_packageName',
55
- true
56
- );
57
- filesOutput.forEach((fileContent, filename) => {
58
- fileContentByPath.set(
59
- this.onGetSharedOutputPath(filename),
60
- fileContent
61
- );
62
- });
63
- });
64
- for (const [filename, schema] of uberSchema
31
+ for (const [_filename, schema] of uberSchema
65
32
  .getSpecSchemaByFilenameMap()
66
33
  .entries()) {
67
34
  if (schema.type === 'Component') {
68
35
  Object.entries(schema.components).map(([componentName, shape]) => {
69
36
  const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(
70
37
  componentName,
71
- 2
38
+ this.codegenNoticeLines
72
39
  );
73
40
  const componentInstanceSpecHTemplate =
74
- new BaseComponentInstanceHTemplate(componentName, libraryName);
41
+ new BaseComponentInstanceHTemplate(
42
+ componentName,
43
+ libraryCppName,
44
+ this.codegenNoticeLines
45
+ );
75
46
  shape.props.forEach((prop) => {
76
47
  componentJSIBinderHTemplate.addProp({
77
48
  name: prop.name,
@@ -103,7 +74,7 @@ export class ComponentCodeGeneratorCAPI implements CodeGenerator<LibraryData> {
103
74
  );
104
75
  this.glueCodeComponentsData.push({
105
76
  name: componentName,
106
- libraryName,
77
+ libraryCppName,
107
78
  });
108
79
  });
109
80
  }
@@ -0,0 +1,91 @@
1
+ import Case from 'case';
2
+ import { AbsolutePath } from '../../core';
3
+ import { CodeGenerator } from '../core';
4
+ import { BasePackageHTemplate } from '../templates/BasePackageHTemplate';
5
+ import { IndexTSTemplate } from '../templates';
6
+ import { GlueCodeTurboModuleData } from './AppBuildTimeGlueCodeGenerator';
7
+
8
+ export type ArkTSComponentLibGlueCodeData = {
9
+ componentName: string;
10
+ eventNames: string[];
11
+ };
12
+ export type CppComponentLibGlueCodeData = { componentName: string };
13
+
14
+ type LibGlueCodeData = {
15
+ libraryCppName: string;
16
+ turboModules: GlueCodeTurboModuleData[];
17
+ arkTSComponents: ArkTSComponentLibGlueCodeData[];
18
+ cppComponents: CppComponentLibGlueCodeData[];
19
+ };
20
+
21
+ /**
22
+ * NOTE: This class is coupled with the generated code structure defined in the codegen-harmony-lib.
23
+ */
24
+ export class LibGlueCodeGenerator implements CodeGenerator<LibGlueCodeData> {
25
+ constructor(
26
+ private cppOutputPath: AbsolutePath,
27
+ private etsOutputPath: AbsolutePath,
28
+ private codegenNoticeLines: string[]
29
+ ) {}
30
+
31
+ generate({
32
+ libraryCppName,
33
+ turboModules,
34
+ arkTSComponents,
35
+ cppComponents,
36
+ }: LibGlueCodeData): Map<AbsolutePath, string> {
37
+ const fileContentByPath = new Map<AbsolutePath, string>();
38
+ const basePackageClassName = `Base${Case.pascal(libraryCppName)}Package`;
39
+ const turboModules_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
40
+ const components_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
41
+ const generated_indexETS = new IndexTSTemplate(this.codegenNoticeLines);
42
+
43
+ const basePackageTemplate = new BasePackageHTemplate(
44
+ basePackageClassName,
45
+ this.codegenNoticeLines
46
+ );
47
+ turboModules.forEach((turboModule) => {
48
+ basePackageTemplate.addTurboModule(turboModule);
49
+ turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
50
+ });
51
+ arkTSComponents.forEach(({ componentName, eventNames }) => {
52
+ components_indexTS.addReexport({ from: `./${componentName}` });
53
+ basePackageTemplate.addComponent({ name: componentName, libraryCppName });
54
+ eventNames.forEach((eventName) =>
55
+ basePackageTemplate.addArkTSEvent({ name: eventName })
56
+ );
57
+ });
58
+ cppComponents.forEach(({ componentName }) => {
59
+ basePackageTemplate.addComponent({ name: componentName, libraryCppName });
60
+ });
61
+ fileContentByPath.set(
62
+ this.cppOutputPath.copyWithNewSegment(
63
+ 'RNOH',
64
+ 'generated',
65
+ `${basePackageClassName}.h`
66
+ ),
67
+ basePackageTemplate.build()
68
+ );
69
+ fileContentByPath.set(
70
+ this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'),
71
+ components_indexTS.build()
72
+ );
73
+ fileContentByPath.set(
74
+ this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'),
75
+ turboModules_indexTS.build()
76
+ );
77
+ fileContentByPath.set(
78
+ this.etsOutputPath.copyWithNewSegment('ts.ts'),
79
+ new IndexTSTemplate(this.codegenNoticeLines)
80
+ .addReexport({ from: './components/ts', as: 'RNC' })
81
+ .addReexport({ from: './turboModules/ts', as: 'TM' })
82
+ .build()
83
+ );
84
+ generated_indexETS.addReexport({ from: './ts' });
85
+ fileContentByPath.set(
86
+ this.etsOutputPath.copyWithNewSegment('index.ets'),
87
+ generated_indexETS.build()
88
+ );
89
+ return fileContentByPath;
90
+ }
91
+ }
@@ -11,7 +11,7 @@ import {
11
11
  SpecSchema,
12
12
  CodegenError,
13
13
  } from '../core';
14
- import { GlueCodeTurboModuleData } from './GlueCodeGenerator';
14
+ import { GlueCodeTurboModuleData } from './AppBuildTimeGlueCodeGenerator';
15
15
 
16
16
  /**
17
17
  * Generates boilerplate code for Turbo Modules.
@@ -21,7 +21,8 @@ export class NativeModuleCodeGenerator implements SpecCodeGenerator {
21
21
  constructor(
22
22
  private cppOutputPath: AbsolutePath,
23
23
  private etsOutputPath: AbsolutePath,
24
- private generatorVersion: number
24
+ private codegenNoticeLines: string[],
25
+ private rnohImport: string
25
26
  ) {}
26
27
 
27
28
  getGlueCodeData() {
@@ -39,11 +40,12 @@ export class NativeModuleCodeGenerator implements SpecCodeGenerator {
39
40
  const typeAnnotationToTS = new TypeAnnotationToTS();
40
41
  const turboModuleInterfaceTS = new TurboModuleInterfaceTS(
41
42
  schema.moduleName,
42
- this.generatorVersion
43
+ this.codegenNoticeLines,
44
+ this.rnohImport
43
45
  );
44
46
  const turboModuleH = new TurboModuleHTemplate(
45
47
  schema.moduleName,
46
- this.generatorVersion
48
+ this.codegenNoticeLines
47
49
  ).build();
48
50
  result.set(
49
51
  this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.h`),
@@ -52,7 +54,7 @@ export class NativeModuleCodeGenerator implements SpecCodeGenerator {
52
54
 
53
55
  const turboModuleCpp = new TurboModuleCppTemplate(
54
56
  schema.moduleName,
55
- this.generatorVersion
57
+ this.codegenNoticeLines
56
58
  );
57
59
 
58
60
  Object.entries(schema.aliasMap).map(([name, typeAnnotation]) => {
@@ -0,0 +1,50 @@
1
+ import RNCodegen from '@react-native/codegen/lib/generators/RNCodegen';
2
+ import { AbsolutePath } from '../../core';
3
+ import { CodeGenerator, UberSchema } from '../core';
4
+
5
+ type LibraryData = {
6
+ libraryCppName: string;
7
+ uberSchema: UberSchema;
8
+ };
9
+
10
+ export class SharedComponentCodeGenerator
11
+ implements CodeGenerator<LibraryData>
12
+ {
13
+ constructor(
14
+ private onGetSharedOutputPath: (filename: string) => AbsolutePath
15
+ ) {}
16
+
17
+ generate({
18
+ libraryCppName,
19
+ uberSchema,
20
+ }: LibraryData): Map<AbsolutePath, string> {
21
+ const fileContentByPath = new Map<AbsolutePath, string>();
22
+
23
+ const generatorFns = [
24
+ RNCodegen.allGenerators.generatePropsH,
25
+ RNCodegen.allGenerators.generatePropsCpp,
26
+ RNCodegen.allGenerators.generateEventEmitterH,
27
+ RNCodegen.allGenerators.generateEventEmitterCpp,
28
+ RNCodegen.allGenerators.generateComponentDescriptorH,
29
+ RNCodegen.allGenerators.generateStateH,
30
+ RNCodegen.allGenerators.generateStateCpp,
31
+ RNCodegen.allGenerators.generateShadowNodeH,
32
+ RNCodegen.allGenerators.generateShadowNodeCpp,
33
+ ];
34
+ generatorFns.forEach((generate) => {
35
+ const filesOutput = generate(
36
+ libraryCppName,
37
+ uberSchema.getValue(),
38
+ 'UNUSED_packageName',
39
+ true
40
+ );
41
+ filesOutput.forEach((fileContent, filename) => {
42
+ fileContentByPath.set(
43
+ this.onGetSharedOutputPath(filename),
44
+ fileContent
45
+ );
46
+ });
47
+ });
48
+ return fileContentByPath;
49
+ }
50
+ }
@@ -6,9 +6,9 @@ import {
6
6
  SpecSchemaType,
7
7
  UberSchema,
8
8
  } from '../core';
9
- import { GlueCodeDataV1 } from './GlueCodeGenerator';
9
+ import { GlueCodeDataV1 } from './AppBuildTimeGlueCodeGenerator';
10
10
  import { NativeModuleCodeGenerator } from './NativeModuleCodeGenerator';
11
- import { ComponentCodeGeneratorArkTS } from './ComponentCodeGeneratorArkTS';
11
+ import { ArkTSComponentCodeGeneratorArkTS } from './ArkTSComponentCodeGeneratorArkTS';
12
12
 
13
13
  /**
14
14
  * Generates code for libraries built on top of RNOH's ArkTS architecture.
@@ -18,7 +18,8 @@ export class UberGeneratorV1 implements CodeGenerator<UberSchema> {
18
18
 
19
19
  constructor(
20
20
  private cppOutputPath: AbsolutePath,
21
- private etsOutputPath: AbsolutePath
21
+ private etsOutputPath: AbsolutePath,
22
+ private codegenNoticeLines: string[]
22
23
  ) {}
23
24
 
24
25
  getGlueCodeData(): GlueCodeDataV1 {
@@ -27,17 +28,20 @@ export class UberGeneratorV1 implements CodeGenerator<UberSchema> {
27
28
 
28
29
  generate(uberSchema: UberSchema) {
29
30
  const fileContentByPath = new Map<AbsolutePath, string>();
30
- const componentCodeGeneratorArkTS = new ComponentCodeGeneratorArkTS(
31
+ const componentCodeGenerator = new ArkTSComponentCodeGeneratorArkTS(
31
32
  this.cppOutputPath,
32
- this.etsOutputPath.copyWithNewSegment('components')
33
+ this.etsOutputPath.copyWithNewSegment('components'),
34
+ this.codegenNoticeLines,
35
+ '../../ts'
33
36
  );
34
37
  const nativeModuleCodeGenerator = new NativeModuleCodeGenerator(
35
38
  this.cppOutputPath,
36
39
  this.etsOutputPath.copyWithNewSegment('turboModules'),
37
- 1
40
+ this.codegenNoticeLines,
41
+ '../../ts'
38
42
  );
39
43
  const generatorBySpecType = {
40
- Component: componentCodeGeneratorArkTS,
44
+ Component: componentCodeGenerator,
41
45
  NativeModule: nativeModuleCodeGenerator,
42
46
  } satisfies Record<SpecSchemaType, CodeGenerator<SpecSchema>>;
43
47
  for (const [_fileName, specSchema] of uberSchema
@@ -56,7 +60,7 @@ export class UberGeneratorV1 implements CodeGenerator<UberSchema> {
56
60
  });
57
61
  }
58
62
  this.glueCodeData = {
59
- components: componentCodeGeneratorArkTS.getGlueCodeData(),
63
+ components: componentCodeGenerator.getGlueCodeData(),
60
64
  turboModules: nativeModuleCodeGenerator.getGlueCodeData(),
61
65
  };
62
66
  return fileContentByPath;
@@ -1,11 +1,12 @@
1
1
  import { AbsolutePath } from '../../core';
2
2
  import { CodeGenerator } from '../core';
3
3
  import {
4
- ComponentCodeGeneratorCAPI,
4
+ CppComponentCodeGenerator,
5
5
  LibraryData,
6
- } from './ComponentCodeGeneratorCAPI';
6
+ } from './CppComponentCodeGenerator';
7
7
  import { NativeModuleCodeGenerator } from './NativeModuleCodeGenerator';
8
- import { GlueCodeDataV2 } from './GlueCodeGenerator';
8
+ import { GlueCodeDataV2 } from './AppBuildTimeGlueCodeGenerator';
9
+ import { SharedComponentCodeGenerator } from './SharedComponentCodeGenerator';
9
10
 
10
11
  /**
11
12
  * Generates code for libraries built on top of RNOH's C-API architecture.
@@ -15,7 +16,8 @@ export class UberGeneratorV2 implements CodeGenerator<LibraryData[]> {
15
16
 
16
17
  constructor(
17
18
  private cppOutputPath: AbsolutePath,
18
- private etsOutputPath: AbsolutePath
19
+ private etsOutputPath: AbsolutePath,
20
+ private codegenNoticeLines: string[]
19
21
  ) {}
20
22
 
21
23
  getGlueCodeData(): GlueCodeDataV2 {
@@ -25,20 +27,26 @@ export class UberGeneratorV2 implements CodeGenerator<LibraryData[]> {
25
27
  generate(npmPackagesInfo: LibraryData[]) {
26
28
  const fileContentByPath: Map<AbsolutePath, string> = new Map();
27
29
 
28
- npmPackagesInfo.forEach(({ name, uberSchema }) => {
29
- this.glueCodeData.set(name, { components: [], turboModules: [] });
30
- const libraryGlueCodeData = this.glueCodeData.get(name)!;
31
- const libraryCppOutput = this.cppOutputPath.copyWithNewSegment(name);
32
- const componentCodeGeneratorCAPI = new ComponentCodeGeneratorCAPI(
30
+ npmPackagesInfo.forEach(({ libraryCppName, uberSchema }) => {
31
+ this.glueCodeData.set(libraryCppName, {
32
+ components: [],
33
+ turboModules: [],
34
+ });
35
+ const libraryGlueCodeData = this.glueCodeData.get(libraryCppName)!;
36
+ const libraryCppOutput =
37
+ this.cppOutputPath.copyWithNewSegment(libraryCppName);
38
+ const sharedComponentCodeGenerator = new SharedComponentCodeGenerator(
33
39
  (filename) => {
34
40
  return libraryCppOutput.copyWithNewSegment(
35
41
  'react',
36
42
  'renderer',
37
43
  'components',
38
- name,
44
+ libraryCppName,
39
45
  filename
40
46
  );
41
- },
47
+ }
48
+ );
49
+ const cppComponentCodeGenerator = new CppComponentCodeGenerator(
42
50
  (filename) => {
43
51
  return libraryCppOutput.copyWithNewSegment(
44
52
  'RNOH',
@@ -46,19 +54,26 @@ export class UberGeneratorV2 implements CodeGenerator<LibraryData[]> {
46
54
  'components',
47
55
  filename
48
56
  );
49
- }
57
+ },
58
+ this.codegenNoticeLines
50
59
  );
51
- componentCodeGeneratorCAPI
52
- .generate({ name, uberSchema })
60
+ cppComponentCodeGenerator
61
+ .generate({ libraryCppName, uberSchema })
53
62
  .forEach((fileContent, path) => {
54
63
  fileContentByPath.set(path, fileContent);
55
64
  });
56
- componentCodeGeneratorCAPI
65
+ cppComponentCodeGenerator
57
66
  .getGlueCodeData()
58
67
  .forEach((componentGlueCodeData) => {
59
68
  libraryGlueCodeData.components.push(componentGlueCodeData);
60
69
  });
61
70
 
71
+ sharedComponentCodeGenerator
72
+ .generate({ libraryCppName, uberSchema })
73
+ .forEach((fileContent, path) => {
74
+ fileContentByPath.set(path, fileContent);
75
+ });
76
+
62
77
  for (const [_fileName, specSchema] of uberSchema
63
78
  .getSpecSchemaByFilenameMap()
64
79
  .entries()) {
@@ -70,7 +85,8 @@ export class UberGeneratorV2 implements CodeGenerator<LibraryData[]> {
70
85
  'turbo_modules'
71
86
  ),
72
87
  this.etsOutputPath.copyWithNewSegment('turboModules'),
73
- 2
88
+ this.codegenNoticeLines,
89
+ '../../ts'
74
90
  );
75
91
  nativeModuleCodeGenerator
76
92
  .generate(specSchema)
@@ -1,6 +1,8 @@
1
1
  export * from './NativeModuleCodeGenerator';
2
- export * from './GlueCodeGenerator';
3
- export * from './ComponentCodeGeneratorArkTS';
4
- export * from './ComponentCodeGeneratorCAPI';
2
+ export * from './AppBuildTimeGlueCodeGenerator';
3
+ export * from './ArkTSComponentCodeGeneratorArkTS';
4
+ export * from './ArkTSComponentCodeGeneratorCAPI';
5
+ export * from './CppComponentCodeGenerator';
5
6
  export * from './UberGeneratorV1';
6
7
  export * from './UberGeneratorV2';
8
+ export * from './SharedComponentCodeGenerator';
@@ -4,13 +4,11 @@ import { TypeAnnotation } from '../core';
4
4
 
5
5
  const TEMPLATE = `
6
6
  /**
7
- * This code was generated by "react-native codegen-harmony"
8
- *
9
- * Do not edit this file as changes may cause incorrect behavior and will be
10
- * lost once the code is regenerated.
11
- *
12
- * @generatorVersion: 2
7
+ {{#codegenNoticeLines}}
8
+ * {{{line}}}
9
+ {{/codegenNoticeLines}}
13
10
  */
11
+
14
12
  #pragma once
15
13
 
16
14
  #include "RNOH/CppComponentInstance.h"
@@ -45,7 +43,11 @@ type BaseComponentInstanceHCommand = {
45
43
  export class BaseComponentInstanceHTemplate {
46
44
  private commands: BaseComponentInstanceHCommand[] = [];
47
45
 
48
- constructor(private componentName: string, private libraryName: string) {}
46
+ constructor(
47
+ private componentName: string,
48
+ private libraryName: string,
49
+ private codegenNoticeLines: string[]
50
+ ) {}
49
51
 
50
52
  addCommand(command: BaseComponentInstanceHCommand) {
51
53
  this.commands.push(command);
@@ -53,6 +55,9 @@ export class BaseComponentInstanceHTemplate {
53
55
 
54
56
  build(): string {
55
57
  return mustache.render(TEMPLATE, {
58
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
59
+ line,
60
+ })),
56
61
  name: this.componentName,
57
62
  libraryName: this.libraryName,
58
63
  commands: this.commands.map(({ name, args }) => {