@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
@@ -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
  }