@react-native-oh/react-native-harmony-cli 0.0.25 → 0.0.26-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.
- package/.prettierrc +6 -6
- package/dist/assetResolver.js +1 -23
- package/dist/codegen/core/CodeGenerator.js +2 -0
- package/dist/codegen/core/UberSchema.js +35 -9
- package/dist/codegen/core/index.js +1 -1
- package/dist/codegen/generators/{ComponentCodeGenerator.js → ComponentCodeGeneratorArkTS.js} +12 -4
- package/dist/codegen/generators/ComponentCodeGeneratorCAPI.js +79 -0
- package/dist/codegen/generators/GlueCodeGenerator.js +60 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +14 -6
- package/dist/codegen/generators/UberGeneratorV1.js +49 -0
- package/dist/codegen/generators/UberGeneratorV2.js +60 -0
- package/dist/codegen/generators/index.js +5 -2
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +103 -0
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +42 -36
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +45 -36
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +135 -127
- package/dist/codegen/templates/GeneratedPackageHTemplate.js +101 -0
- package/dist/codegen/templates/IndexTSTemplate.js +23 -5
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +88 -82
- package/dist/codegen/templates/TurboModuleCppTemplate.js +26 -18
- package/dist/codegen/templates/TurboModuleHTemplate.js +27 -17
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +37 -27
- package/dist/codegen/templates/index.js +1 -0
- package/dist/commands/codegen-harmony.js +99 -14
- package/dist/core/AbsolutePath.js +6 -0
- package/dist/core/CodegenConfig.js +8 -4
- package/dist/core/PackageJSON.js +8 -3
- package/dist/core/ProjectDependenciesManager.js +2 -2
- package/jest.config.js +5 -5
- package/package.json +57 -56
- package/react-native.config.js +10 -10
- package/src/assetResolver.ts +21 -44
- package/src/codegen/core/CodeGenerator.ts +9 -0
- package/src/codegen/core/CodegenError.ts +3 -3
- package/src/codegen/core/EventUtils.ts +18 -18
- package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -75
- package/src/codegen/core/TypeAnnotationToTS.ts +188 -188
- package/src/codegen/core/UberSchema.ts +142 -99
- package/src/codegen/core/index.ts +5 -5
- package/src/codegen/generators/{ComponentCodeGenerator.ts → ComponentCodeGeneratorArkTS.ts} +112 -98
- package/src/codegen/generators/ComponentCodeGeneratorCAPI.ts +114 -0
- package/src/codegen/generators/GlueCodeGenerator.ts +109 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +115 -95
- package/src/codegen/generators/UberGeneratorV1.ts +64 -0
- package/src/codegen/generators/UberGeneratorV2.ts +91 -0
- package/src/codegen/generators/index.ts +6 -3
- package/src/codegen/index.ts +2 -2
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +116 -0
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +55 -49
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +93 -85
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +210 -202
- package/src/codegen/templates/GeneratedPackageHTemplate.ts +107 -0
- package/src/codegen/templates/IndexTSTemplate.ts +53 -33
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +130 -124
- package/src/codegen/templates/TurboModuleCppTemplate.ts +54 -47
- package/src/codegen/templates/TurboModuleHTemplate.ts +35 -26
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +90 -81
- package/src/codegen/templates/index.ts +9 -8
- package/src/commands/bundle-harmony.ts +203 -203
- package/src/commands/codegen-harmony.ts +272 -143
- package/src/commands/create-metro-host-constants.ts +48 -48
- package/src/commands/index.ts +6 -6
- package/src/commands/pack-harmony.ts +121 -121
- package/src/commands/unpack-harmony.ts +231 -231
- package/src/commands/verify-package-harmony.ts +106 -106
- package/src/core/AbsolutePath.ts +50 -43
- package/src/core/CodegenConfig.ts +62 -54
- package/src/core/DescriptiveError.ts +61 -61
- package/src/core/OHPackageJSON5.ts +23 -23
- package/src/core/PackageJSON.ts +75 -63
- package/src/core/ProjectDependenciesManager.ts +77 -77
- package/src/core/ValidationError.ts +1 -1
- package/src/core/ValueObject.ts +2 -2
- package/src/core/fs.ts +31 -31
- package/src/core/index.ts +9 -9
- package/src/index.ts +20 -20
- package/src/io/Logger.ts +68 -68
- package/src/io/TarGz.ts +26 -26
- package/src/io/fsUtils.ts +24 -24
- package/src/io/index.ts +3 -3
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -28
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -24
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -18
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -47
- package/src/package-verifier/checks/index.ts +4 -4
- package/src/package-verifier/index.ts +2 -2
- package/src/package-verifier/types.ts +12 -12
- package/src/package-verifier/verify-package.ts +117 -117
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
- package/dist/codegen/core/Codegen.js +0 -35
- package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
- package/src/codegen/core/Codegen.ts +0 -44
- 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
|
+
}
|
package/tsconfig.build.json
CHANGED
|
@@ -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,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,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PackageCodeGenerator = void 0;
|
|
4
|
-
const core_1 = require("../core");
|
|
5
|
-
const templates_1 = require("../templates");
|
|
6
|
-
class PackageCodeGenerator {
|
|
7
|
-
constructor(cppOutputPath, etsOutputPath) {
|
|
8
|
-
this.cppOutputPath = cppOutputPath;
|
|
9
|
-
this.etsOutputPath = etsOutputPath;
|
|
10
|
-
}
|
|
11
|
-
generate(uberSchema) {
|
|
12
|
-
const result = new Map();
|
|
13
|
-
const generatedPackageH = new templates_1.RNOHGeneratedPackageHTemplate();
|
|
14
|
-
const components_indexTS = new templates_1.IndexTSTemplate();
|
|
15
|
-
const turboModules_indexTS = new templates_1.IndexTSTemplate();
|
|
16
|
-
const generated_indexETS = new templates_1.IndexTSTemplate();
|
|
17
|
-
generated_indexETS.addReexport({ from: './ts' });
|
|
18
|
-
uberSchema
|
|
19
|
-
.findAllSpecSchemasByType('NativeModule')
|
|
20
|
-
.forEach((nativeModuleSchema) => {
|
|
21
|
-
generatedPackageH.addTurboModule({
|
|
22
|
-
name: nativeModuleSchema.moduleName,
|
|
23
|
-
});
|
|
24
|
-
turboModules_indexTS.addReexport({
|
|
25
|
-
from: `./${nativeModuleSchema.moduleName}`,
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
uberSchema
|
|
29
|
-
.findAllSpecSchemasByType('Component')
|
|
30
|
-
.forEach((componentSchema) => {
|
|
31
|
-
Object.entries(componentSchema.components).forEach(([name, componentShape]) => {
|
|
32
|
-
components_indexTS.addReexport({ from: `./${name}` });
|
|
33
|
-
generatedPackageH.addComponent({
|
|
34
|
-
name: name,
|
|
35
|
-
supportedEventNames: componentShape.events.map((e) => {
|
|
36
|
-
return (0, core_1.createEventNameFromEventHandlerName)(e.name);
|
|
37
|
-
}),
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
result.set(this.cppOutputPath.copyWithNewSegment('RNOHGeneratedPackage.h'), generatedPackageH.build());
|
|
42
|
-
result.set(this.etsOutputPath.copyWithNewSegment('ts.ts'), new templates_1.IndexTSTemplate()
|
|
43
|
-
.addReexport({ from: './components/ts', as: 'RNC' })
|
|
44
|
-
.addReexport({ from: './turboModules/ts', as: 'TM' })
|
|
45
|
-
.build());
|
|
46
|
-
result.set(this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'), components_indexTS.build());
|
|
47
|
-
result.set(this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'), turboModules_indexTS.build());
|
|
48
|
-
result.set(this.etsOutputPath.copyWithNewSegment('index.ets'), generated_indexETS.build());
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.PackageCodeGenerator = PackageCodeGenerator;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { AbsolutePath } from '../../core';
|
|
2
|
-
import { CodegenError } from './CodegenError';
|
|
3
|
-
import { SpecSchema, SpecSchemaType, UberSchema } from './UberSchema';
|
|
4
|
-
|
|
5
|
-
export interface CodeGenerator<T> {
|
|
6
|
-
generate(data: T): Map<AbsolutePath, string>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface SpecCodeGenerator extends CodeGenerator<SpecSchema> {}
|
|
10
|
-
|
|
11
|
-
export class Codegen {
|
|
12
|
-
constructor(
|
|
13
|
-
private packageCodeGenerator: CodeGenerator<UberSchema>,
|
|
14
|
-
private codeGeneratorBySpecSchemaType: Record<
|
|
15
|
-
SpecSchemaType,
|
|
16
|
-
SpecCodeGenerator
|
|
17
|
-
>
|
|
18
|
-
) {}
|
|
19
|
-
|
|
20
|
-
generate(uberSchema: UberSchema): Map<AbsolutePath, string> {
|
|
21
|
-
const result = new Map<AbsolutePath, string>();
|
|
22
|
-
for (const [_fileName, specSchema] of uberSchema
|
|
23
|
-
.getSpecSchemaByFilenameMap()
|
|
24
|
-
.entries()) {
|
|
25
|
-
if (!(specSchema.type in this.codeGeneratorBySpecSchemaType)) {
|
|
26
|
-
throw new CodegenError({
|
|
27
|
-
whatHappened: `Could not find a code generator for a specification of type '${specSchema.type}'`,
|
|
28
|
-
unexpected: true,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
this.codeGeneratorBySpecSchemaType[specSchema.type]
|
|
32
|
-
.generate(specSchema)
|
|
33
|
-
.forEach((fileContent, filePath) => {
|
|
34
|
-
result.set(filePath, fileContent);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
this.packageCodeGenerator
|
|
38
|
-
.generate(uberSchema)
|
|
39
|
-
.forEach((fileContent, filePath) => {
|
|
40
|
-
result.set(filePath, fileContent);
|
|
41
|
-
});
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { AbsolutePath } from '../../core';
|
|
2
|
-
import {
|
|
3
|
-
CodeGenerator,
|
|
4
|
-
UberSchema,
|
|
5
|
-
createEventNameFromEventHandlerName,
|
|
6
|
-
} from '../core';
|
|
7
|
-
import { IndexTSTemplate, RNOHGeneratedPackageHTemplate } from '../templates';
|
|
8
|
-
|
|
9
|
-
export class PackageCodeGenerator implements CodeGenerator<UberSchema> {
|
|
10
|
-
constructor(
|
|
11
|
-
private cppOutputPath: AbsolutePath,
|
|
12
|
-
private etsOutputPath: AbsolutePath
|
|
13
|
-
) {}
|
|
14
|
-
|
|
15
|
-
generate(uberSchema: UberSchema): Map<AbsolutePath, string> {
|
|
16
|
-
const result = new Map<AbsolutePath, string>();
|
|
17
|
-
const generatedPackageH = new RNOHGeneratedPackageHTemplate();
|
|
18
|
-
const components_indexTS = new IndexTSTemplate();
|
|
19
|
-
const turboModules_indexTS = new IndexTSTemplate();
|
|
20
|
-
const generated_indexETS = new IndexTSTemplate();
|
|
21
|
-
generated_indexETS.addReexport({ from: './ts' });
|
|
22
|
-
|
|
23
|
-
uberSchema
|
|
24
|
-
.findAllSpecSchemasByType('NativeModule')
|
|
25
|
-
.forEach((nativeModuleSchema) => {
|
|
26
|
-
generatedPackageH.addTurboModule({
|
|
27
|
-
name: nativeModuleSchema.moduleName,
|
|
28
|
-
});
|
|
29
|
-
turboModules_indexTS.addReexport({
|
|
30
|
-
from: `./${nativeModuleSchema.moduleName}`,
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
uberSchema
|
|
34
|
-
.findAllSpecSchemasByType('Component')
|
|
35
|
-
.forEach((componentSchema) => {
|
|
36
|
-
Object.entries(componentSchema.components).forEach(
|
|
37
|
-
([name, componentShape]) => {
|
|
38
|
-
components_indexTS.addReexport({ from: `./${name}` });
|
|
39
|
-
generatedPackageH.addComponent({
|
|
40
|
-
name: name,
|
|
41
|
-
supportedEventNames: componentShape.events.map((e) => {
|
|
42
|
-
return createEventNameFromEventHandlerName(e.name);
|
|
43
|
-
}),
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
result.set(
|
|
49
|
-
this.cppOutputPath.copyWithNewSegment('RNOHGeneratedPackage.h'),
|
|
50
|
-
generatedPackageH.build()
|
|
51
|
-
);
|
|
52
|
-
result.set(
|
|
53
|
-
this.etsOutputPath.copyWithNewSegment('ts.ts'),
|
|
54
|
-
new IndexTSTemplate()
|
|
55
|
-
.addReexport({ from: './components/ts', as: 'RNC' })
|
|
56
|
-
.addReexport({ from: './turboModules/ts', as: 'TM' })
|
|
57
|
-
.build()
|
|
58
|
-
);
|
|
59
|
-
result.set(
|
|
60
|
-
this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'),
|
|
61
|
-
components_indexTS.build()
|
|
62
|
-
);
|
|
63
|
-
result.set(
|
|
64
|
-
this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'),
|
|
65
|
-
turboModules_indexTS.build()
|
|
66
|
-
);
|
|
67
|
-
result.set(
|
|
68
|
-
this.etsOutputPath.copyWithNewSegment('index.ets'),
|
|
69
|
-
generated_indexETS.build()
|
|
70
|
-
);
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
}
|