@react-native-oh/react-native-harmony-cli 0.0.25 → 0.0.26-10
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/commands/verify-package-harmony.js +7 -12
- 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/dist/package-verifier/verify-package.js +5 -4
- 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,98 +1,112 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
);
|
|
91
|
-
result.set(
|
|
92
|
-
this.
|
|
93
|
-
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
+
import { GlueCodeComponentDataV1 } from './GlueCodeGenerator';
|
|
16
|
+
|
|
17
|
+
export class ComponentCodeGeneratorArkTS implements SpecCodeGenerator {
|
|
18
|
+
private glueCodeDataItems: GlueCodeComponentDataV1[] = [];
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
private cppOutputPath: AbsolutePath,
|
|
22
|
+
private tsOutputPath: AbsolutePath
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
getGlueCodeData(): GlueCodeComponentDataV1[] {
|
|
26
|
+
return this.glueCodeDataItems;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
generate(schema: SpecSchema): Map<AbsolutePath, string> {
|
|
30
|
+
if (schema.type !== 'Component') {
|
|
31
|
+
throw new CodegenError({
|
|
32
|
+
whatHappened: `ComponentCodeGenerator can't generate code for a module type: ${schema.type}`,
|
|
33
|
+
unexpected: true,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const typeAnnotationToTS = new TypeAnnotationToTS();
|
|
37
|
+
const result = new Map<AbsolutePath, string>();
|
|
38
|
+
Object.entries(schema.components).map(([name, shape]) => {
|
|
39
|
+
const componentDescriptorHTemplate = new ComponentDescriptorHTemplate(
|
|
40
|
+
name
|
|
41
|
+
);
|
|
42
|
+
const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(
|
|
43
|
+
name,
|
|
44
|
+
1
|
|
45
|
+
);
|
|
46
|
+
const componentUtilsTSTemplate = new ComponentUtilsTSTemplate(name);
|
|
47
|
+
|
|
48
|
+
shape.props.forEach((prop) => {
|
|
49
|
+
componentJSIBinderHTemplate.addProp({
|
|
50
|
+
name: prop.name,
|
|
51
|
+
isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
componentUtilsTSTemplate.addProp({
|
|
55
|
+
name: prop.name,
|
|
56
|
+
tsType: typeAnnotationToTS.convert(prop.typeAnnotation),
|
|
57
|
+
defaultValue: getStringifiedTSDefaultValueFromPropTypeAnnotation(
|
|
58
|
+
prop.typeAnnotation
|
|
59
|
+
),
|
|
60
|
+
isOptional: prop.optional,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
shape.commands.forEach((command) => {
|
|
64
|
+
componentUtilsTSTemplate.addCommand({
|
|
65
|
+
name: command.name,
|
|
66
|
+
argsTSType:
|
|
67
|
+
'[' +
|
|
68
|
+
command.typeAnnotation.params
|
|
69
|
+
.map(
|
|
70
|
+
(param) =>
|
|
71
|
+
typeAnnotationToTS.convert(param.typeAnnotation) +
|
|
72
|
+
(param.optional ? '?' : '')
|
|
73
|
+
)
|
|
74
|
+
.join(', ') +
|
|
75
|
+
']',
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
shape.events.forEach((event) => {
|
|
80
|
+
componentUtilsTSTemplate.addEvent({
|
|
81
|
+
name: createEventNameFromEventHandlerName(event.name),
|
|
82
|
+
payloadTSType: event.typeAnnotation.argument
|
|
83
|
+
? typeAnnotationToTS.convert(event.typeAnnotation.argument)
|
|
84
|
+
: 'undefined',
|
|
85
|
+
});
|
|
86
|
+
componentJSIBinderHTemplate.addEvent({
|
|
87
|
+
type: event.bubblingType,
|
|
88
|
+
eventHandlerName: event.name,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
result.set(
|
|
92
|
+
this.cppOutputPath.copyWithNewSegment(`${name}ComponentDescriptor.h`),
|
|
93
|
+
componentDescriptorHTemplate.build()
|
|
94
|
+
);
|
|
95
|
+
result.set(
|
|
96
|
+
this.cppOutputPath.copyWithNewSegment(`${name}JSIBinder.h`),
|
|
97
|
+
componentJSIBinderHTemplate.build()
|
|
98
|
+
);
|
|
99
|
+
result.set(
|
|
100
|
+
this.tsOutputPath.copyWithNewSegment(`${name}.ts`),
|
|
101
|
+
componentUtilsTSTemplate.build()
|
|
102
|
+
);
|
|
103
|
+
this.glueCodeDataItems.push({
|
|
104
|
+
name,
|
|
105
|
+
eventNames: shape.events.map((e) =>
|
|
106
|
+
createEventNameFromEventHandlerName(e.name)
|
|
107
|
+
),
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import RNCodegen from '@react-native/codegen/lib/generators/RNCodegen';
|
|
2
|
+
import { AbsolutePath } from '../../core';
|
|
3
|
+
import { CodeGenerator, UberSchema } from '../core';
|
|
4
|
+
import {
|
|
5
|
+
BaseComponentInstanceHTemplate,
|
|
6
|
+
ComponentJSIBinderHTemplate,
|
|
7
|
+
} from '../templates';
|
|
8
|
+
import { GlueCodeComponentDataV2 } from './GlueCodeGenerator';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* NPM package that extends RNOH capabilities.
|
|
12
|
+
*/
|
|
13
|
+
export type LibraryData = {
|
|
14
|
+
/**
|
|
15
|
+
* C++ directory name which is used in #include statements
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
uberSchema: UberSchema;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export class ComponentCodeGeneratorCAPI implements CodeGenerator<LibraryData> {
|
|
22
|
+
private glueCodeComponentsData: GlueCodeComponentDataV2[] = [];
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
/// "shared" — platform independent code that can be shared between platforms
|
|
26
|
+
private onGetSharedOutputPath: (filename: string) => AbsolutePath,
|
|
27
|
+
private onGetRNOHOutputPath: (filename: string) => AbsolutePath
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
getGlueCodeData() {
|
|
31
|
+
return this.glueCodeComponentsData;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
generate({
|
|
35
|
+
name: libraryName,
|
|
36
|
+
uberSchema,
|
|
37
|
+
}: LibraryData): Map<AbsolutePath, string> {
|
|
38
|
+
const fileContentByPath = new Map<AbsolutePath, string>();
|
|
39
|
+
const generatorFns = [
|
|
40
|
+
RNCodegen.allGenerators.generatePropsH,
|
|
41
|
+
RNCodegen.allGenerators.generatePropsCpp,
|
|
42
|
+
RNCodegen.allGenerators.generateEventEmitterH,
|
|
43
|
+
RNCodegen.allGenerators.generateEventEmitterCpp,
|
|
44
|
+
RNCodegen.allGenerators.generateComponentDescriptorH,
|
|
45
|
+
RNCodegen.allGenerators.generateStateH,
|
|
46
|
+
RNCodegen.allGenerators.generateStateCpp,
|
|
47
|
+
RNCodegen.allGenerators.generateShadowNodeH,
|
|
48
|
+
RNCodegen.allGenerators.generateShadowNodeCpp,
|
|
49
|
+
];
|
|
50
|
+
generatorFns.forEach((generate) => {
|
|
51
|
+
const filesOutput = generate(
|
|
52
|
+
libraryName,
|
|
53
|
+
uberSchema.getValue(),
|
|
54
|
+
'UNUSED_packageName',
|
|
55
|
+
true
|
|
56
|
+
);
|
|
57
|
+
filesOutput.forEach((fileContent, filename) => {
|
|
58
|
+
fileContentByPath.set(
|
|
59
|
+
this.onGetSharedOutputPath(filename),
|
|
60
|
+
fileContent
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
for (const [filename, schema] of uberSchema
|
|
65
|
+
.getSpecSchemaByFilenameMap()
|
|
66
|
+
.entries()) {
|
|
67
|
+
if (schema.type === 'Component') {
|
|
68
|
+
Object.entries(schema.components).map(([componentName, shape]) => {
|
|
69
|
+
const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(
|
|
70
|
+
componentName,
|
|
71
|
+
2
|
|
72
|
+
);
|
|
73
|
+
const componentInstanceSpecHTemplate =
|
|
74
|
+
new BaseComponentInstanceHTemplate(componentName, libraryName);
|
|
75
|
+
shape.props.forEach((prop) => {
|
|
76
|
+
componentJSIBinderHTemplate.addProp({
|
|
77
|
+
name: prop.name,
|
|
78
|
+
isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
shape.events.forEach((event) => {
|
|
82
|
+
componentJSIBinderHTemplate.addEvent({
|
|
83
|
+
type: event.bubblingType,
|
|
84
|
+
eventHandlerName: event.name,
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
shape.commands.forEach((command) => {
|
|
88
|
+
componentInstanceSpecHTemplate.addCommand({
|
|
89
|
+
name: command.name,
|
|
90
|
+
args: command.typeAnnotation.params.map((param) => ({
|
|
91
|
+
name: param.name,
|
|
92
|
+
typeAnnotation: param.typeAnnotation,
|
|
93
|
+
})),
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
fileContentByPath.set(
|
|
97
|
+
this.onGetRNOHOutputPath(`${componentName}JSIBinder.h`),
|
|
98
|
+
componentJSIBinderHTemplate.build()
|
|
99
|
+
);
|
|
100
|
+
fileContentByPath.set(
|
|
101
|
+
this.onGetRNOHOutputPath(`Base${componentName}ComponentInstance.h`),
|
|
102
|
+
componentInstanceSpecHTemplate.build()
|
|
103
|
+
);
|
|
104
|
+
this.glueCodeComponentsData.push({
|
|
105
|
+
name: componentName,
|
|
106
|
+
libraryName,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return fileContentByPath;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import Case from 'case';
|
|
2
|
+
import { AbsolutePath } from '../../core';
|
|
3
|
+
import { CodeGenerator } from '../core';
|
|
4
|
+
import { IndexTSTemplate, RNOHGeneratedPackageHTemplate } from '../templates';
|
|
5
|
+
import { BasePackageHTemplate } from '../templates/GeneratedPackageHTemplate';
|
|
6
|
+
|
|
7
|
+
export type GlueCodeComponentDataV1 = { name: string; eventNames: string[] };
|
|
8
|
+
|
|
9
|
+
export type GlueCodeComponentDataV2 = { name: string; libraryName: string };
|
|
10
|
+
|
|
11
|
+
export type GlueCodeTurboModuleData = { name: string };
|
|
12
|
+
|
|
13
|
+
export type GlueCodeDataV1 = {
|
|
14
|
+
components: GlueCodeComponentDataV1[];
|
|
15
|
+
turboModules: GlueCodeTurboModuleData[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type LibraryName = string;
|
|
19
|
+
export type GlueCodeDataV2 = Map<
|
|
20
|
+
LibraryName,
|
|
21
|
+
{
|
|
22
|
+
components: GlueCodeComponentDataV2[];
|
|
23
|
+
turboModules: GlueCodeTurboModuleData[];
|
|
24
|
+
}
|
|
25
|
+
>;
|
|
26
|
+
|
|
27
|
+
export type GlueCodeData = {
|
|
28
|
+
v1: GlueCodeDataV1;
|
|
29
|
+
v2: GlueCodeDataV2;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Generates code based on UberGenerators results. If UberGenerators produce "leaves" (concrete turbo module or component classes),
|
|
34
|
+
* this class generates "branches" (barrel files like index.ts) and "trunks" (package file or files).
|
|
35
|
+
*/
|
|
36
|
+
export class GlueCodeGenerator implements CodeGenerator<GlueCodeData> {
|
|
37
|
+
constructor(
|
|
38
|
+
private cppOutputPath: AbsolutePath,
|
|
39
|
+
private etsOutputPath: AbsolutePath
|
|
40
|
+
) {}
|
|
41
|
+
|
|
42
|
+
generate({ v1, v2 }: GlueCodeData): Map<AbsolutePath, string> {
|
|
43
|
+
const fileContentByPath = new Map<AbsolutePath, string>();
|
|
44
|
+
const generatedPackageH_v1 = new RNOHGeneratedPackageHTemplate();
|
|
45
|
+
const components_indexTS = new IndexTSTemplate();
|
|
46
|
+
const turboModules_indexTS = new IndexTSTemplate();
|
|
47
|
+
const generated_indexETS = new IndexTSTemplate();
|
|
48
|
+
|
|
49
|
+
generated_indexETS.addReexport({ from: './ts' });
|
|
50
|
+
v1.components.forEach(({ name, eventNames }) => {
|
|
51
|
+
components_indexTS.addReexport({ from: `./${name}` });
|
|
52
|
+
generatedPackageH_v1.addComponent({
|
|
53
|
+
name,
|
|
54
|
+
supportedEventNames: eventNames,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
v1.turboModules.forEach((turboModule) => {
|
|
59
|
+
turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
|
|
60
|
+
generatedPackageH_v1.addTurboModule(turboModule);
|
|
61
|
+
});
|
|
62
|
+
v2.forEach(({ components, turboModules }, libraryName) => {
|
|
63
|
+
const basePackageClassName = `Base${Case.pascal(libraryName)}Package`;
|
|
64
|
+
const generatedPackageH_v2 = new BasePackageHTemplate(
|
|
65
|
+
basePackageClassName
|
|
66
|
+
);
|
|
67
|
+
components.forEach((component) => {
|
|
68
|
+
generatedPackageH_v2.addComponent(component);
|
|
69
|
+
});
|
|
70
|
+
turboModules.forEach((turboModule) => {
|
|
71
|
+
turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
|
|
72
|
+
generatedPackageH_v2.addTurboModule(turboModule);
|
|
73
|
+
});
|
|
74
|
+
fileContentByPath.set(
|
|
75
|
+
this.cppOutputPath.copyWithNewSegment(
|
|
76
|
+
libraryName,
|
|
77
|
+
'RNOH',
|
|
78
|
+
'generated',
|
|
79
|
+
`${basePackageClassName}.h`
|
|
80
|
+
),
|
|
81
|
+
generatedPackageH_v2.build()
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
fileContentByPath.set(
|
|
85
|
+
this.cppOutputPath.copyWithNewSegment('RNOHGeneratedPackage.h'),
|
|
86
|
+
generatedPackageH_v1.build()
|
|
87
|
+
);
|
|
88
|
+
fileContentByPath.set(
|
|
89
|
+
this.etsOutputPath.copyWithNewSegment('ts.ts'),
|
|
90
|
+
new IndexTSTemplate()
|
|
91
|
+
.addReexport({ from: './components/ts', as: 'RNC' })
|
|
92
|
+
.addReexport({ from: './turboModules/ts', as: 'TM' })
|
|
93
|
+
.build()
|
|
94
|
+
);
|
|
95
|
+
fileContentByPath.set(
|
|
96
|
+
this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'),
|
|
97
|
+
components_indexTS.build()
|
|
98
|
+
);
|
|
99
|
+
fileContentByPath.set(
|
|
100
|
+
this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'),
|
|
101
|
+
turboModules_indexTS.build()
|
|
102
|
+
);
|
|
103
|
+
fileContentByPath.set(
|
|
104
|
+
this.etsOutputPath.copyWithNewSegment('index.ets'),
|
|
105
|
+
generated_indexETS.build()
|
|
106
|
+
);
|
|
107
|
+
return fileContentByPath;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -1,95 +1,115 @@
|
|
|
1
|
-
import { AbsolutePath } from '../../core';
|
|
2
|
-
import type { SpecCodeGenerator } from '../core
|
|
3
|
-
import {
|
|
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
|
-
|
|
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
|
-
schema.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
name:
|
|
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
|
-
|
|
1
|
+
import { AbsolutePath } from '../../core';
|
|
2
|
+
import type { SpecCodeGenerator } from '../core';
|
|
3
|
+
import {
|
|
4
|
+
TurboModuleCppTemplate,
|
|
5
|
+
TurboModuleHTemplate,
|
|
6
|
+
TurboModuleInterfaceTS,
|
|
7
|
+
} from '../templates';
|
|
8
|
+
import {
|
|
9
|
+
TypeAnnotationToTS,
|
|
10
|
+
wrapWithQuotes,
|
|
11
|
+
SpecSchema,
|
|
12
|
+
CodegenError,
|
|
13
|
+
} from '../core';
|
|
14
|
+
import { GlueCodeTurboModuleData } from './GlueCodeGenerator';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generates boilerplate code for Turbo Modules.
|
|
18
|
+
*/
|
|
19
|
+
export class NativeModuleCodeGenerator implements SpecCodeGenerator {
|
|
20
|
+
private glueCodeTurboModulesData: GlueCodeTurboModuleData[] = [];
|
|
21
|
+
constructor(
|
|
22
|
+
private cppOutputPath: AbsolutePath,
|
|
23
|
+
private etsOutputPath: AbsolutePath,
|
|
24
|
+
private generatorVersion: number
|
|
25
|
+
) {}
|
|
26
|
+
|
|
27
|
+
getGlueCodeData() {
|
|
28
|
+
return this.glueCodeTurboModulesData;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
generate(schema: SpecSchema): Map<AbsolutePath, string> {
|
|
32
|
+
const result = new Map<AbsolutePath, string>();
|
|
33
|
+
if (schema.type !== 'NativeModule') {
|
|
34
|
+
throw new CodegenError({
|
|
35
|
+
whatHappened: `NativeModuleCodeGenerator can't generate code for module type: ${schema.type}`,
|
|
36
|
+
unexpected: true,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const typeAnnotationToTS = new TypeAnnotationToTS();
|
|
40
|
+
const turboModuleInterfaceTS = new TurboModuleInterfaceTS(
|
|
41
|
+
schema.moduleName,
|
|
42
|
+
this.generatorVersion
|
|
43
|
+
);
|
|
44
|
+
const turboModuleH = new TurboModuleHTemplate(
|
|
45
|
+
schema.moduleName,
|
|
46
|
+
this.generatorVersion
|
|
47
|
+
).build();
|
|
48
|
+
result.set(
|
|
49
|
+
this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.h`),
|
|
50
|
+
turboModuleH
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const turboModuleCpp = new TurboModuleCppTemplate(
|
|
54
|
+
schema.moduleName,
|
|
55
|
+
this.generatorVersion
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
Object.entries(schema.aliasMap).map(([name, typeAnnotation]) => {
|
|
59
|
+
turboModuleInterfaceTS.addAlias({
|
|
60
|
+
name: name,
|
|
61
|
+
type: typeAnnotationToTS.convert(typeAnnotation),
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
Object.entries(schema.enumMap).map(([name, enumSpec]) => {
|
|
66
|
+
turboModuleInterfaceTS.addEnum({
|
|
67
|
+
name,
|
|
68
|
+
members: enumSpec.members.map((member) => ({
|
|
69
|
+
name: member.name,
|
|
70
|
+
value:
|
|
71
|
+
typeof member.value === 'string'
|
|
72
|
+
? wrapWithQuotes(member.value)
|
|
73
|
+
: member.value.toString(),
|
|
74
|
+
})),
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
schema.spec.properties.map((prop) => {
|
|
79
|
+
if (prop.typeAnnotation.type === 'FunctionTypeAnnotation') {
|
|
80
|
+
turboModuleCpp.addMethod({
|
|
81
|
+
name: prop.name,
|
|
82
|
+
argsCount: prop.typeAnnotation.params.length,
|
|
83
|
+
isAsync:
|
|
84
|
+
prop.typeAnnotation.returnTypeAnnotation.type ===
|
|
85
|
+
'PromiseTypeAnnotation',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
turboModuleInterfaceTS.addMethod({
|
|
89
|
+
name: prop.name,
|
|
90
|
+
returnType: typeAnnotationToTS.convert(
|
|
91
|
+
prop.typeAnnotation.returnTypeAnnotation
|
|
92
|
+
),
|
|
93
|
+
stringifiedArgs: prop.typeAnnotation.params
|
|
94
|
+
.map(
|
|
95
|
+
(param) =>
|
|
96
|
+
`${param.name}: ${typeAnnotationToTS.convert(
|
|
97
|
+
param.typeAnnotation
|
|
98
|
+
)}`
|
|
99
|
+
)
|
|
100
|
+
.join(', '),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
result.set(
|
|
105
|
+
this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.cpp`),
|
|
106
|
+
turboModuleCpp.build()
|
|
107
|
+
);
|
|
108
|
+
result.set(
|
|
109
|
+
this.etsOutputPath.copyWithNewSegment(`${schema.moduleName}.ts`),
|
|
110
|
+
turboModuleInterfaceTS.build()
|
|
111
|
+
);
|
|
112
|
+
this.glueCodeTurboModulesData.push({ name: schema.moduleName });
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
}
|