@react-native-oh/react-native-harmony-cli 0.0.26-9 → 0.0.27
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/dist/codegen/core/UberSchema.js +3 -0
- package/dist/codegen/generators/{GlueCodeGenerator.js → AppBuildTimeGlueCodeGenerator.js} +11 -10
- package/dist/codegen/generators/{ComponentCodeGeneratorArkTS.js → ArkTSComponentCodeGeneratorArkTS.js} +8 -6
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +74 -0
- package/dist/codegen/generators/{ComponentCodeGeneratorCAPI.js → CppComponentCodeGenerator.js} +10 -33
- package/dist/codegen/generators/LibGlueCodeGenerator.js +50 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +6 -5
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +34 -0
- package/dist/codegen/generators/UberGeneratorV1.js +7 -6
- package/dist/codegen/generators/UberGeneratorV2.js +25 -14
- package/dist/codegen/generators/index.js +5 -3
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +9 -7
- package/dist/codegen/templates/{GeneratedPackageHTemplate.js → BasePackageHTemplate.js} +40 -11
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +2 -1
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +9 -11
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +11 -8
- package/dist/codegen/templates/IndexTSTemplate.js +12 -9
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +1 -0
- package/dist/codegen/templates/TurboModuleCppTemplate.js +10 -10
- package/dist/codegen/templates/TurboModuleHTemplate.js +10 -10
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +11 -10
- package/dist/commands/codegen-harmony.js +11 -5
- package/dist/commands/codegen-lib-harmony.js +253 -0
- package/dist/commands/index.js +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/codegen/core/UberSchema.ts +4 -0
- package/src/codegen/generators/{GlueCodeGenerator.ts → AppBuildTimeGlueCodeGenerator.ts} +13 -9
- package/src/codegen/generators/{ComponentCodeGeneratorArkTS.ts → ArkTSComponentCodeGeneratorArkTS.ts} +11 -5
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +112 -0
- package/src/codegen/generators/{ComponentCodeGeneratorCAPI.ts → CppComponentCodeGenerator.ts} +14 -43
- package/src/codegen/generators/LibGlueCodeGenerator.ts +91 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +7 -5
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +50 -0
- package/src/codegen/generators/UberGeneratorV1.ts +12 -8
- package/src/codegen/generators/UberGeneratorV2.ts +32 -16
- package/src/codegen/generators/index.ts +5 -3
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +12 -7
- package/src/codegen/templates/{GeneratedPackageHTemplate.ts → BasePackageHTemplate.ts} +45 -12
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +2 -1
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +8 -10
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +13 -8
- package/src/codegen/templates/IndexTSTemplate.ts +11 -9
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +1 -0
- package/src/codegen/templates/TurboModuleCppTemplate.ts +9 -9
- package/src/codegen/templates/TurboModuleHTemplate.ts +9 -9
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +13 -9
- package/src/commands/codegen-harmony.ts +24 -7
- package/src/commands/codegen-lib-harmony.ts +387 -0
- package/src/commands/index.ts +1 -0
- package/src/index.ts +2 -0
|
@@ -24,6 +24,9 @@ function createRawUberSchemaFromSpecFilePaths(projectSourceFilePaths) {
|
|
|
24
24
|
* Contains component and turbo module (NativeModule) schemas. The "Uber" word is used here to highlight that SpecSchemas don't extend this class.
|
|
25
25
|
*/
|
|
26
26
|
class UberSchema {
|
|
27
|
+
static fromSpecFilePaths(specPaths) {
|
|
28
|
+
return new UberSchema(createRawUberSchemaFromSpecFilePaths(specPaths));
|
|
29
|
+
}
|
|
27
30
|
static fromCodegenConfig(codegenConfig) {
|
|
28
31
|
try {
|
|
29
32
|
return new UberSchema(createRawUberSchemaFromSpecFilePaths(codegenConfig.getSpecFilePaths()));
|
|
@@ -3,25 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.AppBuildTimeGlueCodeGenerator = void 0;
|
|
7
7
|
const case_1 = __importDefault(require("case"));
|
|
8
8
|
const templates_1 = require("../templates");
|
|
9
|
-
const
|
|
9
|
+
const BasePackageHTemplate_1 = require("../templates/BasePackageHTemplate");
|
|
10
10
|
/**
|
|
11
11
|
* Generates code based on UberGenerators results. If UberGenerators produce "leaves" (concrete turbo module or component classes),
|
|
12
12
|
* this class generates "branches" (barrel files like index.ts) and "trunks" (package file or files).
|
|
13
13
|
*/
|
|
14
|
-
class
|
|
15
|
-
constructor(cppOutputPath, etsOutputPath) {
|
|
14
|
+
class AppBuildTimeGlueCodeGenerator {
|
|
15
|
+
constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
|
|
16
16
|
this.cppOutputPath = cppOutputPath;
|
|
17
17
|
this.etsOutputPath = etsOutputPath;
|
|
18
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
18
19
|
}
|
|
19
20
|
generate({ v1, v2 }) {
|
|
20
21
|
const fileContentByPath = new Map();
|
|
21
22
|
const generatedPackageH_v1 = new templates_1.RNOHGeneratedPackageHTemplate();
|
|
22
|
-
const components_indexTS = new templates_1.IndexTSTemplate();
|
|
23
|
-
const turboModules_indexTS = new templates_1.IndexTSTemplate();
|
|
24
|
-
const generated_indexETS = new templates_1.IndexTSTemplate();
|
|
23
|
+
const components_indexTS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
|
|
24
|
+
const turboModules_indexTS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
|
|
25
|
+
const generated_indexETS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
|
|
25
26
|
generated_indexETS.addReexport({ from: './ts' });
|
|
26
27
|
v1.components.forEach(({ name, eventNames }) => {
|
|
27
28
|
components_indexTS.addReexport({ from: `./${name}` });
|
|
@@ -36,7 +37,7 @@ class GlueCodeGenerator {
|
|
|
36
37
|
});
|
|
37
38
|
v2.forEach(({ components, turboModules }, libraryName) => {
|
|
38
39
|
const basePackageClassName = `Base${case_1.default.pascal(libraryName)}Package`;
|
|
39
|
-
const generatedPackageH_v2 = new
|
|
40
|
+
const generatedPackageH_v2 = new BasePackageHTemplate_1.BasePackageHTemplate(basePackageClassName, this.codegenNoticeLines);
|
|
40
41
|
components.forEach((component) => {
|
|
41
42
|
generatedPackageH_v2.addComponent(component);
|
|
42
43
|
});
|
|
@@ -47,7 +48,7 @@ class GlueCodeGenerator {
|
|
|
47
48
|
fileContentByPath.set(this.cppOutputPath.copyWithNewSegment(libraryName, 'RNOH', 'generated', `${basePackageClassName}.h`), generatedPackageH_v2.build());
|
|
48
49
|
});
|
|
49
50
|
fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOHGeneratedPackage.h'), generatedPackageH_v1.build());
|
|
50
|
-
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('ts.ts'), new templates_1.IndexTSTemplate()
|
|
51
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('ts.ts'), new templates_1.IndexTSTemplate(this.codegenNoticeLines)
|
|
51
52
|
.addReexport({ from: './components/ts', as: 'RNC' })
|
|
52
53
|
.addReexport({ from: './turboModules/ts', as: 'TM' })
|
|
53
54
|
.build());
|
|
@@ -57,4 +58,4 @@ class GlueCodeGenerator {
|
|
|
57
58
|
return fileContentByPath;
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
exports.
|
|
61
|
+
exports.AppBuildTimeGlueCodeGenerator = AppBuildTimeGlueCodeGenerator;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ArkTSComponentCodeGeneratorArkTS = void 0;
|
|
4
4
|
const core_1 = require("../core");
|
|
5
5
|
const templates_1 = require("../templates");
|
|
6
|
-
class
|
|
7
|
-
constructor(cppOutputPath, tsOutputPath) {
|
|
6
|
+
class ArkTSComponentCodeGeneratorArkTS {
|
|
7
|
+
constructor(cppOutputPath, tsOutputPath, codegenNoticeLines, rnohImport) {
|
|
8
8
|
this.cppOutputPath = cppOutputPath;
|
|
9
9
|
this.tsOutputPath = tsOutputPath;
|
|
10
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
11
|
+
this.rnohImport = rnohImport;
|
|
10
12
|
this.glueCodeDataItems = [];
|
|
11
13
|
}
|
|
12
14
|
getGlueCodeData() {
|
|
@@ -23,8 +25,8 @@ class ComponentCodeGeneratorArkTS {
|
|
|
23
25
|
const result = new Map();
|
|
24
26
|
Object.entries(schema.components).map(([name, shape]) => {
|
|
25
27
|
const componentDescriptorHTemplate = new templates_1.ComponentDescriptorHTemplate(name);
|
|
26
|
-
const componentJSIBinderHTemplate = new templates_1.ComponentJSIBinderHTemplate(name,
|
|
27
|
-
const componentUtilsTSTemplate = new templates_1.ComponentUtilsTSTemplate(name);
|
|
28
|
+
const componentJSIBinderHTemplate = new templates_1.ComponentJSIBinderHTemplate(name, this.codegenNoticeLines);
|
|
29
|
+
const componentUtilsTSTemplate = new templates_1.ComponentUtilsTSTemplate(name, this.codegenNoticeLines, this.rnohImport);
|
|
28
30
|
shape.props.forEach((prop) => {
|
|
29
31
|
componentJSIBinderHTemplate.addProp({
|
|
30
32
|
name: prop.name,
|
|
@@ -71,4 +73,4 @@ class ComponentCodeGeneratorArkTS {
|
|
|
71
73
|
return result;
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
|
-
exports.
|
|
76
|
+
exports.ArkTSComponentCodeGeneratorArkTS = ArkTSComponentCodeGeneratorArkTS;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArkTSComponentCodeGeneratorCAPI = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
const templates_1 = require("../templates");
|
|
6
|
+
/**
|
|
7
|
+
* Generates component code for ArkTS components used in C-API architecture.
|
|
8
|
+
*/
|
|
9
|
+
class ArkTSComponentCodeGeneratorCAPI {
|
|
10
|
+
constructor(cppOutputPath, tsOutputPath, codegenNoticeLines, rnohImport) {
|
|
11
|
+
this.cppOutputPath = cppOutputPath;
|
|
12
|
+
this.tsOutputPath = tsOutputPath;
|
|
13
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
14
|
+
this.rnohImport = rnohImport;
|
|
15
|
+
this.glueCodeDataItems = [];
|
|
16
|
+
}
|
|
17
|
+
getLibGlueCodeData() {
|
|
18
|
+
return this.glueCodeDataItems;
|
|
19
|
+
}
|
|
20
|
+
generate(uberSchema) {
|
|
21
|
+
const typeAnnotationToTS = new core_1.TypeAnnotationToTS();
|
|
22
|
+
const result = new Map();
|
|
23
|
+
const componentSpecSchemas = uberSchema.findAllSpecSchemasByType('Component');
|
|
24
|
+
for (const componentSpecSchema of componentSpecSchemas) {
|
|
25
|
+
Object.entries(componentSpecSchema.components).map(([name, shape]) => {
|
|
26
|
+
const componentJSIBinderHTemplate = new templates_1.ComponentJSIBinderHTemplate(name, this.codegenNoticeLines);
|
|
27
|
+
const componentUtilsTSTemplate = new templates_1.ComponentUtilsTSTemplate(name, this.codegenNoticeLines, this.rnohImport);
|
|
28
|
+
shape.props.forEach((prop) => {
|
|
29
|
+
componentJSIBinderHTemplate.addProp({
|
|
30
|
+
name: prop.name,
|
|
31
|
+
isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
|
|
32
|
+
});
|
|
33
|
+
componentUtilsTSTemplate.addProp({
|
|
34
|
+
name: prop.name,
|
|
35
|
+
tsType: typeAnnotationToTS.convert(prop.typeAnnotation),
|
|
36
|
+
defaultValue: (0, core_1.getStringifiedTSDefaultValueFromPropTypeAnnotation)(prop.typeAnnotation),
|
|
37
|
+
isOptional: prop.optional,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
shape.commands.forEach((command) => {
|
|
41
|
+
componentUtilsTSTemplate.addCommand({
|
|
42
|
+
name: command.name,
|
|
43
|
+
argsTSType: '[' +
|
|
44
|
+
command.typeAnnotation.params
|
|
45
|
+
.map((param) => typeAnnotationToTS.convert(param.typeAnnotation) +
|
|
46
|
+
(param.optional ? '?' : ''))
|
|
47
|
+
.join(', ') +
|
|
48
|
+
']',
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
shape.events.forEach((event) => {
|
|
52
|
+
componentUtilsTSTemplate.addEvent({
|
|
53
|
+
name: (0, core_1.createEventNameFromEventHandlerName)(event.name),
|
|
54
|
+
payloadTSType: event.typeAnnotation.argument
|
|
55
|
+
? typeAnnotationToTS.convert(event.typeAnnotation.argument)
|
|
56
|
+
: 'undefined',
|
|
57
|
+
});
|
|
58
|
+
componentJSIBinderHTemplate.addEvent({
|
|
59
|
+
type: event.bubblingType,
|
|
60
|
+
eventHandlerName: event.name,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
result.set(this.cppOutputPath.copyWithNewSegment(`${name}JSIBinder.h`), componentJSIBinderHTemplate.build());
|
|
64
|
+
result.set(this.tsOutputPath.copyWithNewSegment(`${name}.ts`), componentUtilsTSTemplate.build());
|
|
65
|
+
this.glueCodeDataItems.push({
|
|
66
|
+
componentName: name,
|
|
67
|
+
eventNames: shape.events.map((event) => (0, core_1.createEventNameFromEventHandlerName)(event.name)),
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.ArkTSComponentCodeGeneratorCAPI = ArkTSComponentCodeGeneratorCAPI;
|
package/dist/codegen/generators/{ComponentCodeGeneratorCAPI.js → CppComponentCodeGenerator.js}
RENAMED
|
@@ -1,48 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const RNCodegen_1 = __importDefault(require("@react-native/codegen/lib/generators/RNCodegen"));
|
|
3
|
+
exports.CppComponentCodeGenerator = void 0;
|
|
8
4
|
const templates_1 = require("../templates");
|
|
9
|
-
class
|
|
10
|
-
constructor(
|
|
11
|
-
/// "shared" — platform independent code that can be shared between platforms
|
|
12
|
-
onGetSharedOutputPath, onGetRNOHOutputPath) {
|
|
13
|
-
this.onGetSharedOutputPath = onGetSharedOutputPath;
|
|
5
|
+
class CppComponentCodeGenerator {
|
|
6
|
+
constructor(onGetRNOHOutputPath, codegenNoticeLines) {
|
|
14
7
|
this.onGetRNOHOutputPath = onGetRNOHOutputPath;
|
|
8
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
15
9
|
this.glueCodeComponentsData = [];
|
|
16
10
|
}
|
|
17
11
|
getGlueCodeData() {
|
|
18
12
|
return this.glueCodeComponentsData;
|
|
19
13
|
}
|
|
20
|
-
generate({
|
|
14
|
+
generate({ libraryCppName, uberSchema, }) {
|
|
21
15
|
const fileContentByPath = new Map();
|
|
22
|
-
const
|
|
23
|
-
RNCodegen_1.default.allGenerators.generatePropsH,
|
|
24
|
-
RNCodegen_1.default.allGenerators.generatePropsCpp,
|
|
25
|
-
RNCodegen_1.default.allGenerators.generateEventEmitterH,
|
|
26
|
-
RNCodegen_1.default.allGenerators.generateEventEmitterCpp,
|
|
27
|
-
RNCodegen_1.default.allGenerators.generateComponentDescriptorH,
|
|
28
|
-
RNCodegen_1.default.allGenerators.generateStateH,
|
|
29
|
-
RNCodegen_1.default.allGenerators.generateStateCpp,
|
|
30
|
-
RNCodegen_1.default.allGenerators.generateShadowNodeH,
|
|
31
|
-
RNCodegen_1.default.allGenerators.generateShadowNodeCpp,
|
|
32
|
-
];
|
|
33
|
-
generatorFns.forEach((generate) => {
|
|
34
|
-
const filesOutput = generate(libraryName, uberSchema.getValue(), 'UNUSED_packageName', true);
|
|
35
|
-
filesOutput.forEach((fileContent, filename) => {
|
|
36
|
-
fileContentByPath.set(this.onGetSharedOutputPath(filename), fileContent);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
for (const [filename, schema] of uberSchema
|
|
16
|
+
for (const [_filename, schema] of uberSchema
|
|
40
17
|
.getSpecSchemaByFilenameMap()
|
|
41
18
|
.entries()) {
|
|
42
19
|
if (schema.type === 'Component') {
|
|
43
20
|
Object.entries(schema.components).map(([componentName, shape]) => {
|
|
44
|
-
const componentJSIBinderHTemplate = new templates_1.ComponentJSIBinderHTemplate(componentName,
|
|
45
|
-
const componentInstanceSpecHTemplate = new templates_1.BaseComponentInstanceHTemplate(componentName,
|
|
21
|
+
const componentJSIBinderHTemplate = new templates_1.ComponentJSIBinderHTemplate(componentName, this.codegenNoticeLines);
|
|
22
|
+
const componentInstanceSpecHTemplate = new templates_1.BaseComponentInstanceHTemplate(componentName, libraryCppName, this.codegenNoticeLines);
|
|
46
23
|
shape.props.forEach((prop) => {
|
|
47
24
|
componentJSIBinderHTemplate.addProp({
|
|
48
25
|
name: prop.name,
|
|
@@ -68,7 +45,7 @@ class ComponentCodeGeneratorCAPI {
|
|
|
68
45
|
fileContentByPath.set(this.onGetRNOHOutputPath(`Base${componentName}ComponentInstance.h`), componentInstanceSpecHTemplate.build());
|
|
69
46
|
this.glueCodeComponentsData.push({
|
|
70
47
|
name: componentName,
|
|
71
|
-
|
|
48
|
+
libraryCppName,
|
|
72
49
|
});
|
|
73
50
|
});
|
|
74
51
|
}
|
|
@@ -76,4 +53,4 @@ class ComponentCodeGeneratorCAPI {
|
|
|
76
53
|
return fileContentByPath;
|
|
77
54
|
}
|
|
78
55
|
}
|
|
79
|
-
exports.
|
|
56
|
+
exports.CppComponentCodeGenerator = CppComponentCodeGenerator;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LibGlueCodeGenerator = void 0;
|
|
7
|
+
const case_1 = __importDefault(require("case"));
|
|
8
|
+
const BasePackageHTemplate_1 = require("../templates/BasePackageHTemplate");
|
|
9
|
+
const templates_1 = require("../templates");
|
|
10
|
+
/**
|
|
11
|
+
* NOTE: This class is coupled with the generated code structure defined in the codegen-harmony-lib.
|
|
12
|
+
*/
|
|
13
|
+
class LibGlueCodeGenerator {
|
|
14
|
+
constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
|
|
15
|
+
this.cppOutputPath = cppOutputPath;
|
|
16
|
+
this.etsOutputPath = etsOutputPath;
|
|
17
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
18
|
+
}
|
|
19
|
+
generate({ libraryCppName, turboModules, arkTSComponents, cppComponents, }) {
|
|
20
|
+
const fileContentByPath = new Map();
|
|
21
|
+
const basePackageClassName = `Base${case_1.default.pascal(libraryCppName)}Package`;
|
|
22
|
+
const turboModules_indexTS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
|
|
23
|
+
const components_indexTS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
|
|
24
|
+
const generated_indexETS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
|
|
25
|
+
const basePackageTemplate = new BasePackageHTemplate_1.BasePackageHTemplate(basePackageClassName, this.codegenNoticeLines);
|
|
26
|
+
turboModules.forEach((turboModule) => {
|
|
27
|
+
basePackageTemplate.addTurboModule(turboModule);
|
|
28
|
+
turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
|
|
29
|
+
});
|
|
30
|
+
arkTSComponents.forEach(({ componentName, eventNames }) => {
|
|
31
|
+
components_indexTS.addReexport({ from: `./${componentName}` });
|
|
32
|
+
basePackageTemplate.addComponent({ name: componentName, libraryCppName });
|
|
33
|
+
eventNames.forEach((eventName) => basePackageTemplate.addArkTSEvent({ name: eventName }));
|
|
34
|
+
});
|
|
35
|
+
cppComponents.forEach(({ componentName }) => {
|
|
36
|
+
basePackageTemplate.addComponent({ name: componentName, libraryCppName });
|
|
37
|
+
});
|
|
38
|
+
fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOH', 'generated', `${basePackageClassName}.h`), basePackageTemplate.build());
|
|
39
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'), components_indexTS.build());
|
|
40
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'), turboModules_indexTS.build());
|
|
41
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('ts.ts'), new templates_1.IndexTSTemplate(this.codegenNoticeLines)
|
|
42
|
+
.addReexport({ from: './components/ts', as: 'RNC' })
|
|
43
|
+
.addReexport({ from: './turboModules/ts', as: 'TM' })
|
|
44
|
+
.build());
|
|
45
|
+
generated_indexETS.addReexport({ from: './ts' });
|
|
46
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('index.ets'), generated_indexETS.build());
|
|
47
|
+
return fileContentByPath;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.LibGlueCodeGenerator = LibGlueCodeGenerator;
|
|
@@ -7,10 +7,11 @@ const core_1 = require("../core");
|
|
|
7
7
|
* Generates boilerplate code for Turbo Modules.
|
|
8
8
|
*/
|
|
9
9
|
class NativeModuleCodeGenerator {
|
|
10
|
-
constructor(cppOutputPath, etsOutputPath,
|
|
10
|
+
constructor(cppOutputPath, etsOutputPath, codegenNoticeLines, rnohImport) {
|
|
11
11
|
this.cppOutputPath = cppOutputPath;
|
|
12
12
|
this.etsOutputPath = etsOutputPath;
|
|
13
|
-
this.
|
|
13
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
14
|
+
this.rnohImport = rnohImport;
|
|
14
15
|
this.glueCodeTurboModulesData = [];
|
|
15
16
|
}
|
|
16
17
|
getGlueCodeData() {
|
|
@@ -25,10 +26,10 @@ class NativeModuleCodeGenerator {
|
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
28
|
const typeAnnotationToTS = new core_1.TypeAnnotationToTS();
|
|
28
|
-
const turboModuleInterfaceTS = new templates_1.TurboModuleInterfaceTS(schema.moduleName, this.
|
|
29
|
-
const turboModuleH = new templates_1.TurboModuleHTemplate(schema.moduleName, this.
|
|
29
|
+
const turboModuleInterfaceTS = new templates_1.TurboModuleInterfaceTS(schema.moduleName, this.codegenNoticeLines, this.rnohImport);
|
|
30
|
+
const turboModuleH = new templates_1.TurboModuleHTemplate(schema.moduleName, this.codegenNoticeLines).build();
|
|
30
31
|
result.set(this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.h`), turboModuleH);
|
|
31
|
-
const turboModuleCpp = new templates_1.TurboModuleCppTemplate(schema.moduleName, this.
|
|
32
|
+
const turboModuleCpp = new templates_1.TurboModuleCppTemplate(schema.moduleName, this.codegenNoticeLines);
|
|
32
33
|
Object.entries(schema.aliasMap).map(([name, typeAnnotation]) => {
|
|
33
34
|
turboModuleInterfaceTS.addAlias({
|
|
34
35
|
name: name,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SharedComponentCodeGenerator = void 0;
|
|
7
|
+
const RNCodegen_1 = __importDefault(require("@react-native/codegen/lib/generators/RNCodegen"));
|
|
8
|
+
class SharedComponentCodeGenerator {
|
|
9
|
+
constructor(onGetSharedOutputPath) {
|
|
10
|
+
this.onGetSharedOutputPath = onGetSharedOutputPath;
|
|
11
|
+
}
|
|
12
|
+
generate({ libraryCppName, uberSchema, }) {
|
|
13
|
+
const fileContentByPath = new Map();
|
|
14
|
+
const generatorFns = [
|
|
15
|
+
RNCodegen_1.default.allGenerators.generatePropsH,
|
|
16
|
+
RNCodegen_1.default.allGenerators.generatePropsCpp,
|
|
17
|
+
RNCodegen_1.default.allGenerators.generateEventEmitterH,
|
|
18
|
+
RNCodegen_1.default.allGenerators.generateEventEmitterCpp,
|
|
19
|
+
RNCodegen_1.default.allGenerators.generateComponentDescriptorH,
|
|
20
|
+
RNCodegen_1.default.allGenerators.generateStateH,
|
|
21
|
+
RNCodegen_1.default.allGenerators.generateStateCpp,
|
|
22
|
+
RNCodegen_1.default.allGenerators.generateShadowNodeH,
|
|
23
|
+
RNCodegen_1.default.allGenerators.generateShadowNodeCpp,
|
|
24
|
+
];
|
|
25
|
+
generatorFns.forEach((generate) => {
|
|
26
|
+
const filesOutput = generate(libraryCppName, uberSchema.getValue(), 'UNUSED_packageName', true);
|
|
27
|
+
filesOutput.forEach((fileContent, filename) => {
|
|
28
|
+
fileContentByPath.set(this.onGetSharedOutputPath(filename), fileContent);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return fileContentByPath;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.SharedComponentCodeGenerator = SharedComponentCodeGenerator;
|
|
@@ -3,14 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.UberGeneratorV1 = void 0;
|
|
4
4
|
const core_1 = require("../core");
|
|
5
5
|
const NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
|
|
6
|
-
const
|
|
6
|
+
const ArkTSComponentCodeGeneratorArkTS_1 = require("./ArkTSComponentCodeGeneratorArkTS");
|
|
7
7
|
/**
|
|
8
8
|
* Generates code for libraries built on top of RNOH's ArkTS architecture.
|
|
9
9
|
*/
|
|
10
10
|
class UberGeneratorV1 {
|
|
11
|
-
constructor(cppOutputPath, etsOutputPath) {
|
|
11
|
+
constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
|
|
12
12
|
this.cppOutputPath = cppOutputPath;
|
|
13
13
|
this.etsOutputPath = etsOutputPath;
|
|
14
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
14
15
|
this.glueCodeData = { components: [], turboModules: [] };
|
|
15
16
|
}
|
|
16
17
|
getGlueCodeData() {
|
|
@@ -18,10 +19,10 @@ class UberGeneratorV1 {
|
|
|
18
19
|
}
|
|
19
20
|
generate(uberSchema) {
|
|
20
21
|
const fileContentByPath = new Map();
|
|
21
|
-
const
|
|
22
|
-
const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('turboModules'),
|
|
22
|
+
const componentCodeGenerator = new ArkTSComponentCodeGeneratorArkTS_1.ArkTSComponentCodeGeneratorArkTS(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('components'), this.codegenNoticeLines, '../../ts');
|
|
23
|
+
const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('turboModules'), this.codegenNoticeLines, '../../ts');
|
|
23
24
|
const generatorBySpecType = {
|
|
24
|
-
Component:
|
|
25
|
+
Component: componentCodeGenerator,
|
|
25
26
|
NativeModule: nativeModuleCodeGenerator,
|
|
26
27
|
};
|
|
27
28
|
for (const [_fileName, specSchema] of uberSchema
|
|
@@ -40,7 +41,7 @@ class UberGeneratorV1 {
|
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
43
|
this.glueCodeData = {
|
|
43
|
-
components:
|
|
44
|
+
components: componentCodeGenerator.getGlueCodeData(),
|
|
44
45
|
turboModules: nativeModuleCodeGenerator.getGlueCodeData(),
|
|
45
46
|
};
|
|
46
47
|
return fileContentByPath;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UberGeneratorV2 = void 0;
|
|
4
|
-
const
|
|
4
|
+
const CppComponentCodeGenerator_1 = require("./CppComponentCodeGenerator");
|
|
5
5
|
const NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
|
|
6
|
+
const SharedComponentCodeGenerator_1 = require("./SharedComponentCodeGenerator");
|
|
6
7
|
/**
|
|
7
8
|
* Generates code for libraries built on top of RNOH's C-API architecture.
|
|
8
9
|
*/
|
|
9
10
|
class UberGeneratorV2 {
|
|
10
|
-
constructor(cppOutputPath, etsOutputPath) {
|
|
11
|
+
constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
|
|
11
12
|
this.cppOutputPath = cppOutputPath;
|
|
12
13
|
this.etsOutputPath = etsOutputPath;
|
|
14
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
13
15
|
this.glueCodeData = new Map();
|
|
14
16
|
}
|
|
15
17
|
getGlueCodeData() {
|
|
@@ -17,30 +19,39 @@ class UberGeneratorV2 {
|
|
|
17
19
|
}
|
|
18
20
|
generate(npmPackagesInfo) {
|
|
19
21
|
const fileContentByPath = new Map();
|
|
20
|
-
npmPackagesInfo.forEach(({
|
|
21
|
-
this.glueCodeData.set(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
npmPackagesInfo.forEach(({ libraryCppName, uberSchema }) => {
|
|
23
|
+
this.glueCodeData.set(libraryCppName, {
|
|
24
|
+
components: [],
|
|
25
|
+
turboModules: [],
|
|
26
|
+
});
|
|
27
|
+
const libraryGlueCodeData = this.glueCodeData.get(libraryCppName);
|
|
28
|
+
const libraryCppOutput = this.cppOutputPath.copyWithNewSegment(libraryCppName);
|
|
29
|
+
const sharedComponentCodeGenerator = new SharedComponentCodeGenerator_1.SharedComponentCodeGenerator((filename) => {
|
|
30
|
+
return libraryCppOutput.copyWithNewSegment('react', 'renderer', 'components', libraryCppName, filename);
|
|
28
31
|
});
|
|
29
|
-
|
|
30
|
-
.
|
|
32
|
+
const cppComponentCodeGenerator = new CppComponentCodeGenerator_1.CppComponentCodeGenerator((filename) => {
|
|
33
|
+
return libraryCppOutput.copyWithNewSegment('RNOH', 'generated', 'components', filename);
|
|
34
|
+
}, this.codegenNoticeLines);
|
|
35
|
+
cppComponentCodeGenerator
|
|
36
|
+
.generate({ libraryCppName, uberSchema })
|
|
31
37
|
.forEach((fileContent, path) => {
|
|
32
38
|
fileContentByPath.set(path, fileContent);
|
|
33
39
|
});
|
|
34
|
-
|
|
40
|
+
cppComponentCodeGenerator
|
|
35
41
|
.getGlueCodeData()
|
|
36
42
|
.forEach((componentGlueCodeData) => {
|
|
37
43
|
libraryGlueCodeData.components.push(componentGlueCodeData);
|
|
38
44
|
});
|
|
45
|
+
sharedComponentCodeGenerator
|
|
46
|
+
.generate({ libraryCppName, uberSchema })
|
|
47
|
+
.forEach((fileContent, path) => {
|
|
48
|
+
fileContentByPath.set(path, fileContent);
|
|
49
|
+
});
|
|
39
50
|
for (const [_fileName, specSchema] of uberSchema
|
|
40
51
|
.getSpecSchemaByFilenameMap()
|
|
41
52
|
.entries()) {
|
|
42
53
|
if (specSchema.type === 'NativeModule') {
|
|
43
|
-
const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(libraryCppOutput.copyWithNewSegment('RNOH', 'generated', 'turbo_modules'), this.etsOutputPath.copyWithNewSegment('turboModules'),
|
|
54
|
+
const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(libraryCppOutput.copyWithNewSegment('RNOH', 'generated', 'turbo_modules'), this.etsOutputPath.copyWithNewSegment('turboModules'), this.codegenNoticeLines, '../../ts');
|
|
44
55
|
nativeModuleCodeGenerator
|
|
45
56
|
.generate(specSchema)
|
|
46
57
|
.forEach((fileContent, filePath) => {
|
|
@@ -15,8 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./NativeModuleCodeGenerator"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./AppBuildTimeGlueCodeGenerator"), exports);
|
|
19
|
+
__exportStar(require("./ArkTSComponentCodeGeneratorArkTS"), exports);
|
|
20
|
+
__exportStar(require("./ArkTSComponentCodeGeneratorCAPI"), exports);
|
|
21
|
+
__exportStar(require("./CppComponentCodeGenerator"), exports);
|
|
21
22
|
__exportStar(require("./UberGeneratorV1"), exports);
|
|
22
23
|
__exportStar(require("./UberGeneratorV2"), exports);
|
|
24
|
+
__exportStar(require("./SharedComponentCodeGenerator"), exports);
|
|
@@ -8,13 +8,11 @@ const mustache_1 = __importDefault(require("mustache"));
|
|
|
8
8
|
const case_1 = __importDefault(require("case"));
|
|
9
9
|
const TEMPLATE = `
|
|
10
10
|
/**
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
* lost once the code is regenerated.
|
|
15
|
-
*
|
|
16
|
-
* @generatorVersion: 2
|
|
11
|
+
{{#codegenNoticeLines}}
|
|
12
|
+
* {{{line}}}
|
|
13
|
+
{{/codegenNoticeLines}}
|
|
17
14
|
*/
|
|
15
|
+
|
|
18
16
|
#pragma once
|
|
19
17
|
|
|
20
18
|
#include "RNOH/CppComponentInstance.h"
|
|
@@ -41,9 +39,10 @@ namespace rnoh {
|
|
|
41
39
|
} // namespace rnoh
|
|
42
40
|
`;
|
|
43
41
|
class BaseComponentInstanceHTemplate {
|
|
44
|
-
constructor(componentName, libraryName) {
|
|
42
|
+
constructor(componentName, libraryName, codegenNoticeLines) {
|
|
45
43
|
this.componentName = componentName;
|
|
46
44
|
this.libraryName = libraryName;
|
|
45
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
47
46
|
this.commands = [];
|
|
48
47
|
}
|
|
49
48
|
addCommand(command) {
|
|
@@ -51,6 +50,9 @@ class BaseComponentInstanceHTemplate {
|
|
|
51
50
|
}
|
|
52
51
|
build() {
|
|
53
52
|
return mustache_1.default.render(TEMPLATE, {
|
|
53
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
54
|
+
line,
|
|
55
|
+
})),
|
|
54
56
|
name: this.componentName,
|
|
55
57
|
libraryName: this.libraryName,
|
|
56
58
|
commands: this.commands.map(({ name, args }) => {
|
|
@@ -7,13 +7,11 @@ exports.BasePackageHTemplate = void 0;
|
|
|
7
7
|
const mustache_1 = __importDefault(require("mustache"));
|
|
8
8
|
const TEMPLATE = `
|
|
9
9
|
/**
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
* lost once the code is regenerated.
|
|
14
|
-
*
|
|
15
|
-
* @generatorVersion: 2
|
|
10
|
+
{{#codegenNoticeLines}}
|
|
11
|
+
* {{{line}}}
|
|
12
|
+
{{/codegenNoticeLines}}
|
|
16
13
|
*/
|
|
14
|
+
|
|
17
15
|
#pragma once
|
|
18
16
|
|
|
19
17
|
{{#libraries}}
|
|
@@ -42,6 +40,26 @@ class {{name}}TurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
|
42
40
|
};
|
|
43
41
|
};
|
|
44
42
|
|
|
43
|
+
class {{name}}EventEmitRequestHandler : public EventEmitRequestHandler {
|
|
44
|
+
public:
|
|
45
|
+
void handleEvent(Context const &ctx) override {
|
|
46
|
+
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
47
|
+
if (eventEmitter == nullptr) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
std::vector<std::string> supportedEventNames = {
|
|
52
|
+
{{#arkTSEvents}}
|
|
53
|
+
"{{name}}",
|
|
54
|
+
{{/arkTSEvents}}
|
|
55
|
+
};
|
|
56
|
+
if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
57
|
+
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
|
|
45
63
|
class {{name}} : public Package {
|
|
46
64
|
public:
|
|
47
65
|
{{name}}(Package::Context ctx) : Package(ctx){};
|
|
@@ -67,32 +85,43 @@ class {{name}} : public Package {
|
|
|
67
85
|
};
|
|
68
86
|
|
|
69
87
|
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
70
|
-
return {
|
|
88
|
+
return {
|
|
89
|
+
std::make_shared<{{name}}EventEmitRequestHandler>(),
|
|
90
|
+
};
|
|
71
91
|
}
|
|
72
92
|
};
|
|
73
93
|
|
|
74
94
|
} // namespace rnoh
|
|
75
95
|
`;
|
|
76
96
|
class BasePackageHTemplate {
|
|
77
|
-
constructor(name) {
|
|
97
|
+
constructor(name, codegenNoticeLines) {
|
|
78
98
|
this.name = name;
|
|
99
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
79
100
|
this.turboModules = [];
|
|
80
101
|
this.components = [];
|
|
81
|
-
this.
|
|
102
|
+
this.arkTSEvents = [];
|
|
103
|
+
this.libraryCppNames = new Set();
|
|
82
104
|
}
|
|
83
105
|
addTurboModule(turboModule) {
|
|
84
106
|
this.turboModules.push(turboModule);
|
|
85
107
|
}
|
|
86
108
|
addComponent(component) {
|
|
87
109
|
this.components.push(component);
|
|
88
|
-
this.
|
|
110
|
+
this.libraryCppNames.add(component.libraryCppName);
|
|
111
|
+
}
|
|
112
|
+
addArkTSEvent(arkTSEvent) {
|
|
113
|
+
this.arkTSEvents.push(arkTSEvent);
|
|
89
114
|
}
|
|
90
115
|
build() {
|
|
91
116
|
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
117
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
118
|
+
line,
|
|
119
|
+
})),
|
|
92
120
|
name: this.name,
|
|
93
121
|
turboModules: this.turboModules,
|
|
94
122
|
components: this.components,
|
|
95
|
-
|
|
123
|
+
arkTSEvents: this.arkTSEvents,
|
|
124
|
+
libraries: Array.from(this.libraryCppNames).map((name) => ({
|
|
96
125
|
name,
|
|
97
126
|
})),
|
|
98
127
|
});
|
|
@@ -14,6 +14,7 @@ const TEMPLATE = `
|
|
|
14
14
|
*
|
|
15
15
|
* @generatorVersion: 1
|
|
16
16
|
*/
|
|
17
|
+
|
|
17
18
|
#pragma once
|
|
18
19
|
|
|
19
20
|
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
@@ -23,7 +24,7 @@ const TEMPLATE = `
|
|
|
23
24
|
namespace facebook {
|
|
24
25
|
namespace react {
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
constexpr char {{name}}ComponentName[] = "{{name}}";
|
|
27
28
|
|
|
28
29
|
class {{name}}Props : public ViewProps {
|
|
29
30
|
public:
|