@react-native-oh/react-native-harmony-cli 0.0.26 → 0.0.28
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/README.md +12 -0
- package/dist/assetResolver.js +25 -0
- package/dist/autolinking/Autolinking.js +275 -0
- package/dist/autolinking/index.js +23 -0
- package/dist/codegen/core/CodeGenerator.js +8 -0
- package/dist/codegen/core/CodegenError.js +13 -0
- package/dist/codegen/core/EventUtils.js +25 -0
- package/dist/codegen/core/TypeAnnotationToTS.js +138 -0
- package/dist/codegen/core/UberSchema.js +109 -0
- package/dist/codegen/core/index.js +27 -0
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +67 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +82 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +80 -0
- package/dist/codegen/generators/CppComponentCodeGenerator.js +62 -0
- package/dist/codegen/generators/LibGlueCodeGenerator.js +56 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +79 -0
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +40 -0
- package/dist/codegen/generators/UberGeneratorV1.js +56 -0
- package/dist/codegen/generators/UberGeneratorV2.js +77 -0
- package/dist/codegen/generators/index.js +30 -0
- package/dist/codegen/index.js +24 -0
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +111 -0
- package/dist/codegen/templates/BasePackageHTemplate.js +136 -0
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +68 -0
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +91 -0
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +198 -0
- package/dist/codegen/templates/IndexTSTemplate.js +58 -0
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +130 -0
- package/dist/codegen/templates/TurboModuleCppTemplate.js +59 -0
- package/dist/codegen/templates/TurboModuleHTemplate.js +48 -0
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +81 -0
- package/dist/codegen/templates/index.js +31 -0
- package/dist/commands/bundle-harmony.js +185 -0
- package/dist/commands/codegen-harmony.js +207 -0
- package/dist/commands/codegen-lib-harmony.js +259 -0
- package/dist/commands/create-metro-host-constants.js +67 -0
- package/dist/commands/index.js +30 -0
- package/dist/commands/link-harmony.js +97 -0
- package/dist/commands/pack-harmony.js +106 -0
- package/dist/commands/unpack-harmony.js +191 -0
- package/dist/commands/verify-package-harmony.js +128 -0
- package/dist/core/AbsolutePath.js +59 -0
- package/dist/core/CodegenConfig.js +63 -0
- package/dist/core/DescriptiveError.js +55 -0
- package/dist/core/FileSystem.js +33 -0
- package/dist/core/OHPackageJSON5.js +29 -0
- package/dist/core/PackageJSON.js +66 -0
- package/dist/core/ProjectDependenciesManager.js +83 -0
- package/dist/core/ValidationError.js +12 -0
- package/dist/core/ValueObject.js +8 -0
- package/dist/core/fs.js +42 -0
- package/dist/core/index.js +32 -0
- package/dist/index.js +22 -0
- package/dist/io/CliExecutor.js +35 -0
- package/dist/io/Logger.js +80 -0
- package/dist/io/RealFS.js +68 -0
- package/dist/io/TarGz.js +34 -0
- package/dist/io/__fixtures__.js +127 -0
- package/dist/io/fsUtils.js +37 -0
- package/dist/io/index.js +26 -0
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +44 -0
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +38 -0
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +32 -0
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +57 -0
- package/dist/package-verifier/checks/index.js +26 -0
- package/dist/package-verifier/index.js +24 -0
- package/dist/package-verifier/types.js +8 -0
- package/dist/package-verifier/verify-package.js +107 -0
- package/jest.config.js +7 -0
- package/package.json +8 -2
- package/react-native.config.js +7 -0
- package/src/assetResolver.ts +7 -0
- package/src/autolinking/Autolinking.test.ts +483 -0
- package/src/autolinking/Autolinking.ts +384 -0
- package/src/autolinking/index.ts +8 -0
- package/src/codegen/core/CodeGenerator.ts +7 -0
- package/src/codegen/core/CodegenError.ts +7 -0
- package/src/codegen/core/EventUtils.ts +7 -0
- package/src/codegen/core/TypeAnnotationToTS.test.ts +7 -0
- package/src/codegen/core/TypeAnnotationToTS.ts +7 -0
- package/src/codegen/core/UberSchema.ts +15 -1
- package/src/codegen/core/index.ts +7 -0
- package/src/codegen/generators/{GlueCodeGenerator.ts → AppBuildTimeGlueCodeGenerator.ts} +20 -9
- package/src/codegen/generators/{ComponentCodeGeneratorArkTS.ts → ArkTSComponentCodeGeneratorArkTS.ts} +18 -5
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +119 -0
- package/src/codegen/generators/{ComponentCodeGeneratorCAPI.ts → CppComponentCodeGenerator.ts} +21 -43
- package/src/codegen/generators/LibGlueCodeGenerator.ts +98 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +14 -5
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +57 -0
- package/src/codegen/generators/UberGeneratorV1.ts +19 -8
- package/src/codegen/generators/UberGeneratorV2.ts +39 -16
- package/src/codegen/generators/index.ts +12 -3
- package/src/codegen/index.ts +7 -0
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +19 -7
- package/src/codegen/templates/{GeneratedPackageHTemplate.ts → BasePackageHTemplate.ts} +52 -12
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +9 -1
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +15 -10
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +20 -8
- package/src/codegen/templates/IndexTSTemplate.ts +18 -9
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +8 -0
- package/src/codegen/templates/TurboModuleCppTemplate.ts +16 -9
- package/src/codegen/templates/TurboModuleHTemplate.ts +16 -9
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +20 -9
- package/src/codegen/templates/index.ts +7 -0
- package/src/commands/bundle-harmony.ts +8 -1
- package/src/commands/codegen-harmony.ts +43 -13
- package/src/commands/codegen-lib-harmony.ts +394 -0
- package/src/commands/create-metro-host-constants.ts +7 -0
- package/src/commands/index.ts +9 -0
- package/src/commands/link-harmony.ts +102 -0
- package/src/commands/pack-harmony.ts +7 -0
- package/src/commands/unpack-harmony.ts +12 -3
- package/src/commands/verify-package-harmony.ts +7 -0
- package/src/core/AbsolutePath.ts +16 -0
- package/src/core/CodegenConfig.ts +7 -0
- package/src/core/DescriptiveError.ts +7 -0
- package/src/core/FileSystem.ts +57 -0
- package/src/core/OHPackageJSON5.ts +7 -0
- package/src/core/PackageJSON.ts +40 -8
- package/src/core/ProjectDependenciesManager.ts +40 -14
- package/src/core/ValidationError.ts +7 -0
- package/src/core/ValueObject.ts +7 -0
- package/src/core/fs.ts +7 -0
- package/src/core/index.ts +8 -0
- package/src/index.ts +11 -0
- package/src/io/CliExecutor.ts +47 -0
- package/src/io/Logger.ts +11 -0
- package/src/io/RealFS.ts +62 -0
- package/src/io/TarGz.ts +7 -0
- package/src/io/__fixtures__.ts +135 -0
- package/src/io/fsUtils.ts +26 -6
- package/src/io/index.ts +8 -0
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +7 -0
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +7 -0
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +7 -0
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +7 -0
- package/src/package-verifier/checks/index.ts +7 -0
- package/src/package-verifier/index.ts +7 -0
- package/src/package-verifier/types.ts +7 -0
- package/src/package-verifier/verify-package.ts +9 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { AbsolutePath } from '../../core';
|
|
9
|
+
import {
|
|
10
|
+
TypeAnnotationToTS,
|
|
11
|
+
createEventNameFromEventHandlerName,
|
|
12
|
+
getStringifiedTSDefaultValueFromPropTypeAnnotation,
|
|
13
|
+
} from '../core';
|
|
14
|
+
import type { CodeGenerator, UberSchema } from '../core';
|
|
15
|
+
import {
|
|
16
|
+
ComponentJSIBinderHTemplate,
|
|
17
|
+
ComponentUtilsTSTemplate,
|
|
18
|
+
} from '../templates';
|
|
19
|
+
import { ArkTSComponentLibGlueCodeData } from './LibGlueCodeGenerator';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Generates component code for ArkTS components used in C-API architecture.
|
|
23
|
+
*/
|
|
24
|
+
export class ArkTSComponentCodeGeneratorCAPI
|
|
25
|
+
implements CodeGenerator<UberSchema>
|
|
26
|
+
{
|
|
27
|
+
private glueCodeDataItems: ArkTSComponentLibGlueCodeData[] = [];
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
private cppOutputPath: AbsolutePath,
|
|
31
|
+
private tsOutputPath: AbsolutePath,
|
|
32
|
+
private codegenNoticeLines: string[],
|
|
33
|
+
private rnohImport: string
|
|
34
|
+
) {}
|
|
35
|
+
|
|
36
|
+
getLibGlueCodeData(): ArkTSComponentLibGlueCodeData[] {
|
|
37
|
+
return this.glueCodeDataItems;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
generate(uberSchema: UberSchema): Map<AbsolutePath, string> {
|
|
41
|
+
const typeAnnotationToTS = new TypeAnnotationToTS();
|
|
42
|
+
const result = new Map<AbsolutePath, string>();
|
|
43
|
+
const componentSpecSchemas =
|
|
44
|
+
uberSchema.findAllSpecSchemasByType('Component');
|
|
45
|
+
|
|
46
|
+
for (const componentSpecSchema of componentSpecSchemas) {
|
|
47
|
+
Object.entries(componentSpecSchema.components).map(([name, shape]) => {
|
|
48
|
+
const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(
|
|
49
|
+
name,
|
|
50
|
+
this.codegenNoticeLines
|
|
51
|
+
);
|
|
52
|
+
const componentUtilsTSTemplate = new ComponentUtilsTSTemplate(
|
|
53
|
+
name,
|
|
54
|
+
this.codegenNoticeLines,
|
|
55
|
+
this.rnohImport
|
|
56
|
+
);
|
|
57
|
+
shape.props.forEach((prop) => {
|
|
58
|
+
componentJSIBinderHTemplate.addProp({
|
|
59
|
+
name: prop.name,
|
|
60
|
+
isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
componentUtilsTSTemplate.addProp({
|
|
64
|
+
name: prop.name,
|
|
65
|
+
tsType: typeAnnotationToTS.convert(prop.typeAnnotation),
|
|
66
|
+
defaultValue: getStringifiedTSDefaultValueFromPropTypeAnnotation(
|
|
67
|
+
prop.typeAnnotation
|
|
68
|
+
),
|
|
69
|
+
isOptional: prop.optional,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
shape.commands.forEach((command) => {
|
|
73
|
+
componentUtilsTSTemplate.addCommand({
|
|
74
|
+
name: command.name,
|
|
75
|
+
argsTSType:
|
|
76
|
+
'[' +
|
|
77
|
+
command.typeAnnotation.params
|
|
78
|
+
.map(
|
|
79
|
+
(param) =>
|
|
80
|
+
typeAnnotationToTS.convert(param.typeAnnotation) +
|
|
81
|
+
(param.optional ? '?' : '')
|
|
82
|
+
)
|
|
83
|
+
.join(', ') +
|
|
84
|
+
']',
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
shape.events.forEach((event) => {
|
|
89
|
+
componentUtilsTSTemplate.addEvent({
|
|
90
|
+
name: createEventNameFromEventHandlerName(event.name),
|
|
91
|
+
payloadTSType: event.typeAnnotation.argument
|
|
92
|
+
? typeAnnotationToTS.convert(event.typeAnnotation.argument)
|
|
93
|
+
: 'undefined',
|
|
94
|
+
});
|
|
95
|
+
componentJSIBinderHTemplate.addEvent({
|
|
96
|
+
type: event.bubblingType,
|
|
97
|
+
eventHandlerName: event.name,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
result.set(
|
|
101
|
+
this.cppOutputPath.copyWithNewSegment(`${name}JSIBinder.h`),
|
|
102
|
+
componentJSIBinderHTemplate.build()
|
|
103
|
+
);
|
|
104
|
+
result.set(
|
|
105
|
+
this.tsOutputPath.copyWithNewSegment(`${name}.ts`),
|
|
106
|
+
componentUtilsTSTemplate.build()
|
|
107
|
+
);
|
|
108
|
+
this.glueCodeDataItems.push({
|
|
109
|
+
componentName: name,
|
|
110
|
+
eventNames: shape.events.map((event) =>
|
|
111
|
+
createEventNameFromEventHandlerName(event.name)
|
|
112
|
+
),
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
}
|
package/src/codegen/generators/{ComponentCodeGeneratorCAPI.ts → CppComponentCodeGenerator.ts}
RENAMED
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
2
8
|
import { AbsolutePath } from '../../core';
|
|
3
9
|
import { CodeGenerator, UberSchema } from '../core';
|
|
4
10
|
import {
|
|
5
11
|
BaseComponentInstanceHTemplate,
|
|
6
12
|
ComponentJSIBinderHTemplate,
|
|
7
13
|
} from '../templates';
|
|
8
|
-
import { GlueCodeComponentDataV2 } from './
|
|
14
|
+
import { GlueCodeComponentDataV2 } from './AppBuildTimeGlueCodeGenerator';
|
|
9
15
|
|
|
10
|
-
/**
|
|
11
|
-
* NPM package that extends RNOH capabilities.
|
|
12
|
-
*/
|
|
13
16
|
export type LibraryData = {
|
|
14
|
-
|
|
15
|
-
* C++ directory name which is used in #include statements
|
|
16
|
-
*/
|
|
17
|
-
name: string;
|
|
17
|
+
libraryCppName: string;
|
|
18
18
|
uberSchema: UberSchema;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export class
|
|
21
|
+
export class CppComponentCodeGenerator implements CodeGenerator<LibraryData> {
|
|
22
22
|
private glueCodeComponentsData: GlueCodeComponentDataV2[] = [];
|
|
23
23
|
|
|
24
24
|
constructor(
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
private onGetRNOHOutputPath: (filename: string) => AbsolutePath
|
|
25
|
+
private onGetRNOHOutputPath: (filename: string) => AbsolutePath,
|
|
26
|
+
private codegenNoticeLines: string[]
|
|
28
27
|
) {}
|
|
29
28
|
|
|
30
29
|
getGlueCodeData() {
|
|
@@ -32,46 +31,25 @@ export class ComponentCodeGeneratorCAPI implements CodeGenerator<LibraryData> {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
generate({
|
|
35
|
-
|
|
34
|
+
libraryCppName,
|
|
36
35
|
uberSchema,
|
|
37
36
|
}: LibraryData): Map<AbsolutePath, string> {
|
|
38
37
|
const fileContentByPath = new Map<AbsolutePath, string>();
|
|
39
|
-
const
|
|
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
|
|
38
|
+
for (const [_filename, schema] of uberSchema
|
|
65
39
|
.getSpecSchemaByFilenameMap()
|
|
66
40
|
.entries()) {
|
|
67
41
|
if (schema.type === 'Component') {
|
|
68
42
|
Object.entries(schema.components).map(([componentName, shape]) => {
|
|
69
43
|
const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(
|
|
70
44
|
componentName,
|
|
71
|
-
|
|
45
|
+
this.codegenNoticeLines
|
|
72
46
|
);
|
|
73
47
|
const componentInstanceSpecHTemplate =
|
|
74
|
-
new BaseComponentInstanceHTemplate(
|
|
48
|
+
new BaseComponentInstanceHTemplate(
|
|
49
|
+
componentName,
|
|
50
|
+
libraryCppName,
|
|
51
|
+
this.codegenNoticeLines
|
|
52
|
+
);
|
|
75
53
|
shape.props.forEach((prop) => {
|
|
76
54
|
componentJSIBinderHTemplate.addProp({
|
|
77
55
|
name: prop.name,
|
|
@@ -103,7 +81,7 @@ export class ComponentCodeGeneratorCAPI implements CodeGenerator<LibraryData> {
|
|
|
103
81
|
);
|
|
104
82
|
this.glueCodeComponentsData.push({
|
|
105
83
|
name: componentName,
|
|
106
|
-
|
|
84
|
+
libraryCppName,
|
|
107
85
|
});
|
|
108
86
|
});
|
|
109
87
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import Case from 'case';
|
|
9
|
+
import { AbsolutePath } from '../../core';
|
|
10
|
+
import { CodeGenerator } from '../core';
|
|
11
|
+
import { BasePackageHTemplate } from '../templates/BasePackageHTemplate';
|
|
12
|
+
import { IndexTSTemplate } from '../templates';
|
|
13
|
+
import { GlueCodeTurboModuleData } from './AppBuildTimeGlueCodeGenerator';
|
|
14
|
+
|
|
15
|
+
export type ArkTSComponentLibGlueCodeData = {
|
|
16
|
+
componentName: string;
|
|
17
|
+
eventNames: string[];
|
|
18
|
+
};
|
|
19
|
+
export type CppComponentLibGlueCodeData = { componentName: string };
|
|
20
|
+
|
|
21
|
+
type LibGlueCodeData = {
|
|
22
|
+
libraryCppName: string;
|
|
23
|
+
turboModules: GlueCodeTurboModuleData[];
|
|
24
|
+
arkTSComponents: ArkTSComponentLibGlueCodeData[];
|
|
25
|
+
cppComponents: CppComponentLibGlueCodeData[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* NOTE: This class is coupled with the generated code structure defined in the codegen-harmony-lib.
|
|
30
|
+
*/
|
|
31
|
+
export class LibGlueCodeGenerator implements CodeGenerator<LibGlueCodeData> {
|
|
32
|
+
constructor(
|
|
33
|
+
private cppOutputPath: AbsolutePath,
|
|
34
|
+
private etsOutputPath: AbsolutePath,
|
|
35
|
+
private codegenNoticeLines: string[]
|
|
36
|
+
) {}
|
|
37
|
+
|
|
38
|
+
generate({
|
|
39
|
+
libraryCppName,
|
|
40
|
+
turboModules,
|
|
41
|
+
arkTSComponents,
|
|
42
|
+
cppComponents,
|
|
43
|
+
}: LibGlueCodeData): Map<AbsolutePath, string> {
|
|
44
|
+
const fileContentByPath = new Map<AbsolutePath, string>();
|
|
45
|
+
const basePackageClassName = `Base${Case.pascal(libraryCppName)}Package`;
|
|
46
|
+
const turboModules_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
|
|
47
|
+
const components_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
|
|
48
|
+
const generated_indexETS = new IndexTSTemplate(this.codegenNoticeLines);
|
|
49
|
+
|
|
50
|
+
const basePackageTemplate = new BasePackageHTemplate(
|
|
51
|
+
basePackageClassName,
|
|
52
|
+
this.codegenNoticeLines
|
|
53
|
+
);
|
|
54
|
+
turboModules.forEach((turboModule) => {
|
|
55
|
+
basePackageTemplate.addTurboModule(turboModule);
|
|
56
|
+
turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
|
|
57
|
+
});
|
|
58
|
+
arkTSComponents.forEach(({ componentName, eventNames }) => {
|
|
59
|
+
components_indexTS.addReexport({ from: `./${componentName}` });
|
|
60
|
+
basePackageTemplate.addComponent({ name: componentName, libraryCppName });
|
|
61
|
+
eventNames.forEach((eventName) =>
|
|
62
|
+
basePackageTemplate.addArkTSEvent({ name: eventName })
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
cppComponents.forEach(({ componentName }) => {
|
|
66
|
+
basePackageTemplate.addComponent({ name: componentName, libraryCppName });
|
|
67
|
+
});
|
|
68
|
+
fileContentByPath.set(
|
|
69
|
+
this.cppOutputPath.copyWithNewSegment(
|
|
70
|
+
'RNOH',
|
|
71
|
+
'generated',
|
|
72
|
+
`${basePackageClassName}.h`
|
|
73
|
+
),
|
|
74
|
+
basePackageTemplate.build()
|
|
75
|
+
);
|
|
76
|
+
fileContentByPath.set(
|
|
77
|
+
this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'),
|
|
78
|
+
components_indexTS.build()
|
|
79
|
+
);
|
|
80
|
+
fileContentByPath.set(
|
|
81
|
+
this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'),
|
|
82
|
+
turboModules_indexTS.build()
|
|
83
|
+
);
|
|
84
|
+
fileContentByPath.set(
|
|
85
|
+
this.etsOutputPath.copyWithNewSegment('ts.ts'),
|
|
86
|
+
new IndexTSTemplate(this.codegenNoticeLines)
|
|
87
|
+
.addReexport({ from: './components/ts', as: 'RNC' })
|
|
88
|
+
.addReexport({ from: './turboModules/ts', as: 'TM' })
|
|
89
|
+
.build()
|
|
90
|
+
);
|
|
91
|
+
generated_indexETS.addReexport({ from: './ts' });
|
|
92
|
+
fileContentByPath.set(
|
|
93
|
+
this.etsOutputPath.copyWithNewSegment('index.ets'),
|
|
94
|
+
generated_indexETS.build()
|
|
95
|
+
);
|
|
96
|
+
return fileContentByPath;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import { AbsolutePath } from '../../core';
|
|
2
9
|
import type { SpecCodeGenerator } from '../core';
|
|
3
10
|
import {
|
|
@@ -11,7 +18,7 @@ import {
|
|
|
11
18
|
SpecSchema,
|
|
12
19
|
CodegenError,
|
|
13
20
|
} from '../core';
|
|
14
|
-
import { GlueCodeTurboModuleData } from './
|
|
21
|
+
import { GlueCodeTurboModuleData } from './AppBuildTimeGlueCodeGenerator';
|
|
15
22
|
|
|
16
23
|
/**
|
|
17
24
|
* Generates boilerplate code for Turbo Modules.
|
|
@@ -21,7 +28,8 @@ export class NativeModuleCodeGenerator implements SpecCodeGenerator {
|
|
|
21
28
|
constructor(
|
|
22
29
|
private cppOutputPath: AbsolutePath,
|
|
23
30
|
private etsOutputPath: AbsolutePath,
|
|
24
|
-
private
|
|
31
|
+
private codegenNoticeLines: string[],
|
|
32
|
+
private rnohImport: string
|
|
25
33
|
) {}
|
|
26
34
|
|
|
27
35
|
getGlueCodeData() {
|
|
@@ -39,11 +47,12 @@ export class NativeModuleCodeGenerator implements SpecCodeGenerator {
|
|
|
39
47
|
const typeAnnotationToTS = new TypeAnnotationToTS();
|
|
40
48
|
const turboModuleInterfaceTS = new TurboModuleInterfaceTS(
|
|
41
49
|
schema.moduleName,
|
|
42
|
-
this.
|
|
50
|
+
this.codegenNoticeLines,
|
|
51
|
+
this.rnohImport
|
|
43
52
|
);
|
|
44
53
|
const turboModuleH = new TurboModuleHTemplate(
|
|
45
54
|
schema.moduleName,
|
|
46
|
-
this.
|
|
55
|
+
this.codegenNoticeLines
|
|
47
56
|
).build();
|
|
48
57
|
result.set(
|
|
49
58
|
this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.h`),
|
|
@@ -52,7 +61,7 @@ export class NativeModuleCodeGenerator implements SpecCodeGenerator {
|
|
|
52
61
|
|
|
53
62
|
const turboModuleCpp = new TurboModuleCppTemplate(
|
|
54
63
|
schema.moduleName,
|
|
55
|
-
this.
|
|
64
|
+
this.codegenNoticeLines
|
|
56
65
|
);
|
|
57
66
|
|
|
58
67
|
Object.entries(schema.aliasMap).map(([name, typeAnnotation]) => {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import RNCodegen from '@react-native/codegen/lib/generators/RNCodegen';
|
|
9
|
+
import { AbsolutePath } from '../../core';
|
|
10
|
+
import { CodeGenerator, UberSchema } from '../core';
|
|
11
|
+
|
|
12
|
+
type LibraryData = {
|
|
13
|
+
libraryCppName: string;
|
|
14
|
+
uberSchema: UberSchema;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export class SharedComponentCodeGenerator
|
|
18
|
+
implements CodeGenerator<LibraryData>
|
|
19
|
+
{
|
|
20
|
+
constructor(
|
|
21
|
+
private onGetSharedOutputPath: (filename: string) => AbsolutePath
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
generate({
|
|
25
|
+
libraryCppName,
|
|
26
|
+
uberSchema,
|
|
27
|
+
}: LibraryData): Map<AbsolutePath, string> {
|
|
28
|
+
const fileContentByPath = new Map<AbsolutePath, string>();
|
|
29
|
+
|
|
30
|
+
const generatorFns = [
|
|
31
|
+
RNCodegen.allGenerators.generatePropsH,
|
|
32
|
+
RNCodegen.allGenerators.generatePropsCpp,
|
|
33
|
+
RNCodegen.allGenerators.generateEventEmitterH,
|
|
34
|
+
RNCodegen.allGenerators.generateEventEmitterCpp,
|
|
35
|
+
RNCodegen.allGenerators.generateComponentDescriptorH,
|
|
36
|
+
RNCodegen.allGenerators.generateStateH,
|
|
37
|
+
RNCodegen.allGenerators.generateStateCpp,
|
|
38
|
+
RNCodegen.allGenerators.generateShadowNodeH,
|
|
39
|
+
RNCodegen.allGenerators.generateShadowNodeCpp,
|
|
40
|
+
];
|
|
41
|
+
generatorFns.forEach((generate) => {
|
|
42
|
+
const filesOutput = generate(
|
|
43
|
+
libraryCppName,
|
|
44
|
+
uberSchema.getValue(),
|
|
45
|
+
'UNUSED_packageName',
|
|
46
|
+
true
|
|
47
|
+
);
|
|
48
|
+
filesOutput.forEach((fileContent, filename) => {
|
|
49
|
+
fileContentByPath.set(
|
|
50
|
+
this.onGetSharedOutputPath(filename),
|
|
51
|
+
fileContent
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
return fileContentByPath;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import { AbsolutePath } from '../../core';
|
|
2
9
|
import {
|
|
3
10
|
CodeGenerator,
|
|
@@ -6,9 +13,9 @@ import {
|
|
|
6
13
|
SpecSchemaType,
|
|
7
14
|
UberSchema,
|
|
8
15
|
} from '../core';
|
|
9
|
-
import { GlueCodeDataV1 } from './
|
|
16
|
+
import { GlueCodeDataV1 } from './AppBuildTimeGlueCodeGenerator';
|
|
10
17
|
import { NativeModuleCodeGenerator } from './NativeModuleCodeGenerator';
|
|
11
|
-
import {
|
|
18
|
+
import { ArkTSComponentCodeGeneratorArkTS } from './ArkTSComponentCodeGeneratorArkTS';
|
|
12
19
|
|
|
13
20
|
/**
|
|
14
21
|
* Generates code for libraries built on top of RNOH's ArkTS architecture.
|
|
@@ -18,7 +25,8 @@ export class UberGeneratorV1 implements CodeGenerator<UberSchema> {
|
|
|
18
25
|
|
|
19
26
|
constructor(
|
|
20
27
|
private cppOutputPath: AbsolutePath,
|
|
21
|
-
private etsOutputPath: AbsolutePath
|
|
28
|
+
private etsOutputPath: AbsolutePath,
|
|
29
|
+
private codegenNoticeLines: string[]
|
|
22
30
|
) {}
|
|
23
31
|
|
|
24
32
|
getGlueCodeData(): GlueCodeDataV1 {
|
|
@@ -27,17 +35,20 @@ export class UberGeneratorV1 implements CodeGenerator<UberSchema> {
|
|
|
27
35
|
|
|
28
36
|
generate(uberSchema: UberSchema) {
|
|
29
37
|
const fileContentByPath = new Map<AbsolutePath, string>();
|
|
30
|
-
const
|
|
38
|
+
const componentCodeGenerator = new ArkTSComponentCodeGeneratorArkTS(
|
|
31
39
|
this.cppOutputPath,
|
|
32
|
-
this.etsOutputPath.copyWithNewSegment('components')
|
|
40
|
+
this.etsOutputPath.copyWithNewSegment('components'),
|
|
41
|
+
this.codegenNoticeLines,
|
|
42
|
+
'../../ts'
|
|
33
43
|
);
|
|
34
44
|
const nativeModuleCodeGenerator = new NativeModuleCodeGenerator(
|
|
35
45
|
this.cppOutputPath,
|
|
36
46
|
this.etsOutputPath.copyWithNewSegment('turboModules'),
|
|
37
|
-
|
|
47
|
+
this.codegenNoticeLines,
|
|
48
|
+
'../../ts'
|
|
38
49
|
);
|
|
39
50
|
const generatorBySpecType = {
|
|
40
|
-
Component:
|
|
51
|
+
Component: componentCodeGenerator,
|
|
41
52
|
NativeModule: nativeModuleCodeGenerator,
|
|
42
53
|
} satisfies Record<SpecSchemaType, CodeGenerator<SpecSchema>>;
|
|
43
54
|
for (const [_fileName, specSchema] of uberSchema
|
|
@@ -56,7 +67,7 @@ export class UberGeneratorV1 implements CodeGenerator<UberSchema> {
|
|
|
56
67
|
});
|
|
57
68
|
}
|
|
58
69
|
this.glueCodeData = {
|
|
59
|
-
components:
|
|
70
|
+
components: componentCodeGenerator.getGlueCodeData(),
|
|
60
71
|
turboModules: nativeModuleCodeGenerator.getGlueCodeData(),
|
|
61
72
|
};
|
|
62
73
|
return fileContentByPath;
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import { AbsolutePath } from '../../core';
|
|
2
9
|
import { CodeGenerator } from '../core';
|
|
3
10
|
import {
|
|
4
|
-
|
|
11
|
+
CppComponentCodeGenerator,
|
|
5
12
|
LibraryData,
|
|
6
|
-
} from './
|
|
13
|
+
} from './CppComponentCodeGenerator';
|
|
7
14
|
import { NativeModuleCodeGenerator } from './NativeModuleCodeGenerator';
|
|
8
|
-
import { GlueCodeDataV2 } from './
|
|
15
|
+
import { GlueCodeDataV2 } from './AppBuildTimeGlueCodeGenerator';
|
|
16
|
+
import { SharedComponentCodeGenerator } from './SharedComponentCodeGenerator';
|
|
9
17
|
|
|
10
18
|
/**
|
|
11
19
|
* Generates code for libraries built on top of RNOH's C-API architecture.
|
|
@@ -15,7 +23,8 @@ export class UberGeneratorV2 implements CodeGenerator<LibraryData[]> {
|
|
|
15
23
|
|
|
16
24
|
constructor(
|
|
17
25
|
private cppOutputPath: AbsolutePath,
|
|
18
|
-
private etsOutputPath: AbsolutePath
|
|
26
|
+
private etsOutputPath: AbsolutePath,
|
|
27
|
+
private codegenNoticeLines: string[]
|
|
19
28
|
) {}
|
|
20
29
|
|
|
21
30
|
getGlueCodeData(): GlueCodeDataV2 {
|
|
@@ -25,20 +34,26 @@ export class UberGeneratorV2 implements CodeGenerator<LibraryData[]> {
|
|
|
25
34
|
generate(npmPackagesInfo: LibraryData[]) {
|
|
26
35
|
const fileContentByPath: Map<AbsolutePath, string> = new Map();
|
|
27
36
|
|
|
28
|
-
npmPackagesInfo.forEach(({
|
|
29
|
-
this.glueCodeData.set(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
npmPackagesInfo.forEach(({ libraryCppName, uberSchema }) => {
|
|
38
|
+
this.glueCodeData.set(libraryCppName, {
|
|
39
|
+
components: [],
|
|
40
|
+
turboModules: [],
|
|
41
|
+
});
|
|
42
|
+
const libraryGlueCodeData = this.glueCodeData.get(libraryCppName)!;
|
|
43
|
+
const libraryCppOutput =
|
|
44
|
+
this.cppOutputPath.copyWithNewSegment(libraryCppName);
|
|
45
|
+
const sharedComponentCodeGenerator = new SharedComponentCodeGenerator(
|
|
33
46
|
(filename) => {
|
|
34
47
|
return libraryCppOutput.copyWithNewSegment(
|
|
35
48
|
'react',
|
|
36
49
|
'renderer',
|
|
37
50
|
'components',
|
|
38
|
-
|
|
51
|
+
libraryCppName,
|
|
39
52
|
filename
|
|
40
53
|
);
|
|
41
|
-
}
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
const cppComponentCodeGenerator = new CppComponentCodeGenerator(
|
|
42
57
|
(filename) => {
|
|
43
58
|
return libraryCppOutput.copyWithNewSegment(
|
|
44
59
|
'RNOH',
|
|
@@ -46,19 +61,26 @@ export class UberGeneratorV2 implements CodeGenerator<LibraryData[]> {
|
|
|
46
61
|
'components',
|
|
47
62
|
filename
|
|
48
63
|
);
|
|
49
|
-
}
|
|
64
|
+
},
|
|
65
|
+
this.codegenNoticeLines
|
|
50
66
|
);
|
|
51
|
-
|
|
52
|
-
.generate({
|
|
67
|
+
cppComponentCodeGenerator
|
|
68
|
+
.generate({ libraryCppName, uberSchema })
|
|
53
69
|
.forEach((fileContent, path) => {
|
|
54
70
|
fileContentByPath.set(path, fileContent);
|
|
55
71
|
});
|
|
56
|
-
|
|
72
|
+
cppComponentCodeGenerator
|
|
57
73
|
.getGlueCodeData()
|
|
58
74
|
.forEach((componentGlueCodeData) => {
|
|
59
75
|
libraryGlueCodeData.components.push(componentGlueCodeData);
|
|
60
76
|
});
|
|
61
77
|
|
|
78
|
+
sharedComponentCodeGenerator
|
|
79
|
+
.generate({ libraryCppName, uberSchema })
|
|
80
|
+
.forEach((fileContent, path) => {
|
|
81
|
+
fileContentByPath.set(path, fileContent);
|
|
82
|
+
});
|
|
83
|
+
|
|
62
84
|
for (const [_fileName, specSchema] of uberSchema
|
|
63
85
|
.getSpecSchemaByFilenameMap()
|
|
64
86
|
.entries()) {
|
|
@@ -70,7 +92,8 @@ export class UberGeneratorV2 implements CodeGenerator<LibraryData[]> {
|
|
|
70
92
|
'turbo_modules'
|
|
71
93
|
),
|
|
72
94
|
this.etsOutputPath.copyWithNewSegment('turboModules'),
|
|
73
|
-
|
|
95
|
+
this.codegenNoticeLines,
|
|
96
|
+
'../../ts'
|
|
74
97
|
);
|
|
75
98
|
nativeModuleCodeGenerator
|
|
76
99
|
.generate(specSchema)
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
export * from './NativeModuleCodeGenerator';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
9
|
+
export * from './AppBuildTimeGlueCodeGenerator';
|
|
10
|
+
export * from './ArkTSComponentCodeGeneratorArkTS';
|
|
11
|
+
export * from './ArkTSComponentCodeGeneratorCAPI';
|
|
12
|
+
export * from './CppComponentCodeGenerator';
|
|
5
13
|
export * from './UberGeneratorV1';
|
|
6
14
|
export * from './UberGeneratorV2';
|
|
15
|
+
export * from './SharedComponentCodeGenerator';
|
package/src/codegen/index.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import mustache from 'mustache';
|
|
2
9
|
import Case from 'case';
|
|
3
10
|
import { TypeAnnotation } from '../core';
|
|
4
11
|
|
|
5
12
|
const TEMPLATE = `
|
|
6
13
|
/**
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
* lost once the code is regenerated.
|
|
11
|
-
*
|
|
12
|
-
* @generatorVersion: 2
|
|
14
|
+
{{#codegenNoticeLines}}
|
|
15
|
+
* {{{line}}}
|
|
16
|
+
{{/codegenNoticeLines}}
|
|
13
17
|
*/
|
|
18
|
+
|
|
14
19
|
#pragma once
|
|
15
20
|
|
|
16
21
|
#include "RNOH/CppComponentInstance.h"
|
|
@@ -45,7 +50,11 @@ type BaseComponentInstanceHCommand = {
|
|
|
45
50
|
export class BaseComponentInstanceHTemplate {
|
|
46
51
|
private commands: BaseComponentInstanceHCommand[] = [];
|
|
47
52
|
|
|
48
|
-
constructor(
|
|
53
|
+
constructor(
|
|
54
|
+
private componentName: string,
|
|
55
|
+
private libraryName: string,
|
|
56
|
+
private codegenNoticeLines: string[]
|
|
57
|
+
) {}
|
|
49
58
|
|
|
50
59
|
addCommand(command: BaseComponentInstanceHCommand) {
|
|
51
60
|
this.commands.push(command);
|
|
@@ -53,6 +62,9 @@ export class BaseComponentInstanceHTemplate {
|
|
|
53
62
|
|
|
54
63
|
build(): string {
|
|
55
64
|
return mustache.render(TEMPLATE, {
|
|
65
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
66
|
+
line,
|
|
67
|
+
})),
|
|
56
68
|
name: this.componentName,
|
|
57
69
|
libraryName: this.libraryName,
|
|
58
70
|
commands: this.commands.map(({ name, args }) => {
|