@react-native-oh/react-native-harmony-cli 0.0.37 → 0.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/dist/assetResolver.js +74 -43
- package/dist/autolinking/Autolinking.js +183 -179
- package/dist/codegen/core/CodegenError.js +23 -3
- package/dist/codegen/core/EventUtils.js +3 -3
- package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
- package/dist/codegen/core/UberSchema.js +96 -57
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +41 -28
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
- package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
- package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
- package/dist/codegen/generators/UberGeneratorV1.js +24 -18
- package/dist/codegen/generators/UberGeneratorV2.js +36 -28
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
- package/dist/codegen/templates/BasePackageHTemplate.js +21 -120
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -53
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
- package/dist/codegen/templates/IndexTSTemplate.js +17 -37
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -119
- package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
- package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
- package/dist/commands/bundle-harmony.js +138 -53
- package/dist/commands/codegen-harmony.js +175 -104
- package/dist/commands/codegen-lib-harmony.js +116 -76
- package/dist/commands/create-metro-host-constants.js +47 -18
- package/dist/commands/init.js +961 -537
- package/dist/commands/link-harmony.js +71 -33
- package/dist/commands/pack-harmony.js +108 -47
- package/dist/commands/run-harmony.js +518 -374
- package/dist/commands/unpack-harmony.js +198 -105
- package/dist/commands/verify-package-harmony.js +108 -54
- package/dist/core/AbsolutePath.js +47 -31
- package/dist/core/CodegenConfig.js +22 -24
- package/dist/core/DescriptiveError.js +37 -18
- package/dist/core/FileSystem.js +18 -14
- package/dist/core/OHPackageJSON5.js +23 -17
- package/dist/core/PackageJSON.js +42 -26
- package/dist/core/ProjectDependenciesManager.js +96 -46
- package/dist/core/ValidationError.js +22 -2
- package/dist/core/fs.js +6 -9
- package/dist/index.js +1 -1
- package/dist/io/CliExecutor.js +98 -46
- package/dist/io/Logger.js +46 -40
- package/dist/io/RealFS.js +88 -35
- package/dist/io/TarGz.js +8 -11
- package/dist/io/__fixtures__.js +141 -79
- package/dist/io/fsUtils.js +12 -13
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
- package/dist/package-verifier/verify-package.js +132 -55
- package/dist/simulator/LaunchSimulator.js +301 -217
- package/jest.config.js +12 -12
- package/package.json +78 -70
- package/react-native.config.js +17 -17
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
- package/.prettierrc +0 -6
- package/src/assetResolver.ts +0 -134
- package/src/autolinking/Autolinking.test.ts +0 -483
- package/src/autolinking/Autolinking.ts +0 -382
- package/src/autolinking/index.ts +0 -8
- package/src/codegen/core/CodeGenerator.ts +0 -16
- package/src/codegen/core/CodegenError.ts +0 -10
- package/src/codegen/core/EventUtils.ts +0 -23
- package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
- package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
- package/src/codegen/core/UberSchema.ts +0 -152
- package/src/codegen/core/index.ts +0 -12
- package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -124
- package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
- package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
- package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
- package/src/codegen/generators/UberGeneratorV1.ts +0 -75
- package/src/codegen/generators/UberGeneratorV2.ts +0 -114
- package/src/codegen/generators/index.ts +0 -15
- package/src/codegen/index.ts +0 -9
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
- package/src/codegen/templates/BasePackageHTemplate.ts +0 -159
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
- package/src/codegen/templates/IndexTSTemplate.ts +0 -62
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -150
- package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
- package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
- package/src/codegen/templates/index.ts +0 -16
- package/src/commands/bundle-harmony.ts +0 -134
- package/src/commands/codegen-harmony.ts +0 -297
- package/src/commands/codegen-lib-harmony.ts +0 -389
- package/src/commands/create-metro-host-constants.ts +0 -55
- package/src/commands/index.ts +0 -16
- package/src/commands/init.ts +0 -755
- package/src/commands/link-harmony.ts +0 -102
- package/src/commands/pack-harmony.ts +0 -128
- package/src/commands/run-harmony.ts +0 -506
- package/src/commands/types.ts +0 -21
- package/src/commands/unpack-harmony.ts +0 -238
- package/src/commands/verify-package-harmony.ts +0 -113
- package/src/core/AbsolutePath.ts +0 -66
- package/src/core/CodegenConfig.ts +0 -67
- package/src/core/DescriptiveError.ts +0 -68
- package/src/core/FileSystem.ts +0 -57
- package/src/core/OHPackageJSON5.ts +0 -30
- package/src/core/PackageJSON.ts +0 -104
- package/src/core/ProjectDependenciesManager.ts +0 -103
- package/src/core/ValidationError.ts +0 -8
- package/src/core/ValueObject.ts +0 -9
- package/src/core/fs.ts +0 -38
- package/src/core/index.ts +0 -17
- package/src/index.ts +0 -33
- package/src/io/CliExecutor.ts +0 -69
- package/src/io/Logger.ts +0 -112
- package/src/io/RealFS.ts +0 -62
- package/src/io/TarGz.ts +0 -33
- package/src/io/__fixtures__.ts +0 -139
- package/src/io/fsUtils.ts +0 -44
- package/src/io/index.ts +0 -11
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
- package/src/package-verifier/checks/index.ts +0 -11
- package/src/package-verifier/index.ts +0 -9
- package/src/package-verifier/types.ts +0 -19
- package/src/package-verifier/verify-package.ts +0 -123
- package/src/simulator/LaunchSimulator.ts +0 -352
- package/src/simulator/index.ts +0 -8
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
BooleanTypeAnnotation,
|
|
10
|
-
DoubleTypeAnnotation,
|
|
11
|
-
FloatTypeAnnotation,
|
|
12
|
-
Int32TypeAnnotation,
|
|
13
|
-
MixedTypeAnnotation,
|
|
14
|
-
ObjectTypeAnnotation,
|
|
15
|
-
PropTypeAnnotation,
|
|
16
|
-
ReservedPropTypeAnnotation,
|
|
17
|
-
ReservedTypeAnnotation,
|
|
18
|
-
StringTypeAnnotation,
|
|
19
|
-
Nullable,
|
|
20
|
-
NativeModuleTypeAnnotation,
|
|
21
|
-
UnionTypeAnnotationMemberType,
|
|
22
|
-
} from '@react-native/codegen/lib/CodegenSchema';
|
|
23
|
-
|
|
24
|
-
type StringEnumTypeAnnotation = {
|
|
25
|
-
readonly type: 'StringEnumTypeAnnotation';
|
|
26
|
-
readonly options: readonly string[];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type Int32EnumTypeAnnotation = {
|
|
30
|
-
readonly type: 'Int32EnumTypeAnnotation';
|
|
31
|
-
readonly options: readonly number[];
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
type ArrayTypeAnnotation = {
|
|
35
|
-
readonly type: 'ArrayTypeAnnotation';
|
|
36
|
-
readonly elementType: TypeAnnotation;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export type TypeAnnotation =
|
|
40
|
-
| BooleanTypeAnnotation
|
|
41
|
-
| StringTypeAnnotation
|
|
42
|
-
| DoubleTypeAnnotation
|
|
43
|
-
| FloatTypeAnnotation
|
|
44
|
-
| Int32TypeAnnotation
|
|
45
|
-
| ReservedPropTypeAnnotation
|
|
46
|
-
| ReservedTypeAnnotation
|
|
47
|
-
| StringEnumTypeAnnotation
|
|
48
|
-
| Int32EnumTypeAnnotation
|
|
49
|
-
| MixedTypeAnnotation
|
|
50
|
-
| ArrayTypeAnnotation
|
|
51
|
-
| NativeModuleTypeAnnotation
|
|
52
|
-
| Nullable<NativeModuleTypeAnnotation>
|
|
53
|
-
| ObjectTypeAnnotation<TypeAnnotation>;
|
|
54
|
-
|
|
55
|
-
export class TypeAnnotationToTS {
|
|
56
|
-
constructor(private aliasPrefix: string = '') {}
|
|
57
|
-
|
|
58
|
-
convert(typeAnnotation: TypeAnnotation | undefined): string {
|
|
59
|
-
if (!typeAnnotation) {
|
|
60
|
-
return 'unknown';
|
|
61
|
-
}
|
|
62
|
-
switch (typeAnnotation.type) {
|
|
63
|
-
case 'BooleanTypeAnnotation':
|
|
64
|
-
return 'boolean';
|
|
65
|
-
case 'DoubleTypeAnnotation':
|
|
66
|
-
return 'number';
|
|
67
|
-
case 'FloatTypeAnnotation':
|
|
68
|
-
return 'number';
|
|
69
|
-
case 'Int32EnumTypeAnnotation':
|
|
70
|
-
return typeAnnotation.options.join(' | ');
|
|
71
|
-
case 'Int32TypeAnnotation':
|
|
72
|
-
return 'number';
|
|
73
|
-
case 'MixedTypeAnnotation':
|
|
74
|
-
return 'unknown';
|
|
75
|
-
case 'ReservedTypeAnnotation':
|
|
76
|
-
switch (typeAnnotation.name) {
|
|
77
|
-
case 'RootTag':
|
|
78
|
-
return 'Tag';
|
|
79
|
-
default:
|
|
80
|
-
return 'unknown';
|
|
81
|
-
}
|
|
82
|
-
case 'ReservedPropTypeAnnotation':
|
|
83
|
-
switch (typeAnnotation.name) {
|
|
84
|
-
case 'ColorPrimitive':
|
|
85
|
-
return 'ColorValue';
|
|
86
|
-
case 'DimensionPrimitive':
|
|
87
|
-
return 'unknown';
|
|
88
|
-
case 'EdgeInsetsPrimitive':
|
|
89
|
-
return 'unknown';
|
|
90
|
-
case 'ImageRequestPrimitive':
|
|
91
|
-
return 'unknown';
|
|
92
|
-
case 'ImageSourcePrimitive':
|
|
93
|
-
return 'unknown';
|
|
94
|
-
case 'PointPrimitive':
|
|
95
|
-
return 'unknown';
|
|
96
|
-
default:
|
|
97
|
-
return 'unknown';
|
|
98
|
-
}
|
|
99
|
-
case 'StringEnumTypeAnnotation':
|
|
100
|
-
return typeAnnotation.options
|
|
101
|
-
.map((option) => {
|
|
102
|
-
if (typeof option !== 'string') {
|
|
103
|
-
return option;
|
|
104
|
-
}
|
|
105
|
-
return wrapWithQuotes(option);
|
|
106
|
-
})
|
|
107
|
-
.join(' | ');
|
|
108
|
-
case 'StringTypeAnnotation':
|
|
109
|
-
return 'string';
|
|
110
|
-
case 'FunctionTypeAnnotation':
|
|
111
|
-
const { params, returnTypeAnnotation } = typeAnnotation;
|
|
112
|
-
const stringifiedArgs = params
|
|
113
|
-
.map(
|
|
114
|
-
(param) => `${param.name}: ${this.convert(param.typeAnnotation)}`
|
|
115
|
-
)
|
|
116
|
-
.join(', ');
|
|
117
|
-
return `(${stringifiedArgs}) => ${this.convert(returnTypeAnnotation)}`;
|
|
118
|
-
|
|
119
|
-
case 'EnumDeclaration':
|
|
120
|
-
return typeAnnotation.name;
|
|
121
|
-
case 'GenericObjectTypeAnnotation':
|
|
122
|
-
return 'Object';
|
|
123
|
-
case 'TypeAliasTypeAnnotation':
|
|
124
|
-
return this.aliasPrefix + typeAnnotation.name;
|
|
125
|
-
case 'UnionTypeAnnotation':
|
|
126
|
-
return this.convertUnionMemberAnnotation(typeAnnotation.memberType);
|
|
127
|
-
case 'NumberTypeAnnotation':
|
|
128
|
-
return 'number';
|
|
129
|
-
case 'NullableTypeAnnotation':
|
|
130
|
-
return `null | ${this.convert(typeAnnotation.typeAnnotation)}`;
|
|
131
|
-
case 'ObjectTypeAnnotation':
|
|
132
|
-
return this.convertObjectTypeAnnotation(typeAnnotation);
|
|
133
|
-
case 'PromiseTypeAnnotation':
|
|
134
|
-
return `Promise<${this.convert(typeAnnotation.elementType)}>`;
|
|
135
|
-
case 'VoidTypeAnnotation':
|
|
136
|
-
return 'void';
|
|
137
|
-
case 'ArrayTypeAnnotation':
|
|
138
|
-
return `${this.convert(typeAnnotation.elementType)}[]`;
|
|
139
|
-
default:
|
|
140
|
-
return 'unknown';
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private convertUnionMemberAnnotation(
|
|
145
|
-
memberAnnotation: UnionTypeAnnotationMemberType
|
|
146
|
-
) {
|
|
147
|
-
switch (memberAnnotation) {
|
|
148
|
-
case 'NumberTypeAnnotation':
|
|
149
|
-
return 'number';
|
|
150
|
-
case 'ObjectTypeAnnotation':
|
|
151
|
-
return 'Object';
|
|
152
|
-
case 'StringTypeAnnotation':
|
|
153
|
-
return 'string';
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private convertObjectTypeAnnotation(
|
|
158
|
-
objectTypeAnnotation: ObjectTypeAnnotation<
|
|
159
|
-
TypeAnnotation | Nullable<NativeModuleTypeAnnotation>
|
|
160
|
-
>
|
|
161
|
-
): string {
|
|
162
|
-
const props = objectTypeAnnotation.properties
|
|
163
|
-
.map((prop) => {
|
|
164
|
-
const maybeOptionalSymbol = prop.optional ? '?' : '';
|
|
165
|
-
return `${prop.name}${maybeOptionalSymbol}: ${this.convert(
|
|
166
|
-
prop.typeAnnotation
|
|
167
|
-
)}`;
|
|
168
|
-
})
|
|
169
|
-
.join(', ');
|
|
170
|
-
if (props.length === 0) {
|
|
171
|
-
return '{}';
|
|
172
|
-
}
|
|
173
|
-
return `{${props}}`;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export function getStringifiedTSDefaultValueFromPropTypeAnnotation(
|
|
178
|
-
propTypeAnnotation: PropTypeAnnotation
|
|
179
|
-
): string | null {
|
|
180
|
-
if ('default' in propTypeAnnotation && propTypeAnnotation.default !== null) {
|
|
181
|
-
if (typeof propTypeAnnotation.default === 'string') {
|
|
182
|
-
return wrapWithQuotes(propTypeAnnotation.default);
|
|
183
|
-
}
|
|
184
|
-
return String(propTypeAnnotation.default);
|
|
185
|
-
}
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function wrapWithQuotes(str: string): string {
|
|
190
|
-
if (str.includes("'")) {
|
|
191
|
-
return `"${str}"`;
|
|
192
|
-
} else {
|
|
193
|
-
return `'${str}'`;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
ComponentSchema,
|
|
10
|
-
NativeModuleSchema,
|
|
11
|
-
SchemaType as RawUberSchema,
|
|
12
|
-
} from '@react-native/codegen/lib/CodegenSchema';
|
|
13
|
-
import {
|
|
14
|
-
AbsolutePath,
|
|
15
|
-
ValueObject,
|
|
16
|
-
PackageJSON,
|
|
17
|
-
ProjectDependenciesManager,
|
|
18
|
-
CodegenConfig,
|
|
19
|
-
FS
|
|
20
|
-
} from '../../core';
|
|
21
|
-
// @ts-expect-error
|
|
22
|
-
import extractUberSchemaFromSpecFilePaths_ from '@react-native/codegen/lib/cli/combine/combine-js-to-schema.js';
|
|
23
|
-
import { CodegenError } from './CodegenError';
|
|
24
|
-
|
|
25
|
-
function createRawUberSchemaFromSpecFilePaths(
|
|
26
|
-
projectSourceFilePaths: AbsolutePath[]
|
|
27
|
-
): RawUberSchema {
|
|
28
|
-
return extractUberSchemaFromSpecFilePaths_(
|
|
29
|
-
projectSourceFilePaths.map((p) => p.getValue())
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type SpecSchema = ComponentSchema | NativeModuleSchema;
|
|
34
|
-
export type SpecSchemaType = SpecSchema['type'];
|
|
35
|
-
type FindSpecSchemaByType<
|
|
36
|
-
TType extends SpecSchemaType,
|
|
37
|
-
TSpecSchema = SpecSchema
|
|
38
|
-
> = TSpecSchema extends { type: TType } ? TSpecSchema : never;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Contains component and turbo module (NativeModule) schemas. The "Uber" word is used here to highlight that SpecSchemas don't extend this class.
|
|
42
|
-
*/
|
|
43
|
-
export class UberSchema implements ValueObject {
|
|
44
|
-
static fromSpecFilePaths(specPaths: AbsolutePath[]): UberSchema {
|
|
45
|
-
return new UberSchema(createRawUberSchemaFromSpecFilePaths(specPaths));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
static fromCodegenConfig(codegenConfig: CodegenConfig): UberSchema {
|
|
49
|
-
try {
|
|
50
|
-
return new UberSchema(
|
|
51
|
-
createRawUberSchemaFromSpecFilePaths(codegenConfig.getSpecFilePaths())
|
|
52
|
-
);
|
|
53
|
-
} catch (err) {
|
|
54
|
-
if (err instanceof Error) {
|
|
55
|
-
throw new CodegenError({
|
|
56
|
-
whatHappened: "Couldn't create the schema",
|
|
57
|
-
whatCanUserDo: [
|
|
58
|
-
`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}`,
|
|
59
|
-
],
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
throw err;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static async fromProject(
|
|
67
|
-
fs: FS,
|
|
68
|
-
projectRootPath: AbsolutePath,
|
|
69
|
-
onShouldAcceptCodegenConfig?: (
|
|
70
|
-
codegenVersion: number,
|
|
71
|
-
packageName: string
|
|
72
|
-
) => boolean
|
|
73
|
-
): Promise<UberSchema> {
|
|
74
|
-
const onShouldAcceptCodegenConfig_ =
|
|
75
|
-
onShouldAcceptCodegenConfig ?? ((x: number) => true);
|
|
76
|
-
const packageJSON = PackageJSON.fromProjectRootPath(
|
|
77
|
-
fs,
|
|
78
|
-
projectRootPath,
|
|
79
|
-
projectRootPath
|
|
80
|
-
);
|
|
81
|
-
const acceptedCodegenConfigs: CodegenConfig[] = [];
|
|
82
|
-
const appCodegenConfigs = packageJSON.getCodegenConfigs();
|
|
83
|
-
for (const codegenConfig of appCodegenConfigs) {
|
|
84
|
-
if (
|
|
85
|
-
onShouldAcceptCodegenConfig_(
|
|
86
|
-
codegenConfig.getVersion(),
|
|
87
|
-
packageJSON.name
|
|
88
|
-
)
|
|
89
|
-
) {
|
|
90
|
-
acceptedCodegenConfigs.push(codegenConfig);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
await new ProjectDependenciesManager(fs, projectRootPath).forEachAsync(
|
|
94
|
-
(dependency) => {
|
|
95
|
-
const codegenConfigs = dependency.getCodegenConfigs();
|
|
96
|
-
for (const codegenConfig of codegenConfigs) {
|
|
97
|
-
if (
|
|
98
|
-
onShouldAcceptCodegenConfig_(
|
|
99
|
-
codegenConfig.getVersion(),
|
|
100
|
-
dependency.readPackageJSON().name
|
|
101
|
-
)
|
|
102
|
-
) {
|
|
103
|
-
acceptedCodegenConfigs.push(codegenConfig);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
);
|
|
108
|
-
try {
|
|
109
|
-
return new UberSchema(
|
|
110
|
-
createRawUberSchemaFromSpecFilePaths(
|
|
111
|
-
acceptedCodegenConfigs.flatMap((codegenConfig) =>
|
|
112
|
-
codegenConfig.getSpecFilePaths()
|
|
113
|
-
)
|
|
114
|
-
)
|
|
115
|
-
);
|
|
116
|
-
} catch (err) {
|
|
117
|
-
if (err instanceof Error) {
|
|
118
|
-
throw new CodegenError({
|
|
119
|
-
whatHappened: "Couldn't create the schema",
|
|
120
|
-
whatCanUserDo: [
|
|
121
|
-
`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}`,
|
|
122
|
-
],
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
throw err;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private constructor(private schemaValue: RawUberSchema) {}
|
|
130
|
-
|
|
131
|
-
getValue(): RawUberSchema {
|
|
132
|
-
return this.schemaValue;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
findAllSpecSchemasByType<TSpecSchemaType extends SpecSchemaType>(
|
|
136
|
-
schemaType: TSpecSchemaType
|
|
137
|
-
): FindSpecSchemaByType<TSpecSchemaType>[] {
|
|
138
|
-
return Object.values(this.schemaValue.modules)
|
|
139
|
-
.filter((module) => module.type === schemaType)
|
|
140
|
-
.map((module) => module as FindSpecSchemaByType<TSpecSchemaType>);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
getSpecSchemaByFilenameMap(): ReadonlyMap<string, SpecSchema> {
|
|
144
|
-
return Object.entries(this.schemaValue.modules).reduce(
|
|
145
|
-
(acc, [moduleName, moduleSchema]) => {
|
|
146
|
-
acc.set(moduleName, moduleSchema);
|
|
147
|
-
return acc;
|
|
148
|
-
},
|
|
149
|
-
new Map<string, SpecSchema>()
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export * from './CodeGenerator';
|
|
9
|
-
export * from './UberSchema';
|
|
10
|
-
export * from './CodegenError';
|
|
11
|
-
export * from './EventUtils';
|
|
12
|
-
export * from './TypeAnnotationToTS';
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import Case from 'case';
|
|
9
|
-
import { AbsolutePath } from '../../core';
|
|
10
|
-
import { CodeGenerator } from '../core';
|
|
11
|
-
import { IndexTSTemplate, RNOHGeneratedPackageHTemplate } from '../templates';
|
|
12
|
-
import { BasePackageHTemplate } from '../templates/BasePackageHTemplate';
|
|
13
|
-
|
|
14
|
-
export type GlueCodeComponentDataV1 = { name: string; eventNames: string[] };
|
|
15
|
-
|
|
16
|
-
export type GlueCodeComponentDataV2 = { name: string; libraryCppName: string };
|
|
17
|
-
|
|
18
|
-
export type GlueCodeTurboModuleData = { name: string };
|
|
19
|
-
|
|
20
|
-
export type GlueCodeDataV1 = {
|
|
21
|
-
components: GlueCodeComponentDataV1[];
|
|
22
|
-
turboModules: GlueCodeTurboModuleData[];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type LibraryName = string;
|
|
26
|
-
export type GlueCodeDataV2 = Map<
|
|
27
|
-
LibraryName,
|
|
28
|
-
{
|
|
29
|
-
components: GlueCodeComponentDataV2[];
|
|
30
|
-
turboModules: GlueCodeTurboModuleData[];
|
|
31
|
-
}
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
export type GlueCodeData = {
|
|
35
|
-
v1: GlueCodeDataV1;
|
|
36
|
-
v2: GlueCodeDataV2;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Generates code based on UberGenerators results. If UberGenerators produce "leaves" (concrete turbo module or component classes),
|
|
41
|
-
* this class generates "branches" (barrel files like index.ts) and "trunks" (package file or files).
|
|
42
|
-
*/
|
|
43
|
-
export class AppBuildTimeGlueCodeGenerator
|
|
44
|
-
implements CodeGenerator<GlueCodeData>
|
|
45
|
-
{
|
|
46
|
-
constructor(
|
|
47
|
-
private cppOutputPath: AbsolutePath,
|
|
48
|
-
private etsOutputPath: AbsolutePath,
|
|
49
|
-
private codegenNoticeLines: string[]
|
|
50
|
-
) {}
|
|
51
|
-
|
|
52
|
-
generate({ v1, v2 }: GlueCodeData): Map<AbsolutePath, string> {
|
|
53
|
-
const fileContentByPath = new Map<AbsolutePath, string>();
|
|
54
|
-
const generatedPackageH_v1 = new RNOHGeneratedPackageHTemplate();
|
|
55
|
-
const components_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
|
|
56
|
-
const turboModules_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
|
|
57
|
-
const generated_indexETS = new IndexTSTemplate(this.codegenNoticeLines);
|
|
58
|
-
|
|
59
|
-
generated_indexETS.addReexport({ from: './ts' });
|
|
60
|
-
v1.components.forEach(({ name, eventNames }) => {
|
|
61
|
-
components_indexTS.addReexport({ from: `./${name}` });
|
|
62
|
-
generatedPackageH_v1.addComponent({
|
|
63
|
-
name,
|
|
64
|
-
supportedEventNames: eventNames,
|
|
65
|
-
isArkTSComponent: true,
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
v1.turboModules.forEach((turboModule) => {
|
|
70
|
-
turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
|
|
71
|
-
generatedPackageH_v1.addTurboModule(turboModule);
|
|
72
|
-
});
|
|
73
|
-
v2.forEach(({ components, turboModules }, libraryName) => {
|
|
74
|
-
const basePackageClassName = `Base${Case.pascal(libraryName)}Package`;
|
|
75
|
-
const generatedPackageH_v2 = new BasePackageHTemplate(
|
|
76
|
-
basePackageClassName,
|
|
77
|
-
this.codegenNoticeLines
|
|
78
|
-
);
|
|
79
|
-
components.forEach((component) => {
|
|
80
|
-
generatedPackageH_v2.addComponent({
|
|
81
|
-
...component,
|
|
82
|
-
isArkTSComponent: false,
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
turboModules.forEach((turboModule) => {
|
|
86
|
-
turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
|
|
87
|
-
generatedPackageH_v2.addTurboModule(turboModule);
|
|
88
|
-
});
|
|
89
|
-
fileContentByPath.set(
|
|
90
|
-
this.cppOutputPath.copyWithNewSegment(
|
|
91
|
-
libraryName,
|
|
92
|
-
'RNOH',
|
|
93
|
-
'generated',
|
|
94
|
-
`${basePackageClassName}.h`
|
|
95
|
-
),
|
|
96
|
-
generatedPackageH_v2.build()
|
|
97
|
-
);
|
|
98
|
-
});
|
|
99
|
-
fileContentByPath.set(
|
|
100
|
-
this.cppOutputPath.copyWithNewSegment('RNOHGeneratedPackage.h'),
|
|
101
|
-
generatedPackageH_v1.build()
|
|
102
|
-
);
|
|
103
|
-
fileContentByPath.set(
|
|
104
|
-
this.etsOutputPath.copyWithNewSegment('ts.ts'),
|
|
105
|
-
new IndexTSTemplate(this.codegenNoticeLines)
|
|
106
|
-
.addReexport({ from: './components/ts', as: 'RNC' })
|
|
107
|
-
.addReexport({ from: './turboModules/ts', as: 'TM' })
|
|
108
|
-
.build()
|
|
109
|
-
);
|
|
110
|
-
fileContentByPath.set(
|
|
111
|
-
this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'),
|
|
112
|
-
components_indexTS.build()
|
|
113
|
-
);
|
|
114
|
-
fileContentByPath.set(
|
|
115
|
-
this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'),
|
|
116
|
-
turboModules_indexTS.build()
|
|
117
|
-
);
|
|
118
|
-
fileContentByPath.set(
|
|
119
|
-
this.etsOutputPath.copyWithNewSegment('index.ets'),
|
|
120
|
-
generated_indexETS.build()
|
|
121
|
-
);
|
|
122
|
-
return fileContentByPath;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { AbsolutePath } from '../../core';
|
|
9
|
-
import {
|
|
10
|
-
CodegenError,
|
|
11
|
-
TypeAnnotationToTS,
|
|
12
|
-
createEventNameFromEventHandlerName,
|
|
13
|
-
getStringifiedTSDefaultValueFromPropTypeAnnotation,
|
|
14
|
-
} from '../core';
|
|
15
|
-
import type { SpecCodeGenerator } from '../core';
|
|
16
|
-
import { SpecSchema } from '../core';
|
|
17
|
-
import {
|
|
18
|
-
ComponentDescriptorHTemplate,
|
|
19
|
-
ComponentJSIBinderHTemplate,
|
|
20
|
-
ComponentUtilsTSTemplate,
|
|
21
|
-
} from '../templates';
|
|
22
|
-
import { GlueCodeComponentDataV1 } from './AppBuildTimeGlueCodeGenerator';
|
|
23
|
-
|
|
24
|
-
export class ArkTSComponentCodeGeneratorArkTS implements SpecCodeGenerator {
|
|
25
|
-
private glueCodeDataItems: GlueCodeComponentDataV1[] = [];
|
|
26
|
-
|
|
27
|
-
constructor(
|
|
28
|
-
private cppOutputPath: AbsolutePath,
|
|
29
|
-
private tsOutputPath: AbsolutePath,
|
|
30
|
-
private codegenNoticeLines: string[],
|
|
31
|
-
private rnohImport: string
|
|
32
|
-
) {}
|
|
33
|
-
|
|
34
|
-
getGlueCodeData(): GlueCodeComponentDataV1[] {
|
|
35
|
-
return this.glueCodeDataItems;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
generate(schema: SpecSchema): Map<AbsolutePath, string> {
|
|
39
|
-
if (schema.type !== 'Component') {
|
|
40
|
-
throw new CodegenError({
|
|
41
|
-
whatHappened: `ComponentCodeGenerator can't generate code for a module type: ${schema.type}`,
|
|
42
|
-
unexpected: true,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
const typeAnnotationToTS = new TypeAnnotationToTS();
|
|
46
|
-
const result = new Map<AbsolutePath, string>();
|
|
47
|
-
Object.entries(schema.components).map(([name, shape]) => {
|
|
48
|
-
const componentDescriptorHTemplate = new ComponentDescriptorHTemplate(
|
|
49
|
-
name
|
|
50
|
-
);
|
|
51
|
-
const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(
|
|
52
|
-
name,
|
|
53
|
-
this.codegenNoticeLines
|
|
54
|
-
);
|
|
55
|
-
const componentUtilsTSTemplate = new ComponentUtilsTSTemplate(
|
|
56
|
-
name,
|
|
57
|
-
this.codegenNoticeLines,
|
|
58
|
-
this.rnohImport
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
shape.props.forEach((prop) => {
|
|
62
|
-
componentJSIBinderHTemplate.addProp({
|
|
63
|
-
name: prop.name,
|
|
64
|
-
isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
componentUtilsTSTemplate.addProp({
|
|
68
|
-
name: prop.name,
|
|
69
|
-
tsType: typeAnnotationToTS.convert(prop.typeAnnotation),
|
|
70
|
-
defaultValue: getStringifiedTSDefaultValueFromPropTypeAnnotation(
|
|
71
|
-
prop.typeAnnotation
|
|
72
|
-
),
|
|
73
|
-
isOptional: prop.optional,
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
shape.commands.forEach((command) => {
|
|
77
|
-
componentJSIBinderHTemplate.addCommand({
|
|
78
|
-
name: command.name,
|
|
79
|
-
});
|
|
80
|
-
componentUtilsTSTemplate.addCommand({
|
|
81
|
-
name: command.name,
|
|
82
|
-
argsTSType:
|
|
83
|
-
'[' +
|
|
84
|
-
command.typeAnnotation.params
|
|
85
|
-
.map(
|
|
86
|
-
(param) =>
|
|
87
|
-
typeAnnotationToTS.convert(param.typeAnnotation) +
|
|
88
|
-
(param.optional ? '?' : '')
|
|
89
|
-
)
|
|
90
|
-
.join(', ') +
|
|
91
|
-
']',
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
shape.events.forEach((event) => {
|
|
96
|
-
componentUtilsTSTemplate.addEvent({
|
|
97
|
-
name: createEventNameFromEventHandlerName(event.name),
|
|
98
|
-
payloadTSType: event.typeAnnotation.argument
|
|
99
|
-
? typeAnnotationToTS.convert(event.typeAnnotation.argument)
|
|
100
|
-
: 'undefined',
|
|
101
|
-
});
|
|
102
|
-
componentJSIBinderHTemplate.addEvent({
|
|
103
|
-
type: event.bubblingType,
|
|
104
|
-
eventHandlerName: event.name,
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
result.set(
|
|
108
|
-
this.cppOutputPath.copyWithNewSegment(`${name}ComponentDescriptor.h`),
|
|
109
|
-
componentDescriptorHTemplate.build()
|
|
110
|
-
);
|
|
111
|
-
result.set(
|
|
112
|
-
this.cppOutputPath.copyWithNewSegment(`${name}JSIBinder.h`),
|
|
113
|
-
componentJSIBinderHTemplate.build()
|
|
114
|
-
);
|
|
115
|
-
result.set(
|
|
116
|
-
this.tsOutputPath.copyWithNewSegment(`${name}.ts`),
|
|
117
|
-
componentUtilsTSTemplate.build()
|
|
118
|
-
);
|
|
119
|
-
this.glueCodeDataItems.push({
|
|
120
|
-
name,
|
|
121
|
-
eventNames: shape.events.map((e) =>
|
|
122
|
-
createEventNameFromEventHandlerName(e.name)
|
|
123
|
-
),
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
}
|