@react-native-oh/react-native-harmony-cli 0.0.26 → 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 (86) hide show
  1. package/dist/assetResolver.js +19 -0
  2. package/dist/codegen/core/CodeGenerator.js +2 -0
  3. package/dist/codegen/core/CodegenError.js +7 -0
  4. package/dist/codegen/core/EventUtils.js +19 -0
  5. package/dist/codegen/core/TypeAnnotationToTS.js +132 -0
  6. package/dist/codegen/core/UberSchema.js +103 -0
  7. package/dist/codegen/core/index.js +21 -0
  8. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +61 -0
  9. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +76 -0
  10. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +74 -0
  11. package/dist/codegen/generators/CppComponentCodeGenerator.js +56 -0
  12. package/dist/codegen/generators/LibGlueCodeGenerator.js +50 -0
  13. package/dist/codegen/generators/NativeModuleCodeGenerator.js +73 -0
  14. package/dist/codegen/generators/SharedComponentCodeGenerator.js +34 -0
  15. package/dist/codegen/generators/UberGeneratorV1.js +50 -0
  16. package/dist/codegen/generators/UberGeneratorV2.js +71 -0
  17. package/dist/codegen/generators/index.js +24 -0
  18. package/dist/codegen/index.js +18 -0
  19. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +105 -0
  20. package/dist/codegen/templates/BasePackageHTemplate.js +130 -0
  21. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +62 -0
  22. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +85 -0
  23. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +192 -0
  24. package/dist/codegen/templates/IndexTSTemplate.js +52 -0
  25. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +124 -0
  26. package/dist/codegen/templates/TurboModuleCppTemplate.js +53 -0
  27. package/dist/codegen/templates/TurboModuleHTemplate.js +42 -0
  28. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +75 -0
  29. package/dist/codegen/templates/index.js +25 -0
  30. package/dist/commands/bundle-harmony.js +179 -0
  31. package/dist/commands/codegen-harmony.js +201 -0
  32. package/dist/commands/codegen-lib-harmony.js +253 -0
  33. package/dist/commands/create-metro-host-constants.js +61 -0
  34. package/dist/commands/index.js +23 -0
  35. package/dist/commands/pack-harmony.js +100 -0
  36. package/dist/commands/unpack-harmony.js +184 -0
  37. package/dist/commands/verify-package-harmony.js +122 -0
  38. package/dist/core/AbsolutePath.js +47 -0
  39. package/dist/core/CodegenConfig.js +57 -0
  40. package/dist/core/DescriptiveError.js +49 -0
  41. package/dist/core/OHPackageJSON5.js +23 -0
  42. package/dist/core/PackageJSON.js +58 -0
  43. package/dist/core/ProjectDependenciesManager.js +70 -0
  44. package/dist/core/ValidationError.js +6 -0
  45. package/dist/core/ValueObject.js +2 -0
  46. package/dist/core/fs.js +36 -0
  47. package/dist/core/index.js +25 -0
  48. package/dist/index.js +15 -0
  49. package/dist/io/Logger.js +71 -0
  50. package/dist/io/TarGz.js +28 -0
  51. package/dist/io/fsUtils.js +23 -0
  52. package/dist/io/index.js +19 -0
  53. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +38 -0
  54. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +32 -0
  55. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +26 -0
  56. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +51 -0
  57. package/dist/package-verifier/checks/index.js +20 -0
  58. package/dist/package-verifier/index.js +18 -0
  59. package/dist/package-verifier/types.js +2 -0
  60. package/dist/package-verifier/verify-package.js +101 -0
  61. package/package.json +1 -1
  62. package/src/codegen/core/UberSchema.ts +4 -0
  63. package/src/codegen/generators/{GlueCodeGenerator.ts → AppBuildTimeGlueCodeGenerator.ts} +13 -9
  64. package/src/codegen/generators/{ComponentCodeGeneratorArkTS.ts → ArkTSComponentCodeGeneratorArkTS.ts} +11 -5
  65. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +112 -0
  66. package/src/codegen/generators/{ComponentCodeGeneratorCAPI.ts → CppComponentCodeGenerator.ts} +14 -43
  67. package/src/codegen/generators/LibGlueCodeGenerator.ts +91 -0
  68. package/src/codegen/generators/NativeModuleCodeGenerator.ts +7 -5
  69. package/src/codegen/generators/SharedComponentCodeGenerator.ts +50 -0
  70. package/src/codegen/generators/UberGeneratorV1.ts +12 -8
  71. package/src/codegen/generators/UberGeneratorV2.ts +32 -16
  72. package/src/codegen/generators/index.ts +5 -3
  73. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +12 -7
  74. package/src/codegen/templates/{GeneratedPackageHTemplate.ts → BasePackageHTemplate.ts} +45 -12
  75. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +2 -1
  76. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +8 -10
  77. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +13 -8
  78. package/src/codegen/templates/IndexTSTemplate.ts +11 -9
  79. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +1 -0
  80. package/src/codegen/templates/TurboModuleCppTemplate.ts +9 -9
  81. package/src/codegen/templates/TurboModuleHTemplate.ts +9 -9
  82. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +13 -9
  83. package/src/commands/codegen-harmony.ts +24 -7
  84. package/src/commands/codegen-lib-harmony.ts +387 -0
  85. package/src/commands/index.ts +1 -0
  86. package/src/index.ts +2 -0
@@ -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 }) => {
@@ -2,13 +2,11 @@ import mustache from 'mustache';
2
2
 
3
3
  const TEMPLATE = `
4
4
  /**
5
- * This code was generated by "react-native codegen-harmony"
6
- *
7
- * Do not edit this file as changes may cause incorrect behavior and will be
8
- * lost once the code is regenerated.
9
- *
10
- * @generatorVersion: 2
5
+ {{#codegenNoticeLines}}
6
+ * {{{line}}}
7
+ {{/codegenNoticeLines}}
11
8
  */
9
+
12
10
  #pragma once
13
11
 
14
12
  {{#libraries}}
@@ -37,6 +35,26 @@ class {{name}}TurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
37
35
  };
38
36
  };
39
37
 
38
+ class {{name}}EventEmitRequestHandler : public EventEmitRequestHandler {
39
+ public:
40
+ void handleEvent(Context const &ctx) override {
41
+ auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
42
+ if (eventEmitter == nullptr) {
43
+ return;
44
+ }
45
+
46
+ std::vector<std::string> supportedEventNames = {
47
+ {{#arkTSEvents}}
48
+ "{{name}}",
49
+ {{/arkTSEvents}}
50
+ };
51
+ if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
52
+ eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
53
+ }
54
+ }
55
+ };
56
+
57
+
40
58
  class {{name}} : public Package {
41
59
  public:
42
60
  {{name}}(Package::Context ctx) : Package(ctx){};
@@ -62,7 +80,9 @@ class {{name}} : public Package {
62
80
  };
63
81
 
64
82
  EventEmitRequestHandlers createEventEmitRequestHandlers() override {
65
- return {};
83
+ return {
84
+ std::make_shared<{{name}}EventEmitRequestHandler>(),
85
+ };
66
86
  }
67
87
  };
68
88
 
@@ -75,15 +95,20 @@ type GeneratedPackageTurboModule = {
75
95
 
76
96
  type GeneratedPackageComponent = {
77
97
  name: string;
78
- libraryName: string;
98
+ libraryCppName: string;
99
+ };
100
+
101
+ type ArkTSEvent = {
102
+ name: string;
79
103
  };
80
104
 
81
105
  export class BasePackageHTemplate {
82
106
  private turboModules: GeneratedPackageTurboModule[] = [];
83
107
  private components: GeneratedPackageComponent[] = [];
84
- private libraryNames = new Set<string>();
108
+ private arkTSEvents: ArkTSEvent[] = [];
109
+ private libraryCppNames = new Set<string>();
85
110
 
86
- constructor(private name: string) {}
111
+ constructor(private name: string, private codegenNoticeLines: string[]) {}
87
112
 
88
113
  addTurboModule(turboModule: GeneratedPackageTurboModule) {
89
114
  this.turboModules.push(turboModule);
@@ -91,15 +116,23 @@ export class BasePackageHTemplate {
91
116
 
92
117
  addComponent(component: GeneratedPackageComponent) {
93
118
  this.components.push(component);
94
- this.libraryNames.add(component.libraryName);
119
+ this.libraryCppNames.add(component.libraryCppName);
120
+ }
121
+
122
+ addArkTSEvent(arkTSEvent: ArkTSEvent) {
123
+ this.arkTSEvents.push(arkTSEvent);
95
124
  }
96
125
 
97
126
  build(): string {
98
127
  return mustache.render(TEMPLATE.trimStart(), {
128
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
129
+ line,
130
+ })),
99
131
  name: this.name,
100
132
  turboModules: this.turboModules,
101
133
  components: this.components,
102
- libraries: Array.from(this.libraryNames).map((name) => ({
134
+ arkTSEvents: this.arkTSEvents,
135
+ libraries: Array.from(this.libraryCppNames).map((name) => ({
103
136
  name,
104
137
  })),
105
138
  });
@@ -9,6 +9,7 @@ const TEMPLATE = `
9
9
  *
10
10
  * @generatorVersion: 1
11
11
  */
12
+
12
13
  #pragma once
13
14
 
14
15
  #include <react/renderer/core/ConcreteComponentDescriptor.h>
@@ -18,7 +19,7 @@ const TEMPLATE = `
18
19
  namespace facebook {
19
20
  namespace react {
20
21
 
21
- extern const char {{name}}ComponentName[] = "{{name}}";
22
+ constexpr char {{name}}ComponentName[] = "{{name}}";
22
23
 
23
24
  class {{name}}Props : public ViewProps {
24
25
  public:
@@ -1,17 +1,13 @@
1
1
  import mustache from 'mustache';
2
2
 
3
3
  const TEMPLATE = `
4
- #pragma once
5
-
6
4
  /**
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: {{generatorVersion}}
5
+ {{#codegenNoticeLines}}
6
+ * {{{line}}}
7
+ {{/codegenNoticeLines}}
13
8
  */
14
9
 
10
+ #pragma once
15
11
  #include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
16
12
 
17
13
  namespace rnoh {
@@ -58,7 +54,7 @@ export class ComponentJSIBinderHTemplate {
58
54
  private props: ComponentJSIBinderHProp[] = [];
59
55
  private events: ComponentJSIBinderHEvent[] = [];
60
56
 
61
- constructor(private name: string, private generatorVersion: number) {}
57
+ constructor(private name: string, private codegenNoticeLines: string[]) {}
62
58
 
63
59
  addProp(prop: ComponentJSIBinderHProp) {
64
60
  this.props.push(prop);
@@ -70,8 +66,10 @@ export class ComponentJSIBinderHTemplate {
70
66
 
71
67
  build(): string {
72
68
  return mustache.render(TEMPLATE.trimStart(), {
69
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
70
+ line,
71
+ })),
73
72
  name: this.name,
74
- generatorVersion: this.generatorVersion,
75
73
  props: this.props.map((prop) => ({
76
74
  name: prop.name,
77
75
  type: prop.isObject ? '"Object"' : 'true',
@@ -2,12 +2,9 @@ import mustache from 'mustache';
2
2
 
3
3
  const TEMPLATE = `
4
4
  /**
5
- * This code was generated by "react-native codegen-harmony"
6
- *
7
- * Do not edit this file as changes may cause incorrect behavior and will be
8
- * lost once the code is regenerated.
9
- *
10
- * @generatorVersion: 1
5
+ {{#codegenNoticeLines}}
6
+ * {{{line}}}
7
+ {{/codegenNoticeLines}}
11
8
  */
12
9
 
13
10
  import {
@@ -21,7 +18,7 @@ import {
21
18
  Tag,
22
19
  RNComponentCommandReceiver,
23
20
  ViewPropsSelector,
24
- } from '../../ts';
21
+ } from '{{{rnohImport}}}';
25
22
 
26
23
 
27
24
  export namespace {{name}} {
@@ -162,7 +159,11 @@ export class ComponentUtilsTSTemplate {
162
159
  private commands: Command[] = [];
163
160
  private getterTemplateByTSType = new Map<string, string>();
164
161
 
165
- constructor(private name: string) {
162
+ constructor(
163
+ private name: string,
164
+ private codegenNoticeLines: string[],
165
+ private rnohImport: string
166
+ ) {
166
167
  this.getterTemplateByTSType.set('ColorValue', COLOR_VALUE_GETTER_TEMPLATE);
167
168
  }
168
169
 
@@ -180,7 +181,11 @@ export class ComponentUtilsTSTemplate {
180
181
 
181
182
  build(): string {
182
183
  return mustache.render(TEMPLATE.trimStart(), {
184
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
185
+ line,
186
+ })),
183
187
  name: this.name,
188
+ rnohImport: this.rnohImport,
184
189
  props: this.props.map((prop) => ({
185
190
  name: prop.name,
186
191
  type: prop.tsType,
@@ -2,11 +2,11 @@ import mustache from 'mustache';
2
2
 
3
3
  const TEMPLATE = `
4
4
  /**
5
- * This code was generated by "react-native codegen-harmony"
6
- *
7
- * Do not edit this file as changes may cause incorrect behavior and will be
8
- * lost once the code is regenerated.
5
+ {{#codegenNoticeLines}}
6
+ * {{{line}}}
7
+ {{/codegenNoticeLines}}
9
8
  */
9
+
10
10
  {{#reexports}}
11
11
  export * {{as}}from "{{{from}}}"
12
12
  {{/reexports}}
@@ -14,10 +14,9 @@ export * {{as}}from "{{{from}}}"
14
14
 
15
15
  const TEMPLATE_EMPTY = `
16
16
  /**
17
- * This code was generated by "react-native codegen-harmony"
18
- *
19
- * Do not edit this file as changes may cause incorrect behavior and will be
20
- * lost once the code is regenerated.
17
+ {{#codegenNoticeLines}}
18
+ * {{{line}}}
19
+ {{/codegenNoticeLines}}
21
20
  */
22
21
 
23
22
  export {}
@@ -31,7 +30,7 @@ type Reexport = {
31
30
  export class IndexTSTemplate {
32
31
  private reexports: Reexport[] = [];
33
32
 
34
- constructor() {}
33
+ constructor(private codegenNoticeLines: string[]) {}
35
34
 
36
35
  addReexport(reexport: Reexport) {
37
36
  this.reexports.push(reexport);
@@ -44,6 +43,9 @@ export class IndexTSTemplate {
44
43
  }
45
44
 
46
45
  return mustache.render(TEMPLATE.trimStart(), {
46
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
47
+ line,
48
+ })),
47
49
  reexports: this.reexports.map((reexport) => ({
48
50
  from: reexport.from,
49
51
  as: reexport.as ? `as ${reexport.as} ` : '',
@@ -9,6 +9,7 @@ const TEMPLATE = `
9
9
  *
10
10
  * @generatorVersion: 1
11
11
  */
12
+
12
13
  #pragma once
13
14
 
14
15
  #include "RNOH/Package.h"
@@ -2,13 +2,11 @@ import mustache from 'mustache';
2
2
 
3
3
  const TEMPLATE = `
4
4
  /**
5
- * This code was generated by "react-native codegen-harmony"
6
- *
7
- * Do not edit this file as changes may cause incorrect behavior and will be
8
- * lost once the code is regenerated.
9
- *
10
- * @generatorVersion: {{generatorVersion}}
5
+ {{#codegenNoticeLines}}
6
+ * {{{line}}}
7
+ {{/codegenNoticeLines}}
11
8
  */
9
+
12
10
  #include "{{className}}.h"
13
11
 
14
12
  namespace rnoh {
@@ -34,16 +32,18 @@ export type TurboModuleCppTemplateMethod = {
34
32
  export class TurboModuleCppTemplate {
35
33
  private methods: TurboModuleCppTemplateMethod[] = [];
36
34
 
37
- constructor(private name: string, private generatorVersion: number) {}
35
+ constructor(private name: string, private codegenNoticeLines: string[]) {}
38
36
 
39
37
  addMethod(method: TurboModuleCppTemplateMethod) {
40
38
  this.methods.push(method);
41
39
  }
42
40
 
43
41
  build(): string {
44
- return mustache.render(TEMPLATE, {
42
+ return mustache.render(TEMPLATE.trimStart(), {
43
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
44
+ line,
45
+ })),
45
46
  className: this.name,
46
- generatorVersion: this.generatorVersion,
47
47
  methods: this.methods.map((method) => ({
48
48
  name: method.name,
49
49
  argsCount: method.argsCount,
@@ -2,13 +2,11 @@ import mustache from 'mustache';
2
2
 
3
3
  const TEMPLATE = `
4
4
  /**
5
- * This code was generated by "react-native codegen-harmony"
6
- *
7
- * Do not edit this file as changes may cause incorrect behavior and will be
8
- * lost once the code is regenerated.
9
- *
10
- * @generatorVersion: {{generatorVersion}}
5
+ {{#codegenNoticeLines}}
6
+ * {{{line}}}
7
+ {{/codegenNoticeLines}}
11
8
  */
9
+
12
10
  #pragma once
13
11
 
14
12
  #include "RNOH/ArkTSTurboModule.h"
@@ -24,12 +22,14 @@ class JSI_EXPORT {{className}} : public ArkTSTurboModule {
24
22
  `;
25
23
 
26
24
  export class TurboModuleHTemplate {
27
- constructor(private name: string, private generatorVersion: number) {}
25
+ constructor(private name: string, private codegenNoticeLines: string[]) {}
28
26
 
29
27
  build(): string {
30
- return mustache.render(TEMPLATE, {
28
+ return mustache.render(TEMPLATE.trimStart(), {
31
29
  className: this.name,
32
- generatorVersion: this.generatorVersion,
30
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
31
+ line,
32
+ })),
33
33
  });
34
34
  }
35
35
  }
@@ -2,15 +2,12 @@ import mustache from 'mustache';
2
2
 
3
3
  const TEMPLATE = `
4
4
  /**
5
- * This code was generated by "react-native codegen-harmony"
6
- *
7
- * Do not edit this file as changes may cause incorrect behavior and will be
8
- * lost once the code is regenerated.
9
- *
10
- * @generatorVersion: {{generatorVersion}}
5
+ {{#codegenNoticeLines}}
6
+ * {{{line}}}
7
+ {{/codegenNoticeLines}}
11
8
  */
12
9
 
13
- import { Tag } from "../../ts"
10
+ import { Tag } from "{{{rnohImport}}}"
14
11
 
15
12
  export namespace {{name}} {
16
13
  export const NAME = '{{name}}' as const
@@ -60,7 +57,11 @@ export class TurboModuleInterfaceTS {
60
57
  private aliases: Alias[] = [];
61
58
  private enumModels: EnumModel[] = [];
62
59
 
63
- constructor(private name: string, private generatorVersion: number) {}
60
+ constructor(
61
+ private name: string,
62
+ private codegenNoticeLines: string[],
63
+ private rnohImport: string
64
+ ) {}
64
65
 
65
66
  addAlias(alias: Alias) {
66
67
  this.aliases.push(alias);
@@ -76,10 +77,13 @@ export class TurboModuleInterfaceTS {
76
77
 
77
78
  build(): string {
78
79
  return mustache.render(TEMPLATE.trimStart(), {
80
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
81
+ line,
82
+ })),
79
83
  name: this.name,
80
84
  aliases: this.aliases,
81
85
  enums: this.enumModels,
82
- generatorVersion: this.generatorVersion,
86
+ rnohImport: this.rnohImport,
83
87
  methods: this.methods.map((method) => ({
84
88
  name: method.name,
85
89
  stringifiedArgs: method.stringifiedArgs,
@@ -15,7 +15,7 @@ import {
15
15
  LibraryData,
16
16
  UberGeneratorV1,
17
17
  UberGeneratorV2,
18
- GlueCodeGenerator,
18
+ AppBuildTimeGlueCodeGenerator,
19
19
  CodegenError,
20
20
  } from '../codegen';
21
21
  import { Logger } from '../io';
@@ -23,7 +23,7 @@ import { Logger } from '../io';
23
23
  export const commandCodegenHarmony: Command = {
24
24
  name: 'codegen-harmony',
25
25
  description:
26
- 'Generates a glue layer and native utilities from Turbo Module or Fabric Components specifications',
26
+ 'Generates boilerplate, types, and utilities from Turbo Module and Fabric Component specifications. This command is meant to be executed during the application build process.',
27
27
  options: [
28
28
  {
29
29
  name: '--rnoh-module-path <path>',
@@ -87,11 +87,26 @@ export const commandCodegenHarmony: Command = {
87
87
  );
88
88
 
89
89
  // instantiate objects
90
- const uberGeneratorV1 = new UberGeneratorV1(cppOutputPath, etsOutputPath);
91
- const uberGeneratorV2 = new UberGeneratorV2(cppOutputPath, etsOutputPath);
92
- const glueCodeGenerator = new GlueCodeGenerator(
90
+ const codegenNoticeLines = [
91
+ 'This code was generated by "react-native codegen-harmony"',
92
+ '',
93
+ 'Do not edit this file as changes may cause incorrect behavior and will be',
94
+ 'lost once the code is regenerated.',
95
+ ];
96
+ const uberGeneratorV1 = new UberGeneratorV1(
93
97
  cppOutputPath,
94
- etsOutputPath
98
+ etsOutputPath,
99
+ [...codegenNoticeLines, '', '@generatorVersion: 1']
100
+ );
101
+ const uberGeneratorV2 = new UberGeneratorV2(
102
+ cppOutputPath,
103
+ etsOutputPath,
104
+ [...codegenNoticeLines, '', '@generatorVersion: 2']
105
+ );
106
+ const glueCodeGenerator = new AppBuildTimeGlueCodeGenerator(
107
+ cppOutputPath,
108
+ etsOutputPath,
109
+ codegenNoticeLines
95
110
  );
96
111
 
97
112
  // generate the code
@@ -176,7 +191,9 @@ async function collectLibrariesData(
176
191
  )
177
192
  ) {
178
193
  results.push({
179
- name: deriveCppDirectoryNameFromNpmPackageName(packageJSON.name),
194
+ libraryCppName: deriveCppDirectoryNameFromNpmPackageName(
195
+ packageJSON.name
196
+ ),
180
197
  uberSchema: UberSchema.fromCodegenConfig(codegenConfig),
181
198
  });
182
199
  }