@react-native-oh/react-native-harmony-cli 0.0.26 → 0.0.28
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/README.md +12 -0
- package/dist/assetResolver.js +25 -0
- package/dist/autolinking/Autolinking.js +275 -0
- package/dist/autolinking/index.js +23 -0
- package/dist/codegen/core/CodeGenerator.js +8 -0
- package/dist/codegen/core/CodegenError.js +13 -0
- package/dist/codegen/core/EventUtils.js +25 -0
- package/dist/codegen/core/TypeAnnotationToTS.js +138 -0
- package/dist/codegen/core/UberSchema.js +109 -0
- package/dist/codegen/core/index.js +27 -0
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +67 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +82 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +80 -0
- package/dist/codegen/generators/CppComponentCodeGenerator.js +62 -0
- package/dist/codegen/generators/LibGlueCodeGenerator.js +56 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +79 -0
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +40 -0
- package/dist/codegen/generators/UberGeneratorV1.js +56 -0
- package/dist/codegen/generators/UberGeneratorV2.js +77 -0
- package/dist/codegen/generators/index.js +30 -0
- package/dist/codegen/index.js +24 -0
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +111 -0
- package/dist/codegen/templates/BasePackageHTemplate.js +136 -0
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +68 -0
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +91 -0
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +198 -0
- package/dist/codegen/templates/IndexTSTemplate.js +58 -0
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +130 -0
- package/dist/codegen/templates/TurboModuleCppTemplate.js +59 -0
- package/dist/codegen/templates/TurboModuleHTemplate.js +48 -0
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +81 -0
- package/dist/codegen/templates/index.js +31 -0
- package/dist/commands/bundle-harmony.js +185 -0
- package/dist/commands/codegen-harmony.js +207 -0
- package/dist/commands/codegen-lib-harmony.js +259 -0
- package/dist/commands/create-metro-host-constants.js +67 -0
- package/dist/commands/index.js +30 -0
- package/dist/commands/link-harmony.js +97 -0
- package/dist/commands/pack-harmony.js +106 -0
- package/dist/commands/unpack-harmony.js +191 -0
- package/dist/commands/verify-package-harmony.js +128 -0
- package/dist/core/AbsolutePath.js +59 -0
- package/dist/core/CodegenConfig.js +63 -0
- package/dist/core/DescriptiveError.js +55 -0
- package/dist/core/FileSystem.js +33 -0
- package/dist/core/OHPackageJSON5.js +29 -0
- package/dist/core/PackageJSON.js +66 -0
- package/dist/core/ProjectDependenciesManager.js +83 -0
- package/dist/core/ValidationError.js +12 -0
- package/dist/core/ValueObject.js +8 -0
- package/dist/core/fs.js +42 -0
- package/dist/core/index.js +32 -0
- package/dist/index.js +22 -0
- package/dist/io/CliExecutor.js +35 -0
- package/dist/io/Logger.js +80 -0
- package/dist/io/RealFS.js +68 -0
- package/dist/io/TarGz.js +34 -0
- package/dist/io/__fixtures__.js +127 -0
- package/dist/io/fsUtils.js +37 -0
- package/dist/io/index.js +26 -0
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +44 -0
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +38 -0
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +32 -0
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +57 -0
- package/dist/package-verifier/checks/index.js +26 -0
- package/dist/package-verifier/index.js +24 -0
- package/dist/package-verifier/types.js +8 -0
- package/dist/package-verifier/verify-package.js +107 -0
- package/jest.config.js +7 -0
- package/package.json +8 -2
- package/react-native.config.js +7 -0
- package/src/assetResolver.ts +7 -0
- package/src/autolinking/Autolinking.test.ts +483 -0
- package/src/autolinking/Autolinking.ts +384 -0
- package/src/autolinking/index.ts +8 -0
- package/src/codegen/core/CodeGenerator.ts +7 -0
- package/src/codegen/core/CodegenError.ts +7 -0
- package/src/codegen/core/EventUtils.ts +7 -0
- package/src/codegen/core/TypeAnnotationToTS.test.ts +7 -0
- package/src/codegen/core/TypeAnnotationToTS.ts +7 -0
- package/src/codegen/core/UberSchema.ts +15 -1
- package/src/codegen/core/index.ts +7 -0
- package/src/codegen/generators/{GlueCodeGenerator.ts → AppBuildTimeGlueCodeGenerator.ts} +20 -9
- package/src/codegen/generators/{ComponentCodeGeneratorArkTS.ts → ArkTSComponentCodeGeneratorArkTS.ts} +18 -5
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +119 -0
- package/src/codegen/generators/{ComponentCodeGeneratorCAPI.ts → CppComponentCodeGenerator.ts} +21 -43
- package/src/codegen/generators/LibGlueCodeGenerator.ts +98 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +14 -5
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +57 -0
- package/src/codegen/generators/UberGeneratorV1.ts +19 -8
- package/src/codegen/generators/UberGeneratorV2.ts +39 -16
- package/src/codegen/generators/index.ts +12 -3
- package/src/codegen/index.ts +7 -0
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +19 -7
- package/src/codegen/templates/{GeneratedPackageHTemplate.ts → BasePackageHTemplate.ts} +52 -12
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +9 -1
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +15 -10
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +20 -8
- package/src/codegen/templates/IndexTSTemplate.ts +18 -9
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +8 -0
- package/src/codegen/templates/TurboModuleCppTemplate.ts +16 -9
- package/src/codegen/templates/TurboModuleHTemplate.ts +16 -9
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +20 -9
- package/src/codegen/templates/index.ts +7 -0
- package/src/commands/bundle-harmony.ts +8 -1
- package/src/commands/codegen-harmony.ts +43 -13
- package/src/commands/codegen-lib-harmony.ts +394 -0
- package/src/commands/create-metro-host-constants.ts +7 -0
- package/src/commands/index.ts +9 -0
- package/src/commands/link-harmony.ts +102 -0
- package/src/commands/pack-harmony.ts +7 -0
- package/src/commands/unpack-harmony.ts +12 -3
- package/src/commands/verify-package-harmony.ts +7 -0
- package/src/core/AbsolutePath.ts +16 -0
- package/src/core/CodegenConfig.ts +7 -0
- package/src/core/DescriptiveError.ts +7 -0
- package/src/core/FileSystem.ts +57 -0
- package/src/core/OHPackageJSON5.ts +7 -0
- package/src/core/PackageJSON.ts +40 -8
- package/src/core/ProjectDependenciesManager.ts +40 -14
- package/src/core/ValidationError.ts +7 -0
- package/src/core/ValueObject.ts +7 -0
- package/src/core/fs.ts +7 -0
- package/src/core/index.ts +8 -0
- package/src/index.ts +11 -0
- package/src/io/CliExecutor.ts +47 -0
- package/src/io/Logger.ts +11 -0
- package/src/io/RealFS.ts +62 -0
- package/src/io/TarGz.ts +7 -0
- package/src/io/__fixtures__.ts +135 -0
- package/src/io/fsUtils.ts +26 -6
- package/src/io/index.ts +8 -0
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +7 -0
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +7 -0
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +7 -0
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +7 -0
- package/src/package-verifier/checks/index.ts +7 -0
- package/src/package-verifier/index.ts +7 -0
- package/src/package-verifier/types.ts +7 -0
- package/src/package-verifier/verify-package.ts +9 -1
|
@@ -0,0 +1,384 @@
|
|
|
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 JSON5 from 'json5';
|
|
9
|
+
import {
|
|
10
|
+
AbsolutePath,
|
|
11
|
+
ProjectDependenciesManager,
|
|
12
|
+
FS,
|
|
13
|
+
DescriptiveError,
|
|
14
|
+
} from '../core';
|
|
15
|
+
import Mustache from 'mustache';
|
|
16
|
+
import Case from 'case';
|
|
17
|
+
import { Logger } from '../io';
|
|
18
|
+
|
|
19
|
+
type Version = string;
|
|
20
|
+
type DependencySpecifier = `file:${string}` | Version;
|
|
21
|
+
|
|
22
|
+
export type AutolinkingConfig = {
|
|
23
|
+
harmonyProjectPath: AbsolutePath;
|
|
24
|
+
nodeModulesPath: AbsolutePath;
|
|
25
|
+
ohPackagePathRelativeToHarmony: string;
|
|
26
|
+
etsRNOHPackagesFactoryPathRelativeToHarmony: string;
|
|
27
|
+
cppRNOHPackagesFactoryPathRelativeToHarmony: string;
|
|
28
|
+
cmakeAutolinkPathRelativeToHarmony: string;
|
|
29
|
+
excludedNpmPackageNames: Set<string>;
|
|
30
|
+
includedNpmPackageNames: Set<string>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type AutolinkableLibrary = {
|
|
34
|
+
npmPackageName: string;
|
|
35
|
+
harFilePathRelativeToHarmony: string;
|
|
36
|
+
etsRNOHPackageClassName?: string;
|
|
37
|
+
cppRNOHPackageClassName?: string;
|
|
38
|
+
cmakeLibraryTargetName?: string;
|
|
39
|
+
ohPackageName?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type AutolinkingInput = {
|
|
43
|
+
projectRootPath: AbsolutePath;
|
|
44
|
+
etsRNOHPackagesFactoryPath: AbsolutePath;
|
|
45
|
+
cppRNOHPackagesFactoryPath: AbsolutePath;
|
|
46
|
+
cmakeAutolinkingPath: AbsolutePath;
|
|
47
|
+
ohPackagePathAndContent: [AbsolutePath, string];
|
|
48
|
+
autolinkableLibraries: AutolinkableLibrary[];
|
|
49
|
+
nodeModuleHarFilePathsRelativeToHarmony: string[];
|
|
50
|
+
skippedLibraryNpmPackageNames: string[];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type AutolinkingOutput = {
|
|
54
|
+
linkedLibraryNpmPackageNames: string[];
|
|
55
|
+
skippedLibraryNpmPackageNames: string[];
|
|
56
|
+
projectRootPath: AbsolutePath;
|
|
57
|
+
etsRNOHPackagesFactoryPathAndContent: [AbsolutePath, string];
|
|
58
|
+
cppRNOHPackagesFactoryPathAndContent: [AbsolutePath, string];
|
|
59
|
+
cmakeAutolinkingPathAndContent: [AbsolutePath, string];
|
|
60
|
+
ohPackagePathAndContent: [AbsolutePath, string];
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = `
|
|
64
|
+
/*
|
|
65
|
+
* This file was generated by RNOH autolinking.
|
|
66
|
+
* DO NOT modify it manually, your changes WILL be overwritten.
|
|
67
|
+
*/
|
|
68
|
+
import type { RNPackageContext, RNOHPackage } from '@rnoh/react-native-openharmony';
|
|
69
|
+
{{#libraries}}
|
|
70
|
+
import {{etsRNOHPackageClassName}} from '{{{ohPackageName}}}';
|
|
71
|
+
{{/libraries}}
|
|
72
|
+
|
|
73
|
+
export function createRNOHPackages(ctx: RNPackageContext): RNOHPackage[] {
|
|
74
|
+
return [
|
|
75
|
+
{{#libraries}}
|
|
76
|
+
new {{etsRNOHPackageClassName}}(ctx),
|
|
77
|
+
{{/libraries}}
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
`.trimStart();
|
|
81
|
+
|
|
82
|
+
const CPP_RNOH_PACKAGES_FACTORY_TEMPLATE = `
|
|
83
|
+
/*
|
|
84
|
+
* This file was generated by RNOH autolinking.
|
|
85
|
+
* DO NOT modify it manually, your changes WILL be overwritten.
|
|
86
|
+
*/
|
|
87
|
+
// clang-format off
|
|
88
|
+
#pragma once
|
|
89
|
+
#include "RNOH/Package.h"
|
|
90
|
+
{{#libraries}}
|
|
91
|
+
#include "{{etsRNOHPackageClassName}}.h"
|
|
92
|
+
{{/libraries}}
|
|
93
|
+
|
|
94
|
+
std::vector<rnoh::Package::Shared> createRNOHPackages(const rnoh::Package::Context &ctx) {
|
|
95
|
+
return {
|
|
96
|
+
{{#libraries}}
|
|
97
|
+
std::make_shared<rnoh::{{cppRNOHPackageClassName}}>(ctx),
|
|
98
|
+
{{/libraries}}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
`.trimStart();
|
|
102
|
+
|
|
103
|
+
const CMAKE_AUTOLINKING_TEMPLATE = `
|
|
104
|
+
# This file was generated by RNOH autolinking.
|
|
105
|
+
# DO NOT modify it manually, your changes WILL be overwritten.
|
|
106
|
+
cmake_minimum_required(VERSION 3.5)
|
|
107
|
+
|
|
108
|
+
# @api
|
|
109
|
+
function(autolink_libraries target)
|
|
110
|
+
{{#libraries}}
|
|
111
|
+
add_subdirectory("\${OH_MODULES_DIR}/{{{ohPackageName}}}/src/main/cpp" ./{{cmakeLibraryTargetName}})
|
|
112
|
+
{{/libraries}}
|
|
113
|
+
|
|
114
|
+
set(AUTOLINKED_LIBRARIES
|
|
115
|
+
{{#libraries}}
|
|
116
|
+
{{cmakeLibraryTargetName}}
|
|
117
|
+
{{/libraries}}
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
foreach(lib \${AUTOLINKED_LIBRARIES})
|
|
121
|
+
target_link_libraries(\${target} PUBLIC \${lib})
|
|
122
|
+
endforeach()
|
|
123
|
+
endfunction()
|
|
124
|
+
`.trimStart();
|
|
125
|
+
|
|
126
|
+
export class Autolinking {
|
|
127
|
+
constructor(private fs: FS, private logger: Logger) {}
|
|
128
|
+
|
|
129
|
+
async prepareInput(config: AutolinkingConfig): Promise<AutolinkingInput> {
|
|
130
|
+
if (
|
|
131
|
+
config.includedNpmPackageNames.size > 0 &&
|
|
132
|
+
config.excludedNpmPackageNames.size > 0
|
|
133
|
+
) {
|
|
134
|
+
throw new DescriptiveError({
|
|
135
|
+
whatHappened: 'Tried to exclude and include npm packages.',
|
|
136
|
+
whatCanUserDo: {
|
|
137
|
+
default: ['Include or exclude npm packages, but not both.'],
|
|
138
|
+
},
|
|
139
|
+
extraData: {
|
|
140
|
+
includedNpmPackageNamesCount: config.includedNpmPackageNames.size,
|
|
141
|
+
excludedNpmPackageNamesCount: config.excludedNpmPackageNames.size,
|
|
142
|
+
includedNpmPackageNames: config.includedNpmPackageNames,
|
|
143
|
+
excludedNpmPackageNames: config.excludedNpmPackageNames,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const harmonyProjectPath =
|
|
148
|
+
config.harmonyProjectPath ?? new AbsolutePath('./');
|
|
149
|
+
const nodeModuleHarPaths: AbsolutePath[] = [];
|
|
150
|
+
const autolinkableLibraries: AutolinkableLibrary[] = [];
|
|
151
|
+
const projectRootPath = config.nodeModulesPath.copyWithNewSegment('..');
|
|
152
|
+
const skippedLibraryNpmPackageNames: string[] = [];
|
|
153
|
+
await new ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync(
|
|
154
|
+
(dependency) => {
|
|
155
|
+
const harFilePath = dependency.getHarFilePath();
|
|
156
|
+
if (!harFilePath) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
nodeModuleHarPaths.push(harFilePath);
|
|
160
|
+
const packageJson = dependency.readPackageJSON();
|
|
161
|
+
const providedAutolinkingConfig = packageJson.harmony?.autolinking;
|
|
162
|
+
|
|
163
|
+
if (
|
|
164
|
+
providedAutolinkingConfig === undefined ||
|
|
165
|
+
providedAutolinkingConfig === null ||
|
|
166
|
+
(config.excludedNpmPackageNames.has(packageJson.name) &&
|
|
167
|
+
config.excludedNpmPackageNames.size > 0) ||
|
|
168
|
+
(!config.includedNpmPackageNames.has(packageJson.name) &&
|
|
169
|
+
config.includedNpmPackageNames.size > 0)
|
|
170
|
+
) {
|
|
171
|
+
skippedLibraryNpmPackageNames.push(packageJson.name);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const autolinkingConfig =
|
|
175
|
+
providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
|
|
176
|
+
autolinkableLibraries.push({
|
|
177
|
+
npmPackageName: packageJson.name,
|
|
178
|
+
etsRNOHPackageClassName: autolinkingConfig?.etsPackageClassName,
|
|
179
|
+
cppRNOHPackageClassName: autolinkingConfig?.cppPackageClassName,
|
|
180
|
+
cmakeLibraryTargetName: autolinkingConfig?.cmakeLibraryTargetName,
|
|
181
|
+
ohPackageName: autolinkingConfig?.ohPackageName,
|
|
182
|
+
harFilePathRelativeToHarmony: harFilePath
|
|
183
|
+
.relativeTo(harmonyProjectPath)
|
|
184
|
+
.toString(),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
const ohPackagePath = harmonyProjectPath.copyWithNewSegment(
|
|
189
|
+
config.ohPackagePathRelativeToHarmony
|
|
190
|
+
);
|
|
191
|
+
const ohPackageContent = await this.fs.readText(ohPackagePath);
|
|
192
|
+
const cppRNOHPackagesFactoryPath = harmonyProjectPath.copyWithNewSegment(
|
|
193
|
+
config.cppRNOHPackagesFactoryPathRelativeToHarmony
|
|
194
|
+
);
|
|
195
|
+
const cmakeAutolinkingPath = harmonyProjectPath.copyWithNewSegment(
|
|
196
|
+
config.cmakeAutolinkPathRelativeToHarmony
|
|
197
|
+
);
|
|
198
|
+
return {
|
|
199
|
+
projectRootPath,
|
|
200
|
+
skippedLibraryNpmPackageNames,
|
|
201
|
+
etsRNOHPackagesFactoryPath: harmonyProjectPath.copyWithNewSegment(
|
|
202
|
+
config.etsRNOHPackagesFactoryPathRelativeToHarmony
|
|
203
|
+
),
|
|
204
|
+
cppRNOHPackagesFactoryPath,
|
|
205
|
+
cmakeAutolinkingPath: cmakeAutolinkingPath,
|
|
206
|
+
ohPackagePathAndContent: [ohPackagePath, ohPackageContent],
|
|
207
|
+
autolinkableLibraries,
|
|
208
|
+
nodeModuleHarFilePathsRelativeToHarmony: nodeModuleHarPaths.map((p) =>
|
|
209
|
+
p.relativeTo(harmonyProjectPath).toString()
|
|
210
|
+
),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
evaluate(input: AutolinkingInput): AutolinkingOutput {
|
|
215
|
+
const autolinkableLibraries: Required<AutolinkableLibrary>[] =
|
|
216
|
+
input.autolinkableLibraries.map((lib) => {
|
|
217
|
+
return {
|
|
218
|
+
...lib,
|
|
219
|
+
etsRNOHPackageClassName:
|
|
220
|
+
lib.etsRNOHPackageClassName ??
|
|
221
|
+
this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName),
|
|
222
|
+
cppRNOHPackageClassName:
|
|
223
|
+
lib.cppRNOHPackageClassName ??
|
|
224
|
+
this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName),
|
|
225
|
+
cmakeLibraryTargetName:
|
|
226
|
+
lib.cmakeLibraryTargetName ??
|
|
227
|
+
this.npmPackageNameToCMakeLibraryTargetName(lib.npmPackageName),
|
|
228
|
+
ohPackageName:
|
|
229
|
+
lib.ohPackageName ??
|
|
230
|
+
this.npmPackageNameToOHPackageName(lib.npmPackageName),
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
autolinkableLibraries.sort((a, b) => {
|
|
234
|
+
if (a.npmPackageName < b.npmPackageName) return -1;
|
|
235
|
+
if (a.npmPackageName > b.npmPackageName) return 1;
|
|
236
|
+
return 0;
|
|
237
|
+
});
|
|
238
|
+
const ohPackage = JSON5.parse(input.ohPackagePathAndContent[1]);
|
|
239
|
+
const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map(
|
|
240
|
+
(lib) => lib.harFilePathRelativeToHarmony
|
|
241
|
+
);
|
|
242
|
+
const unmanagedNativeDependencySpecifierByName: Record<
|
|
243
|
+
string,
|
|
244
|
+
DependencySpecifier
|
|
245
|
+
> = {};
|
|
246
|
+
Object.entries<DependencySpecifier>(ohPackage.dependencies).forEach(
|
|
247
|
+
([name, dependencySpecifier]) => {
|
|
248
|
+
if (!dependencySpecifier.includes('file:')) {
|
|
249
|
+
unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
|
|
250
|
+
} else {
|
|
251
|
+
const harFilePathRelativeToHarmony = dependencySpecifier.replace(
|
|
252
|
+
'file:',
|
|
253
|
+
''
|
|
254
|
+
);
|
|
255
|
+
if (
|
|
256
|
+
!autolinkableHarFilePathsRelativeToHarmony.includes(
|
|
257
|
+
harFilePathRelativeToHarmony
|
|
258
|
+
) &&
|
|
259
|
+
input.nodeModuleHarFilePathsRelativeToHarmony.includes(
|
|
260
|
+
harFilePathRelativeToHarmony
|
|
261
|
+
)
|
|
262
|
+
) {
|
|
263
|
+
unmanagedNativeDependencySpecifierByName[name] =
|
|
264
|
+
dependencySpecifier;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
);
|
|
269
|
+
const managedNativeDependencySpecifierByName: Record<string, string> = {};
|
|
270
|
+
for (const library of autolinkableLibraries) {
|
|
271
|
+
managedNativeDependencySpecifierByName[library.ohPackageName] =
|
|
272
|
+
'file:' + library.harFilePathRelativeToHarmony;
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
|
|
276
|
+
linkedLibraryNpmPackageNames: autolinkableLibraries.map(
|
|
277
|
+
(lib) => lib.npmPackageName
|
|
278
|
+
),
|
|
279
|
+
projectRootPath: input.projectRootPath,
|
|
280
|
+
cppRNOHPackagesFactoryPathAndContent: [
|
|
281
|
+
input.cppRNOHPackagesFactoryPath,
|
|
282
|
+
Mustache.render(CPP_RNOH_PACKAGES_FACTORY_TEMPLATE, {
|
|
283
|
+
libraries: autolinkableLibraries,
|
|
284
|
+
}),
|
|
285
|
+
],
|
|
286
|
+
etsRNOHPackagesFactoryPathAndContent: [
|
|
287
|
+
input.etsRNOHPackagesFactoryPath,
|
|
288
|
+
Mustache.render(ETS_RNOH_PACKAGES_FACTORY_TEMPLATE, {
|
|
289
|
+
libraries: autolinkableLibraries,
|
|
290
|
+
}),
|
|
291
|
+
],
|
|
292
|
+
cmakeAutolinkingPathAndContent: [
|
|
293
|
+
input.cmakeAutolinkingPath,
|
|
294
|
+
Mustache.render(CMAKE_AUTOLINKING_TEMPLATE, {
|
|
295
|
+
libraries: autolinkableLibraries,
|
|
296
|
+
}),
|
|
297
|
+
],
|
|
298
|
+
ohPackagePathAndContent: [
|
|
299
|
+
input.ohPackagePathAndContent[0],
|
|
300
|
+
JSON5.stringify(
|
|
301
|
+
{
|
|
302
|
+
...ohPackage,
|
|
303
|
+
dependencies: {
|
|
304
|
+
...unmanagedNativeDependencySpecifierByName,
|
|
305
|
+
...managedNativeDependencySpecifierByName,
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
{ space: 2, quote: '"' }
|
|
309
|
+
) + '\n',
|
|
310
|
+
],
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private npmPackageNameToRNOHPackageClassName(fullNpmPackageName: string) {
|
|
315
|
+
if (fullNpmPackageName.startsWith('@')) {
|
|
316
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
317
|
+
.replace('@', '')
|
|
318
|
+
.split('/');
|
|
319
|
+
return Case.pascal(scopeName) + Case.pascal(packageName) + 'Package';
|
|
320
|
+
}
|
|
321
|
+
return Case.pascal(fullNpmPackageName) + 'Package';
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
private npmPackageNameToCMakeLibraryTargetName(fullNpmPackageName: string) {
|
|
325
|
+
if (fullNpmPackageName.startsWith('@')) {
|
|
326
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
327
|
+
.replace('@', '')
|
|
328
|
+
.split('/');
|
|
329
|
+
return 'rnoh__' + Case.snake(scopeName) + '__' + Case.snake(packageName);
|
|
330
|
+
}
|
|
331
|
+
return 'rnoh__' + Case.snake(fullNpmPackageName);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
private npmPackageNameToOHPackageName(fullNpmPackageName: string): string {
|
|
335
|
+
if (fullNpmPackageName.startsWith('@')) {
|
|
336
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
337
|
+
.replace('@', '')
|
|
338
|
+
.split('/');
|
|
339
|
+
return '@rnoh/' + Case.kebab(scopeName) + '--' + Case.kebab(packageName);
|
|
340
|
+
}
|
|
341
|
+
return '@rnoh/' + Case.kebab(fullNpmPackageName);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
saveAndLogOutput(output: AutolinkingOutput) {
|
|
345
|
+
const pathAndContentPairs: [AbsolutePath, string][] = [];
|
|
346
|
+
pathAndContentPairs.push(output.etsRNOHPackagesFactoryPathAndContent);
|
|
347
|
+
pathAndContentPairs.push(output.cppRNOHPackagesFactoryPathAndContent);
|
|
348
|
+
pathAndContentPairs.push(output.cmakeAutolinkingPathAndContent);
|
|
349
|
+
pathAndContentPairs.push(output.ohPackagePathAndContent);
|
|
350
|
+
pathAndContentPairs.forEach(([path, content]) => {
|
|
351
|
+
this.fs.writeTextSync(path, content);
|
|
352
|
+
});
|
|
353
|
+
output.linkedLibraryNpmPackageNames.forEach((npmPackageName) => {
|
|
354
|
+
this.logger.info(
|
|
355
|
+
(styles) => `[${styles.green(styles.bold('link'))}] ${npmPackageName}`
|
|
356
|
+
);
|
|
357
|
+
});
|
|
358
|
+
output.skippedLibraryNpmPackageNames.forEach((npmPackageName) => {
|
|
359
|
+
this.logger.warn(
|
|
360
|
+
(styles) => `[${styles.yellow(styles.bold('skip'))}] ${npmPackageName}`
|
|
361
|
+
);
|
|
362
|
+
});
|
|
363
|
+
this.logger.info(() => '');
|
|
364
|
+
const sortedPathsRelativeToRoot = pathAndContentPairs
|
|
365
|
+
.map(([path]) => path.relativeTo(output.projectRootPath).toString())
|
|
366
|
+
.sort();
|
|
367
|
+
sortedPathsRelativeToRoot.forEach((pathStr) => {
|
|
368
|
+
this.logger.info((styles) => styles.gray(`• ${pathStr}`));
|
|
369
|
+
});
|
|
370
|
+
this.logger.info(() => '');
|
|
371
|
+
this.logger.info(
|
|
372
|
+
(styles) =>
|
|
373
|
+
`updated ${styles.green(
|
|
374
|
+
styles.bold(sortedPathsRelativeToRoot.length)
|
|
375
|
+
)} file(s), linked ${styles.green(
|
|
376
|
+
styles.bold(output.linkedLibraryNpmPackageNames.length)
|
|
377
|
+
)} libraries, skipped ${styles.yellow(
|
|
378
|
+
styles.bold(output.skippedLibraryNpmPackageNames.length)
|
|
379
|
+
)} libraries`,
|
|
380
|
+
{ prefix: true }
|
|
381
|
+
);
|
|
382
|
+
this.logger.info(() => '');
|
|
383
|
+
}
|
|
384
|
+
}
|
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
import { AbsolutePath } from '../../core';
|
|
2
9
|
import { SpecSchema } from './UberSchema';
|
|
3
10
|
|
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
import { DescriptiveError } from '../../core';
|
|
2
9
|
|
|
3
10
|
export class CodegenError extends DescriptiveError {}
|
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
import { CodegenError } from './CodegenError';
|
|
2
9
|
|
|
3
10
|
export function createEventNameFromEventHandlerName(
|
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
import { TypeAnnotationToTS, TypeAnnotation } from './TypeAnnotationToTS';
|
|
2
9
|
|
|
3
10
|
function convert(typeAnnotation: TypeAnnotation) {
|
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
import {
|
|
2
9
|
ComponentSchema,
|
|
3
10
|
NativeModuleSchema,
|
|
@@ -9,6 +16,7 @@ import {
|
|
|
9
16
|
PackageJSON,
|
|
10
17
|
ProjectDependenciesManager,
|
|
11
18
|
CodegenConfig,
|
|
19
|
+
FS
|
|
12
20
|
} from '../../core';
|
|
13
21
|
// @ts-expect-error
|
|
14
22
|
import extractUberSchemaFromSpecFilePaths_ from '@react-native/codegen/lib/cli/combine/combine-js-to-schema.js';
|
|
@@ -33,6 +41,10 @@ type FindSpecSchemaByType<
|
|
|
33
41
|
* Contains component and turbo module (NativeModule) schemas. The "Uber" word is used here to highlight that SpecSchemas don't extend this class.
|
|
34
42
|
*/
|
|
35
43
|
export class UberSchema implements ValueObject {
|
|
44
|
+
static fromSpecFilePaths(specPaths: AbsolutePath[]): UberSchema {
|
|
45
|
+
return new UberSchema(createRawUberSchemaFromSpecFilePaths(specPaths));
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
static fromCodegenConfig(codegenConfig: CodegenConfig): UberSchema {
|
|
37
49
|
try {
|
|
38
50
|
return new UberSchema(
|
|
@@ -54,6 +66,7 @@ export class UberSchema implements ValueObject {
|
|
|
54
66
|
}
|
|
55
67
|
|
|
56
68
|
static async fromProject(
|
|
69
|
+
fs: FS,
|
|
57
70
|
projectRootPath: AbsolutePath,
|
|
58
71
|
onShouldAcceptCodegenConfig?: (
|
|
59
72
|
codegenVersion: number,
|
|
@@ -63,6 +76,7 @@ export class UberSchema implements ValueObject {
|
|
|
63
76
|
const onShouldAcceptCodegenConfig_ =
|
|
64
77
|
onShouldAcceptCodegenConfig ?? ((x: number) => true);
|
|
65
78
|
const packageJSON = PackageJSON.fromProjectRootPath(
|
|
79
|
+
fs,
|
|
66
80
|
projectRootPath,
|
|
67
81
|
projectRootPath
|
|
68
82
|
);
|
|
@@ -78,7 +92,7 @@ export class UberSchema implements ValueObject {
|
|
|
78
92
|
acceptedCodegenConfigs.push(codegenConfig);
|
|
79
93
|
}
|
|
80
94
|
}
|
|
81
|
-
await new ProjectDependenciesManager(projectRootPath).forEachAsync(
|
|
95
|
+
await new ProjectDependenciesManager(fs, projectRootPath).forEachAsync(
|
|
82
96
|
(dependency) => {
|
|
83
97
|
const codegenConfigs = dependency.getCodegenConfigs();
|
|
84
98
|
for (const codegenConfig of codegenConfigs) {
|
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
export * from './CodeGenerator';
|
|
2
9
|
export * from './UberSchema';
|
|
3
10
|
export * from './CodegenError';
|
|
@@ -1,12 +1,19 @@
|
|
|
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
|
+
|
|
1
8
|
import Case from 'case';
|
|
2
9
|
import { AbsolutePath } from '../../core';
|
|
3
10
|
import { CodeGenerator } from '../core';
|
|
4
11
|
import { IndexTSTemplate, RNOHGeneratedPackageHTemplate } from '../templates';
|
|
5
|
-
import { BasePackageHTemplate } from '../templates/
|
|
12
|
+
import { BasePackageHTemplate } from '../templates/BasePackageHTemplate';
|
|
6
13
|
|
|
7
14
|
export type GlueCodeComponentDataV1 = { name: string; eventNames: string[] };
|
|
8
15
|
|
|
9
|
-
export type GlueCodeComponentDataV2 = { name: string;
|
|
16
|
+
export type GlueCodeComponentDataV2 = { name: string; libraryCppName: string };
|
|
10
17
|
|
|
11
18
|
export type GlueCodeTurboModuleData = { name: string };
|
|
12
19
|
|
|
@@ -33,18 +40,21 @@ export type GlueCodeData = {
|
|
|
33
40
|
* Generates code based on UberGenerators results. If UberGenerators produce "leaves" (concrete turbo module or component classes),
|
|
34
41
|
* this class generates "branches" (barrel files like index.ts) and "trunks" (package file or files).
|
|
35
42
|
*/
|
|
36
|
-
export class
|
|
43
|
+
export class AppBuildTimeGlueCodeGenerator
|
|
44
|
+
implements CodeGenerator<GlueCodeData>
|
|
45
|
+
{
|
|
37
46
|
constructor(
|
|
38
47
|
private cppOutputPath: AbsolutePath,
|
|
39
|
-
private etsOutputPath: AbsolutePath
|
|
48
|
+
private etsOutputPath: AbsolutePath,
|
|
49
|
+
private codegenNoticeLines: string[]
|
|
40
50
|
) {}
|
|
41
51
|
|
|
42
52
|
generate({ v1, v2 }: GlueCodeData): Map<AbsolutePath, string> {
|
|
43
53
|
const fileContentByPath = new Map<AbsolutePath, string>();
|
|
44
54
|
const generatedPackageH_v1 = new RNOHGeneratedPackageHTemplate();
|
|
45
|
-
const components_indexTS = new IndexTSTemplate();
|
|
46
|
-
const turboModules_indexTS = new IndexTSTemplate();
|
|
47
|
-
const generated_indexETS = new IndexTSTemplate();
|
|
55
|
+
const components_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
|
|
56
|
+
const turboModules_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
|
|
57
|
+
const generated_indexETS = new IndexTSTemplate(this.codegenNoticeLines);
|
|
48
58
|
|
|
49
59
|
generated_indexETS.addReexport({ from: './ts' });
|
|
50
60
|
v1.components.forEach(({ name, eventNames }) => {
|
|
@@ -62,7 +72,8 @@ export class GlueCodeGenerator implements CodeGenerator<GlueCodeData> {
|
|
|
62
72
|
v2.forEach(({ components, turboModules }, libraryName) => {
|
|
63
73
|
const basePackageClassName = `Base${Case.pascal(libraryName)}Package`;
|
|
64
74
|
const generatedPackageH_v2 = new BasePackageHTemplate(
|
|
65
|
-
basePackageClassName
|
|
75
|
+
basePackageClassName,
|
|
76
|
+
this.codegenNoticeLines
|
|
66
77
|
);
|
|
67
78
|
components.forEach((component) => {
|
|
68
79
|
generatedPackageH_v2.addComponent(component);
|
|
@@ -87,7 +98,7 @@ export class GlueCodeGenerator implements CodeGenerator<GlueCodeData> {
|
|
|
87
98
|
);
|
|
88
99
|
fileContentByPath.set(
|
|
89
100
|
this.etsOutputPath.copyWithNewSegment('ts.ts'),
|
|
90
|
-
new IndexTSTemplate()
|
|
101
|
+
new IndexTSTemplate(this.codegenNoticeLines)
|
|
91
102
|
.addReexport({ from: './components/ts', as: 'RNC' })
|
|
92
103
|
.addReexport({ from: './turboModules/ts', as: 'TM' })
|
|
93
104
|
.build()
|
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
import { AbsolutePath } from '../../core';
|
|
2
9
|
import {
|
|
3
10
|
CodegenError,
|
|
@@ -12,14 +19,16 @@ import {
|
|
|
12
19
|
ComponentJSIBinderHTemplate,
|
|
13
20
|
ComponentUtilsTSTemplate,
|
|
14
21
|
} from '../templates';
|
|
15
|
-
import { GlueCodeComponentDataV1 } from './
|
|
22
|
+
import { GlueCodeComponentDataV1 } from './AppBuildTimeGlueCodeGenerator';
|
|
16
23
|
|
|
17
|
-
export class
|
|
24
|
+
export class ArkTSComponentCodeGeneratorArkTS implements SpecCodeGenerator {
|
|
18
25
|
private glueCodeDataItems: GlueCodeComponentDataV1[] = [];
|
|
19
26
|
|
|
20
27
|
constructor(
|
|
21
28
|
private cppOutputPath: AbsolutePath,
|
|
22
|
-
private tsOutputPath: AbsolutePath
|
|
29
|
+
private tsOutputPath: AbsolutePath,
|
|
30
|
+
private codegenNoticeLines: string[],
|
|
31
|
+
private rnohImport: string
|
|
23
32
|
) {}
|
|
24
33
|
|
|
25
34
|
getGlueCodeData(): GlueCodeComponentDataV1[] {
|
|
@@ -41,9 +50,13 @@ export class ComponentCodeGeneratorArkTS implements SpecCodeGenerator {
|
|
|
41
50
|
);
|
|
42
51
|
const componentJSIBinderHTemplate = new ComponentJSIBinderHTemplate(
|
|
43
52
|
name,
|
|
44
|
-
|
|
53
|
+
this.codegenNoticeLines
|
|
54
|
+
);
|
|
55
|
+
const componentUtilsTSTemplate = new ComponentUtilsTSTemplate(
|
|
56
|
+
name,
|
|
57
|
+
this.codegenNoticeLines,
|
|
58
|
+
this.rnohImport
|
|
45
59
|
);
|
|
46
|
-
const componentUtilsTSTemplate = new ComponentUtilsTSTemplate(name);
|
|
47
60
|
|
|
48
61
|
shape.props.forEach((prop) => {
|
|
49
62
|
componentJSIBinderHTemplate.addProp({
|