@react-native-oh/react-native-harmony-cli 0.0.25 → 0.0.26-1
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
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AbsolutePath } from '../../core';
|
|
2
|
+
import {
|
|
3
|
+
CodeGenerator,
|
|
4
|
+
CodegenError,
|
|
5
|
+
SpecSchema,
|
|
6
|
+
SpecSchemaType,
|
|
7
|
+
UberSchema,
|
|
8
|
+
} from '../core';
|
|
9
|
+
import { GlueCodeDataV1 } from './GlueCodeGenerator';
|
|
10
|
+
import { NativeModuleCodeGenerator } from './NativeModuleCodeGenerator';
|
|
11
|
+
import { ComponentCodeGeneratorArkTS } from './ComponentCodeGeneratorArkTS';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generates code for libraries built on top of RNOH's ArkTS architecture.
|
|
15
|
+
*/
|
|
16
|
+
export class UberGeneratorV1 implements CodeGenerator<UberSchema> {
|
|
17
|
+
private glueCodeData: GlueCodeDataV1 = { components: [], turboModules: [] };
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
private cppOutputPath: AbsolutePath,
|
|
21
|
+
private etsOutputPath: AbsolutePath
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
getGlueCodeData(): GlueCodeDataV1 {
|
|
25
|
+
return this.glueCodeData;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
generate(uberSchema: UberSchema) {
|
|
29
|
+
const fileContentByPath = new Map<AbsolutePath, string>();
|
|
30
|
+
const componentCodeGeneratorArkTS = new ComponentCodeGeneratorArkTS(
|
|
31
|
+
this.cppOutputPath,
|
|
32
|
+
this.etsOutputPath.copyWithNewSegment('components')
|
|
33
|
+
);
|
|
34
|
+
const nativeModuleCodeGenerator = new NativeModuleCodeGenerator(
|
|
35
|
+
this.cppOutputPath,
|
|
36
|
+
this.etsOutputPath.copyWithNewSegment('turboModules'),
|
|
37
|
+
1
|
|
38
|
+
);
|
|
39
|
+
const generatorBySpecType = {
|
|
40
|
+
Component: componentCodeGeneratorArkTS,
|
|
41
|
+
NativeModule: nativeModuleCodeGenerator,
|
|
42
|
+
} satisfies Record<SpecSchemaType, CodeGenerator<SpecSchema>>;
|
|
43
|
+
for (const [_fileName, specSchema] of uberSchema
|
|
44
|
+
.getSpecSchemaByFilenameMap()
|
|
45
|
+
.entries()) {
|
|
46
|
+
if (!(specSchema.type in generatorBySpecType)) {
|
|
47
|
+
throw new CodegenError({
|
|
48
|
+
whatHappened: `Could not find a code generator for a specification of type '${specSchema.type}'`,
|
|
49
|
+
unexpected: true,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
generatorBySpecType[specSchema.type]
|
|
53
|
+
.generate(specSchema)
|
|
54
|
+
.forEach((fileContent, filePath) => {
|
|
55
|
+
fileContentByPath.set(filePath, fileContent);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
this.glueCodeData = {
|
|
59
|
+
components: componentCodeGeneratorArkTS.getGlueCodeData(),
|
|
60
|
+
turboModules: nativeModuleCodeGenerator.getGlueCodeData(),
|
|
61
|
+
};
|
|
62
|
+
return fileContentByPath;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { AbsolutePath } from '../../core';
|
|
2
|
+
import { CodeGenerator } from '../core';
|
|
3
|
+
import {
|
|
4
|
+
ComponentCodeGeneratorCAPI,
|
|
5
|
+
LibraryData,
|
|
6
|
+
} from './ComponentCodeGeneratorCAPI';
|
|
7
|
+
import { NativeModuleCodeGenerator } from './NativeModuleCodeGenerator';
|
|
8
|
+
import { GlueCodeDataV2 } from './GlueCodeGenerator';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generates code for libraries built on top of RNOH's C-API architecture.
|
|
12
|
+
*/
|
|
13
|
+
export class UberGeneratorV2 implements CodeGenerator<LibraryData[]> {
|
|
14
|
+
private glueCodeData: GlueCodeDataV2 = new Map();
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
private cppOutputPath: AbsolutePath,
|
|
18
|
+
private etsOutputPath: AbsolutePath
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
getGlueCodeData(): GlueCodeDataV2 {
|
|
22
|
+
return this.glueCodeData;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
generate(npmPackagesInfo: LibraryData[]) {
|
|
26
|
+
const fileContentByPath: Map<AbsolutePath, string> = new Map();
|
|
27
|
+
|
|
28
|
+
npmPackagesInfo.forEach(({ name, uberSchema }) => {
|
|
29
|
+
this.glueCodeData.set(name, { components: [], turboModules: [] });
|
|
30
|
+
const libraryGlueCodeData = this.glueCodeData.get(name)!;
|
|
31
|
+
const libraryCppOutput = this.cppOutputPath.copyWithNewSegment(name);
|
|
32
|
+
const componentCodeGeneratorCAPI = new ComponentCodeGeneratorCAPI(
|
|
33
|
+
(filename) => {
|
|
34
|
+
return libraryCppOutput.copyWithNewSegment(
|
|
35
|
+
'react',
|
|
36
|
+
'renderer',
|
|
37
|
+
'components',
|
|
38
|
+
name,
|
|
39
|
+
filename
|
|
40
|
+
);
|
|
41
|
+
},
|
|
42
|
+
(filename) => {
|
|
43
|
+
return libraryCppOutput.copyWithNewSegment(
|
|
44
|
+
'RNOH',
|
|
45
|
+
'generated',
|
|
46
|
+
'components',
|
|
47
|
+
filename
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
componentCodeGeneratorCAPI
|
|
52
|
+
.generate({ name, uberSchema })
|
|
53
|
+
.forEach((fileContent, path) => {
|
|
54
|
+
fileContentByPath.set(path, fileContent);
|
|
55
|
+
});
|
|
56
|
+
componentCodeGeneratorCAPI
|
|
57
|
+
.getGlueCodeData()
|
|
58
|
+
.forEach((componentGlueCodeData) => {
|
|
59
|
+
libraryGlueCodeData.components.push(componentGlueCodeData);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
for (const [_fileName, specSchema] of uberSchema
|
|
63
|
+
.getSpecSchemaByFilenameMap()
|
|
64
|
+
.entries()) {
|
|
65
|
+
if (specSchema.type === 'NativeModule') {
|
|
66
|
+
const nativeModuleCodeGenerator = new NativeModuleCodeGenerator(
|
|
67
|
+
libraryCppOutput.copyWithNewSegment(
|
|
68
|
+
'RNOH',
|
|
69
|
+
'generated',
|
|
70
|
+
'turbo_modules'
|
|
71
|
+
),
|
|
72
|
+
this.etsOutputPath.copyWithNewSegment('turboModules'),
|
|
73
|
+
2
|
|
74
|
+
);
|
|
75
|
+
nativeModuleCodeGenerator
|
|
76
|
+
.generate(specSchema)
|
|
77
|
+
.forEach((fileContent, filePath) => {
|
|
78
|
+
fileContentByPath.set(filePath, fileContent);
|
|
79
|
+
});
|
|
80
|
+
nativeModuleCodeGenerator
|
|
81
|
+
.getGlueCodeData()
|
|
82
|
+
.forEach((turboModuleGlueCodeData) => {
|
|
83
|
+
libraryGlueCodeData.turboModules.push(turboModuleGlueCodeData);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return fileContentByPath;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
1
|
+
export * from './NativeModuleCodeGenerator';
|
|
2
|
+
export * from './GlueCodeGenerator';
|
|
3
|
+
export * from './ComponentCodeGeneratorArkTS';
|
|
4
|
+
export * from './ComponentCodeGeneratorCAPI';
|
|
5
|
+
export * from './UberGeneratorV1';
|
|
6
|
+
export * from './UberGeneratorV2';
|
package/src/codegen/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './core';
|
|
2
|
-
export * from './generators';
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './generators';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import mustache from 'mustache';
|
|
2
|
+
import Case from 'case';
|
|
3
|
+
import { TypeAnnotation } from '../core';
|
|
4
|
+
|
|
5
|
+
const TEMPLATE = `
|
|
6
|
+
/**
|
|
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: 2
|
|
13
|
+
*/
|
|
14
|
+
#pragma once
|
|
15
|
+
|
|
16
|
+
#include "RNOH/CppComponentInstance.h"
|
|
17
|
+
#include <react/renderer/components/{{libraryName}}/ShadowNodes.h>
|
|
18
|
+
|
|
19
|
+
namespace rnoh {
|
|
20
|
+
class Base{{name}}ComponentInstance
|
|
21
|
+
: public CppComponentInstance<facebook::react::{{name}}ShadowNode> {
|
|
22
|
+
public:
|
|
23
|
+
using CppComponentInstance::CppComponentInstance;
|
|
24
|
+
|
|
25
|
+
void handleCommand(std::string const &commandName, folly::dynamic const &args) override {
|
|
26
|
+
{{#commands}}
|
|
27
|
+
if (commandName == "{{commandName}}") {
|
|
28
|
+
this->on{{CommandName}}Command({{argsFromDynamic}});
|
|
29
|
+
}
|
|
30
|
+
{{/commands}}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
{{#commands}}
|
|
34
|
+
virtual void on{{CommandName}}Command({{argsDeclaration}}) = 0;
|
|
35
|
+
{{/commands}}
|
|
36
|
+
};
|
|
37
|
+
} // namespace rnoh
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
type BaseComponentInstanceHCommand = {
|
|
41
|
+
name: string;
|
|
42
|
+
args: { name: string; typeAnnotation: TypeAnnotation }[];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export class BaseComponentInstanceHTemplate {
|
|
46
|
+
private commands: BaseComponentInstanceHCommand[] = [];
|
|
47
|
+
|
|
48
|
+
constructor(private componentName: string, private libraryName: string) {}
|
|
49
|
+
|
|
50
|
+
addCommand(command: BaseComponentInstanceHCommand) {
|
|
51
|
+
this.commands.push(command);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
build(): string {
|
|
55
|
+
return mustache.render(TEMPLATE, {
|
|
56
|
+
name: this.componentName,
|
|
57
|
+
libraryName: this.libraryName,
|
|
58
|
+
commands: this.commands.map(({ name, args }) => {
|
|
59
|
+
return {
|
|
60
|
+
commandName: name,
|
|
61
|
+
CommandName: Case.pascal(name),
|
|
62
|
+
argsDeclaration: args
|
|
63
|
+
.map(
|
|
64
|
+
({ name, typeAnnotation }) =>
|
|
65
|
+
`${cppTypeFromTypeAnnotation(typeAnnotation)} ${name}`
|
|
66
|
+
)
|
|
67
|
+
.join(', '),
|
|
68
|
+
argsFromDynamic: args
|
|
69
|
+
.map(
|
|
70
|
+
({ typeAnnotation }, index) =>
|
|
71
|
+
`args[${index}]${dynamicExtractorFromTypeAnnotation(
|
|
72
|
+
typeAnnotation
|
|
73
|
+
)}`
|
|
74
|
+
)
|
|
75
|
+
.join(', '),
|
|
76
|
+
};
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function cppTypeFromTypeAnnotation(typeAnnotation: TypeAnnotation): string {
|
|
83
|
+
switch (typeAnnotation.type) {
|
|
84
|
+
case 'BooleanTypeAnnotation':
|
|
85
|
+
return 'bool';
|
|
86
|
+
case 'Int32TypeAnnotation':
|
|
87
|
+
return 'int';
|
|
88
|
+
case 'FloatTypeAnnotation':
|
|
89
|
+
return 'float';
|
|
90
|
+
case 'DoubleTypeAnnotation':
|
|
91
|
+
return 'double';
|
|
92
|
+
case 'StringTypeAnnotation':
|
|
93
|
+
return 'std::string';
|
|
94
|
+
default:
|
|
95
|
+
return 'folly::dynamic';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function dynamicExtractorFromTypeAnnotation(
|
|
100
|
+
typeAnnotation: TypeAnnotation
|
|
101
|
+
): string {
|
|
102
|
+
switch (typeAnnotation.type) {
|
|
103
|
+
case 'BooleanTypeAnnotation':
|
|
104
|
+
return '.asBool()';
|
|
105
|
+
case 'Int32TypeAnnotation':
|
|
106
|
+
return '.asInt()';
|
|
107
|
+
case 'FloatTypeAnnotation':
|
|
108
|
+
return '.asDouble()';
|
|
109
|
+
case 'DoubleTypeAnnotation':
|
|
110
|
+
return '.asDouble()';
|
|
111
|
+
case 'StringTypeAnnotation':
|
|
112
|
+
return '.asString()';
|
|
113
|
+
default:
|
|
114
|
+
return '';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -1,49 +1,55 @@
|
|
|
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
|
-
{{name}}Props,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{{name}}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
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 <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
15
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
16
|
+
#include <react/renderer/components/view/ViewShadowNode.h>
|
|
17
|
+
|
|
18
|
+
namespace facebook {
|
|
19
|
+
namespace react {
|
|
20
|
+
|
|
21
|
+
extern const char {{name}}ComponentName[] = "{{name}}";
|
|
22
|
+
|
|
23
|
+
class {{name}}Props : public ViewProps {
|
|
24
|
+
public:
|
|
25
|
+
{{name}}Props() = default;
|
|
26
|
+
|
|
27
|
+
{{name}}Props(const PropsParserContext &context, const {{name}}Props &sourceProps, const RawProps &rawProps)
|
|
28
|
+
: ViewProps(context, sourceProps, rawProps) {}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
using {{name}}ShadowNode = ConcreteViewShadowNode<
|
|
32
|
+
{{name}}ComponentName,
|
|
33
|
+
{{name}}Props,
|
|
34
|
+
ViewEventEmitter>;
|
|
35
|
+
|
|
36
|
+
class {{name}}ComponentDescriptor final
|
|
37
|
+
: public ConcreteComponentDescriptor<{{name}}ShadowNode> {
|
|
38
|
+
public:
|
|
39
|
+
{{name}}ComponentDescriptor(ComponentDescriptorParameters const ¶meters)
|
|
40
|
+
: ConcreteComponentDescriptor(parameters) {}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
} // namespace react
|
|
44
|
+
} // namespace facebook
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
export class ComponentDescriptorHTemplate {
|
|
48
|
+
constructor(private name: string) {}
|
|
49
|
+
|
|
50
|
+
build(): string {
|
|
51
|
+
return mustache.render(TEMPLATE, {
|
|
52
|
+
name: this.name,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,85 +1,93 @@
|
|
|
1
|
-
import mustache from 'mustache';
|
|
2
|
-
|
|
3
|
-
const TEMPLATE = `
|
|
4
|
-
#pragma once
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
import mustache from 'mustache';
|
|
2
|
+
|
|
3
|
+
const TEMPLATE = `
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
/**
|
|
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}}
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
#include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
|
|
16
|
+
|
|
17
|
+
namespace rnoh {
|
|
18
|
+
class {{name}}JSIBinder : public ViewComponentJSIBinder {
|
|
19
|
+
protected:
|
|
20
|
+
facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override {
|
|
21
|
+
auto object = ViewComponentJSIBinder::createNativeProps(rt);
|
|
22
|
+
{{#props}}
|
|
23
|
+
object.setProperty(rt, "{{name}}", {{{type}}});
|
|
24
|
+
{{/props}}
|
|
25
|
+
return object;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
|
|
29
|
+
facebook::jsi::Object events(rt);
|
|
30
|
+
{{#bubblingEvents}}
|
|
31
|
+
events.setProperty(rt, "{{TOPname}}", createBubblingCapturedEvent(rt, "{{name}}"));
|
|
32
|
+
{{/bubblingEvents}}
|
|
33
|
+
return events;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
|
|
37
|
+
facebook::jsi::Object events(rt);
|
|
38
|
+
{{#directEvents}}
|
|
39
|
+
events.setProperty(rt, "{{TOPname}}", createDirectEvent(rt, "{{name}}"));
|
|
40
|
+
{{/directEvents}}
|
|
41
|
+
return events;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
} // namespace rnoh
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
type ComponentJSIBinderHProp = {
|
|
48
|
+
name: string;
|
|
49
|
+
isObject: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type ComponentJSIBinderHEvent = {
|
|
53
|
+
type: 'direct' | 'bubble';
|
|
54
|
+
eventHandlerName: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export class ComponentJSIBinderHTemplate {
|
|
58
|
+
private props: ComponentJSIBinderHProp[] = [];
|
|
59
|
+
private events: ComponentJSIBinderHEvent[] = [];
|
|
60
|
+
|
|
61
|
+
constructor(private name: string, private generatorVersion: number) {}
|
|
62
|
+
|
|
63
|
+
addProp(prop: ComponentJSIBinderHProp) {
|
|
64
|
+
this.props.push(prop);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
addEvent(event: ComponentJSIBinderHEvent) {
|
|
68
|
+
this.events.push(event);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
build(): string {
|
|
72
|
+
return mustache.render(TEMPLATE.trimStart(), {
|
|
73
|
+
name: this.name,
|
|
74
|
+
generatorVersion: this.generatorVersion,
|
|
75
|
+
props: this.props.map((prop) => ({
|
|
76
|
+
name: prop.name,
|
|
77
|
+
type: prop.isObject ? '"Object"' : 'true',
|
|
78
|
+
})),
|
|
79
|
+
bubblingEvents: this.events
|
|
80
|
+
.filter((event) => event.type === 'bubble')
|
|
81
|
+
.map((event) => ({
|
|
82
|
+
TOPname: event.eventHandlerName.replace('on', 'top'),
|
|
83
|
+
name: event.eventHandlerName,
|
|
84
|
+
})),
|
|
85
|
+
directEvents: this.events
|
|
86
|
+
.filter((event) => event.type === 'direct')
|
|
87
|
+
.map((event) => ({
|
|
88
|
+
TOPname: event.eventHandlerName.replace('on', 'top'),
|
|
89
|
+
name: event.eventHandlerName,
|
|
90
|
+
})),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|