@react-native-oh/react-native-harmony-cli 0.0.25 → 0.0.26

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 (116) hide show
  1. package/.prettierrc +6 -6
  2. package/jest.config.js +5 -5
  3. package/package.json +57 -56
  4. package/react-native.config.js +10 -10
  5. package/src/assetResolver.ts +21 -44
  6. package/src/codegen/core/CodeGenerator.ts +9 -0
  7. package/src/codegen/core/CodegenError.ts +3 -3
  8. package/src/codegen/core/EventUtils.ts +18 -18
  9. package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -75
  10. package/src/codegen/core/TypeAnnotationToTS.ts +188 -188
  11. package/src/codegen/core/UberSchema.ts +142 -99
  12. package/src/codegen/core/index.ts +5 -5
  13. package/src/codegen/generators/{ComponentCodeGenerator.ts → ComponentCodeGeneratorArkTS.ts} +112 -98
  14. package/src/codegen/generators/ComponentCodeGeneratorCAPI.ts +114 -0
  15. package/src/codegen/generators/GlueCodeGenerator.ts +109 -0
  16. package/src/codegen/generators/NativeModuleCodeGenerator.ts +115 -95
  17. package/src/codegen/generators/UberGeneratorV1.ts +64 -0
  18. package/src/codegen/generators/UberGeneratorV2.ts +91 -0
  19. package/src/codegen/generators/index.ts +6 -3
  20. package/src/codegen/index.ts +2 -2
  21. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +116 -0
  22. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +55 -49
  23. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +93 -85
  24. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +210 -202
  25. package/src/codegen/templates/GeneratedPackageHTemplate.ts +107 -0
  26. package/src/codegen/templates/IndexTSTemplate.ts +53 -33
  27. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +130 -124
  28. package/src/codegen/templates/TurboModuleCppTemplate.ts +54 -47
  29. package/src/codegen/templates/TurboModuleHTemplate.ts +35 -26
  30. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +90 -81
  31. package/src/codegen/templates/index.ts +9 -8
  32. package/src/commands/bundle-harmony.ts +203 -203
  33. package/src/commands/codegen-harmony.ts +272 -143
  34. package/src/commands/create-metro-host-constants.ts +48 -48
  35. package/src/commands/index.ts +6 -6
  36. package/src/commands/pack-harmony.ts +121 -121
  37. package/src/commands/unpack-harmony.ts +231 -231
  38. package/src/commands/verify-package-harmony.ts +106 -106
  39. package/src/core/AbsolutePath.ts +50 -43
  40. package/src/core/CodegenConfig.ts +62 -54
  41. package/src/core/DescriptiveError.ts +61 -61
  42. package/src/core/OHPackageJSON5.ts +23 -23
  43. package/src/core/PackageJSON.ts +75 -63
  44. package/src/core/ProjectDependenciesManager.ts +77 -77
  45. package/src/core/ValidationError.ts +1 -1
  46. package/src/core/ValueObject.ts +2 -2
  47. package/src/core/fs.ts +31 -31
  48. package/src/core/index.ts +9 -9
  49. package/src/index.ts +20 -20
  50. package/src/io/Logger.ts +68 -68
  51. package/src/io/TarGz.ts +26 -26
  52. package/src/io/fsUtils.ts +24 -24
  53. package/src/io/index.ts +3 -3
  54. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -28
  55. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -24
  56. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -18
  57. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -47
  58. package/src/package-verifier/checks/index.ts +4 -4
  59. package/src/package-verifier/index.ts +2 -2
  60. package/src/package-verifier/types.ts +12 -12
  61. package/src/package-verifier/verify-package.ts +117 -117
  62. package/tsconfig.build.json +6 -6
  63. package/tsconfig.json +2 -2
  64. package/dist/assetResolver.js +0 -41
  65. package/dist/codegen/core/Codegen.js +0 -35
  66. package/dist/codegen/core/CodegenError.js +0 -7
  67. package/dist/codegen/core/EventUtils.js +0 -19
  68. package/dist/codegen/core/TypeAnnotationToTS.js +0 -132
  69. package/dist/codegen/core/UberSchema.js +0 -74
  70. package/dist/codegen/core/index.js +0 -21
  71. package/dist/codegen/generators/ComponentCodeGenerator.js +0 -66
  72. package/dist/codegen/generators/NativeModuleCodeGenerator.js +0 -64
  73. package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
  74. package/dist/codegen/generators/index.js +0 -19
  75. package/dist/codegen/index.js +0 -18
  76. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +0 -55
  77. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +0 -78
  78. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -181
  79. package/dist/codegen/templates/IndexTSTemplate.js +0 -31
  80. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +0 -117
  81. package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -45
  82. package/dist/codegen/templates/TurboModuleHTemplate.js +0 -32
  83. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -64
  84. package/dist/codegen/templates/index.js +0 -24
  85. package/dist/commands/bundle-harmony.js +0 -179
  86. package/dist/commands/codegen-harmony.js +0 -110
  87. package/dist/commands/create-metro-host-constants.js +0 -61
  88. package/dist/commands/index.js +0 -22
  89. package/dist/commands/pack-harmony.js +0 -100
  90. package/dist/commands/unpack-harmony.js +0 -184
  91. package/dist/commands/verify-package-harmony.js +0 -127
  92. package/dist/core/AbsolutePath.js +0 -41
  93. package/dist/core/CodegenConfig.js +0 -53
  94. package/dist/core/DescriptiveError.js +0 -49
  95. package/dist/core/OHPackageJSON5.js +0 -23
  96. package/dist/core/PackageJSON.js +0 -53
  97. package/dist/core/ProjectDependenciesManager.js +0 -70
  98. package/dist/core/ValidationError.js +0 -6
  99. package/dist/core/ValueObject.js +0 -2
  100. package/dist/core/fs.js +0 -36
  101. package/dist/core/index.js +0 -25
  102. package/dist/index.js +0 -14
  103. package/dist/io/Logger.js +0 -71
  104. package/dist/io/TarGz.js +0 -28
  105. package/dist/io/fsUtils.js +0 -23
  106. package/dist/io/index.js +0 -19
  107. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +0 -38
  108. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +0 -32
  109. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +0 -26
  110. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +0 -51
  111. package/dist/package-verifier/checks/index.js +0 -20
  112. package/dist/package-verifier/index.js +0 -18
  113. package/dist/package-verifier/types.js +0 -2
  114. package/dist/package-verifier/verify-package.js +0 -100
  115. package/src/codegen/core/Codegen.ts +0 -44
  116. package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
@@ -1,117 +1,117 @@
1
- import fs from 'node:fs';
2
- import tmp from 'tmp';
3
- import {
4
- AbsolutePath,
5
- DescriptiveError,
6
- OHPackageJSON5,
7
- PackageJSON,
8
- } from '../core';
9
- import {
10
- createHarmonyDirContainsOnlyHarsCheck,
11
- createHarmonyDirExistsCheck,
12
- createOhPackageNameFollowsNamingConventionCheck,
13
- createNpmAndOhPackageVersionsAreEqualCheck,
14
- } from './checks';
15
- import { Check, CheckStatus } from './types';
16
- import { unpackTarGz } from '../io';
17
-
18
- type StartProcessMessage = {
19
- type: 'START_PROCESS';
20
- name: string;
21
- };
22
-
23
- type FinishedCheckingMessage = {
24
- type: 'FINISHED_CHECKING';
25
- name: string;
26
- status: CheckStatus;
27
- message: string;
28
- };
29
-
30
- type VerificationMessage = StartProcessMessage | FinishedCheckingMessage;
31
-
32
- export async function* verifyRNOHPackage({
33
- npmPackagePath,
34
- hasHarmonyCode,
35
- checkNamesToSkip,
36
- }: {
37
- npmPackagePath: AbsolutePath;
38
- hasHarmonyCode: boolean;
39
- checkNamesToSkip: string[];
40
- }): AsyncGenerator<VerificationMessage, void, unknown> {
41
- const npmPackageJson = PackageJSON.fromProjectRootPath(
42
- npmPackagePath,
43
- npmPackagePath
44
- );
45
- const initialChecks: Check[] = [
46
- createHarmonyDirExistsCheck(npmPackagePath, hasHarmonyCode),
47
- createHarmonyDirContainsOnlyHarsCheck(npmPackagePath, hasHarmonyCode),
48
- ];
49
- yield* runChecks(initialChecks, checkNamesToSkip);
50
- if (hasHarmonyCode) {
51
- const harPath = findHarPath(npmPackagePath);
52
- if (!harPath) {
53
- throw new DescriptiveError({
54
- whatHappened: 'Attempted to verify har but no har was found',
55
- whatCanUserDo: {
56
- default: [
57
- 'Run this command without --no-harmony-code flag.',
58
- 'Create har files by running DevEco Studio > Build > Make Module (MODULE_NAME). The har file can be later found in MODULE_NAME/build/default/outputs/default/MODULE_NAME.har. Copy that file to the PACKAGE_ROOT/harmony directory.',
59
- ],
60
- },
61
- });
62
- }
63
- const tmpDirPath = new AbsolutePath(tmp.dirSync().name);
64
- yield {
65
- type: 'START_PROCESS',
66
- name: `Unpacking the har file to the tmpdir`,
67
- };
68
- await unpackTarGz(harPath, tmpDirPath);
69
- const ohPackageJson5 = OHPackageJSON5.fromPath(
70
- tmpDirPath.copyWithNewSegment('package', 'oh-package.json5')
71
- );
72
- const harChecks: Check[] = [
73
- createOhPackageNameFollowsNamingConventionCheck(
74
- npmPackageJson.name,
75
- ohPackageJson5.name
76
- ),
77
- createNpmAndOhPackageVersionsAreEqualCheck(
78
- npmPackageJson.version,
79
- ohPackageJson5.version
80
- ),
81
- ];
82
- yield* runChecks(harChecks, checkNamesToSkip);
83
- }
84
- }
85
-
86
- async function* runChecks(
87
- checks: Check[],
88
- checkNamesToSkip: string[]
89
- ): AsyncGenerator<VerificationMessage, void, unknown> {
90
- for (const { checkIf, run } of checks) {
91
- if (checkNamesToSkip.includes(checkIf)) {
92
- yield {
93
- type: 'FINISHED_CHECKING',
94
- name: checkIf,
95
- status: 'skip' as CheckStatus,
96
- message: '',
97
- };
98
- continue;
99
- }
100
- const result = await run();
101
- const status = typeof result === 'string' ? result : result.status;
102
- const message = typeof result === 'string' ? '' : result.message;
103
- yield { type: 'FINISHED_CHECKING', name: checkIf, status, message };
104
- }
105
- }
106
-
107
- function findHarPath(packagePath: AbsolutePath): AbsolutePath | null {
108
- const packageHarmonyPath = packagePath.copyWithNewSegment('harmony');
109
- const fileOrDirNames = fs.readdirSync(packageHarmonyPath.getValue());
110
- const harFilenames = fileOrDirNames.filter((fileOrDirName) =>
111
- fileOrDirName.endsWith('.har')
112
- );
113
- if (harFilenames.length != 1) {
114
- return null;
115
- }
116
- return packageHarmonyPath.copyWithNewSegment(harFilenames[0]);
117
- }
1
+ import fs from 'node:fs';
2
+ import tmp from 'tmp';
3
+ import {
4
+ AbsolutePath,
5
+ DescriptiveError,
6
+ OHPackageJSON5,
7
+ PackageJSON,
8
+ } from '../core';
9
+ import {
10
+ createHarmonyDirContainsOnlyHarsCheck,
11
+ createHarmonyDirExistsCheck,
12
+ createOhPackageNameFollowsNamingConventionCheck,
13
+ createNpmAndOhPackageVersionsAreEqualCheck,
14
+ } from './checks';
15
+ import { Check, CheckStatus } from './types';
16
+ import { unpackTarGz } from '../io';
17
+
18
+ type StartProcessMessage = {
19
+ type: 'START_PROCESS';
20
+ name: string;
21
+ };
22
+
23
+ type FinishedCheckingMessage = {
24
+ type: 'FINISHED_CHECKING';
25
+ name: string;
26
+ status: CheckStatus;
27
+ message: string;
28
+ };
29
+
30
+ type VerificationMessage = StartProcessMessage | FinishedCheckingMessage;
31
+
32
+ export async function* verifyRNOHPackage({
33
+ npmPackagePath,
34
+ hasHarmonyCode,
35
+ checkNamesToSkip,
36
+ }: {
37
+ npmPackagePath: AbsolutePath;
38
+ hasHarmonyCode: boolean;
39
+ checkNamesToSkip: string[];
40
+ }): AsyncGenerator<VerificationMessage, void, unknown> {
41
+ const npmPackageJson = PackageJSON.fromProjectRootPath(
42
+ npmPackagePath,
43
+ npmPackagePath
44
+ );
45
+ const initialChecks: Check[] = [
46
+ createHarmonyDirExistsCheck(npmPackagePath, hasHarmonyCode),
47
+ createHarmonyDirContainsOnlyHarsCheck(npmPackagePath, hasHarmonyCode),
48
+ ];
49
+ yield* runChecks(initialChecks, checkNamesToSkip);
50
+ if (hasHarmonyCode) {
51
+ const harPath = findHarPath(npmPackagePath);
52
+ if (!harPath) {
53
+ throw new DescriptiveError({
54
+ whatHappened: 'Attempted to verify har but no har was found',
55
+ whatCanUserDo: {
56
+ default: [
57
+ 'Run this command without --no-harmony-code flag.',
58
+ 'Create har files by running DevEco Studio > Build > Make Module (MODULE_NAME). The har file can be later found in MODULE_NAME/build/default/outputs/default/MODULE_NAME.har. Copy that file to the PACKAGE_ROOT/harmony directory.',
59
+ ],
60
+ },
61
+ });
62
+ }
63
+ const tmpDirPath = new AbsolutePath(tmp.dirSync().name);
64
+ yield {
65
+ type: 'START_PROCESS',
66
+ name: `Unpacking the har file to the tmpdir`,
67
+ };
68
+ await unpackTarGz(harPath, tmpDirPath);
69
+ const ohPackageJson5 = OHPackageJSON5.fromPath(
70
+ tmpDirPath.copyWithNewSegment('package', 'oh-package.json5')
71
+ );
72
+ const harChecks: Check[] = [
73
+ createOhPackageNameFollowsNamingConventionCheck(
74
+ npmPackageJson.name,
75
+ ohPackageJson5.name
76
+ ),
77
+ createNpmAndOhPackageVersionsAreEqualCheck(
78
+ npmPackageJson.version,
79
+ ohPackageJson5.version
80
+ ),
81
+ ];
82
+ yield* runChecks(harChecks, checkNamesToSkip);
83
+ }
84
+ }
85
+
86
+ async function* runChecks(
87
+ checks: Check[],
88
+ checkNamesToSkip: string[]
89
+ ): AsyncGenerator<VerificationMessage, void, unknown> {
90
+ for (const { checkIf, run } of checks) {
91
+ if (checkNamesToSkip.includes(checkIf)) {
92
+ yield {
93
+ type: 'FINISHED_CHECKING',
94
+ name: checkIf,
95
+ status: 'skip' as CheckStatus,
96
+ message: '',
97
+ };
98
+ continue;
99
+ }
100
+ const result = await run();
101
+ const status = typeof result === 'string' ? result : result.status;
102
+ const message = typeof result === 'string' ? '' : result.message;
103
+ yield { type: 'FINISHED_CHECKING', name: checkIf, status, message };
104
+ }
105
+ }
106
+
107
+ function findHarPath(packagePath: AbsolutePath): AbsolutePath | null {
108
+ const packageHarmonyPath = packagePath.copyWithNewSegment('harmony');
109
+ const fileOrDirNames = fs.readdirSync(packageHarmonyPath.getValue());
110
+ const harFilenames = fileOrDirNames.filter((fileOrDirName) =>
111
+ fileOrDirName.endsWith('.har')
112
+ );
113
+ if (harFilenames.length != 1) {
114
+ return null;
115
+ }
116
+ return packageHarmonyPath.copyWithNewSegment(harFilenames[0]);
117
+ }
@@ -1,7 +1,7 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": [
4
- "tests",
5
- "**/*.test.ts",
6
- ]
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": [
4
+ "tests",
5
+ "**/*.test.ts",
6
+ ]
7
7
  }
package/tsconfig.json CHANGED
@@ -1,3 +1,3 @@
1
- {
2
- "extends": "@tsconfig/recommended/tsconfig.json",
1
+ {
2
+ "extends": "@tsconfig/recommended/tsconfig.json",
3
3
  }
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAssetDestRelativePath = void 0;
4
- /*
5
- cyrb53 (c) 2018 bryc (github.com/bryc)
6
- License: Public domain. Attribution appreciated.
7
- A fast and simple 53-bit string hash function with decent collision resistance.
8
- Largely inspired by MurmurHash2/3, but with a focus on speed/simplicity.
9
- */
10
- function cyrb53(str, seed = 0) {
11
- let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
12
- for (let i = 0, ch; i < str.length; i++) {
13
- ch = str.charCodeAt(i);
14
- h1 = Math.imul(h1 ^ ch, 2654435761);
15
- h2 = Math.imul(h2 ^ ch, 1597334677);
16
- }
17
- h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
18
- h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
19
- h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
20
- h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
21
- return 4294967296 * (2097151 & h2) + (h1 >>> 0);
22
- }
23
- ;
24
- function getAssetDestRelativePath(asset) {
25
- const fileName = getResourceIdentifier(asset);
26
- return `${fileName}.${asset.type}`;
27
- }
28
- exports.getAssetDestRelativePath = getAssetDestRelativePath;
29
- function getResourceIdentifier(asset) {
30
- const folderPath = getBasePath(asset);
31
- const fullAssetPath = `${folderPath}/${asset.name}.${asset.type}`.toLowerCase();
32
- const assetPathHash = cyrb53(fullAssetPath);
33
- return assetPathHash.toString(16);
34
- }
35
- function getBasePath(asset) {
36
- let basePath = asset.httpServerLocation;
37
- if (basePath[0] === '/') {
38
- basePath = basePath.substr(1);
39
- }
40
- return basePath;
41
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Codegen = void 0;
4
- const CodegenError_1 = require("./CodegenError");
5
- class Codegen {
6
- constructor(packageCodeGenerator, codeGeneratorBySpecSchemaType) {
7
- this.packageCodeGenerator = packageCodeGenerator;
8
- this.codeGeneratorBySpecSchemaType = codeGeneratorBySpecSchemaType;
9
- }
10
- generate(uberSchema) {
11
- const result = new Map();
12
- for (const [_fileName, specSchema] of uberSchema
13
- .getSpecSchemaByFilenameMap()
14
- .entries()) {
15
- if (!(specSchema.type in this.codeGeneratorBySpecSchemaType)) {
16
- throw new CodegenError_1.CodegenError({
17
- whatHappened: `Could not find a code generator for a specification of type '${specSchema.type}'`,
18
- unexpected: true,
19
- });
20
- }
21
- this.codeGeneratorBySpecSchemaType[specSchema.type]
22
- .generate(specSchema)
23
- .forEach((fileContent, filePath) => {
24
- result.set(filePath, fileContent);
25
- });
26
- }
27
- this.packageCodeGenerator
28
- .generate(uberSchema)
29
- .forEach((fileContent, filePath) => {
30
- result.set(filePath, fileContent);
31
- });
32
- return result;
33
- }
34
- }
35
- exports.Codegen = Codegen;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CodegenError = void 0;
4
- const core_1 = require("../../core");
5
- class CodegenError extends core_1.DescriptiveError {
6
- }
7
- exports.CodegenError = CodegenError;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEventNameFromEventHandlerName = void 0;
4
- const CodegenError_1 = require("./CodegenError");
5
- function createEventNameFromEventHandlerName(eventHandlerName) {
6
- const eventName = eventHandlerName.replace('on', '');
7
- if (eventName.length === 0) {
8
- throw new CodegenError_1.CodegenError({
9
- whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
10
- whatCanUserDo: {
11
- default: [
12
- 'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
13
- ],
14
- },
15
- });
16
- }
17
- return eventName.charAt(0).toLowerCase() + eventName.slice(1);
18
- }
19
- exports.createEventNameFromEventHandlerName = createEventNameFromEventHandlerName;
@@ -1,132 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapWithQuotes = exports.getStringifiedTSDefaultValueFromPropTypeAnnotation = exports.TypeAnnotationToTS = void 0;
4
- class TypeAnnotationToTS {
5
- constructor(aliasPrefix = '') {
6
- this.aliasPrefix = aliasPrefix;
7
- }
8
- convert(typeAnnotation) {
9
- if (!typeAnnotation) {
10
- return 'unknown';
11
- }
12
- switch (typeAnnotation.type) {
13
- case 'BooleanTypeAnnotation':
14
- return 'boolean';
15
- case 'DoubleTypeAnnotation':
16
- return 'number';
17
- case 'FloatTypeAnnotation':
18
- return 'number';
19
- case 'Int32EnumTypeAnnotation':
20
- return typeAnnotation.options.join(' | ');
21
- case 'Int32TypeAnnotation':
22
- return 'number';
23
- case 'MixedTypeAnnotation':
24
- return 'unknown';
25
- case 'ReservedTypeAnnotation':
26
- switch (typeAnnotation.name) {
27
- case 'RootTag':
28
- return 'Tag';
29
- default:
30
- return 'unknown';
31
- }
32
- case 'ReservedPropTypeAnnotation':
33
- switch (typeAnnotation.name) {
34
- case 'ColorPrimitive':
35
- return 'ColorValue';
36
- case 'DimensionPrimitive':
37
- return 'unknown';
38
- case 'EdgeInsetsPrimitive':
39
- return 'unknown';
40
- case 'ImageRequestPrimitive':
41
- return 'unknown';
42
- case 'ImageSourcePrimitive':
43
- return 'unknown';
44
- case 'PointPrimitive':
45
- return 'unknown';
46
- default:
47
- return 'unknown';
48
- }
49
- case 'StringEnumTypeAnnotation':
50
- return typeAnnotation.options
51
- .map((option) => {
52
- if (typeof option !== 'string') {
53
- return option;
54
- }
55
- return wrapWithQuotes(option);
56
- })
57
- .join(' | ');
58
- case 'StringTypeAnnotation':
59
- return 'string';
60
- case 'FunctionTypeAnnotation':
61
- const { params, returnTypeAnnotation } = typeAnnotation;
62
- const stringifiedArgs = params
63
- .map((param) => `${param.name}: ${this.convert(param.typeAnnotation)}`)
64
- .join(', ');
65
- return `(${stringifiedArgs}) => ${this.convert(returnTypeAnnotation)}`;
66
- case 'EnumDeclaration':
67
- return typeAnnotation.name;
68
- case 'GenericObjectTypeAnnotation':
69
- return 'Object';
70
- case 'TypeAliasTypeAnnotation':
71
- return this.aliasPrefix + typeAnnotation.name;
72
- case 'UnionTypeAnnotation':
73
- return this.convertUnionMemberAnnotation(typeAnnotation.memberType);
74
- case 'NumberTypeAnnotation':
75
- return 'number';
76
- case 'NullableTypeAnnotation':
77
- return `null | ${this.convert(typeAnnotation.typeAnnotation)}`;
78
- case 'ObjectTypeAnnotation':
79
- return this.convertObjectTypeAnnotation(typeAnnotation);
80
- case 'PromiseTypeAnnotation':
81
- return `Promise<${this.convert(typeAnnotation.elementType)}>`;
82
- case 'VoidTypeAnnotation':
83
- return 'void';
84
- case 'ArrayTypeAnnotation':
85
- return `${this.convert(typeAnnotation.elementType)}[]`;
86
- default:
87
- return 'unknown';
88
- }
89
- }
90
- convertUnionMemberAnnotation(memberAnnotation) {
91
- switch (memberAnnotation) {
92
- case 'NumberTypeAnnotation':
93
- return 'number';
94
- case 'ObjectTypeAnnotation':
95
- return 'Object';
96
- case 'StringTypeAnnotation':
97
- return 'string';
98
- }
99
- }
100
- convertObjectTypeAnnotation(objectTypeAnnotation) {
101
- const props = objectTypeAnnotation.properties
102
- .map((prop) => {
103
- const maybeOptionalSymbol = prop.optional ? '?' : '';
104
- return `${prop.name}${maybeOptionalSymbol}: ${this.convert(prop.typeAnnotation)}`;
105
- })
106
- .join(', ');
107
- if (props.length === 0) {
108
- return '{}';
109
- }
110
- return `{${props}}`;
111
- }
112
- }
113
- exports.TypeAnnotationToTS = TypeAnnotationToTS;
114
- function getStringifiedTSDefaultValueFromPropTypeAnnotation(propTypeAnnotation) {
115
- if ('default' in propTypeAnnotation && propTypeAnnotation.default !== null) {
116
- if (typeof propTypeAnnotation.default === 'string') {
117
- return wrapWithQuotes(propTypeAnnotation.default);
118
- }
119
- return String(propTypeAnnotation.default);
120
- }
121
- return null;
122
- }
123
- exports.getStringifiedTSDefaultValueFromPropTypeAnnotation = getStringifiedTSDefaultValueFromPropTypeAnnotation;
124
- function wrapWithQuotes(str) {
125
- if (str.includes("'")) {
126
- return `"${str}"`;
127
- }
128
- else {
129
- return `'${str}'`;
130
- }
131
- }
132
- exports.wrapWithQuotes = wrapWithQuotes;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.UberSchema = void 0;
16
- const core_1 = require("../../core");
17
- // @ts-expect-error
18
- const combine_js_to_schema_js_1 = __importDefault(require("@react-native/codegen/lib/cli/combine/combine-js-to-schema.js"));
19
- const CodegenError_1 = require("./CodegenError");
20
- function createRawUberSchemaFromSpecFilePaths(projectSourceFilePaths) {
21
- return (0, combine_js_to_schema_js_1.default)(projectSourceFilePaths.map((p) => p.getValue()));
22
- }
23
- class UberSchema {
24
- static fromProjectRootPath(projectRootPath) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const packageJSON = core_1.PackageJSON.fromProjectRootPath(projectRootPath, projectRootPath);
27
- const codegenConfigs = [];
28
- const appCodegenConfig = packageJSON.maybeCreateCodegenConfig();
29
- if (appCodegenConfig) {
30
- codegenConfigs.push(appCodegenConfig);
31
- }
32
- yield new core_1.ProjectDependenciesManager(projectRootPath).forEachAsync((dependency) => {
33
- const codegenConfig = dependency.maybeCreateCodegenConfig();
34
- if (codegenConfig) {
35
- codegenConfigs.push(codegenConfig);
36
- }
37
- });
38
- try {
39
- return new UberSchema(createRawUberSchemaFromSpecFilePaths(codegenConfigs.flatMap((codegenConfig) => codegenConfig.getSpecFilePaths())));
40
- }
41
- catch (err) {
42
- if (err instanceof Error) {
43
- throw new CodegenError_1.CodegenError({
44
- whatHappened: "Couldn't create the schema",
45
- whatCanUserDo: {
46
- default: [
47
- `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}`,
48
- ],
49
- },
50
- });
51
- }
52
- throw err;
53
- }
54
- });
55
- }
56
- constructor(schemaValue) {
57
- this.schemaValue = schemaValue;
58
- }
59
- getValue() {
60
- return this.schemaValue;
61
- }
62
- findAllSpecSchemasByType(schemaType) {
63
- return Object.values(this.schemaValue.modules)
64
- .filter((module) => module.type === schemaType)
65
- .map((module) => module);
66
- }
67
- getSpecSchemaByFilenameMap() {
68
- return Object.entries(this.schemaValue.modules).reduce((acc, [moduleName, moduleSchema]) => {
69
- acc.set(moduleName, moduleSchema);
70
- return acc;
71
- }, new Map());
72
- }
73
- }
74
- exports.UberSchema = UberSchema;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Codegen"), exports);
18
- __exportStar(require("./UberSchema"), exports);
19
- __exportStar(require("./CodegenError"), exports);
20
- __exportStar(require("./EventUtils"), exports);
21
- __exportStar(require("./TypeAnnotationToTS"), exports);
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ComponentCodeGenerator = void 0;
4
- const core_1 = require("../core");
5
- const templates_1 = require("../templates");
6
- class ComponentCodeGenerator {
7
- constructor(cppOutputPath, tsOutputPath) {
8
- this.cppOutputPath = cppOutputPath;
9
- this.tsOutputPath = tsOutputPath;
10
- }
11
- generate(schema) {
12
- if (schema.type !== 'Component') {
13
- throw new core_1.CodegenError({
14
- whatHappened: `ComponentCodeGenerator can't generate code for a module type: ${schema.type}`,
15
- unexpected: true,
16
- });
17
- }
18
- const typeAnnotationToTS = new core_1.TypeAnnotationToTS();
19
- const result = new Map();
20
- Object.entries(schema.components).map(([name, shape]) => {
21
- const componentDescriptorHTemplate = new templates_1.ComponentDescriptorHTemplate(name);
22
- const componentJSIBinderHTemplate = new templates_1.ComponentJSIBinderHTemplate(name);
23
- const componentUtilsTSTemplate = new templates_1.ComponentUtilsTSTemplate(name);
24
- shape.props.forEach((prop) => {
25
- componentJSIBinderHTemplate.addProp({
26
- name: prop.name,
27
- isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
28
- });
29
- componentUtilsTSTemplate.addProp({
30
- name: prop.name,
31
- tsType: typeAnnotationToTS.convert(prop.typeAnnotation),
32
- defaultValue: (0, core_1.getStringifiedTSDefaultValueFromPropTypeAnnotation)(prop.typeAnnotation),
33
- isOptional: prop.optional,
34
- });
35
- });
36
- shape.commands.forEach((command) => {
37
- componentUtilsTSTemplate.addCommand({
38
- name: command.name,
39
- argsTSType: '[' +
40
- command.typeAnnotation.params
41
- .map((param) => typeAnnotationToTS.convert(param.typeAnnotation) +
42
- (param.optional ? '?' : ''))
43
- .join(', ') +
44
- ']',
45
- });
46
- });
47
- shape.events.forEach((event) => {
48
- componentUtilsTSTemplate.addEvent({
49
- name: (0, core_1.createEventNameFromEventHandlerName)(event.name),
50
- payloadTSType: event.typeAnnotation.argument
51
- ? typeAnnotationToTS.convert(event.typeAnnotation.argument)
52
- : 'undefined',
53
- });
54
- componentJSIBinderHTemplate.addEvent({
55
- type: event.bubblingType,
56
- eventHandlerName: event.name,
57
- });
58
- });
59
- result.set(this.cppOutputPath.copyWithNewSegment(`${name}ComponentDescriptor.h`), componentDescriptorHTemplate.build());
60
- result.set(this.cppOutputPath.copyWithNewSegment(`${name}JSIBinder.h`), componentJSIBinderHTemplate.build());
61
- result.set(this.tsOutputPath.copyWithNewSegment(`${name}.ts`), componentUtilsTSTemplate.build());
62
- });
63
- return result;
64
- }
65
- }
66
- exports.ComponentCodeGenerator = ComponentCodeGenerator;