@react-native-oh/react-native-harmony-cli 0.0.26 → 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/assetResolver.js +19 -0
- package/dist/codegen/core/CodeGenerator.js +2 -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 +103 -0
- package/dist/codegen/core/index.js +21 -0
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +61 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +76 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +74 -0
- package/dist/codegen/generators/CppComponentCodeGenerator.js +56 -0
- package/dist/codegen/generators/LibGlueCodeGenerator.js +50 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +73 -0
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +34 -0
- package/dist/codegen/generators/UberGeneratorV1.js +50 -0
- package/dist/codegen/generators/UberGeneratorV2.js +71 -0
- package/dist/codegen/generators/index.js +24 -0
- package/dist/codegen/index.js +18 -0
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +105 -0
- package/dist/codegen/templates/BasePackageHTemplate.js +130 -0
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +62 -0
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +85 -0
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +192 -0
- package/dist/codegen/templates/IndexTSTemplate.js +52 -0
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +124 -0
- package/dist/codegen/templates/TurboModuleCppTemplate.js +53 -0
- package/dist/codegen/templates/TurboModuleHTemplate.js +42 -0
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +75 -0
- package/dist/codegen/templates/index.js +25 -0
- package/dist/commands/bundle-harmony.js +179 -0
- package/dist/commands/codegen-harmony.js +201 -0
- package/dist/commands/codegen-lib-harmony.js +253 -0
- package/dist/commands/create-metro-host-constants.js +61 -0
- package/dist/commands/index.js +23 -0
- package/dist/commands/pack-harmony.js +100 -0
- package/dist/commands/unpack-harmony.js +184 -0
- package/dist/commands/verify-package-harmony.js +122 -0
- package/dist/core/AbsolutePath.js +47 -0
- package/dist/core/CodegenConfig.js +57 -0
- package/dist/core/DescriptiveError.js +49 -0
- package/dist/core/OHPackageJSON5.js +23 -0
- package/dist/core/PackageJSON.js +58 -0
- package/dist/core/ProjectDependenciesManager.js +70 -0
- package/dist/core/ValidationError.js +6 -0
- package/dist/core/ValueObject.js +2 -0
- package/dist/core/fs.js +36 -0
- package/dist/core/index.js +25 -0
- package/dist/index.js +15 -0
- package/dist/io/Logger.js +71 -0
- package/dist/io/TarGz.js +28 -0
- package/dist/io/fsUtils.js +23 -0
- package/dist/io/index.js +19 -0
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +38 -0
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +32 -0
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +26 -0
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +51 -0
- package/dist/package-verifier/checks/index.js +20 -0
- package/dist/package-verifier/index.js +18 -0
- package/dist/package-verifier/types.js +2 -0
- package/dist/package-verifier/verify-package.js +101 -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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAssetDestRelativePath = void 0;
|
|
4
|
+
function getAssetDestRelativePath(asset) {
|
|
5
|
+
const fileName = getResourceIdentifier(asset);
|
|
6
|
+
return `${fileName}.${asset.type}`;
|
|
7
|
+
}
|
|
8
|
+
exports.getAssetDestRelativePath = getAssetDestRelativePath;
|
|
9
|
+
function getResourceIdentifier(asset) {
|
|
10
|
+
const folderPath = getBasePath(asset);
|
|
11
|
+
return `${folderPath}/${asset.name}`.slice('assets/'.length);
|
|
12
|
+
}
|
|
13
|
+
function getBasePath(asset) {
|
|
14
|
+
let basePath = asset.httpServerLocation;
|
|
15
|
+
if (basePath[0] === '/') {
|
|
16
|
+
basePath = basePath.substr(1);
|
|
17
|
+
}
|
|
18
|
+
return basePath;
|
|
19
|
+
}
|
|
@@ -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,103 @@
|
|
|
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
|
+
/**
|
|
24
|
+
* Contains component and turbo module (NativeModule) schemas. The "Uber" word is used here to highlight that SpecSchemas don't extend this class.
|
|
25
|
+
*/
|
|
26
|
+
class UberSchema {
|
|
27
|
+
static fromSpecFilePaths(specPaths) {
|
|
28
|
+
return new UberSchema(createRawUberSchemaFromSpecFilePaths(specPaths));
|
|
29
|
+
}
|
|
30
|
+
static fromCodegenConfig(codegenConfig) {
|
|
31
|
+
try {
|
|
32
|
+
return new UberSchema(createRawUberSchemaFromSpecFilePaths(codegenConfig.getSpecFilePaths()));
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (err instanceof Error) {
|
|
36
|
+
throw new CodegenError_1.CodegenError({
|
|
37
|
+
whatHappened: "Couldn't create the schema",
|
|
38
|
+
whatCanUserDo: {
|
|
39
|
+
default: [
|
|
40
|
+
`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}`,
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
static fromProject(projectRootPath, onShouldAcceptCodegenConfig) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const onShouldAcceptCodegenConfig_ = onShouldAcceptCodegenConfig !== null && onShouldAcceptCodegenConfig !== void 0 ? onShouldAcceptCodegenConfig : ((x) => true);
|
|
51
|
+
const packageJSON = core_1.PackageJSON.fromProjectRootPath(projectRootPath, projectRootPath);
|
|
52
|
+
const acceptedCodegenConfigs = [];
|
|
53
|
+
const appCodegenConfigs = packageJSON.getCodegenConfigs();
|
|
54
|
+
for (const codegenConfig of appCodegenConfigs) {
|
|
55
|
+
if (onShouldAcceptCodegenConfig_(codegenConfig.getVersion(), packageJSON.name)) {
|
|
56
|
+
acceptedCodegenConfigs.push(codegenConfig);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
yield new core_1.ProjectDependenciesManager(projectRootPath).forEachAsync((dependency) => {
|
|
60
|
+
const codegenConfigs = dependency.getCodegenConfigs();
|
|
61
|
+
for (const codegenConfig of codegenConfigs) {
|
|
62
|
+
if (onShouldAcceptCodegenConfig_(codegenConfig.getVersion(), dependency.readPackageJSON().name)) {
|
|
63
|
+
acceptedCodegenConfigs.push(codegenConfig);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
return new UberSchema(createRawUberSchemaFromSpecFilePaths(acceptedCodegenConfigs.flatMap((codegenConfig) => codegenConfig.getSpecFilePaths())));
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
if (err instanceof Error) {
|
|
72
|
+
throw new CodegenError_1.CodegenError({
|
|
73
|
+
whatHappened: "Couldn't create the schema",
|
|
74
|
+
whatCanUserDo: {
|
|
75
|
+
default: [
|
|
76
|
+
`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}`,
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
constructor(schemaValue) {
|
|
86
|
+
this.schemaValue = schemaValue;
|
|
87
|
+
}
|
|
88
|
+
getValue() {
|
|
89
|
+
return this.schemaValue;
|
|
90
|
+
}
|
|
91
|
+
findAllSpecSchemasByType(schemaType) {
|
|
92
|
+
return Object.values(this.schemaValue.modules)
|
|
93
|
+
.filter((module) => module.type === schemaType)
|
|
94
|
+
.map((module) => module);
|
|
95
|
+
}
|
|
96
|
+
getSpecSchemaByFilenameMap() {
|
|
97
|
+
return Object.entries(this.schemaValue.modules).reduce((acc, [moduleName, moduleSchema]) => {
|
|
98
|
+
acc.set(moduleName, moduleSchema);
|
|
99
|
+
return acc;
|
|
100
|
+
}, new Map());
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
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("./CodeGenerator"), exports);
|
|
18
|
+
__exportStar(require("./UberSchema"), exports);
|
|
19
|
+
__exportStar(require("./CodegenError"), exports);
|
|
20
|
+
__exportStar(require("./EventUtils"), exports);
|
|
21
|
+
__exportStar(require("./TypeAnnotationToTS"), exports);
|
|
@@ -0,0 +1,61 @@
|
|
|
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.AppBuildTimeGlueCodeGenerator = void 0;
|
|
7
|
+
const case_1 = __importDefault(require("case"));
|
|
8
|
+
const templates_1 = require("../templates");
|
|
9
|
+
const BasePackageHTemplate_1 = require("../templates/BasePackageHTemplate");
|
|
10
|
+
/**
|
|
11
|
+
* Generates code based on UberGenerators results. If UberGenerators produce "leaves" (concrete turbo module or component classes),
|
|
12
|
+
* this class generates "branches" (barrel files like index.ts) and "trunks" (package file or files).
|
|
13
|
+
*/
|
|
14
|
+
class AppBuildTimeGlueCodeGenerator {
|
|
15
|
+
constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
|
|
16
|
+
this.cppOutputPath = cppOutputPath;
|
|
17
|
+
this.etsOutputPath = etsOutputPath;
|
|
18
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
19
|
+
}
|
|
20
|
+
generate({ v1, v2 }) {
|
|
21
|
+
const fileContentByPath = new Map();
|
|
22
|
+
const generatedPackageH_v1 = new templates_1.RNOHGeneratedPackageHTemplate();
|
|
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);
|
|
26
|
+
generated_indexETS.addReexport({ from: './ts' });
|
|
27
|
+
v1.components.forEach(({ name, eventNames }) => {
|
|
28
|
+
components_indexTS.addReexport({ from: `./${name}` });
|
|
29
|
+
generatedPackageH_v1.addComponent({
|
|
30
|
+
name,
|
|
31
|
+
supportedEventNames: eventNames,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
v1.turboModules.forEach((turboModule) => {
|
|
35
|
+
turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
|
|
36
|
+
generatedPackageH_v1.addTurboModule(turboModule);
|
|
37
|
+
});
|
|
38
|
+
v2.forEach(({ components, turboModules }, libraryName) => {
|
|
39
|
+
const basePackageClassName = `Base${case_1.default.pascal(libraryName)}Package`;
|
|
40
|
+
const generatedPackageH_v2 = new BasePackageHTemplate_1.BasePackageHTemplate(basePackageClassName, this.codegenNoticeLines);
|
|
41
|
+
components.forEach((component) => {
|
|
42
|
+
generatedPackageH_v2.addComponent(component);
|
|
43
|
+
});
|
|
44
|
+
turboModules.forEach((turboModule) => {
|
|
45
|
+
turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
|
|
46
|
+
generatedPackageH_v2.addTurboModule(turboModule);
|
|
47
|
+
});
|
|
48
|
+
fileContentByPath.set(this.cppOutputPath.copyWithNewSegment(libraryName, 'RNOH', 'generated', `${basePackageClassName}.h`), generatedPackageH_v2.build());
|
|
49
|
+
});
|
|
50
|
+
fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOHGeneratedPackage.h'), generatedPackageH_v1.build());
|
|
51
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('ts.ts'), new templates_1.IndexTSTemplate(this.codegenNoticeLines)
|
|
52
|
+
.addReexport({ from: './components/ts', as: 'RNC' })
|
|
53
|
+
.addReexport({ from: './turboModules/ts', as: 'TM' })
|
|
54
|
+
.build());
|
|
55
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'), components_indexTS.build());
|
|
56
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'), turboModules_indexTS.build());
|
|
57
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('index.ets'), generated_indexETS.build());
|
|
58
|
+
return fileContentByPath;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.AppBuildTimeGlueCodeGenerator = AppBuildTimeGlueCodeGenerator;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArkTSComponentCodeGeneratorArkTS = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
const templates_1 = require("../templates");
|
|
6
|
+
class ArkTSComponentCodeGeneratorArkTS {
|
|
7
|
+
constructor(cppOutputPath, tsOutputPath, codegenNoticeLines, rnohImport) {
|
|
8
|
+
this.cppOutputPath = cppOutputPath;
|
|
9
|
+
this.tsOutputPath = tsOutputPath;
|
|
10
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
11
|
+
this.rnohImport = rnohImport;
|
|
12
|
+
this.glueCodeDataItems = [];
|
|
13
|
+
}
|
|
14
|
+
getGlueCodeData() {
|
|
15
|
+
return this.glueCodeDataItems;
|
|
16
|
+
}
|
|
17
|
+
generate(schema) {
|
|
18
|
+
if (schema.type !== 'Component') {
|
|
19
|
+
throw new core_1.CodegenError({
|
|
20
|
+
whatHappened: `ComponentCodeGenerator can't generate code for a module type: ${schema.type}`,
|
|
21
|
+
unexpected: true,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const typeAnnotationToTS = new core_1.TypeAnnotationToTS();
|
|
25
|
+
const result = new Map();
|
|
26
|
+
Object.entries(schema.components).map(([name, shape]) => {
|
|
27
|
+
const componentDescriptorHTemplate = new templates_1.ComponentDescriptorHTemplate(name);
|
|
28
|
+
const componentJSIBinderHTemplate = new templates_1.ComponentJSIBinderHTemplate(name, this.codegenNoticeLines);
|
|
29
|
+
const componentUtilsTSTemplate = new templates_1.ComponentUtilsTSTemplate(name, this.codegenNoticeLines, this.rnohImport);
|
|
30
|
+
shape.props.forEach((prop) => {
|
|
31
|
+
componentJSIBinderHTemplate.addProp({
|
|
32
|
+
name: prop.name,
|
|
33
|
+
isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
|
|
34
|
+
});
|
|
35
|
+
componentUtilsTSTemplate.addProp({
|
|
36
|
+
name: prop.name,
|
|
37
|
+
tsType: typeAnnotationToTS.convert(prop.typeAnnotation),
|
|
38
|
+
defaultValue: (0, core_1.getStringifiedTSDefaultValueFromPropTypeAnnotation)(prop.typeAnnotation),
|
|
39
|
+
isOptional: prop.optional,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
shape.commands.forEach((command) => {
|
|
43
|
+
componentUtilsTSTemplate.addCommand({
|
|
44
|
+
name: command.name,
|
|
45
|
+
argsTSType: '[' +
|
|
46
|
+
command.typeAnnotation.params
|
|
47
|
+
.map((param) => typeAnnotationToTS.convert(param.typeAnnotation) +
|
|
48
|
+
(param.optional ? '?' : ''))
|
|
49
|
+
.join(', ') +
|
|
50
|
+
']',
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
shape.events.forEach((event) => {
|
|
54
|
+
componentUtilsTSTemplate.addEvent({
|
|
55
|
+
name: (0, core_1.createEventNameFromEventHandlerName)(event.name),
|
|
56
|
+
payloadTSType: event.typeAnnotation.argument
|
|
57
|
+
? typeAnnotationToTS.convert(event.typeAnnotation.argument)
|
|
58
|
+
: 'undefined',
|
|
59
|
+
});
|
|
60
|
+
componentJSIBinderHTemplate.addEvent({
|
|
61
|
+
type: event.bubblingType,
|
|
62
|
+
eventHandlerName: event.name,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
result.set(this.cppOutputPath.copyWithNewSegment(`${name}ComponentDescriptor.h`), componentDescriptorHTemplate.build());
|
|
66
|
+
result.set(this.cppOutputPath.copyWithNewSegment(`${name}JSIBinder.h`), componentJSIBinderHTemplate.build());
|
|
67
|
+
result.set(this.tsOutputPath.copyWithNewSegment(`${name}.ts`), componentUtilsTSTemplate.build());
|
|
68
|
+
this.glueCodeDataItems.push({
|
|
69
|
+
name,
|
|
70
|
+
eventNames: shape.events.map((e) => (0, core_1.createEventNameFromEventHandlerName)(e.name)),
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
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;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CppComponentCodeGenerator = void 0;
|
|
4
|
+
const templates_1 = require("../templates");
|
|
5
|
+
class CppComponentCodeGenerator {
|
|
6
|
+
constructor(onGetRNOHOutputPath, codegenNoticeLines) {
|
|
7
|
+
this.onGetRNOHOutputPath = onGetRNOHOutputPath;
|
|
8
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
9
|
+
this.glueCodeComponentsData = [];
|
|
10
|
+
}
|
|
11
|
+
getGlueCodeData() {
|
|
12
|
+
return this.glueCodeComponentsData;
|
|
13
|
+
}
|
|
14
|
+
generate({ libraryCppName, uberSchema, }) {
|
|
15
|
+
const fileContentByPath = new Map();
|
|
16
|
+
for (const [_filename, schema] of uberSchema
|
|
17
|
+
.getSpecSchemaByFilenameMap()
|
|
18
|
+
.entries()) {
|
|
19
|
+
if (schema.type === 'Component') {
|
|
20
|
+
Object.entries(schema.components).map(([componentName, shape]) => {
|
|
21
|
+
const componentJSIBinderHTemplate = new templates_1.ComponentJSIBinderHTemplate(componentName, this.codegenNoticeLines);
|
|
22
|
+
const componentInstanceSpecHTemplate = new templates_1.BaseComponentInstanceHTemplate(componentName, libraryCppName, this.codegenNoticeLines);
|
|
23
|
+
shape.props.forEach((prop) => {
|
|
24
|
+
componentJSIBinderHTemplate.addProp({
|
|
25
|
+
name: prop.name,
|
|
26
|
+
isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
shape.events.forEach((event) => {
|
|
30
|
+
componentJSIBinderHTemplate.addEvent({
|
|
31
|
+
type: event.bubblingType,
|
|
32
|
+
eventHandlerName: event.name,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
shape.commands.forEach((command) => {
|
|
36
|
+
componentInstanceSpecHTemplate.addCommand({
|
|
37
|
+
name: command.name,
|
|
38
|
+
args: command.typeAnnotation.params.map((param) => ({
|
|
39
|
+
name: param.name,
|
|
40
|
+
typeAnnotation: param.typeAnnotation,
|
|
41
|
+
})),
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
fileContentByPath.set(this.onGetRNOHOutputPath(`${componentName}JSIBinder.h`), componentJSIBinderHTemplate.build());
|
|
45
|
+
fileContentByPath.set(this.onGetRNOHOutputPath(`Base${componentName}ComponentInstance.h`), componentInstanceSpecHTemplate.build());
|
|
46
|
+
this.glueCodeComponentsData.push({
|
|
47
|
+
name: componentName,
|
|
48
|
+
libraryCppName,
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return fileContentByPath;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
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;
|