@react-native-oh/react-native-harmony-cli 0.0.36 → 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.
Files changed (137) hide show
  1. package/README.md +11 -11
  2. package/dist/assetResolver.js +74 -43
  3. package/dist/autolinking/Autolinking.js +183 -179
  4. package/dist/codegen/core/CodegenError.js +23 -3
  5. package/dist/codegen/core/EventUtils.js +3 -3
  6. package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
  7. package/dist/codegen/core/UberSchema.js +96 -57
  8. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +42 -28
  9. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
  10. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
  11. package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
  12. package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
  13. package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
  14. package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
  15. package/dist/codegen/generators/UberGeneratorV1.js +24 -18
  16. package/dist/codegen/generators/UberGeneratorV2.js +36 -28
  17. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
  18. package/dist/codegen/templates/BasePackageHTemplate.js +21 -109
  19. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -53
  20. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
  21. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
  22. package/dist/codegen/templates/IndexTSTemplate.js +17 -37
  23. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -108
  24. package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
  25. package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
  26. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
  27. package/dist/commands/bundle-harmony.js +138 -53
  28. package/dist/commands/codegen-harmony.js +175 -104
  29. package/dist/commands/codegen-lib-harmony.js +116 -76
  30. package/dist/commands/create-metro-host-constants.js +47 -18
  31. package/dist/commands/init.js +961 -537
  32. package/dist/commands/link-harmony.js +71 -33
  33. package/dist/commands/pack-harmony.js +108 -47
  34. package/dist/commands/run-harmony.js +520 -352
  35. package/dist/commands/unpack-harmony.js +198 -105
  36. package/dist/commands/verify-package-harmony.js +108 -54
  37. package/dist/core/AbsolutePath.js +47 -31
  38. package/dist/core/CodegenConfig.js +22 -24
  39. package/dist/core/DescriptiveError.js +37 -18
  40. package/dist/core/FileSystem.js +18 -14
  41. package/dist/core/OHPackageJSON5.js +23 -17
  42. package/dist/core/PackageJSON.js +42 -26
  43. package/dist/core/ProjectDependenciesManager.js +96 -46
  44. package/dist/core/ValidationError.js +22 -2
  45. package/dist/core/fs.js +6 -9
  46. package/dist/index.js +1 -1
  47. package/dist/io/CliExecutor.js +98 -46
  48. package/dist/io/Logger.js +46 -40
  49. package/dist/io/RealFS.js +88 -35
  50. package/dist/io/TarGz.js +8 -11
  51. package/dist/io/__fixtures__.js +141 -79
  52. package/dist/io/fsUtils.js +12 -13
  53. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
  54. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
  55. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
  56. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
  57. package/dist/package-verifier/verify-package.js +132 -55
  58. package/dist/simulator/LaunchSimulator.js +395 -0
  59. package/dist/simulator/index.js +23 -0
  60. package/jest.config.js +12 -12
  61. package/package.json +78 -70
  62. package/react-native.config.js +17 -17
  63. package/tsconfig.build.json +6 -6
  64. package/tsconfig.json +2 -2
  65. package/.prettierrc +0 -6
  66. package/src/assetResolver.ts +0 -134
  67. package/src/autolinking/Autolinking.test.ts +0 -483
  68. package/src/autolinking/Autolinking.ts +0 -382
  69. package/src/autolinking/index.ts +0 -8
  70. package/src/codegen/core/CodeGenerator.ts +0 -16
  71. package/src/codegen/core/CodegenError.ts +0 -10
  72. package/src/codegen/core/EventUtils.ts +0 -23
  73. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
  74. package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
  75. package/src/codegen/core/UberSchema.ts +0 -152
  76. package/src/codegen/core/index.ts +0 -12
  77. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -120
  78. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
  79. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
  80. package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
  81. package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
  82. package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
  83. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
  84. package/src/codegen/generators/UberGeneratorV1.ts +0 -75
  85. package/src/codegen/generators/UberGeneratorV2.ts +0 -114
  86. package/src/codegen/generators/index.ts +0 -15
  87. package/src/codegen/index.ts +0 -9
  88. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
  89. package/src/codegen/templates/BasePackageHTemplate.ts +0 -147
  90. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
  91. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
  92. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
  93. package/src/codegen/templates/IndexTSTemplate.ts +0 -62
  94. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -138
  95. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
  96. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
  97. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
  98. package/src/codegen/templates/index.ts +0 -16
  99. package/src/commands/bundle-harmony.ts +0 -134
  100. package/src/commands/codegen-harmony.ts +0 -297
  101. package/src/commands/codegen-lib-harmony.ts +0 -389
  102. package/src/commands/create-metro-host-constants.ts +0 -55
  103. package/src/commands/index.ts +0 -16
  104. package/src/commands/init.ts +0 -755
  105. package/src/commands/link-harmony.ts +0 -102
  106. package/src/commands/pack-harmony.ts +0 -128
  107. package/src/commands/run-harmony.ts +0 -478
  108. package/src/commands/types.ts +0 -21
  109. package/src/commands/unpack-harmony.ts +0 -238
  110. package/src/commands/verify-package-harmony.ts +0 -113
  111. package/src/core/AbsolutePath.ts +0 -66
  112. package/src/core/CodegenConfig.ts +0 -67
  113. package/src/core/DescriptiveError.ts +0 -68
  114. package/src/core/FileSystem.ts +0 -57
  115. package/src/core/OHPackageJSON5.ts +0 -30
  116. package/src/core/PackageJSON.ts +0 -104
  117. package/src/core/ProjectDependenciesManager.ts +0 -103
  118. package/src/core/ValidationError.ts +0 -8
  119. package/src/core/ValueObject.ts +0 -9
  120. package/src/core/fs.ts +0 -38
  121. package/src/core/index.ts +0 -17
  122. package/src/index.ts +0 -33
  123. package/src/io/CliExecutor.ts +0 -69
  124. package/src/io/Logger.ts +0 -112
  125. package/src/io/RealFS.ts +0 -62
  126. package/src/io/TarGz.ts +0 -33
  127. package/src/io/__fixtures__.ts +0 -139
  128. package/src/io/fsUtils.ts +0 -44
  129. package/src/io/index.ts +0 -11
  130. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
  131. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
  132. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
  133. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
  134. package/src/package-verifier/checks/index.ts +0 -11
  135. package/src/package-verifier/index.ts +0 -9
  136. package/src/package-verifier/types.ts +0 -19
  137. package/src/package-verifier/verify-package.ts +0 -123
@@ -1,122 +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
- TypeAnnotationToTS,
11
- createEventNameFromEventHandlerName,
12
- getStringifiedTSDefaultValueFromPropTypeAnnotation,
13
- } from '../core';
14
- import type { CodeGenerator, UberSchema } from '../core';
15
- import {
16
- ComponentJSIBinderHTemplate,
17
- ComponentUtilsTSTemplate,
18
- } from '../templates';
19
- import { ArkTSComponentLibGlueCodeData } from './LibGlueCodeGenerator';
20
-
21
- /**
22
- * Generates component code for ArkTS components used in C-API architecture.
23
- */
24
- export class ArkTSComponentCodeGeneratorCAPI
25
- implements CodeGenerator<UberSchema>
26
- {
27
- private glueCodeDataItems: ArkTSComponentLibGlueCodeData[] = [];
28
-
29
- constructor(
30
- private cppOutputPath: AbsolutePath,
31
- private tsOutputPath: AbsolutePath,
32
- private codegenNoticeLines: string[],
33
- private rnohImport: string
34
- ) {}
35
-
36
- getLibGlueCodeData(): ArkTSComponentLibGlueCodeData[] {
37
- return this.glueCodeDataItems;
38
- }
39
-
40
- generate(uberSchema: UberSchema): Map<AbsolutePath, string> {
41
- const typeAnnotationToTS = new TypeAnnotationToTS();
42
- const result = new Map<AbsolutePath, string>();
43
- const componentSpecSchemas =
44
- uberSchema.findAllSpecSchemasByType('Component');
45
-
46
- for (const componentSpecSchema of componentSpecSchemas) {
47
- Object.entries(componentSpecSchema.components).map(([name, shape]) => {
48
- const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(
49
- name,
50
- this.codegenNoticeLines
51
- );
52
- const componentUtilsTSTemplate = new ComponentUtilsTSTemplate(
53
- name,
54
- this.codegenNoticeLines,
55
- this.rnohImport
56
- );
57
- shape.props.forEach((prop) => {
58
- componentJSIBinderHTemplate.addProp({
59
- name: prop.name,
60
- isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
61
- });
62
-
63
- componentUtilsTSTemplate.addProp({
64
- name: prop.name,
65
- tsType: typeAnnotationToTS.convert(prop.typeAnnotation),
66
- defaultValue: getStringifiedTSDefaultValueFromPropTypeAnnotation(
67
- prop.typeAnnotation
68
- ),
69
- isOptional: prop.optional,
70
- });
71
- });
72
- shape.commands.forEach((command) => {
73
- componentJSIBinderHTemplate.addCommand({
74
- name: command.name,
75
- });
76
- componentUtilsTSTemplate.addCommand({
77
- name: command.name,
78
- argsTSType:
79
- '[' +
80
- command.typeAnnotation.params
81
- .map(
82
- (param) =>
83
- typeAnnotationToTS.convert(param.typeAnnotation) +
84
- (param.optional ? '?' : '')
85
- )
86
- .join(', ') +
87
- ']',
88
- });
89
- });
90
-
91
- shape.events.forEach((event) => {
92
- componentUtilsTSTemplate.addEvent({
93
- name: createEventNameFromEventHandlerName(event.name),
94
- payloadTSType: event.typeAnnotation.argument
95
- ? typeAnnotationToTS.convert(event.typeAnnotation.argument)
96
- : 'undefined',
97
- });
98
- componentJSIBinderHTemplate.addEvent({
99
- type: event.bubblingType,
100
- eventHandlerName: event.name,
101
- });
102
- });
103
- result.set(
104
- this.cppOutputPath.copyWithNewSegment(`${name}JSIBinder.h`),
105
- componentJSIBinderHTemplate.build()
106
- );
107
- result.set(
108
- this.tsOutputPath.copyWithNewSegment(`${name}.ts`),
109
- componentUtilsTSTemplate.build()
110
- );
111
- this.glueCodeDataItems.push({
112
- componentName: name,
113
- eventNames: shape.events.map((event) =>
114
- createEventNameFromEventHandlerName(event.name)
115
- ),
116
- });
117
- });
118
- }
119
-
120
- return result;
121
- }
122
- }
@@ -1,95 +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 { CodeGenerator, UberSchema } from '../core';
10
- import {
11
- BaseComponentInstanceHTemplate,
12
- ComponentJSIBinderHTemplate,
13
- } from '../templates';
14
- import { GlueCodeComponentDataV2 } from './AppBuildTimeGlueCodeGenerator';
15
-
16
- export type LibraryData = {
17
- libraryCppName: string;
18
- uberSchema: UberSchema;
19
- };
20
-
21
- export class CppComponentCodeGenerator implements CodeGenerator<LibraryData> {
22
- private glueCodeComponentsData: GlueCodeComponentDataV2[] = [];
23
-
24
- constructor(
25
- private onGetRNOHOutputPath: (filename: string) => AbsolutePath,
26
- private codegenNoticeLines: string[]
27
- ) {}
28
-
29
- getGlueCodeData() {
30
- return this.glueCodeComponentsData;
31
- }
32
-
33
- generate({
34
- libraryCppName,
35
- uberSchema,
36
- }: LibraryData): Map<AbsolutePath, string> {
37
- const fileContentByPath = new Map<AbsolutePath, string>();
38
- for (const [_filename, schema] of uberSchema
39
- .getSpecSchemaByFilenameMap()
40
- .entries()) {
41
- if (schema.type === 'Component') {
42
- Object.entries(schema.components).map(([componentName, shape]) => {
43
- const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(
44
- componentName,
45
- this.codegenNoticeLines
46
- );
47
- const componentInstanceSpecHTemplate =
48
- new BaseComponentInstanceHTemplate(
49
- componentName,
50
- libraryCppName,
51
- this.codegenNoticeLines
52
- );
53
- shape.props.forEach((prop) => {
54
- componentJSIBinderHTemplate.addProp({
55
- name: prop.name,
56
- isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
57
- });
58
- });
59
- shape.events.forEach((event) => {
60
- componentJSIBinderHTemplate.addEvent({
61
- type: event.bubblingType,
62
- eventHandlerName: event.name,
63
- });
64
- });
65
- shape.commands.forEach((command) => {
66
- componentJSIBinderHTemplate.addCommand({
67
- name: command.name,
68
- });
69
- componentInstanceSpecHTemplate.addCommand({
70
- name: command.name,
71
- args: command.typeAnnotation.params.map((param) => ({
72
- name: param.name,
73
- typeAnnotation: param.typeAnnotation,
74
- })),
75
- });
76
- });
77
- fileContentByPath.set(
78
- this.onGetRNOHOutputPath(`${componentName}JSIBinder.h`),
79
- componentJSIBinderHTemplate.build()
80
- );
81
- fileContentByPath.set(
82
- this.onGetRNOHOutputPath(`Base${componentName}ComponentInstance.h`),
83
- componentInstanceSpecHTemplate.build()
84
- );
85
- this.glueCodeComponentsData.push({
86
- name: componentName,
87
- libraryCppName,
88
- });
89
- });
90
- }
91
- }
92
-
93
- return fileContentByPath;
94
- }
95
- }
@@ -1,98 +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 { BasePackageHTemplate } from '../templates/BasePackageHTemplate';
12
- import { IndexTSTemplate } from '../templates';
13
- import { GlueCodeTurboModuleData } from './AppBuildTimeGlueCodeGenerator';
14
-
15
- export type ArkTSComponentLibGlueCodeData = {
16
- componentName: string;
17
- eventNames: string[];
18
- };
19
- export type CppComponentLibGlueCodeData = { componentName: string };
20
-
21
- type LibGlueCodeData = {
22
- libraryCppName: string;
23
- turboModules: GlueCodeTurboModuleData[];
24
- arkTSComponents: ArkTSComponentLibGlueCodeData[];
25
- cppComponents: CppComponentLibGlueCodeData[];
26
- };
27
-
28
- /**
29
- * NOTE: This class is coupled with the generated code structure defined in the codegen-harmony-lib.
30
- */
31
- export class LibGlueCodeGenerator implements CodeGenerator<LibGlueCodeData> {
32
- constructor(
33
- private cppOutputPath: AbsolutePath,
34
- private etsOutputPath: AbsolutePath,
35
- private codegenNoticeLines: string[]
36
- ) {}
37
-
38
- generate({
39
- libraryCppName,
40
- turboModules,
41
- arkTSComponents,
42
- cppComponents,
43
- }: LibGlueCodeData): Map<AbsolutePath, string> {
44
- const fileContentByPath = new Map<AbsolutePath, string>();
45
- const basePackageClassName = `Base${Case.pascal(libraryCppName)}Package`;
46
- const turboModules_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
47
- const components_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
48
- const generated_indexETS = new IndexTSTemplate(this.codegenNoticeLines);
49
-
50
- const basePackageTemplate = new BasePackageHTemplate(
51
- basePackageClassName,
52
- this.codegenNoticeLines
53
- );
54
- turboModules.forEach((turboModule) => {
55
- basePackageTemplate.addTurboModule(turboModule);
56
- turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
57
- });
58
- arkTSComponents.forEach(({ componentName, eventNames }) => {
59
- components_indexTS.addReexport({ from: `./${componentName}` });
60
- basePackageTemplate.addComponent({ name: componentName, libraryCppName });
61
- eventNames.forEach((eventName) =>
62
- basePackageTemplate.addArkTSEvent({ name: eventName })
63
- );
64
- });
65
- cppComponents.forEach(({ componentName }) => {
66
- basePackageTemplate.addComponent({ name: componentName, libraryCppName });
67
- });
68
- fileContentByPath.set(
69
- this.cppOutputPath.copyWithNewSegment(
70
- 'RNOH',
71
- 'generated',
72
- `${basePackageClassName}.h`
73
- ),
74
- basePackageTemplate.build()
75
- );
76
- fileContentByPath.set(
77
- this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'),
78
- components_indexTS.build()
79
- );
80
- fileContentByPath.set(
81
- this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'),
82
- turboModules_indexTS.build()
83
- );
84
- fileContentByPath.set(
85
- this.etsOutputPath.copyWithNewSegment('ts.ts'),
86
- new IndexTSTemplate(this.codegenNoticeLines)
87
- .addReexport({ from: './components/ts', as: 'RNC' })
88
- .addReexport({ from: './turboModules/ts', as: 'TM' })
89
- .build()
90
- );
91
- generated_indexETS.addReexport({ from: './ts' });
92
- fileContentByPath.set(
93
- this.etsOutputPath.copyWithNewSegment('index.ets'),
94
- generated_indexETS.build()
95
- );
96
- return fileContentByPath;
97
- }
98
- }
@@ -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 { AbsolutePath } from '../../core';
9
- import type { SpecCodeGenerator } from '../core';
10
- import {
11
- TurboModuleCppTemplate,
12
- TurboModuleHTemplate,
13
- TurboModuleInterfaceTS,
14
- } from '../templates';
15
- import {
16
- TypeAnnotationToTS,
17
- wrapWithQuotes,
18
- SpecSchema,
19
- CodegenError,
20
- } from '../core';
21
- import { GlueCodeTurboModuleData } from './AppBuildTimeGlueCodeGenerator';
22
-
23
- /**
24
- * Generates boilerplate code for Turbo Modules.
25
- */
26
- export class NativeModuleCodeGenerator implements SpecCodeGenerator {
27
- private glueCodeTurboModulesData: GlueCodeTurboModuleData[] = [];
28
- constructor(
29
- private cppOutputPath: AbsolutePath,
30
- private etsOutputPath: AbsolutePath,
31
- private codegenNoticeLines: string[],
32
- private rnohImport: string
33
- ) {}
34
-
35
- getGlueCodeData() {
36
- return this.glueCodeTurboModulesData;
37
- }
38
-
39
- generate(schema: SpecSchema): Map<AbsolutePath, string> {
40
- const result = new Map<AbsolutePath, string>();
41
- if (schema.type !== 'NativeModule') {
42
- throw new CodegenError({
43
- whatHappened: `NativeModuleCodeGenerator can't generate code for module type: ${schema.type}`,
44
- unexpected: true,
45
- });
46
- }
47
- const typeAnnotationToTS = new TypeAnnotationToTS();
48
- const turboModuleInterfaceTS = new TurboModuleInterfaceTS(
49
- schema.moduleName,
50
- this.codegenNoticeLines,
51
- this.rnohImport
52
- );
53
- const turboModuleH = new TurboModuleHTemplate(
54
- schema.moduleName,
55
- this.codegenNoticeLines
56
- ).build();
57
- result.set(
58
- this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.h`),
59
- turboModuleH
60
- );
61
-
62
- const turboModuleCpp = new TurboModuleCppTemplate(
63
- schema.moduleName,
64
- this.codegenNoticeLines
65
- );
66
-
67
- Object.entries(schema.aliasMap).map(([name, typeAnnotation]) => {
68
- turboModuleInterfaceTS.addAlias({
69
- name: name,
70
- type: typeAnnotationToTS.convert(typeAnnotation),
71
- });
72
- });
73
-
74
- Object.entries(schema.enumMap).map(([name, enumSpec]) => {
75
- turboModuleInterfaceTS.addEnum({
76
- name,
77
- members: enumSpec.members.map((member) => ({
78
- name: member.name,
79
- value:
80
- typeof member.value === 'string'
81
- ? wrapWithQuotes(member.value)
82
- : member.value.toString(),
83
- })),
84
- });
85
- });
86
-
87
- schema.spec.properties.map((prop) => {
88
- if (prop.typeAnnotation.type === 'FunctionTypeAnnotation') {
89
- turboModuleCpp.addMethod({
90
- name: prop.name,
91
- argsCount: prop.typeAnnotation.params.length,
92
- isAsync:
93
- prop.typeAnnotation.returnTypeAnnotation.type ===
94
- 'PromiseTypeAnnotation',
95
- });
96
-
97
- turboModuleInterfaceTS.addMethod({
98
- name: prop.name,
99
- returnType: typeAnnotationToTS.convert(
100
- prop.typeAnnotation.returnTypeAnnotation
101
- ),
102
- stringifiedArgs: prop.typeAnnotation.params
103
- .map(
104
- (param) =>
105
- `${param.name}: ${typeAnnotationToTS.convert(
106
- param.typeAnnotation
107
- )}`
108
- )
109
- .join(', '),
110
- });
111
- }
112
- });
113
- result.set(
114
- this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.cpp`),
115
- turboModuleCpp.build()
116
- );
117
- result.set(
118
- this.etsOutputPath.copyWithNewSegment(`${schema.moduleName}.ts`),
119
- turboModuleInterfaceTS.build()
120
- );
121
- this.glueCodeTurboModulesData.push({ name: schema.moduleName });
122
- return result;
123
- }
124
- }
@@ -1,57 +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 RNCodegen from '@react-native/codegen/lib/generators/RNCodegen';
9
- import { AbsolutePath } from '../../core';
10
- import { CodeGenerator, UberSchema } from '../core';
11
-
12
- type LibraryData = {
13
- libraryCppName: string;
14
- uberSchema: UberSchema;
15
- };
16
-
17
- export class SharedComponentCodeGenerator
18
- implements CodeGenerator<LibraryData>
19
- {
20
- constructor(
21
- private onGetSharedOutputPath: (filename: string) => AbsolutePath
22
- ) {}
23
-
24
- generate({
25
- libraryCppName,
26
- uberSchema,
27
- }: LibraryData): Map<AbsolutePath, string> {
28
- const fileContentByPath = new Map<AbsolutePath, string>();
29
-
30
- const generatorFns = [
31
- RNCodegen.allGenerators.generatePropsH,
32
- RNCodegen.allGenerators.generatePropsCpp,
33
- RNCodegen.allGenerators.generateEventEmitterH,
34
- RNCodegen.allGenerators.generateEventEmitterCpp,
35
- RNCodegen.allGenerators.generateComponentDescriptorH,
36
- RNCodegen.allGenerators.generateStateH,
37
- RNCodegen.allGenerators.generateStateCpp,
38
- RNCodegen.allGenerators.generateShadowNodeH,
39
- RNCodegen.allGenerators.generateShadowNodeCpp,
40
- ];
41
- generatorFns.forEach((generate) => {
42
- const filesOutput = generate(
43
- libraryCppName,
44
- uberSchema.getValue(),
45
- 'UNUSED_packageName',
46
- true
47
- );
48
- filesOutput.forEach((fileContent, filename) => {
49
- fileContentByPath.set(
50
- this.onGetSharedOutputPath(filename),
51
- fileContent
52
- );
53
- });
54
- });
55
- return fileContentByPath;
56
- }
57
- }
@@ -1,75 +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
- CodeGenerator,
11
- CodegenError,
12
- SpecSchema,
13
- SpecSchemaType,
14
- UberSchema,
15
- } from '../core';
16
- import { GlueCodeDataV1 } from './AppBuildTimeGlueCodeGenerator';
17
- import { NativeModuleCodeGenerator } from './NativeModuleCodeGenerator';
18
- import { ArkTSComponentCodeGeneratorArkTS } from './ArkTSComponentCodeGeneratorArkTS';
19
-
20
- /**
21
- * Generates code for libraries built on top of RNOH's ArkTS architecture.
22
- */
23
- export class UberGeneratorV1 implements CodeGenerator<UberSchema> {
24
- private glueCodeData: GlueCodeDataV1 = { components: [], turboModules: [] };
25
-
26
- constructor(
27
- private cppOutputPath: AbsolutePath,
28
- private etsOutputPath: AbsolutePath,
29
- private codegenNoticeLines: string[]
30
- ) {}
31
-
32
- getGlueCodeData(): GlueCodeDataV1 {
33
- return this.glueCodeData;
34
- }
35
-
36
- generate(uberSchema: UberSchema) {
37
- const fileContentByPath = new Map<AbsolutePath, string>();
38
- const componentCodeGenerator = new ArkTSComponentCodeGeneratorArkTS(
39
- this.cppOutputPath,
40
- this.etsOutputPath.copyWithNewSegment('components'),
41
- this.codegenNoticeLines,
42
- '../../ts'
43
- );
44
- const nativeModuleCodeGenerator = new NativeModuleCodeGenerator(
45
- this.cppOutputPath,
46
- this.etsOutputPath.copyWithNewSegment('turboModules'),
47
- this.codegenNoticeLines,
48
- '../../ts'
49
- );
50
- const generatorBySpecType = {
51
- Component: componentCodeGenerator,
52
- NativeModule: nativeModuleCodeGenerator,
53
- } satisfies Record<SpecSchemaType, CodeGenerator<SpecSchema>>;
54
- for (const [_fileName, specSchema] of uberSchema
55
- .getSpecSchemaByFilenameMap()
56
- .entries()) {
57
- if (!(specSchema.type in generatorBySpecType)) {
58
- throw new CodegenError({
59
- whatHappened: `Could not find a code generator for a specification of type '${specSchema.type}'`,
60
- unexpected: true,
61
- });
62
- }
63
- generatorBySpecType[specSchema.type]
64
- .generate(specSchema)
65
- .forEach((fileContent, filePath) => {
66
- fileContentByPath.set(filePath, fileContent);
67
- });
68
- }
69
- this.glueCodeData = {
70
- components: componentCodeGenerator.getGlueCodeData(),
71
- turboModules: nativeModuleCodeGenerator.getGlueCodeData(),
72
- };
73
- return fileContentByPath;
74
- }
75
- }
@@ -1,114 +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 { CodeGenerator } from '../core';
10
- import {
11
- CppComponentCodeGenerator,
12
- LibraryData,
13
- } from './CppComponentCodeGenerator';
14
- import { NativeModuleCodeGenerator } from './NativeModuleCodeGenerator';
15
- import { GlueCodeDataV2 } from './AppBuildTimeGlueCodeGenerator';
16
- import { SharedComponentCodeGenerator } from './SharedComponentCodeGenerator';
17
-
18
- /**
19
- * Generates code for libraries built on top of RNOH's C-API architecture.
20
- */
21
- export class UberGeneratorV2 implements CodeGenerator<LibraryData[]> {
22
- private glueCodeData: GlueCodeDataV2 = new Map();
23
-
24
- constructor(
25
- private cppOutputPath: AbsolutePath,
26
- private etsOutputPath: AbsolutePath,
27
- private codegenNoticeLines: string[]
28
- ) {}
29
-
30
- getGlueCodeData(): GlueCodeDataV2 {
31
- return this.glueCodeData;
32
- }
33
-
34
- generate(npmPackagesInfo: LibraryData[]) {
35
- const fileContentByPath: Map<AbsolutePath, string> = new Map();
36
-
37
- npmPackagesInfo.forEach(({ libraryCppName, uberSchema }) => {
38
- this.glueCodeData.set(libraryCppName, {
39
- components: [],
40
- turboModules: [],
41
- });
42
- const libraryGlueCodeData = this.glueCodeData.get(libraryCppName)!;
43
- const libraryCppOutput =
44
- this.cppOutputPath.copyWithNewSegment(libraryCppName);
45
- const sharedComponentCodeGenerator = new SharedComponentCodeGenerator(
46
- (filename) => {
47
- return libraryCppOutput.copyWithNewSegment(
48
- 'react',
49
- 'renderer',
50
- 'components',
51
- libraryCppName,
52
- filename
53
- );
54
- }
55
- );
56
- const cppComponentCodeGenerator = new CppComponentCodeGenerator(
57
- (filename) => {
58
- return libraryCppOutput.copyWithNewSegment(
59
- 'RNOH',
60
- 'generated',
61
- 'components',
62
- filename
63
- );
64
- },
65
- this.codegenNoticeLines
66
- );
67
- cppComponentCodeGenerator
68
- .generate({ libraryCppName, uberSchema })
69
- .forEach((fileContent, path) => {
70
- fileContentByPath.set(path, fileContent);
71
- });
72
- cppComponentCodeGenerator
73
- .getGlueCodeData()
74
- .forEach((componentGlueCodeData) => {
75
- libraryGlueCodeData.components.push(componentGlueCodeData);
76
- });
77
-
78
- sharedComponentCodeGenerator
79
- .generate({ libraryCppName, uberSchema })
80
- .forEach((fileContent, path) => {
81
- fileContentByPath.set(path, fileContent);
82
- });
83
-
84
- for (const [_fileName, specSchema] of uberSchema
85
- .getSpecSchemaByFilenameMap()
86
- .entries()) {
87
- if (specSchema.type === 'NativeModule') {
88
- const nativeModuleCodeGenerator = new NativeModuleCodeGenerator(
89
- libraryCppOutput.copyWithNewSegment(
90
- 'RNOH',
91
- 'generated',
92
- 'turbo_modules'
93
- ),
94
- this.etsOutputPath.copyWithNewSegment('turboModules'),
95
- this.codegenNoticeLines,
96
- '../../ts'
97
- );
98
- nativeModuleCodeGenerator
99
- .generate(specSchema)
100
- .forEach((fileContent, filePath) => {
101
- fileContentByPath.set(filePath, fileContent);
102
- });
103
- nativeModuleCodeGenerator
104
- .getGlueCodeData()
105
- .forEach((turboModuleGlueCodeData) => {
106
- libraryGlueCodeData.turboModules.push(turboModuleGlueCodeData);
107
- });
108
- }
109
- }
110
- });
111
-
112
- return fileContentByPath;
113
- }
114
- }
@@ -1,15 +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 './NativeModuleCodeGenerator';
9
- export * from './AppBuildTimeGlueCodeGenerator';
10
- export * from './ArkTSComponentCodeGeneratorArkTS';
11
- export * from './ArkTSComponentCodeGeneratorCAPI';
12
- export * from './CppComponentCodeGenerator';
13
- export * from './UberGeneratorV1';
14
- export * from './UberGeneratorV2';
15
- export * from './SharedComponentCodeGenerator';