@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,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';