@react-native-oh/react-native-harmony-cli 0.0.15 → 0.0.23

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 (85) hide show
  1. package/.prettierrc +6 -6
  2. package/dist/assetResolver.js +23 -5
  3. package/dist/codegen/core/Codegen.js +35 -0
  4. package/dist/codegen/core/CodegenError.js +7 -0
  5. package/dist/codegen/core/EventUtils.js +19 -0
  6. package/dist/codegen/core/TypeAnnotationToTS.js +132 -0
  7. package/dist/codegen/core/UberSchema.js +74 -0
  8. package/dist/codegen/core/index.js +21 -0
  9. package/dist/codegen/generators/ComponentCodeGenerator.js +66 -0
  10. package/dist/codegen/generators/NativeModuleCodeGenerator.js +64 -0
  11. package/dist/codegen/generators/PackageCodeGenerator.js +52 -0
  12. package/dist/codegen/generators/index.js +19 -0
  13. package/dist/codegen/index.js +18 -0
  14. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +55 -0
  15. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +78 -0
  16. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +181 -0
  17. package/dist/codegen/templates/IndexTSTemplate.js +31 -0
  18. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +117 -0
  19. package/dist/codegen/templates/TurboModuleCppTemplate.js +45 -0
  20. package/dist/codegen/templates/TurboModuleHTemplate.js +32 -0
  21. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +64 -0
  22. package/dist/codegen/templates/index.js +24 -0
  23. package/dist/commands/codegen-harmony.js +110 -0
  24. package/dist/commands/create-metro-host-constants.js +61 -0
  25. package/dist/commands/index.js +2 -0
  26. package/dist/commands/pack-harmony.js +4 -1
  27. package/dist/commands/unpack-harmony.js +86 -43
  28. package/dist/core/AbsolutePath.js +41 -0
  29. package/dist/core/CodegenConfig.js +53 -0
  30. package/dist/core/DescriptiveError.js +49 -0
  31. package/dist/core/PackageJSON.js +53 -0
  32. package/dist/core/ProjectDependenciesManager.js +70 -0
  33. package/dist/core/ValueObject.js +2 -0
  34. package/dist/core/fs.js +36 -0
  35. package/dist/core/index.js +7 -0
  36. package/dist/index.js +7 -1
  37. package/dist/io/Logger.js +71 -0
  38. package/dist/io/fsUtils.js +23 -0
  39. package/dist/io/index.js +18 -0
  40. package/jest.config.js +5 -5
  41. package/package.json +52 -47
  42. package/react-native.config.js +10 -10
  43. package/src/assetResolver.ts +44 -25
  44. package/src/codegen/core/Codegen.ts +44 -0
  45. package/src/codegen/core/CodegenError.ts +3 -0
  46. package/src/codegen/core/EventUtils.ts +18 -0
  47. package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -0
  48. package/src/codegen/core/TypeAnnotationToTS.ts +188 -0
  49. package/src/codegen/core/UberSchema.ts +99 -0
  50. package/src/codegen/core/index.ts +5 -0
  51. package/src/codegen/generators/ComponentCodeGenerator.ts +98 -0
  52. package/src/codegen/generators/NativeModuleCodeGenerator.ts +95 -0
  53. package/src/codegen/generators/PackageCodeGenerator.ts +73 -0
  54. package/src/codegen/generators/index.ts +3 -0
  55. package/src/codegen/index.ts +2 -0
  56. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +49 -0
  57. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +85 -0
  58. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +202 -0
  59. package/src/codegen/templates/IndexTSTemplate.ts +33 -0
  60. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +124 -0
  61. package/src/codegen/templates/TurboModuleCppTemplate.ts +47 -0
  62. package/src/codegen/templates/TurboModuleHTemplate.ts +26 -0
  63. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +81 -0
  64. package/src/codegen/templates/index.ts +8 -0
  65. package/src/commands/bundle-harmony.ts +202 -202
  66. package/src/commands/codegen-harmony.ts +143 -0
  67. package/src/commands/create-metro-host-constants.ts +48 -0
  68. package/src/commands/index.ts +5 -3
  69. package/src/commands/pack-harmony.ts +121 -118
  70. package/src/commands/unpack-harmony.ts +231 -156
  71. package/src/core/AbsolutePath.ts +43 -0
  72. package/src/core/CodegenConfig.ts +54 -0
  73. package/src/core/DescriptiveError.ts +61 -0
  74. package/src/core/PackageJSON.ts +63 -0
  75. package/src/core/ProjectDependenciesManager.ts +77 -0
  76. package/src/core/ValidationError.ts +1 -1
  77. package/src/core/ValueObject.ts +2 -0
  78. package/src/core/fs.ts +31 -0
  79. package/src/core/index.ts +8 -1
  80. package/src/index.ts +18 -10
  81. package/src/io/Logger.ts +68 -0
  82. package/src/io/fsUtils.ts +24 -0
  83. package/src/io/index.ts +2 -0
  84. package/tsconfig.build.json +6 -5
  85. package/tsconfig.json +2 -2
@@ -0,0 +1,99 @@
1
+ import {
2
+ ComponentSchema,
3
+ NativeModuleSchema,
4
+ SchemaType as RawUberSchema,
5
+ } from '@react-native/codegen/lib/CodegenSchema';
6
+ import {
7
+ AbsolutePath,
8
+ ValueObject,
9
+ PackageJSON,
10
+ ProjectDependenciesManager,
11
+ CodegenConfig,
12
+ } from '../../core';
13
+ // @ts-expect-error
14
+ import extractUberSchemaFromSpecFilePaths_ from '@react-native/codegen/lib/cli/combine/combine-js-to-schema.js';
15
+ import { CodegenError } from './CodegenError';
16
+
17
+ function createRawUberSchemaFromSpecFilePaths(
18
+ projectSourceFilePaths: AbsolutePath[]
19
+ ): RawUberSchema {
20
+ return extractUberSchemaFromSpecFilePaths_(
21
+ projectSourceFilePaths.map((p) => p.getValue())
22
+ );
23
+ }
24
+
25
+ export type SpecSchema = ComponentSchema | NativeModuleSchema;
26
+ export type SpecSchemaType = SpecSchema['type'];
27
+ type FindSpecSchemaByType<
28
+ TType extends SpecSchemaType,
29
+ TSpecSchema = SpecSchema
30
+ > = TSpecSchema extends { type: TType } ? TSpecSchema : never;
31
+
32
+ export class UberSchema implements ValueObject {
33
+ static async fromProjectRootPath(
34
+ projectRootPath: AbsolutePath
35
+ ): Promise<UberSchema> {
36
+ const packageJSON = PackageJSON.fromProjectRootPath(
37
+ projectRootPath,
38
+ projectRootPath
39
+ );
40
+ const codegenConfigs: CodegenConfig[] = [];
41
+ const appCodegenConfig = packageJSON.maybeCreateCodegenConfig();
42
+ if (appCodegenConfig) {
43
+ codegenConfigs.push(appCodegenConfig);
44
+ }
45
+ await new ProjectDependenciesManager(projectRootPath).forEachAsync(
46
+ (dependency) => {
47
+ const codegenConfig = dependency.maybeCreateCodegenConfig();
48
+ if (codegenConfig) {
49
+ codegenConfigs.push(codegenConfig);
50
+ }
51
+ }
52
+ );
53
+ try {
54
+ return new UberSchema(
55
+ createRawUberSchemaFromSpecFilePaths(
56
+ codegenConfigs.flatMap((codegenConfig) =>
57
+ codegenConfig.getSpecFilePaths()
58
+ )
59
+ )
60
+ );
61
+ } catch (err) {
62
+ if (err instanceof Error) {
63
+ throw new CodegenError({
64
+ whatHappened: "Couldn't create the schema",
65
+ whatCanUserDo: {
66
+ default: [
67
+ `There's probably at least one spec file defined in your project or in a third-party package that breaks some code generation restrictions. Please check the message below. If it's ambiguous, debug the problem with divide and conquer strategy.\n\n${err.message}`,
68
+ ],
69
+ },
70
+ });
71
+ }
72
+ throw err;
73
+ }
74
+ }
75
+
76
+ private constructor(private schemaValue: RawUberSchema) {}
77
+
78
+ getValue(): RawUberSchema {
79
+ return this.schemaValue;
80
+ }
81
+
82
+ findAllSpecSchemasByType<TSpecSchemaType extends SpecSchemaType>(
83
+ schemaType: TSpecSchemaType
84
+ ): FindSpecSchemaByType<TSpecSchemaType>[] {
85
+ return Object.values(this.schemaValue.modules)
86
+ .filter((module) => module.type === schemaType)
87
+ .map((module) => module as FindSpecSchemaByType<TSpecSchemaType>);
88
+ }
89
+
90
+ getSpecSchemaByFilenameMap(): ReadonlyMap<string, SpecSchema> {
91
+ return Object.entries(this.schemaValue.modules).reduce(
92
+ (acc, [moduleName, moduleSchema]) => {
93
+ acc.set(moduleName, moduleSchema);
94
+ return acc;
95
+ },
96
+ new Map<string, SpecSchema>()
97
+ );
98
+ }
99
+ }
@@ -0,0 +1,5 @@
1
+ export * from './Codegen';
2
+ export * from './UberSchema';
3
+ export * from './CodegenError';
4
+ export * from './EventUtils';
5
+ export * from './TypeAnnotationToTS';
@@ -0,0 +1,98 @@
1
+ import { AbsolutePath } from '../../core';
2
+ import {
3
+ CodegenError,
4
+ TypeAnnotationToTS,
5
+ createEventNameFromEventHandlerName,
6
+ getStringifiedTSDefaultValueFromPropTypeAnnotation,
7
+ } from '../core';
8
+ import type { SpecCodeGenerator } from '../core';
9
+ import { SpecSchema } from '../core';
10
+ import {
11
+ ComponentDescriptorHTemplate,
12
+ ComponentJSIBinderHTemplate,
13
+ ComponentUtilsTSTemplate,
14
+ } from '../templates';
15
+
16
+ export class ComponentCodeGenerator implements SpecCodeGenerator {
17
+ constructor(
18
+ private cppOutputPath: AbsolutePath,
19
+ private tsOutputPath: AbsolutePath
20
+ ) {}
21
+
22
+ generate(schema: SpecSchema): Map<AbsolutePath, string> {
23
+ if (schema.type !== 'Component') {
24
+ throw new CodegenError({
25
+ whatHappened: `ComponentCodeGenerator can't generate code for a module type: ${schema.type}`,
26
+ unexpected: true,
27
+ });
28
+ }
29
+ const typeAnnotationToTS = new TypeAnnotationToTS();
30
+ const result = new Map<AbsolutePath, string>();
31
+ Object.entries(schema.components).map(([name, shape]) => {
32
+ const componentDescriptorHTemplate = new ComponentDescriptorHTemplate(
33
+ name
34
+ );
35
+ const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(name);
36
+ const componentUtilsTSTemplate = new ComponentUtilsTSTemplate(name);
37
+
38
+ shape.props.forEach((prop) => {
39
+ componentJSIBinderHTemplate.addProp({
40
+ name: prop.name,
41
+ isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
42
+ });
43
+
44
+ componentUtilsTSTemplate.addProp({
45
+ name: prop.name,
46
+ tsType: typeAnnotationToTS.convert(prop.typeAnnotation),
47
+ defaultValue: getStringifiedTSDefaultValueFromPropTypeAnnotation(
48
+ prop.typeAnnotation
49
+ ),
50
+ isOptional: prop.optional,
51
+ });
52
+ });
53
+
54
+ shape.commands.forEach((command) => {
55
+ componentUtilsTSTemplate.addCommand({
56
+ name: command.name,
57
+ argsTSType:
58
+ '[' +
59
+ command.typeAnnotation.params
60
+ .map(
61
+ (param) =>
62
+ typeAnnotationToTS.convert(param.typeAnnotation) +
63
+ (param.optional ? '?' : '')
64
+ )
65
+ .join(', ') +
66
+ ']',
67
+ });
68
+ });
69
+
70
+ shape.events.forEach((event) => {
71
+ componentUtilsTSTemplate.addEvent({
72
+ name: createEventNameFromEventHandlerName(event.name),
73
+ payloadTSType: event.typeAnnotation.argument
74
+ ? typeAnnotationToTS.convert(event.typeAnnotation.argument)
75
+ : 'undefined',
76
+ });
77
+ componentJSIBinderHTemplate.addEvent({
78
+ type: event.bubblingType,
79
+ eventHandlerName: event.name,
80
+ });
81
+ });
82
+
83
+ result.set(
84
+ this.cppOutputPath.copyWithNewSegment(`${name}ComponentDescriptor.h`),
85
+ componentDescriptorHTemplate.build()
86
+ );
87
+ result.set(
88
+ this.cppOutputPath.copyWithNewSegment(`${name}JSIBinder.h`),
89
+ componentJSIBinderHTemplate.build()
90
+ );
91
+ result.set(
92
+ this.tsOutputPath.copyWithNewSegment(`${name}.ts`),
93
+ componentUtilsTSTemplate.build()
94
+ );
95
+ });
96
+ return result;
97
+ }
98
+ }
@@ -0,0 +1,95 @@
1
+ import { AbsolutePath } from '../../core';
2
+ import type { SpecCodeGenerator } from '../core/Codegen';
3
+ import { CodegenError } from '../core/CodegenError';
4
+ import {
5
+ TurboModuleCppTemplate,
6
+ TurboModuleHTemplate,
7
+ TurboModuleInterfaceTS,
8
+ } from '../templates';
9
+ import { SpecSchema } from '../core/UberSchema';
10
+ import { TypeAnnotationToTS, wrapWithQuotes } from '../core';
11
+
12
+ export class NativeModuleCodeGenerator implements SpecCodeGenerator {
13
+ constructor(
14
+ private cppOutputPath: AbsolutePath,
15
+ private etsOutputPath: AbsolutePath
16
+ ) {}
17
+
18
+ generate(schema: SpecSchema): Map<AbsolutePath, string> {
19
+ const result = new Map<AbsolutePath, string>();
20
+ if (schema.type !== 'NativeModule') {
21
+ throw new CodegenError({
22
+ whatHappened: `NativeModuleCodeGenerator can't generate code for module type: ${schema.type}`,
23
+ unexpected: true,
24
+ });
25
+ }
26
+ const typeAnnotationToTS = new TypeAnnotationToTS();
27
+ const turboModuleInterfaceTS = new TurboModuleInterfaceTS(
28
+ schema.moduleName
29
+ );
30
+ const turboModuleH = new TurboModuleHTemplate(schema.moduleName).build();
31
+ result.set(
32
+ this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.h`),
33
+ turboModuleH
34
+ );
35
+
36
+ const turboModuleCpp = new TurboModuleCppTemplate(schema.moduleName);
37
+
38
+ Object.entries(schema.aliasMap).map(([name, typeAnnotation]) => {
39
+ turboModuleInterfaceTS.addAlias({
40
+ name: name,
41
+ type: typeAnnotationToTS.convert(typeAnnotation),
42
+ });
43
+ });
44
+
45
+ Object.entries(schema.enumMap).map(([name, enumSpec]) => {
46
+ turboModuleInterfaceTS.addEnum({
47
+ name,
48
+ members: enumSpec.members.map((member) => ({
49
+ name: member.name,
50
+ value:
51
+ typeof member.value === 'string'
52
+ ? wrapWithQuotes(member.value)
53
+ : member.value.toString(),
54
+ })),
55
+ });
56
+ });
57
+
58
+ schema.spec.properties.map((prop) => {
59
+ if (prop.typeAnnotation.type === 'FunctionTypeAnnotation') {
60
+ turboModuleCpp.addMethod({
61
+ name: prop.name,
62
+ argsCount: prop.typeAnnotation.params.length,
63
+ isAsync:
64
+ prop.typeAnnotation.returnTypeAnnotation.type ===
65
+ 'PromiseTypeAnnotation',
66
+ });
67
+
68
+ turboModuleInterfaceTS.addMethod({
69
+ name: prop.name,
70
+ returnType: typeAnnotationToTS.convert(
71
+ prop.typeAnnotation.returnTypeAnnotation
72
+ ),
73
+ stringifiedArgs: prop.typeAnnotation.params
74
+ .map(
75
+ (param) =>
76
+ `${param.name}: ${typeAnnotationToTS.convert(
77
+ param.typeAnnotation
78
+ )}`
79
+ )
80
+ .join(', '),
81
+ });
82
+ }
83
+ });
84
+ result.set(
85
+ this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.cpp`),
86
+ turboModuleCpp.build()
87
+ );
88
+ result.set(
89
+ this.etsOutputPath.copyWithNewSegment(`${schema.moduleName}.ts`),
90
+ turboModuleInterfaceTS.build()
91
+ );
92
+
93
+ return result;
94
+ }
95
+ }
@@ -0,0 +1,73 @@
1
+ import { AbsolutePath } from '../../core';
2
+ import {
3
+ CodeGenerator,
4
+ UberSchema,
5
+ createEventNameFromEventHandlerName,
6
+ } from '../core';
7
+ import { IndexTSTemplate, RNOHGeneratedPackageHTemplate } from '../templates';
8
+
9
+ export class PackageCodeGenerator implements CodeGenerator<UberSchema> {
10
+ constructor(
11
+ private cppOutputPath: AbsolutePath,
12
+ private etsOutputPath: AbsolutePath
13
+ ) {}
14
+
15
+ generate(uberSchema: UberSchema): Map<AbsolutePath, string> {
16
+ const result = new Map<AbsolutePath, string>();
17
+ const generatedPackageH = new RNOHGeneratedPackageHTemplate();
18
+ const components_indexTS = new IndexTSTemplate();
19
+ const turboModules_indexTS = new IndexTSTemplate();
20
+ const generated_indexETS = new IndexTSTemplate();
21
+ generated_indexETS.addReexport({ from: './ts' });
22
+
23
+ uberSchema
24
+ .findAllSpecSchemasByType('NativeModule')
25
+ .forEach((nativeModuleSchema) => {
26
+ generatedPackageH.addTurboModule({
27
+ name: nativeModuleSchema.moduleName,
28
+ });
29
+ turboModules_indexTS.addReexport({
30
+ from: `./${nativeModuleSchema.moduleName}`,
31
+ });
32
+ });
33
+ uberSchema
34
+ .findAllSpecSchemasByType('Component')
35
+ .forEach((componentSchema) => {
36
+ Object.entries(componentSchema.components).forEach(
37
+ ([name, componentShape]) => {
38
+ components_indexTS.addReexport({ from: `./${name}` });
39
+ generatedPackageH.addComponent({
40
+ name: name,
41
+ supportedEventNames: componentShape.events.map((e) => {
42
+ return createEventNameFromEventHandlerName(e.name);
43
+ }),
44
+ });
45
+ }
46
+ );
47
+ });
48
+ result.set(
49
+ this.cppOutputPath.copyWithNewSegment('RNOHGeneratedPackage.h'),
50
+ generatedPackageH.build()
51
+ );
52
+ result.set(
53
+ this.etsOutputPath.copyWithNewSegment('ts.ts'),
54
+ new IndexTSTemplate()
55
+ .addReexport({ from: './components/ts', as: 'RNC' })
56
+ .addReexport({ from: './turboModules/ts', as: 'TM' })
57
+ .build()
58
+ );
59
+ result.set(
60
+ this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'),
61
+ components_indexTS.build()
62
+ );
63
+ result.set(
64
+ this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'),
65
+ turboModules_indexTS.build()
66
+ );
67
+ result.set(
68
+ this.etsOutputPath.copyWithNewSegment('index.ets'),
69
+ generated_indexETS.build()
70
+ );
71
+ return result;
72
+ }
73
+ }
@@ -0,0 +1,3 @@
1
+ export * from './ComponentCodeGenerator';
2
+ export * from './NativeModuleCodeGenerator';
3
+ export * from './PackageCodeGenerator';
@@ -0,0 +1,2 @@
1
+ export * from './core';
2
+ export * from './generators';
@@ -0,0 +1,49 @@
1
+ import mustache from 'mustache';
2
+
3
+ const TEMPLATE = `
4
+ #pragma once
5
+
6
+ // This file was generated.
7
+
8
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
9
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
10
+ #include <react/renderer/components/view/ViewShadowNode.h>
11
+
12
+ namespace facebook {
13
+ namespace react {
14
+
15
+ extern const char {{name}}ComponentName[] = "{{name}}";
16
+
17
+ class {{name}}Props : public ViewProps {
18
+ public:
19
+ {{name}}Props() = default;
20
+
21
+ {{name}}Props(const PropsParserContext &context, const {{name}}Props &sourceProps, const RawProps &rawProps)
22
+ : ViewProps(context, sourceProps, rawProps) {}
23
+ };
24
+
25
+ using {{name}}ShadowNode = ConcreteViewShadowNode<
26
+ {{name}}ComponentName,
27
+ {{name}}Props,
28
+ ViewEventEmitter>;
29
+
30
+ class {{name}}ComponentDescriptor final
31
+ : public ConcreteComponentDescriptor<{{name}}ShadowNode> {
32
+ public:
33
+ {{name}}ComponentDescriptor(ComponentDescriptorParameters const &parameters)
34
+ : ConcreteComponentDescriptor(parameters) {}
35
+ };
36
+
37
+ } // namespace react
38
+ } // namespace facebook
39
+ `;
40
+
41
+ export class ComponentDescriptorHTemplate {
42
+ constructor(private name: string) {}
43
+
44
+ build(): string {
45
+ return mustache.render(TEMPLATE, {
46
+ name: this.name,
47
+ });
48
+ }
49
+ }
@@ -0,0 +1,85 @@
1
+ import mustache from 'mustache';
2
+
3
+ const TEMPLATE = `
4
+ #pragma once
5
+
6
+ // This file was generated.
7
+
8
+ #include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
9
+
10
+ namespace rnoh {
11
+ class {{name}}JSIBinder : public ViewComponentJSIBinder {
12
+ protected:
13
+ facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override {
14
+ auto object = ViewComponentJSIBinder::createNativeProps(rt);
15
+ {{#props}}
16
+ object.setProperty(rt, "{{name}}", {{{type}}});
17
+ {{/props}}
18
+ return object;
19
+ }
20
+
21
+ facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
22
+ facebook::jsi::Object events(rt);
23
+ {{#bubblingEvents}}
24
+ events.setProperty(rt, "{{TOPname}}", createBubblingCapturedEvent(rt, "{{name}}"));
25
+ {{/bubblingEvents}}
26
+ return events;
27
+ }
28
+
29
+ facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
30
+ facebook::jsi::Object events(rt);
31
+ {{#directEvents}}
32
+ events.setProperty(rt, "{{TOPname}}", createDirectEvent(rt, "{{name}}"));
33
+ {{/directEvents}}
34
+ return events;
35
+ }
36
+ };
37
+ } // namespace rnoh
38
+ `;
39
+
40
+ type ComponentJSIBinderHProp = {
41
+ name: string;
42
+ isObject: boolean;
43
+ };
44
+
45
+ type ComponentJSIBinderHEvent = {
46
+ type: 'direct' | 'bubble';
47
+ eventHandlerName: string;
48
+ };
49
+
50
+ export class ComponentJSIBinderHTemplate {
51
+ private props: ComponentJSIBinderHProp[] = [];
52
+ private events: ComponentJSIBinderHEvent[] = [];
53
+
54
+ constructor(private name: string) {}
55
+
56
+ addProp(prop: ComponentJSIBinderHProp) {
57
+ this.props.push(prop);
58
+ }
59
+
60
+ addEvent(event: ComponentJSIBinderHEvent) {
61
+ this.events.push(event);
62
+ }
63
+
64
+ build(): string {
65
+ return mustache.render(TEMPLATE.trimStart(), {
66
+ name: this.name,
67
+ props: this.props.map((prop) => ({
68
+ name: prop.name,
69
+ type: prop.isObject ? '"Object"' : 'true',
70
+ })),
71
+ bubblingEvents: this.events
72
+ .filter((event) => event.type === 'bubble')
73
+ .map((event) => ({
74
+ TOPname: event.eventHandlerName.replace('on', 'top'),
75
+ name: event.eventHandlerName,
76
+ })),
77
+ directEvents: this.events
78
+ .filter((event) => event.type === 'direct')
79
+ .map((event) => ({
80
+ TOPname: event.eventHandlerName.replace('on', 'top'),
81
+ name: event.eventHandlerName,
82
+ })),
83
+ });
84
+ }
85
+ }