@react-native-oh/react-native-harmony-cli 0.0.24 → 0.0.26
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.
- package/.prettierrc +6 -6
- package/jest.config.js +5 -5
- package/package.json +57 -52
- package/react-native.config.js +10 -10
- package/src/assetResolver.ts +21 -44
- package/src/codegen/core/CodeGenerator.ts +9 -0
- package/src/codegen/core/CodegenError.ts +3 -3
- package/src/codegen/core/EventUtils.ts +18 -18
- package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -75
- package/src/codegen/core/TypeAnnotationToTS.ts +188 -188
- package/src/codegen/core/UberSchema.ts +142 -99
- package/src/codegen/core/index.ts +5 -5
- package/src/codegen/generators/{ComponentCodeGenerator.ts → ComponentCodeGeneratorArkTS.ts} +112 -98
- package/src/codegen/generators/ComponentCodeGeneratorCAPI.ts +114 -0
- package/src/codegen/generators/GlueCodeGenerator.ts +109 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +115 -95
- package/src/codegen/generators/UberGeneratorV1.ts +64 -0
- package/src/codegen/generators/UberGeneratorV2.ts +91 -0
- package/src/codegen/generators/index.ts +6 -3
- package/src/codegen/index.ts +2 -2
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +116 -0
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +55 -49
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +93 -85
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +210 -202
- package/src/codegen/templates/GeneratedPackageHTemplate.ts +107 -0
- package/src/codegen/templates/IndexTSTemplate.ts +53 -33
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +130 -124
- package/src/codegen/templates/TurboModuleCppTemplate.ts +54 -47
- package/src/codegen/templates/TurboModuleHTemplate.ts +35 -26
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +90 -81
- package/src/codegen/templates/index.ts +9 -8
- package/src/commands/bundle-harmony.ts +203 -202
- package/src/commands/codegen-harmony.ts +272 -143
- package/src/commands/create-metro-host-constants.ts +48 -48
- package/src/commands/index.ts +6 -5
- package/src/commands/pack-harmony.ts +121 -121
- package/src/commands/unpack-harmony.ts +231 -231
- package/src/commands/verify-package-harmony.ts +106 -0
- package/src/core/AbsolutePath.ts +50 -43
- package/src/core/CodegenConfig.ts +62 -54
- package/src/core/DescriptiveError.ts +61 -61
- package/src/core/OHPackageJSON5.ts +23 -0
- package/src/core/PackageJSON.ts +75 -63
- package/src/core/ProjectDependenciesManager.ts +77 -77
- package/src/core/ValidationError.ts +1 -1
- package/src/core/ValueObject.ts +2 -2
- package/src/core/fs.ts +31 -31
- package/src/core/index.ts +9 -8
- package/src/index.ts +20 -18
- package/src/io/Logger.ts +68 -68
- package/src/io/TarGz.ts +26 -0
- package/src/io/fsUtils.ts +24 -24
- package/src/io/index.ts +3 -2
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -0
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -0
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -0
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -0
- package/src/package-verifier/checks/index.ts +4 -0
- package/src/package-verifier/index.ts +2 -0
- package/src/package-verifier/types.ts +12 -0
- package/src/package-verifier/verify-package.ts +117 -0
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
- package/dist/assetResolver.js +0 -41
- package/dist/codegen/core/Codegen.js +0 -35
- package/dist/codegen/core/CodegenError.js +0 -7
- package/dist/codegen/core/EventUtils.js +0 -19
- package/dist/codegen/core/TypeAnnotationToTS.js +0 -132
- package/dist/codegen/core/UberSchema.js +0 -74
- package/dist/codegen/core/index.js +0 -21
- package/dist/codegen/generators/ComponentCodeGenerator.js +0 -66
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +0 -64
- package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
- package/dist/codegen/generators/index.js +0 -19
- package/dist/codegen/index.js +0 -18
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +0 -55
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +0 -78
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -181
- package/dist/codegen/templates/IndexTSTemplate.js +0 -31
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +0 -117
- package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -45
- package/dist/codegen/templates/TurboModuleHTemplate.js +0 -32
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -64
- package/dist/codegen/templates/index.js +0 -24
- package/dist/commands/bundle-harmony.js +0 -179
- package/dist/commands/codegen-harmony.js +0 -110
- package/dist/commands/create-metro-host-constants.js +0 -61
- package/dist/commands/index.js +0 -21
- package/dist/commands/pack-harmony.js +0 -100
- package/dist/commands/unpack-harmony.js +0 -184
- package/dist/core/AbsolutePath.js +0 -41
- package/dist/core/CodegenConfig.js +0 -53
- package/dist/core/DescriptiveError.js +0 -49
- package/dist/core/PackageJSON.js +0 -53
- package/dist/core/ProjectDependenciesManager.js +0 -70
- package/dist/core/ValidationError.js +0 -6
- package/dist/core/ValueObject.js +0 -2
- package/dist/core/fs.js +0 -36
- package/dist/core/index.js +0 -24
- package/dist/index.js +0 -13
- package/dist/io/Logger.js +0 -71
- package/dist/io/fsUtils.js +0 -23
- package/dist/io/index.js +0 -18
- package/src/codegen/core/Codegen.ts +0 -44
- package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
|
@@ -1,202 +1,210 @@
|
|
|
1
|
-
import mustache from 'mustache';
|
|
2
|
-
|
|
3
|
-
const TEMPLATE = `
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
export interface
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
{{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export
|
|
84
|
-
{
|
|
85
|
-
|
|
86
|
-
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this.
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this.
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
1
|
+
import mustache from 'mustache';
|
|
2
|
+
|
|
3
|
+
const TEMPLATE = `
|
|
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
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
Descriptor as ComponentDescriptor,
|
|
15
|
+
ViewBaseProps,
|
|
16
|
+
ViewRawProps,
|
|
17
|
+
ViewDescriptorWrapperBase,
|
|
18
|
+
ColorValue,
|
|
19
|
+
Color,
|
|
20
|
+
RNInstance,
|
|
21
|
+
Tag,
|
|
22
|
+
RNComponentCommandReceiver,
|
|
23
|
+
ViewPropsSelector,
|
|
24
|
+
} from '../../ts';
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export namespace {{name}} {
|
|
28
|
+
export const NAME = "{{name}}" as const
|
|
29
|
+
|
|
30
|
+
export interface DirectRawProps {
|
|
31
|
+
{{#props}}
|
|
32
|
+
{{name}}{{optionalityMarker}}: {{{type}}};
|
|
33
|
+
{{/props}}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Props extends ViewBaseProps {}
|
|
37
|
+
|
|
38
|
+
export interface State {}
|
|
39
|
+
|
|
40
|
+
export interface RawProps extends ViewRawProps, DirectRawProps {}
|
|
41
|
+
|
|
42
|
+
export class PropsSelector extends ViewPropsSelector<Props, RawProps> {
|
|
43
|
+
{{#simpleProps}}
|
|
44
|
+
get {{name}}() {
|
|
45
|
+
return this.rawProps.{{name}}{{{orDefaultValue}}};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
{{/simpleProps}}
|
|
49
|
+
|
|
50
|
+
{{#complexProps}}
|
|
51
|
+
get {{name}}() {
|
|
52
|
+
{{{implementation}}}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
{{/complexProps}}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type Descriptor = ComponentDescriptor<
|
|
59
|
+
typeof NAME,
|
|
60
|
+
Props,
|
|
61
|
+
State,
|
|
62
|
+
RawProps
|
|
63
|
+
>;
|
|
64
|
+
|
|
65
|
+
export class DescriptorWrapper extends ViewDescriptorWrapperBase<
|
|
66
|
+
typeof NAME,
|
|
67
|
+
Props,
|
|
68
|
+
State,
|
|
69
|
+
RawProps,
|
|
70
|
+
PropsSelector
|
|
71
|
+
> {
|
|
72
|
+
protected createPropsSelector() {
|
|
73
|
+
return new PropsSelector(this.descriptor.props, this.descriptor.rawProps)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface EventPayloadByName {
|
|
78
|
+
{{#events}}
|
|
79
|
+
"{{name}}": {{{payloadTSType}}}
|
|
80
|
+
{{/events}}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class EventEmitter {
|
|
84
|
+
constructor(private rnInstance: RNInstance, private tag: Tag) {}
|
|
85
|
+
|
|
86
|
+
emit<TEventName extends keyof EventPayloadByName>(eventName: TEventName, payload: EventPayloadByName[TEventName]) {
|
|
87
|
+
this.rnInstance.emitComponentEvent(this.tag, eventName, payload)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface CommandArgvByName {
|
|
92
|
+
{{#commands}}
|
|
93
|
+
"{{name}}": {{{argsTSType}}}
|
|
94
|
+
{{/commands}}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export class CommandReceiver {
|
|
98
|
+
private listenersByCommandName = new Map<string, Set<(...args: any[]) => void>>()
|
|
99
|
+
private cleanUp: (() => void) | undefined = undefined
|
|
100
|
+
|
|
101
|
+
constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) {
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
subscribe<TCommandName extends keyof CommandArgvByName>(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) {
|
|
105
|
+
if (!this.listenersByCommandName.has(commandName)) {
|
|
106
|
+
this.listenersByCommandName.set(commandName, new Set())
|
|
107
|
+
}
|
|
108
|
+
this.listenersByCommandName.get(commandName)!.add(listener)
|
|
109
|
+
const hasRegisteredCommandReceiver = !!this.cleanUp
|
|
110
|
+
if (!hasRegisteredCommandReceiver) {
|
|
111
|
+
this.cleanUp = this.componentCommandReceiver.registerCommandCallback(this.tag, (commandName: string, argv: any[]) => {
|
|
112
|
+
if (this.listenersByCommandName.has(commandName)) {
|
|
113
|
+
const listeners = this.listenersByCommandName.get(commandName)!
|
|
114
|
+
listeners.forEach(listener => {
|
|
115
|
+
listener(argv)
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return () => {
|
|
122
|
+
this.listenersByCommandName.get(commandName)?.delete(listener)
|
|
123
|
+
if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) {
|
|
124
|
+
this.listenersByCommandName.delete(commandName)
|
|
125
|
+
}
|
|
126
|
+
if (this.listenersByCommandName.size === 0) {
|
|
127
|
+
this.cleanUp?.()
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
`;
|
|
135
|
+
|
|
136
|
+
const COLOR_VALUE_GETTER_TEMPLATE = ` if (this.rawProps.{{name}}) {
|
|
137
|
+
return Color.fromColorValue(this.rawProps.{{name}})
|
|
138
|
+
} else {
|
|
139
|
+
return new Color({ r: 0, g: 0, b: 0, a: 255})
|
|
140
|
+
}`;
|
|
141
|
+
|
|
142
|
+
type Prop = {
|
|
143
|
+
name: string;
|
|
144
|
+
tsType: string;
|
|
145
|
+
defaultValue: string | null;
|
|
146
|
+
isOptional: boolean;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
type Event = {
|
|
150
|
+
name: string;
|
|
151
|
+
payloadTSType: string;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
type Command = {
|
|
155
|
+
name: string;
|
|
156
|
+
argsTSType: string;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export class ComponentUtilsTSTemplate {
|
|
160
|
+
private props: Prop[] = [];
|
|
161
|
+
private events: Event[] = [];
|
|
162
|
+
private commands: Command[] = [];
|
|
163
|
+
private getterTemplateByTSType = new Map<string, string>();
|
|
164
|
+
|
|
165
|
+
constructor(private name: string) {
|
|
166
|
+
this.getterTemplateByTSType.set('ColorValue', COLOR_VALUE_GETTER_TEMPLATE);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
addProp(prop: Prop) {
|
|
170
|
+
this.props.push(prop);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
addEvent(event: Event) {
|
|
174
|
+
this.events.push(event);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
addCommand(command: Command) {
|
|
178
|
+
this.commands.push(command);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
build(): string {
|
|
182
|
+
return mustache.render(TEMPLATE.trimStart(), {
|
|
183
|
+
name: this.name,
|
|
184
|
+
props: this.props.map((prop) => ({
|
|
185
|
+
name: prop.name,
|
|
186
|
+
type: prop.tsType,
|
|
187
|
+
optionalityMarker: prop.isOptional ? '?' : '',
|
|
188
|
+
})),
|
|
189
|
+
events: this.events,
|
|
190
|
+
commands: this.commands,
|
|
191
|
+
simpleProps: this.props
|
|
192
|
+
.filter((prop) => !this.getterTemplateByTSType.has(prop.tsType))
|
|
193
|
+
.map((prop) => ({
|
|
194
|
+
name: prop.name,
|
|
195
|
+
type: prop.tsType,
|
|
196
|
+
orDefaultValue: prop.defaultValue ? ` ?? ${prop.defaultValue}` : '',
|
|
197
|
+
})),
|
|
198
|
+
complexProps: this.props
|
|
199
|
+
.filter((prop) => this.getterTemplateByTSType.has(prop.tsType))
|
|
200
|
+
.map((prop) => ({
|
|
201
|
+
name: prop.name,
|
|
202
|
+
implementation: mustache.render(
|
|
203
|
+
this.getterTemplateByTSType.get(prop.tsType)!,
|
|
204
|
+
{ name: prop.name },
|
|
205
|
+
{}
|
|
206
|
+
),
|
|
207
|
+
})),
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import mustache from 'mustache';
|
|
2
|
+
|
|
3
|
+
const TEMPLATE = `
|
|
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
|
|
11
|
+
*/
|
|
12
|
+
#pragma once
|
|
13
|
+
|
|
14
|
+
{{#libraries}}
|
|
15
|
+
#include <react/renderer/components/{{name}}/ComponentDescriptors.h>
|
|
16
|
+
{{/libraries}}
|
|
17
|
+
#include "RNOH/Package.h"
|
|
18
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
19
|
+
{{#turboModules}}
|
|
20
|
+
#include "RNOH/generated/turbo_modules/{{name}}.h"
|
|
21
|
+
{{/turboModules}}
|
|
22
|
+
{{#components}}
|
|
23
|
+
#include "RNOH/generated/components/{{name}}JSIBinder.h"
|
|
24
|
+
{{/components}}
|
|
25
|
+
|
|
26
|
+
namespace rnoh {
|
|
27
|
+
|
|
28
|
+
class {{name}}TurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
29
|
+
public:
|
|
30
|
+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
|
31
|
+
{{#turboModules}}
|
|
32
|
+
if (name == "{{name}}") {
|
|
33
|
+
return std::make_shared<{{name}}>(ctx, name);
|
|
34
|
+
}
|
|
35
|
+
{{/turboModules}}
|
|
36
|
+
return nullptr;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
class {{name}} : public Package {
|
|
41
|
+
public:
|
|
42
|
+
{{name}}(Package::Context ctx) : Package(ctx){};
|
|
43
|
+
|
|
44
|
+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
|
45
|
+
return std::make_unique<{{name}}TurboModuleFactoryDelegate>();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
|
|
49
|
+
return {
|
|
50
|
+
{{#components}}
|
|
51
|
+
facebook::react::concreteComponentDescriptorProvider<facebook::react::{{name}}ComponentDescriptor>(),
|
|
52
|
+
{{/components}}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
ComponentJSIBinderByString createComponentJSIBinderByName() override {
|
|
57
|
+
return {
|
|
58
|
+
{{#components}}
|
|
59
|
+
{"{{name}}", std::make_shared<{{name}}JSIBinder>()},
|
|
60
|
+
{{/components}}
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
} // namespace rnoh
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
type GeneratedPackageTurboModule = {
|
|
73
|
+
name: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
type GeneratedPackageComponent = {
|
|
77
|
+
name: string;
|
|
78
|
+
libraryName: string;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export class BasePackageHTemplate {
|
|
82
|
+
private turboModules: GeneratedPackageTurboModule[] = [];
|
|
83
|
+
private components: GeneratedPackageComponent[] = [];
|
|
84
|
+
private libraryNames = new Set<string>();
|
|
85
|
+
|
|
86
|
+
constructor(private name: string) {}
|
|
87
|
+
|
|
88
|
+
addTurboModule(turboModule: GeneratedPackageTurboModule) {
|
|
89
|
+
this.turboModules.push(turboModule);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
addComponent(component: GeneratedPackageComponent) {
|
|
93
|
+
this.components.push(component);
|
|
94
|
+
this.libraryNames.add(component.libraryName);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
build(): string {
|
|
98
|
+
return mustache.render(TEMPLATE.trimStart(), {
|
|
99
|
+
name: this.name,
|
|
100
|
+
turboModules: this.turboModules,
|
|
101
|
+
components: this.components,
|
|
102
|
+
libraries: Array.from(this.libraryNames).map((name) => ({
|
|
103
|
+
name,
|
|
104
|
+
})),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -1,33 +1,53 @@
|
|
|
1
|
-
import mustache from 'mustache';
|
|
2
|
-
|
|
3
|
-
const TEMPLATE = `
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import mustache from 'mustache';
|
|
2
|
+
|
|
3
|
+
const TEMPLATE = `
|
|
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
|
+
{{#reexports}}
|
|
11
|
+
export * {{as}}from "{{{from}}}"
|
|
12
|
+
{{/reexports}}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
const TEMPLATE_EMPTY = `
|
|
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.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export {}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
type Reexport = {
|
|
27
|
+
from: string;
|
|
28
|
+
as?: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export class IndexTSTemplate {
|
|
32
|
+
private reexports: Reexport[] = [];
|
|
33
|
+
|
|
34
|
+
constructor() {}
|
|
35
|
+
|
|
36
|
+
addReexport(reexport: Reexport) {
|
|
37
|
+
this.reexports.push(reexport);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
build(): string {
|
|
42
|
+
if (this.reexports.length === 0) {
|
|
43
|
+
return mustache.render(TEMPLATE_EMPTY, {});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return mustache.render(TEMPLATE.trimStart(), {
|
|
47
|
+
reexports: this.reexports.map((reexport) => ({
|
|
48
|
+
from: reexport.from,
|
|
49
|
+
as: reexport.as ? `as ${reexport.as} ` : '',
|
|
50
|
+
})),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|