@react-native-oh/react-native-harmony-cli 0.0.36 → 0.0.40-1

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.
Files changed (87) hide show
  1. package/dist/autolinking/Autolinking.js +14 -11
  2. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +2 -1
  3. package/dist/codegen/generators/LibGlueCodeGenerator.js +2 -2
  4. package/dist/codegen/generators/UberGeneratorV1.js +9 -2
  5. package/dist/codegen/generators/UberGeneratorV2.js +8 -1
  6. package/dist/codegen/templates/BasePackageHTemplate.js +12 -1
  7. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +12 -1
  8. package/dist/commands/codegen-harmony.js +16 -5
  9. package/dist/commands/run-harmony.js +49 -27
  10. package/dist/core/ProjectDependenciesManager.js +5 -7
  11. package/dist/simulator/LaunchSimulator.js +318 -0
  12. package/dist/simulator/index.js +23 -0
  13. package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
  14. package/package.json +13 -5
  15. package/.prettierrc +0 -6
  16. package/src/assetResolver.ts +0 -134
  17. package/src/autolinking/Autolinking.test.ts +0 -483
  18. package/src/autolinking/Autolinking.ts +0 -382
  19. package/src/autolinking/index.ts +0 -8
  20. package/src/codegen/core/CodeGenerator.ts +0 -16
  21. package/src/codegen/core/CodegenError.ts +0 -10
  22. package/src/codegen/core/EventUtils.ts +0 -23
  23. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
  24. package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
  25. package/src/codegen/core/UberSchema.ts +0 -152
  26. package/src/codegen/core/index.ts +0 -12
  27. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -120
  28. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
  29. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
  30. package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
  31. package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
  32. package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
  33. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
  34. package/src/codegen/generators/UberGeneratorV1.ts +0 -75
  35. package/src/codegen/generators/UberGeneratorV2.ts +0 -114
  36. package/src/codegen/generators/index.ts +0 -15
  37. package/src/codegen/index.ts +0 -9
  38. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
  39. package/src/codegen/templates/BasePackageHTemplate.ts +0 -147
  40. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
  41. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
  42. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
  43. package/src/codegen/templates/IndexTSTemplate.ts +0 -62
  44. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -138
  45. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
  46. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
  47. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
  48. package/src/codegen/templates/index.ts +0 -16
  49. package/src/commands/bundle-harmony.ts +0 -134
  50. package/src/commands/codegen-harmony.ts +0 -297
  51. package/src/commands/codegen-lib-harmony.ts +0 -389
  52. package/src/commands/create-metro-host-constants.ts +0 -55
  53. package/src/commands/index.ts +0 -16
  54. package/src/commands/init.ts +0 -755
  55. package/src/commands/link-harmony.ts +0 -102
  56. package/src/commands/pack-harmony.ts +0 -128
  57. package/src/commands/run-harmony.ts +0 -478
  58. package/src/commands/types.ts +0 -21
  59. package/src/commands/unpack-harmony.ts +0 -238
  60. package/src/commands/verify-package-harmony.ts +0 -113
  61. package/src/core/AbsolutePath.ts +0 -66
  62. package/src/core/CodegenConfig.ts +0 -67
  63. package/src/core/DescriptiveError.ts +0 -68
  64. package/src/core/FileSystem.ts +0 -57
  65. package/src/core/OHPackageJSON5.ts +0 -30
  66. package/src/core/PackageJSON.ts +0 -104
  67. package/src/core/ProjectDependenciesManager.ts +0 -103
  68. package/src/core/ValidationError.ts +0 -8
  69. package/src/core/ValueObject.ts +0 -9
  70. package/src/core/fs.ts +0 -38
  71. package/src/core/index.ts +0 -17
  72. package/src/index.ts +0 -33
  73. package/src/io/CliExecutor.ts +0 -69
  74. package/src/io/Logger.ts +0 -112
  75. package/src/io/RealFS.ts +0 -62
  76. package/src/io/TarGz.ts +0 -33
  77. package/src/io/__fixtures__.ts +0 -139
  78. package/src/io/fsUtils.ts +0 -44
  79. package/src/io/index.ts +0 -11
  80. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
  81. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
  82. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
  83. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
  84. package/src/package-verifier/checks/index.ts +0 -11
  85. package/src/package-verifier/index.ts +0 -9
  86. package/src/package-verifier/types.ts +0 -19
  87. package/src/package-verifier/verify-package.ts +0 -123
@@ -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,120 +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
- });
66
- });
67
-
68
- v1.turboModules.forEach((turboModule) => {
69
- turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
70
- generatedPackageH_v1.addTurboModule(turboModule);
71
- });
72
- v2.forEach(({ components, turboModules }, libraryName) => {
73
- const basePackageClassName = `Base${Case.pascal(libraryName)}Package`;
74
- const generatedPackageH_v2 = new BasePackageHTemplate(
75
- basePackageClassName,
76
- this.codegenNoticeLines
77
- );
78
- components.forEach((component) => {
79
- generatedPackageH_v2.addComponent(component);
80
- });
81
- turboModules.forEach((turboModule) => {
82
- turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
83
- generatedPackageH_v2.addTurboModule(turboModule);
84
- });
85
- fileContentByPath.set(
86
- this.cppOutputPath.copyWithNewSegment(
87
- libraryName,
88
- 'RNOH',
89
- 'generated',
90
- `${basePackageClassName}.h`
91
- ),
92
- generatedPackageH_v2.build()
93
- );
94
- });
95
- fileContentByPath.set(
96
- this.cppOutputPath.copyWithNewSegment('RNOHGeneratedPackage.h'),
97
- generatedPackageH_v1.build()
98
- );
99
- fileContentByPath.set(
100
- this.etsOutputPath.copyWithNewSegment('ts.ts'),
101
- new IndexTSTemplate(this.codegenNoticeLines)
102
- .addReexport({ from: './components/ts', as: 'RNC' })
103
- .addReexport({ from: './turboModules/ts', as: 'TM' })
104
- .build()
105
- );
106
- fileContentByPath.set(
107
- this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'),
108
- components_indexTS.build()
109
- );
110
- fileContentByPath.set(
111
- this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'),
112
- turboModules_indexTS.build()
113
- );
114
- fileContentByPath.set(
115
- this.etsOutputPath.copyWithNewSegment('index.ets'),
116
- generated_indexETS.build()
117
- );
118
- return fileContentByPath;
119
- }
120
- }
@@ -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
- }