@react-native-oh/react-native-harmony-cli 0.0.16 → 0.0.24
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/Codegen.js +35 -0
- package/dist/codegen/core/CodegenError.js +7 -0
- package/dist/codegen/core/EventUtils.js +19 -0
- package/dist/codegen/core/TypeAnnotationToTS.js +132 -0
- package/dist/codegen/core/UberSchema.js +74 -0
- package/dist/codegen/core/index.js +21 -0
- package/dist/codegen/generators/ComponentCodeGenerator.js +66 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +64 -0
- package/dist/codegen/generators/PackageCodeGenerator.js +52 -0
- package/dist/codegen/generators/index.js +19 -0
- package/dist/codegen/index.js +18 -0
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +55 -0
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +78 -0
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +181 -0
- package/dist/codegen/templates/IndexTSTemplate.js +31 -0
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +117 -0
- package/dist/codegen/templates/TurboModuleCppTemplate.js +45 -0
- package/dist/codegen/templates/TurboModuleHTemplate.js +32 -0
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +64 -0
- package/dist/codegen/templates/index.js +24 -0
- package/dist/commands/codegen-harmony.js +110 -0
- package/dist/commands/create-metro-host-constants.js +61 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/pack-harmony.js +4 -1
- package/dist/commands/unpack-harmony.js +86 -43
- package/dist/core/AbsolutePath.js +41 -0
- package/dist/core/CodegenConfig.js +53 -0
- package/dist/core/DescriptiveError.js +49 -0
- package/dist/core/PackageJSON.js +53 -0
- package/dist/core/ProjectDependenciesManager.js +70 -0
- package/dist/core/ValueObject.js +2 -0
- package/dist/core/fs.js +36 -0
- package/dist/core/index.js +7 -0
- package/dist/index.js +7 -1
- package/dist/io/Logger.js +71 -0
- package/dist/io/fsUtils.js +23 -0
- package/dist/io/index.js +18 -0
- package/package.json +6 -1
- package/src/codegen/core/Codegen.ts +44 -0
- package/src/codegen/core/CodegenError.ts +3 -0
- package/src/codegen/core/EventUtils.ts +18 -0
- package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -0
- package/src/codegen/core/TypeAnnotationToTS.ts +188 -0
- package/src/codegen/core/UberSchema.ts +99 -0
- package/src/codegen/core/index.ts +5 -0
- package/src/codegen/generators/ComponentCodeGenerator.ts +98 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +95 -0
- package/src/codegen/generators/PackageCodeGenerator.ts +73 -0
- package/src/codegen/generators/index.ts +3 -0
- package/src/codegen/index.ts +2 -0
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +49 -0
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +85 -0
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +202 -0
- package/src/codegen/templates/IndexTSTemplate.ts +33 -0
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +124 -0
- package/src/codegen/templates/TurboModuleCppTemplate.ts +47 -0
- package/src/codegen/templates/TurboModuleHTemplate.ts +26 -0
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +81 -0
- package/src/codegen/templates/index.ts +8 -0
- package/src/commands/codegen-harmony.ts +143 -0
- package/src/commands/create-metro-host-constants.ts +48 -0
- package/src/commands/index.ts +2 -0
- package/src/commands/pack-harmony.ts +4 -1
- package/src/commands/unpack-harmony.ts +133 -58
- package/src/core/AbsolutePath.ts +43 -0
- package/src/core/CodegenConfig.ts +54 -0
- package/src/core/DescriptiveError.ts +61 -0
- package/src/core/PackageJSON.ts +63 -0
- package/src/core/ProjectDependenciesManager.ts +77 -0
- package/src/core/ValueObject.ts +2 -0
- package/src/core/fs.ts +31 -0
- package/src/core/index.ts +7 -0
- package/src/index.ts +9 -1
- package/src/io/Logger.ts +68 -0
- package/src/io/fsUtils.ts +24 -0
- package/src/io/index.ts +2 -0
- package/tsconfig.build.json +2 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Codegen = void 0;
|
|
4
|
+
const CodegenError_1 = require("./CodegenError");
|
|
5
|
+
class Codegen {
|
|
6
|
+
constructor(packageCodeGenerator, codeGeneratorBySpecSchemaType) {
|
|
7
|
+
this.packageCodeGenerator = packageCodeGenerator;
|
|
8
|
+
this.codeGeneratorBySpecSchemaType = codeGeneratorBySpecSchemaType;
|
|
9
|
+
}
|
|
10
|
+
generate(uberSchema) {
|
|
11
|
+
const result = new Map();
|
|
12
|
+
for (const [_fileName, specSchema] of uberSchema
|
|
13
|
+
.getSpecSchemaByFilenameMap()
|
|
14
|
+
.entries()) {
|
|
15
|
+
if (!(specSchema.type in this.codeGeneratorBySpecSchemaType)) {
|
|
16
|
+
throw new CodegenError_1.CodegenError({
|
|
17
|
+
whatHappened: `Could not find a code generator for a specification of type '${specSchema.type}'`,
|
|
18
|
+
unexpected: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
this.codeGeneratorBySpecSchemaType[specSchema.type]
|
|
22
|
+
.generate(specSchema)
|
|
23
|
+
.forEach((fileContent, filePath) => {
|
|
24
|
+
result.set(filePath, fileContent);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
this.packageCodeGenerator
|
|
28
|
+
.generate(uberSchema)
|
|
29
|
+
.forEach((fileContent, filePath) => {
|
|
30
|
+
result.set(filePath, fileContent);
|
|
31
|
+
});
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Codegen = Codegen;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEventNameFromEventHandlerName = void 0;
|
|
4
|
+
const CodegenError_1 = require("./CodegenError");
|
|
5
|
+
function createEventNameFromEventHandlerName(eventHandlerName) {
|
|
6
|
+
const eventName = eventHandlerName.replace('on', '');
|
|
7
|
+
if (eventName.length === 0) {
|
|
8
|
+
throw new CodegenError_1.CodegenError({
|
|
9
|
+
whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
|
|
10
|
+
whatCanUserDo: {
|
|
11
|
+
default: [
|
|
12
|
+
'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return eventName.charAt(0).toLowerCase() + eventName.slice(1);
|
|
18
|
+
}
|
|
19
|
+
exports.createEventNameFromEventHandlerName = createEventNameFromEventHandlerName;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapWithQuotes = exports.getStringifiedTSDefaultValueFromPropTypeAnnotation = exports.TypeAnnotationToTS = void 0;
|
|
4
|
+
class TypeAnnotationToTS {
|
|
5
|
+
constructor(aliasPrefix = '') {
|
|
6
|
+
this.aliasPrefix = aliasPrefix;
|
|
7
|
+
}
|
|
8
|
+
convert(typeAnnotation) {
|
|
9
|
+
if (!typeAnnotation) {
|
|
10
|
+
return 'unknown';
|
|
11
|
+
}
|
|
12
|
+
switch (typeAnnotation.type) {
|
|
13
|
+
case 'BooleanTypeAnnotation':
|
|
14
|
+
return 'boolean';
|
|
15
|
+
case 'DoubleTypeAnnotation':
|
|
16
|
+
return 'number';
|
|
17
|
+
case 'FloatTypeAnnotation':
|
|
18
|
+
return 'number';
|
|
19
|
+
case 'Int32EnumTypeAnnotation':
|
|
20
|
+
return typeAnnotation.options.join(' | ');
|
|
21
|
+
case 'Int32TypeAnnotation':
|
|
22
|
+
return 'number';
|
|
23
|
+
case 'MixedTypeAnnotation':
|
|
24
|
+
return 'unknown';
|
|
25
|
+
case 'ReservedTypeAnnotation':
|
|
26
|
+
switch (typeAnnotation.name) {
|
|
27
|
+
case 'RootTag':
|
|
28
|
+
return 'Tag';
|
|
29
|
+
default:
|
|
30
|
+
return 'unknown';
|
|
31
|
+
}
|
|
32
|
+
case 'ReservedPropTypeAnnotation':
|
|
33
|
+
switch (typeAnnotation.name) {
|
|
34
|
+
case 'ColorPrimitive':
|
|
35
|
+
return 'ColorValue';
|
|
36
|
+
case 'DimensionPrimitive':
|
|
37
|
+
return 'unknown';
|
|
38
|
+
case 'EdgeInsetsPrimitive':
|
|
39
|
+
return 'unknown';
|
|
40
|
+
case 'ImageRequestPrimitive':
|
|
41
|
+
return 'unknown';
|
|
42
|
+
case 'ImageSourcePrimitive':
|
|
43
|
+
return 'unknown';
|
|
44
|
+
case 'PointPrimitive':
|
|
45
|
+
return 'unknown';
|
|
46
|
+
default:
|
|
47
|
+
return 'unknown';
|
|
48
|
+
}
|
|
49
|
+
case 'StringEnumTypeAnnotation':
|
|
50
|
+
return typeAnnotation.options
|
|
51
|
+
.map((option) => {
|
|
52
|
+
if (typeof option !== 'string') {
|
|
53
|
+
return option;
|
|
54
|
+
}
|
|
55
|
+
return wrapWithQuotes(option);
|
|
56
|
+
})
|
|
57
|
+
.join(' | ');
|
|
58
|
+
case 'StringTypeAnnotation':
|
|
59
|
+
return 'string';
|
|
60
|
+
case 'FunctionTypeAnnotation':
|
|
61
|
+
const { params, returnTypeAnnotation } = typeAnnotation;
|
|
62
|
+
const stringifiedArgs = params
|
|
63
|
+
.map((param) => `${param.name}: ${this.convert(param.typeAnnotation)}`)
|
|
64
|
+
.join(', ');
|
|
65
|
+
return `(${stringifiedArgs}) => ${this.convert(returnTypeAnnotation)}`;
|
|
66
|
+
case 'EnumDeclaration':
|
|
67
|
+
return typeAnnotation.name;
|
|
68
|
+
case 'GenericObjectTypeAnnotation':
|
|
69
|
+
return 'Object';
|
|
70
|
+
case 'TypeAliasTypeAnnotation':
|
|
71
|
+
return this.aliasPrefix + typeAnnotation.name;
|
|
72
|
+
case 'UnionTypeAnnotation':
|
|
73
|
+
return this.convertUnionMemberAnnotation(typeAnnotation.memberType);
|
|
74
|
+
case 'NumberTypeAnnotation':
|
|
75
|
+
return 'number';
|
|
76
|
+
case 'NullableTypeAnnotation':
|
|
77
|
+
return `null | ${this.convert(typeAnnotation.typeAnnotation)}`;
|
|
78
|
+
case 'ObjectTypeAnnotation':
|
|
79
|
+
return this.convertObjectTypeAnnotation(typeAnnotation);
|
|
80
|
+
case 'PromiseTypeAnnotation':
|
|
81
|
+
return `Promise<${this.convert(typeAnnotation.elementType)}>`;
|
|
82
|
+
case 'VoidTypeAnnotation':
|
|
83
|
+
return 'void';
|
|
84
|
+
case 'ArrayTypeAnnotation':
|
|
85
|
+
return `${this.convert(typeAnnotation.elementType)}[]`;
|
|
86
|
+
default:
|
|
87
|
+
return 'unknown';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
convertUnionMemberAnnotation(memberAnnotation) {
|
|
91
|
+
switch (memberAnnotation) {
|
|
92
|
+
case 'NumberTypeAnnotation':
|
|
93
|
+
return 'number';
|
|
94
|
+
case 'ObjectTypeAnnotation':
|
|
95
|
+
return 'Object';
|
|
96
|
+
case 'StringTypeAnnotation':
|
|
97
|
+
return 'string';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
convertObjectTypeAnnotation(objectTypeAnnotation) {
|
|
101
|
+
const props = objectTypeAnnotation.properties
|
|
102
|
+
.map((prop) => {
|
|
103
|
+
const maybeOptionalSymbol = prop.optional ? '?' : '';
|
|
104
|
+
return `${prop.name}${maybeOptionalSymbol}: ${this.convert(prop.typeAnnotation)}`;
|
|
105
|
+
})
|
|
106
|
+
.join(', ');
|
|
107
|
+
if (props.length === 0) {
|
|
108
|
+
return '{}';
|
|
109
|
+
}
|
|
110
|
+
return `{${props}}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.TypeAnnotationToTS = TypeAnnotationToTS;
|
|
114
|
+
function getStringifiedTSDefaultValueFromPropTypeAnnotation(propTypeAnnotation) {
|
|
115
|
+
if ('default' in propTypeAnnotation && propTypeAnnotation.default !== null) {
|
|
116
|
+
if (typeof propTypeAnnotation.default === 'string') {
|
|
117
|
+
return wrapWithQuotes(propTypeAnnotation.default);
|
|
118
|
+
}
|
|
119
|
+
return String(propTypeAnnotation.default);
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
exports.getStringifiedTSDefaultValueFromPropTypeAnnotation = getStringifiedTSDefaultValueFromPropTypeAnnotation;
|
|
124
|
+
function wrapWithQuotes(str) {
|
|
125
|
+
if (str.includes("'")) {
|
|
126
|
+
return `"${str}"`;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return `'${str}'`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.wrapWithQuotes = wrapWithQuotes;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.UberSchema = void 0;
|
|
16
|
+
const core_1 = require("../../core");
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
const combine_js_to_schema_js_1 = __importDefault(require("@react-native/codegen/lib/cli/combine/combine-js-to-schema.js"));
|
|
19
|
+
const CodegenError_1 = require("./CodegenError");
|
|
20
|
+
function createRawUberSchemaFromSpecFilePaths(projectSourceFilePaths) {
|
|
21
|
+
return (0, combine_js_to_schema_js_1.default)(projectSourceFilePaths.map((p) => p.getValue()));
|
|
22
|
+
}
|
|
23
|
+
class UberSchema {
|
|
24
|
+
static fromProjectRootPath(projectRootPath) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const packageJSON = core_1.PackageJSON.fromProjectRootPath(projectRootPath, projectRootPath);
|
|
27
|
+
const codegenConfigs = [];
|
|
28
|
+
const appCodegenConfig = packageJSON.maybeCreateCodegenConfig();
|
|
29
|
+
if (appCodegenConfig) {
|
|
30
|
+
codegenConfigs.push(appCodegenConfig);
|
|
31
|
+
}
|
|
32
|
+
yield new core_1.ProjectDependenciesManager(projectRootPath).forEachAsync((dependency) => {
|
|
33
|
+
const codegenConfig = dependency.maybeCreateCodegenConfig();
|
|
34
|
+
if (codegenConfig) {
|
|
35
|
+
codegenConfigs.push(codegenConfig);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
try {
|
|
39
|
+
return new UberSchema(createRawUberSchemaFromSpecFilePaths(codegenConfigs.flatMap((codegenConfig) => codegenConfig.getSpecFilePaths())));
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err instanceof Error) {
|
|
43
|
+
throw new CodegenError_1.CodegenError({
|
|
44
|
+
whatHappened: "Couldn't create the schema",
|
|
45
|
+
whatCanUserDo: {
|
|
46
|
+
default: [
|
|
47
|
+
`There's probably at least one spec file defined in your project or in a third-party package that breaks some code generation restrictions. Please check the message below. If it's ambiguous, debug the problem with divide and conquer strategy.\n\n${err.message}`,
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
constructor(schemaValue) {
|
|
57
|
+
this.schemaValue = schemaValue;
|
|
58
|
+
}
|
|
59
|
+
getValue() {
|
|
60
|
+
return this.schemaValue;
|
|
61
|
+
}
|
|
62
|
+
findAllSpecSchemasByType(schemaType) {
|
|
63
|
+
return Object.values(this.schemaValue.modules)
|
|
64
|
+
.filter((module) => module.type === schemaType)
|
|
65
|
+
.map((module) => module);
|
|
66
|
+
}
|
|
67
|
+
getSpecSchemaByFilenameMap() {
|
|
68
|
+
return Object.entries(this.schemaValue.modules).reduce((acc, [moduleName, moduleSchema]) => {
|
|
69
|
+
acc.set(moduleName, moduleSchema);
|
|
70
|
+
return acc;
|
|
71
|
+
}, new Map());
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.UberSchema = UberSchema;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Codegen"), exports);
|
|
18
|
+
__exportStar(require("./UberSchema"), exports);
|
|
19
|
+
__exportStar(require("./CodegenError"), exports);
|
|
20
|
+
__exportStar(require("./EventUtils"), exports);
|
|
21
|
+
__exportStar(require("./TypeAnnotationToTS"), exports);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentCodeGenerator = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
const templates_1 = require("../templates");
|
|
6
|
+
class ComponentCodeGenerator {
|
|
7
|
+
constructor(cppOutputPath, tsOutputPath) {
|
|
8
|
+
this.cppOutputPath = cppOutputPath;
|
|
9
|
+
this.tsOutputPath = tsOutputPath;
|
|
10
|
+
}
|
|
11
|
+
generate(schema) {
|
|
12
|
+
if (schema.type !== 'Component') {
|
|
13
|
+
throw new core_1.CodegenError({
|
|
14
|
+
whatHappened: `ComponentCodeGenerator can't generate code for a module type: ${schema.type}`,
|
|
15
|
+
unexpected: true,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const typeAnnotationToTS = new core_1.TypeAnnotationToTS();
|
|
19
|
+
const result = new Map();
|
|
20
|
+
Object.entries(schema.components).map(([name, shape]) => {
|
|
21
|
+
const componentDescriptorHTemplate = new templates_1.ComponentDescriptorHTemplate(name);
|
|
22
|
+
const componentJSIBinderHTemplate = new templates_1.ComponentJSIBinderHTemplate(name);
|
|
23
|
+
const componentUtilsTSTemplate = new templates_1.ComponentUtilsTSTemplate(name);
|
|
24
|
+
shape.props.forEach((prop) => {
|
|
25
|
+
componentJSIBinderHTemplate.addProp({
|
|
26
|
+
name: prop.name,
|
|
27
|
+
isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
|
|
28
|
+
});
|
|
29
|
+
componentUtilsTSTemplate.addProp({
|
|
30
|
+
name: prop.name,
|
|
31
|
+
tsType: typeAnnotationToTS.convert(prop.typeAnnotation),
|
|
32
|
+
defaultValue: (0, core_1.getStringifiedTSDefaultValueFromPropTypeAnnotation)(prop.typeAnnotation),
|
|
33
|
+
isOptional: prop.optional,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
shape.commands.forEach((command) => {
|
|
37
|
+
componentUtilsTSTemplate.addCommand({
|
|
38
|
+
name: command.name,
|
|
39
|
+
argsTSType: '[' +
|
|
40
|
+
command.typeAnnotation.params
|
|
41
|
+
.map((param) => typeAnnotationToTS.convert(param.typeAnnotation) +
|
|
42
|
+
(param.optional ? '?' : ''))
|
|
43
|
+
.join(', ') +
|
|
44
|
+
']',
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
shape.events.forEach((event) => {
|
|
48
|
+
componentUtilsTSTemplate.addEvent({
|
|
49
|
+
name: (0, core_1.createEventNameFromEventHandlerName)(event.name),
|
|
50
|
+
payloadTSType: event.typeAnnotation.argument
|
|
51
|
+
? typeAnnotationToTS.convert(event.typeAnnotation.argument)
|
|
52
|
+
: 'undefined',
|
|
53
|
+
});
|
|
54
|
+
componentJSIBinderHTemplate.addEvent({
|
|
55
|
+
type: event.bubblingType,
|
|
56
|
+
eventHandlerName: event.name,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
result.set(this.cppOutputPath.copyWithNewSegment(`${name}ComponentDescriptor.h`), componentDescriptorHTemplate.build());
|
|
60
|
+
result.set(this.cppOutputPath.copyWithNewSegment(`${name}JSIBinder.h`), componentJSIBinderHTemplate.build());
|
|
61
|
+
result.set(this.tsOutputPath.copyWithNewSegment(`${name}.ts`), componentUtilsTSTemplate.build());
|
|
62
|
+
});
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.ComponentCodeGenerator = ComponentCodeGenerator;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NativeModuleCodeGenerator = void 0;
|
|
4
|
+
const CodegenError_1 = require("../core/CodegenError");
|
|
5
|
+
const templates_1 = require("../templates");
|
|
6
|
+
const core_1 = require("../core");
|
|
7
|
+
class NativeModuleCodeGenerator {
|
|
8
|
+
constructor(cppOutputPath, etsOutputPath) {
|
|
9
|
+
this.cppOutputPath = cppOutputPath;
|
|
10
|
+
this.etsOutputPath = etsOutputPath;
|
|
11
|
+
}
|
|
12
|
+
generate(schema) {
|
|
13
|
+
const result = new Map();
|
|
14
|
+
if (schema.type !== 'NativeModule') {
|
|
15
|
+
throw new CodegenError_1.CodegenError({
|
|
16
|
+
whatHappened: `NativeModuleCodeGenerator can't generate code for module type: ${schema.type}`,
|
|
17
|
+
unexpected: true,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const typeAnnotationToTS = new core_1.TypeAnnotationToTS();
|
|
21
|
+
const turboModuleInterfaceTS = new templates_1.TurboModuleInterfaceTS(schema.moduleName);
|
|
22
|
+
const turboModuleH = new templates_1.TurboModuleHTemplate(schema.moduleName).build();
|
|
23
|
+
result.set(this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.h`), turboModuleH);
|
|
24
|
+
const turboModuleCpp = new templates_1.TurboModuleCppTemplate(schema.moduleName);
|
|
25
|
+
Object.entries(schema.aliasMap).map(([name, typeAnnotation]) => {
|
|
26
|
+
turboModuleInterfaceTS.addAlias({
|
|
27
|
+
name: name,
|
|
28
|
+
type: typeAnnotationToTS.convert(typeAnnotation),
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
Object.entries(schema.enumMap).map(([name, enumSpec]) => {
|
|
32
|
+
turboModuleInterfaceTS.addEnum({
|
|
33
|
+
name,
|
|
34
|
+
members: enumSpec.members.map((member) => ({
|
|
35
|
+
name: member.name,
|
|
36
|
+
value: typeof member.value === 'string'
|
|
37
|
+
? (0, core_1.wrapWithQuotes)(member.value)
|
|
38
|
+
: member.value.toString(),
|
|
39
|
+
})),
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
schema.spec.properties.map((prop) => {
|
|
43
|
+
if (prop.typeAnnotation.type === 'FunctionTypeAnnotation') {
|
|
44
|
+
turboModuleCpp.addMethod({
|
|
45
|
+
name: prop.name,
|
|
46
|
+
argsCount: prop.typeAnnotation.params.length,
|
|
47
|
+
isAsync: prop.typeAnnotation.returnTypeAnnotation.type ===
|
|
48
|
+
'PromiseTypeAnnotation',
|
|
49
|
+
});
|
|
50
|
+
turboModuleInterfaceTS.addMethod({
|
|
51
|
+
name: prop.name,
|
|
52
|
+
returnType: typeAnnotationToTS.convert(prop.typeAnnotation.returnTypeAnnotation),
|
|
53
|
+
stringifiedArgs: prop.typeAnnotation.params
|
|
54
|
+
.map((param) => `${param.name}: ${typeAnnotationToTS.convert(param.typeAnnotation)}`)
|
|
55
|
+
.join(', '),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
result.set(this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.cpp`), turboModuleCpp.build());
|
|
60
|
+
result.set(this.etsOutputPath.copyWithNewSegment(`${schema.moduleName}.ts`), turboModuleInterfaceTS.build());
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.NativeModuleCodeGenerator = NativeModuleCodeGenerator;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PackageCodeGenerator = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
const templates_1 = require("../templates");
|
|
6
|
+
class PackageCodeGenerator {
|
|
7
|
+
constructor(cppOutputPath, etsOutputPath) {
|
|
8
|
+
this.cppOutputPath = cppOutputPath;
|
|
9
|
+
this.etsOutputPath = etsOutputPath;
|
|
10
|
+
}
|
|
11
|
+
generate(uberSchema) {
|
|
12
|
+
const result = new Map();
|
|
13
|
+
const generatedPackageH = new templates_1.RNOHGeneratedPackageHTemplate();
|
|
14
|
+
const components_indexTS = new templates_1.IndexTSTemplate();
|
|
15
|
+
const turboModules_indexTS = new templates_1.IndexTSTemplate();
|
|
16
|
+
const generated_indexETS = new templates_1.IndexTSTemplate();
|
|
17
|
+
generated_indexETS.addReexport({ from: './ts' });
|
|
18
|
+
uberSchema
|
|
19
|
+
.findAllSpecSchemasByType('NativeModule')
|
|
20
|
+
.forEach((nativeModuleSchema) => {
|
|
21
|
+
generatedPackageH.addTurboModule({
|
|
22
|
+
name: nativeModuleSchema.moduleName,
|
|
23
|
+
});
|
|
24
|
+
turboModules_indexTS.addReexport({
|
|
25
|
+
from: `./${nativeModuleSchema.moduleName}`,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
uberSchema
|
|
29
|
+
.findAllSpecSchemasByType('Component')
|
|
30
|
+
.forEach((componentSchema) => {
|
|
31
|
+
Object.entries(componentSchema.components).forEach(([name, componentShape]) => {
|
|
32
|
+
components_indexTS.addReexport({ from: `./${name}` });
|
|
33
|
+
generatedPackageH.addComponent({
|
|
34
|
+
name: name,
|
|
35
|
+
supportedEventNames: componentShape.events.map((e) => {
|
|
36
|
+
return (0, core_1.createEventNameFromEventHandlerName)(e.name);
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
result.set(this.cppOutputPath.copyWithNewSegment('RNOHGeneratedPackage.h'), generatedPackageH.build());
|
|
42
|
+
result.set(this.etsOutputPath.copyWithNewSegment('ts.ts'), new templates_1.IndexTSTemplate()
|
|
43
|
+
.addReexport({ from: './components/ts', as: 'RNC' })
|
|
44
|
+
.addReexport({ from: './turboModules/ts', as: 'TM' })
|
|
45
|
+
.build());
|
|
46
|
+
result.set(this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'), components_indexTS.build());
|
|
47
|
+
result.set(this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'), turboModules_indexTS.build());
|
|
48
|
+
result.set(this.etsOutputPath.copyWithNewSegment('index.ets'), generated_indexETS.build());
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.PackageCodeGenerator = PackageCodeGenerator;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ComponentCodeGenerator"), exports);
|
|
18
|
+
__exportStar(require("./NativeModuleCodeGenerator"), exports);
|
|
19
|
+
__exportStar(require("./PackageCodeGenerator"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./core"), exports);
|
|
18
|
+
__exportStar(require("./generators"), exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
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.ComponentDescriptorHTemplate = void 0;
|
|
7
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
+
const TEMPLATE = `
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
// This file was generated.
|
|
12
|
+
|
|
13
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
14
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
15
|
+
#include <react/renderer/components/view/ViewShadowNode.h>
|
|
16
|
+
|
|
17
|
+
namespace facebook {
|
|
18
|
+
namespace react {
|
|
19
|
+
|
|
20
|
+
extern const char {{name}}ComponentName[] = "{{name}}";
|
|
21
|
+
|
|
22
|
+
class {{name}}Props : public ViewProps {
|
|
23
|
+
public:
|
|
24
|
+
{{name}}Props() = default;
|
|
25
|
+
|
|
26
|
+
{{name}}Props(const PropsParserContext &context, const {{name}}Props &sourceProps, const RawProps &rawProps)
|
|
27
|
+
: ViewProps(context, sourceProps, rawProps) {}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
using {{name}}ShadowNode = ConcreteViewShadowNode<
|
|
31
|
+
{{name}}ComponentName,
|
|
32
|
+
{{name}}Props,
|
|
33
|
+
ViewEventEmitter>;
|
|
34
|
+
|
|
35
|
+
class {{name}}ComponentDescriptor final
|
|
36
|
+
: public ConcreteComponentDescriptor<{{name}}ShadowNode> {
|
|
37
|
+
public:
|
|
38
|
+
{{name}}ComponentDescriptor(ComponentDescriptorParameters const ¶meters)
|
|
39
|
+
: ConcreteComponentDescriptor(parameters) {}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
} // namespace react
|
|
43
|
+
} // namespace facebook
|
|
44
|
+
`;
|
|
45
|
+
class ComponentDescriptorHTemplate {
|
|
46
|
+
constructor(name) {
|
|
47
|
+
this.name = name;
|
|
48
|
+
}
|
|
49
|
+
build() {
|
|
50
|
+
return mustache_1.default.render(TEMPLATE, {
|
|
51
|
+
name: this.name,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ComponentDescriptorHTemplate = ComponentDescriptorHTemplate;
|
|
@@ -0,0 +1,78 @@
|
|
|
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.ComponentJSIBinderHTemplate = void 0;
|
|
7
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
+
const TEMPLATE = `
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
// This file was generated.
|
|
12
|
+
|
|
13
|
+
#include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
|
|
14
|
+
|
|
15
|
+
namespace rnoh {
|
|
16
|
+
class {{name}}JSIBinder : public ViewComponentJSIBinder {
|
|
17
|
+
protected:
|
|
18
|
+
facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override {
|
|
19
|
+
auto object = ViewComponentJSIBinder::createNativeProps(rt);
|
|
20
|
+
{{#props}}
|
|
21
|
+
object.setProperty(rt, "{{name}}", {{{type}}});
|
|
22
|
+
{{/props}}
|
|
23
|
+
return object;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
|
|
27
|
+
facebook::jsi::Object events(rt);
|
|
28
|
+
{{#bubblingEvents}}
|
|
29
|
+
events.setProperty(rt, "{{TOPname}}", createBubblingCapturedEvent(rt, "{{name}}"));
|
|
30
|
+
{{/bubblingEvents}}
|
|
31
|
+
return events;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
|
|
35
|
+
facebook::jsi::Object events(rt);
|
|
36
|
+
{{#directEvents}}
|
|
37
|
+
events.setProperty(rt, "{{TOPname}}", createDirectEvent(rt, "{{name}}"));
|
|
38
|
+
{{/directEvents}}
|
|
39
|
+
return events;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
} // namespace rnoh
|
|
43
|
+
`;
|
|
44
|
+
class ComponentJSIBinderHTemplate {
|
|
45
|
+
constructor(name) {
|
|
46
|
+
this.name = name;
|
|
47
|
+
this.props = [];
|
|
48
|
+
this.events = [];
|
|
49
|
+
}
|
|
50
|
+
addProp(prop) {
|
|
51
|
+
this.props.push(prop);
|
|
52
|
+
}
|
|
53
|
+
addEvent(event) {
|
|
54
|
+
this.events.push(event);
|
|
55
|
+
}
|
|
56
|
+
build() {
|
|
57
|
+
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
58
|
+
name: this.name,
|
|
59
|
+
props: this.props.map((prop) => ({
|
|
60
|
+
name: prop.name,
|
|
61
|
+
type: prop.isObject ? '"Object"' : 'true',
|
|
62
|
+
})),
|
|
63
|
+
bubblingEvents: this.events
|
|
64
|
+
.filter((event) => event.type === 'bubble')
|
|
65
|
+
.map((event) => ({
|
|
66
|
+
TOPname: event.eventHandlerName.replace('on', 'top'),
|
|
67
|
+
name: event.eventHandlerName,
|
|
68
|
+
})),
|
|
69
|
+
directEvents: this.events
|
|
70
|
+
.filter((event) => event.type === 'direct')
|
|
71
|
+
.map((event) => ({
|
|
72
|
+
TOPname: event.eventHandlerName.replace('on', 'top'),
|
|
73
|
+
name: event.eventHandlerName,
|
|
74
|
+
})),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.ComponentJSIBinderHTemplate = ComponentJSIBinderHTemplate;
|