@react-native-oh/react-native-harmony-cli 0.0.25 → 0.0.26-2
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 +1 -23
- package/dist/codegen/core/CodeGenerator.js +2 -0
- package/dist/codegen/core/UberSchema.js +35 -9
- package/dist/codegen/core/index.js +1 -1
- package/dist/codegen/generators/{ComponentCodeGenerator.js → ComponentCodeGeneratorArkTS.js} +12 -4
- package/dist/codegen/generators/ComponentCodeGeneratorCAPI.js +79 -0
- package/dist/codegen/generators/GlueCodeGenerator.js +60 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +14 -6
- package/dist/codegen/generators/UberGeneratorV1.js +49 -0
- package/dist/codegen/generators/UberGeneratorV2.js +60 -0
- package/dist/codegen/generators/index.js +5 -2
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +103 -0
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +42 -36
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +45 -36
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +135 -127
- package/dist/codegen/templates/GeneratedPackageHTemplate.js +101 -0
- package/dist/codegen/templates/IndexTSTemplate.js +23 -5
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +88 -82
- package/dist/codegen/templates/TurboModuleCppTemplate.js +26 -18
- package/dist/codegen/templates/TurboModuleHTemplate.js +27 -17
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +37 -27
- package/dist/codegen/templates/index.js +1 -0
- package/dist/commands/codegen-harmony.js +99 -14
- package/dist/core/AbsolutePath.js +6 -0
- package/dist/core/CodegenConfig.js +8 -4
- package/dist/core/PackageJSON.js +8 -3
- package/dist/core/ProjectDependenciesManager.js +2 -2
- package/jest.config.js +5 -5
- package/package.json +57 -56
- 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 -203
- package/src/commands/codegen-harmony.ts +272 -143
- package/src/commands/create-metro-host-constants.ts +48 -48
- package/src/commands/index.ts +6 -6
- package/src/commands/pack-harmony.ts +121 -121
- package/src/commands/unpack-harmony.ts +231 -231
- package/src/commands/verify-package-harmony.ts +106 -106
- 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 -23
- 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 -9
- package/src/index.ts +20 -20
- package/src/io/Logger.ts +68 -68
- package/src/io/TarGz.ts +26 -26
- package/src/io/fsUtils.ts +24 -24
- package/src/io/index.ts +3 -3
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -28
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -24
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -18
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -47
- package/src/package-verifier/checks/index.ts +4 -4
- package/src/package-verifier/index.ts +2 -2
- package/src/package-verifier/types.ts +12 -12
- package/src/package-verifier/verify-package.ts +117 -117
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
- package/dist/codegen/core/Codegen.js +0 -35
- package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
- package/src/codegen/core/Codegen.ts +0 -44
- package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
|
@@ -1,124 +1,130 @@
|
|
|
1
|
-
import mustache from 'mustache';
|
|
2
|
-
|
|
3
|
-
const TEMPLATE = `
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
#include "
|
|
15
|
-
|
|
16
|
-
{{#
|
|
17
|
-
#include "generated/{{name}}
|
|
18
|
-
{{/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
#pragma once
|
|
13
|
+
|
|
14
|
+
#include "RNOH/Package.h"
|
|
15
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
16
|
+
{{#turboModules}}
|
|
17
|
+
#include "generated/{{name}}.h"
|
|
18
|
+
{{/turboModules}}
|
|
19
|
+
{{#components}}
|
|
20
|
+
#include "generated/{{name}}ComponentDescriptor.h"
|
|
21
|
+
{{/components}}
|
|
22
|
+
{{#components}}
|
|
23
|
+
#include "generated/{{name}}JSIBinder.h"
|
|
24
|
+
{{/components}}
|
|
25
|
+
|
|
26
|
+
namespace rnoh {
|
|
27
|
+
|
|
28
|
+
class RNOHGeneratedPackageTurboModuleFactoryDelegate : 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 GeneratedEventEmitRequestHandler : public EventEmitRequestHandler {
|
|
41
|
+
public:
|
|
42
|
+
void handleEvent(Context const &ctx) override {
|
|
43
|
+
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
44
|
+
if (eventEmitter == nullptr) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
std::vector<std::string> supportedEventNames = {
|
|
49
|
+
{{#supportedEvents}}
|
|
50
|
+
"{{name}}",
|
|
51
|
+
{{/supportedEvents}}
|
|
52
|
+
};
|
|
53
|
+
if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
54
|
+
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
class RNOHGeneratedPackage : public Package {
|
|
60
|
+
public:
|
|
61
|
+
RNOHGeneratedPackage(Package::Context ctx) : Package(ctx){};
|
|
62
|
+
|
|
63
|
+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
|
64
|
+
return std::make_unique<RNOHGeneratedPackageTurboModuleFactoryDelegate>();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
|
|
68
|
+
return {
|
|
69
|
+
{{#components}}
|
|
70
|
+
facebook::react::concreteComponentDescriptorProvider<facebook::react::{{name}}ComponentDescriptor>(),
|
|
71
|
+
{{/components}}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
ComponentJSIBinderByString createComponentJSIBinderByName() override {
|
|
76
|
+
return {
|
|
77
|
+
{{#components}}
|
|
78
|
+
{"{{name}}", std::make_shared<{{name}}JSIBinder>()},
|
|
79
|
+
{{/components}}
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
84
|
+
return {
|
|
85
|
+
std::make_shared<GeneratedEventEmitRequestHandler>(),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
} // namespace rnoh
|
|
91
|
+
`;
|
|
92
|
+
|
|
93
|
+
type RNOHGeneratedPackageTurboModule = {
|
|
94
|
+
name: string;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
type RNOHGeneratedPackageComponent = {
|
|
98
|
+
name: string;
|
|
99
|
+
supportedEventNames: string[];
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export class RNOHGeneratedPackageHTemplate {
|
|
103
|
+
private turboModules: RNOHGeneratedPackageTurboModule[] = [];
|
|
104
|
+
private components: RNOHGeneratedPackageComponent[] = [];
|
|
105
|
+
private supportedEventNames: string[] = [];
|
|
106
|
+
|
|
107
|
+
constructor() {}
|
|
108
|
+
|
|
109
|
+
addTurboModule(turboModule: RNOHGeneratedPackageTurboModule) {
|
|
110
|
+
this.turboModules.push(turboModule);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
addComponent(component: RNOHGeneratedPackageComponent) {
|
|
114
|
+
this.components.push(component);
|
|
115
|
+
this.supportedEventNames = [
|
|
116
|
+
...this.supportedEventNames,
|
|
117
|
+
...component.supportedEventNames,
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
build(): string {
|
|
122
|
+
return mustache.render(TEMPLATE.trimStart(), {
|
|
123
|
+
turboModules: this.turboModules,
|
|
124
|
+
components: this.components,
|
|
125
|
+
supportedEvents: this.supportedEventNames.map((eventName) => ({
|
|
126
|
+
name: eventName,
|
|
127
|
+
})),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -1,47 +1,54 @@
|
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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: {{generatorVersion}}
|
|
11
|
+
*/
|
|
12
|
+
#include "{{className}}.h"
|
|
13
|
+
|
|
14
|
+
namespace rnoh {
|
|
15
|
+
using namespace facebook;
|
|
16
|
+
|
|
17
|
+
{{className}}::{{className}}(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) {
|
|
18
|
+
methodMap_ = {
|
|
19
|
+
{{#methods}}
|
|
20
|
+
ARK_{{asyncMarker}}METHOD_METADATA({{name}}, {{argsCount}}),
|
|
21
|
+
{{/methods}}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
} // namespace rnoh
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
export type TurboModuleCppTemplateMethod = {
|
|
29
|
+
name: string;
|
|
30
|
+
isAsync: boolean;
|
|
31
|
+
argsCount: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export class TurboModuleCppTemplate {
|
|
35
|
+
private methods: TurboModuleCppTemplateMethod[] = [];
|
|
36
|
+
|
|
37
|
+
constructor(private name: string, private generatorVersion: number) {}
|
|
38
|
+
|
|
39
|
+
addMethod(method: TurboModuleCppTemplateMethod) {
|
|
40
|
+
this.methods.push(method);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
build(): string {
|
|
44
|
+
return mustache.render(TEMPLATE, {
|
|
45
|
+
className: this.name,
|
|
46
|
+
generatorVersion: this.generatorVersion,
|
|
47
|
+
methods: this.methods.map((method) => ({
|
|
48
|
+
name: method.name,
|
|
49
|
+
argsCount: method.argsCount,
|
|
50
|
+
asyncMarker: method.isAsync ? 'ASYNC_' : undefined,
|
|
51
|
+
})),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,26 +1,35 @@
|
|
|
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
|
-
|
|
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: {{generatorVersion}}
|
|
11
|
+
*/
|
|
12
|
+
#pragma once
|
|
13
|
+
|
|
14
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
15
|
+
|
|
16
|
+
namespace rnoh {
|
|
17
|
+
|
|
18
|
+
class JSI_EXPORT {{className}} : public ArkTSTurboModule {
|
|
19
|
+
public:
|
|
20
|
+
{{className}}(const ArkTSTurboModule::Context ctx, const std::string name);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
} // namespace rnoh
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export class TurboModuleHTemplate {
|
|
27
|
+
constructor(private name: string, private generatorVersion: number) {}
|
|
28
|
+
|
|
29
|
+
build(): string {
|
|
30
|
+
return mustache.render(TEMPLATE, {
|
|
31
|
+
className: this.name,
|
|
32
|
+
generatorVersion: this.generatorVersion,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,81 +1,90 @@
|
|
|
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
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
type
|
|
45
|
-
name: string;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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: {{generatorVersion}}
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { Tag } from "../../ts"
|
|
14
|
+
|
|
15
|
+
export namespace {{name}} {
|
|
16
|
+
export const NAME = '{{name}}' as const
|
|
17
|
+
|
|
18
|
+
{{#enums}}
|
|
19
|
+
export enum {{name}} {
|
|
20
|
+
{{#members}}
|
|
21
|
+
{{name}} = {{{value}}},
|
|
22
|
+
{{/members}}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
{{/enums}}
|
|
26
|
+
{{#aliases}}
|
|
27
|
+
export type {{name}} = {{{type}}}
|
|
28
|
+
|
|
29
|
+
{{/aliases}}
|
|
30
|
+
export interface Spec {
|
|
31
|
+
{{#methods}}
|
|
32
|
+
{{name}}({{{stringifiedArgs}}}): {{{returnType}}};
|
|
33
|
+
|
|
34
|
+
{{/methods}}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
type Alias = {
|
|
40
|
+
name: string;
|
|
41
|
+
type: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type EnumModel = {
|
|
45
|
+
name: string;
|
|
46
|
+
members: {
|
|
47
|
+
name: string;
|
|
48
|
+
value: string;
|
|
49
|
+
}[];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type Method = {
|
|
53
|
+
name: string;
|
|
54
|
+
stringifiedArgs: string;
|
|
55
|
+
returnType: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export class TurboModuleInterfaceTS {
|
|
59
|
+
private methods: Method[] = [];
|
|
60
|
+
private aliases: Alias[] = [];
|
|
61
|
+
private enumModels: EnumModel[] = [];
|
|
62
|
+
|
|
63
|
+
constructor(private name: string, private generatorVersion: number) {}
|
|
64
|
+
|
|
65
|
+
addAlias(alias: Alias) {
|
|
66
|
+
this.aliases.push(alias);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
addEnum(enumModel: EnumModel) {
|
|
70
|
+
this.enumModels.push(enumModel);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
addMethod(method: Method) {
|
|
74
|
+
this.methods.push(method);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
build(): string {
|
|
78
|
+
return mustache.render(TEMPLATE.trimStart(), {
|
|
79
|
+
name: this.name,
|
|
80
|
+
aliases: this.aliases,
|
|
81
|
+
enums: this.enumModels,
|
|
82
|
+
generatorVersion: this.generatorVersion,
|
|
83
|
+
methods: this.methods.map((method) => ({
|
|
84
|
+
name: method.name,
|
|
85
|
+
stringifiedArgs: method.stringifiedArgs,
|
|
86
|
+
returnType: method.returnType,
|
|
87
|
+
})),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
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';
|
|
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';
|
|
9
|
+
export * from './BaseComponentInstanceHTemplate';
|