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