@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
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @react-native-oh/react-native-harmony-cli
|
|
2
|
+
|
|
3
|
+
Please refer to: [RNOH repo](https://gitee.com/openharmony-sig/ohos_react_native) for more detail.
|
|
4
|
+
|
|
5
|
+
# Documentation
|
|
6
|
+
|
|
7
|
+
- [中文](https://gitee.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/README.md)
|
|
8
|
+
- [English](https://gitee.com/openharmony-sig/ohos_react_native/blob/master/docs/en/README.md)
|
|
9
|
+
|
|
10
|
+
# License
|
|
11
|
+
|
|
12
|
+
This library is licensed under The [MIT License (MIT)](https://gitee.com/openharmony-sig/ohos_react_native)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getAssetDestRelativePath = void 0;
|
|
10
|
+
function getAssetDestRelativePath(asset) {
|
|
11
|
+
const fileName = getResourceIdentifier(asset);
|
|
12
|
+
return `${fileName}.${asset.type}`;
|
|
13
|
+
}
|
|
14
|
+
exports.getAssetDestRelativePath = getAssetDestRelativePath;
|
|
15
|
+
function getResourceIdentifier(asset) {
|
|
16
|
+
const folderPath = getBasePath(asset);
|
|
17
|
+
return `${folderPath}/${asset.name}`.slice('assets/'.length);
|
|
18
|
+
}
|
|
19
|
+
function getBasePath(asset) {
|
|
20
|
+
let basePath = asset.httpServerLocation;
|
|
21
|
+
if (basePath[0] === '/') {
|
|
22
|
+
basePath = basePath.substr(1);
|
|
23
|
+
}
|
|
24
|
+
return basePath;
|
|
25
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.Autolinking = void 0;
|
|
22
|
+
const json5_1 = __importDefault(require("json5"));
|
|
23
|
+
const core_1 = require("../core");
|
|
24
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
25
|
+
const case_1 = __importDefault(require("case"));
|
|
26
|
+
const ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = `
|
|
27
|
+
/*
|
|
28
|
+
* This file was generated by RNOH autolinking.
|
|
29
|
+
* DO NOT modify it manually, your changes WILL be overwritten.
|
|
30
|
+
*/
|
|
31
|
+
import type { RNPackageContext, RNOHPackage } from '@rnoh/react-native-openharmony';
|
|
32
|
+
{{#libraries}}
|
|
33
|
+
import {{etsRNOHPackageClassName}} from '{{{ohPackageName}}}';
|
|
34
|
+
{{/libraries}}
|
|
35
|
+
|
|
36
|
+
export function createRNOHPackages(ctx: RNPackageContext): RNOHPackage[] {
|
|
37
|
+
return [
|
|
38
|
+
{{#libraries}}
|
|
39
|
+
new {{etsRNOHPackageClassName}}(ctx),
|
|
40
|
+
{{/libraries}}
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
`.trimStart();
|
|
44
|
+
const CPP_RNOH_PACKAGES_FACTORY_TEMPLATE = `
|
|
45
|
+
/*
|
|
46
|
+
* This file was generated by RNOH autolinking.
|
|
47
|
+
* DO NOT modify it manually, your changes WILL be overwritten.
|
|
48
|
+
*/
|
|
49
|
+
// clang-format off
|
|
50
|
+
#pragma once
|
|
51
|
+
#include "RNOH/Package.h"
|
|
52
|
+
{{#libraries}}
|
|
53
|
+
#include "{{etsRNOHPackageClassName}}.h"
|
|
54
|
+
{{/libraries}}
|
|
55
|
+
|
|
56
|
+
std::vector<rnoh::Package::Shared> createRNOHPackages(const rnoh::Package::Context &ctx) {
|
|
57
|
+
return {
|
|
58
|
+
{{#libraries}}
|
|
59
|
+
std::make_shared<rnoh::{{cppRNOHPackageClassName}}>(ctx),
|
|
60
|
+
{{/libraries}}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
`.trimStart();
|
|
64
|
+
const CMAKE_AUTOLINKING_TEMPLATE = `
|
|
65
|
+
# This file was generated by RNOH autolinking.
|
|
66
|
+
# DO NOT modify it manually, your changes WILL be overwritten.
|
|
67
|
+
cmake_minimum_required(VERSION 3.5)
|
|
68
|
+
|
|
69
|
+
# @api
|
|
70
|
+
function(autolink_libraries target)
|
|
71
|
+
{{#libraries}}
|
|
72
|
+
add_subdirectory("\${OH_MODULES_DIR}/{{{ohPackageName}}}/src/main/cpp" ./{{cmakeLibraryTargetName}})
|
|
73
|
+
{{/libraries}}
|
|
74
|
+
|
|
75
|
+
set(AUTOLINKED_LIBRARIES
|
|
76
|
+
{{#libraries}}
|
|
77
|
+
{{cmakeLibraryTargetName}}
|
|
78
|
+
{{/libraries}}
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
foreach(lib \${AUTOLINKED_LIBRARIES})
|
|
82
|
+
target_link_libraries(\${target} PUBLIC \${lib})
|
|
83
|
+
endforeach()
|
|
84
|
+
endfunction()
|
|
85
|
+
`.trimStart();
|
|
86
|
+
class Autolinking {
|
|
87
|
+
constructor(fs, logger) {
|
|
88
|
+
this.fs = fs;
|
|
89
|
+
this.logger = logger;
|
|
90
|
+
}
|
|
91
|
+
prepareInput(config) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
var _a;
|
|
94
|
+
if (config.includedNpmPackageNames.size > 0 &&
|
|
95
|
+
config.excludedNpmPackageNames.size > 0) {
|
|
96
|
+
throw new core_1.DescriptiveError({
|
|
97
|
+
whatHappened: 'Tried to exclude and include npm packages.',
|
|
98
|
+
whatCanUserDo: {
|
|
99
|
+
default: ['Include or exclude npm packages, but not both.'],
|
|
100
|
+
},
|
|
101
|
+
extraData: {
|
|
102
|
+
includedNpmPackageNamesCount: config.includedNpmPackageNames.size,
|
|
103
|
+
excludedNpmPackageNamesCount: config.excludedNpmPackageNames.size,
|
|
104
|
+
includedNpmPackageNames: config.includedNpmPackageNames,
|
|
105
|
+
excludedNpmPackageNames: config.excludedNpmPackageNames,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const harmonyProjectPath = (_a = config.harmonyProjectPath) !== null && _a !== void 0 ? _a : new core_1.AbsolutePath('./');
|
|
110
|
+
const nodeModuleHarPaths = [];
|
|
111
|
+
const autolinkableLibraries = [];
|
|
112
|
+
const projectRootPath = config.nodeModulesPath.copyWithNewSegment('..');
|
|
113
|
+
const skippedLibraryNpmPackageNames = [];
|
|
114
|
+
yield new core_1.ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync((dependency) => {
|
|
115
|
+
var _a;
|
|
116
|
+
const harFilePath = dependency.getHarFilePath();
|
|
117
|
+
if (!harFilePath) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
nodeModuleHarPaths.push(harFilePath);
|
|
121
|
+
const packageJson = dependency.readPackageJSON();
|
|
122
|
+
const providedAutolinkingConfig = (_a = packageJson.harmony) === null || _a === void 0 ? void 0 : _a.autolinking;
|
|
123
|
+
if (providedAutolinkingConfig === undefined ||
|
|
124
|
+
providedAutolinkingConfig === null ||
|
|
125
|
+
(config.excludedNpmPackageNames.has(packageJson.name) &&
|
|
126
|
+
config.excludedNpmPackageNames.size > 0) ||
|
|
127
|
+
(!config.includedNpmPackageNames.has(packageJson.name) &&
|
|
128
|
+
config.includedNpmPackageNames.size > 0)) {
|
|
129
|
+
skippedLibraryNpmPackageNames.push(packageJson.name);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const autolinkingConfig = providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
|
|
133
|
+
autolinkableLibraries.push({
|
|
134
|
+
npmPackageName: packageJson.name,
|
|
135
|
+
etsRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.etsPackageClassName,
|
|
136
|
+
cppRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cppPackageClassName,
|
|
137
|
+
cmakeLibraryTargetName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cmakeLibraryTargetName,
|
|
138
|
+
ohPackageName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.ohPackageName,
|
|
139
|
+
harFilePathRelativeToHarmony: harFilePath
|
|
140
|
+
.relativeTo(harmonyProjectPath)
|
|
141
|
+
.toString(),
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
const ohPackagePath = harmonyProjectPath.copyWithNewSegment(config.ohPackagePathRelativeToHarmony);
|
|
145
|
+
const ohPackageContent = yield this.fs.readText(ohPackagePath);
|
|
146
|
+
const cppRNOHPackagesFactoryPath = harmonyProjectPath.copyWithNewSegment(config.cppRNOHPackagesFactoryPathRelativeToHarmony);
|
|
147
|
+
const cmakeAutolinkingPath = harmonyProjectPath.copyWithNewSegment(config.cmakeAutolinkPathRelativeToHarmony);
|
|
148
|
+
return {
|
|
149
|
+
projectRootPath,
|
|
150
|
+
skippedLibraryNpmPackageNames,
|
|
151
|
+
etsRNOHPackagesFactoryPath: harmonyProjectPath.copyWithNewSegment(config.etsRNOHPackagesFactoryPathRelativeToHarmony),
|
|
152
|
+
cppRNOHPackagesFactoryPath,
|
|
153
|
+
cmakeAutolinkingPath: cmakeAutolinkingPath,
|
|
154
|
+
ohPackagePathAndContent: [ohPackagePath, ohPackageContent],
|
|
155
|
+
autolinkableLibraries,
|
|
156
|
+
nodeModuleHarFilePathsRelativeToHarmony: nodeModuleHarPaths.map((p) => p.relativeTo(harmonyProjectPath).toString()),
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
evaluate(input) {
|
|
161
|
+
const autolinkableLibraries = input.autolinkableLibraries.map((lib) => {
|
|
162
|
+
var _a, _b, _c, _d;
|
|
163
|
+
return Object.assign(Object.assign({}, lib), { etsRNOHPackageClassName: (_a = lib.etsRNOHPackageClassName) !== null && _a !== void 0 ? _a : this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName), cppRNOHPackageClassName: (_b = lib.cppRNOHPackageClassName) !== null && _b !== void 0 ? _b : this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName), cmakeLibraryTargetName: (_c = lib.cmakeLibraryTargetName) !== null && _c !== void 0 ? _c : this.npmPackageNameToCMakeLibraryTargetName(lib.npmPackageName), ohPackageName: (_d = lib.ohPackageName) !== null && _d !== void 0 ? _d : this.npmPackageNameToOHPackageName(lib.npmPackageName) });
|
|
164
|
+
});
|
|
165
|
+
autolinkableLibraries.sort((a, b) => {
|
|
166
|
+
if (a.npmPackageName < b.npmPackageName)
|
|
167
|
+
return -1;
|
|
168
|
+
if (a.npmPackageName > b.npmPackageName)
|
|
169
|
+
return 1;
|
|
170
|
+
return 0;
|
|
171
|
+
});
|
|
172
|
+
const ohPackage = json5_1.default.parse(input.ohPackagePathAndContent[1]);
|
|
173
|
+
const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map((lib) => lib.harFilePathRelativeToHarmony);
|
|
174
|
+
const unmanagedNativeDependencySpecifierByName = {};
|
|
175
|
+
Object.entries(ohPackage.dependencies).forEach(([name, dependencySpecifier]) => {
|
|
176
|
+
if (!dependencySpecifier.includes('file:')) {
|
|
177
|
+
unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
const harFilePathRelativeToHarmony = dependencySpecifier.replace('file:', '');
|
|
181
|
+
if (!autolinkableHarFilePathsRelativeToHarmony.includes(harFilePathRelativeToHarmony) &&
|
|
182
|
+
input.nodeModuleHarFilePathsRelativeToHarmony.includes(harFilePathRelativeToHarmony)) {
|
|
183
|
+
unmanagedNativeDependencySpecifierByName[name] =
|
|
184
|
+
dependencySpecifier;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
const managedNativeDependencySpecifierByName = {};
|
|
189
|
+
for (const library of autolinkableLibraries) {
|
|
190
|
+
managedNativeDependencySpecifierByName[library.ohPackageName] =
|
|
191
|
+
'file:' + library.harFilePathRelativeToHarmony;
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
|
|
195
|
+
linkedLibraryNpmPackageNames: autolinkableLibraries.map((lib) => lib.npmPackageName),
|
|
196
|
+
projectRootPath: input.projectRootPath,
|
|
197
|
+
cppRNOHPackagesFactoryPathAndContent: [
|
|
198
|
+
input.cppRNOHPackagesFactoryPath,
|
|
199
|
+
mustache_1.default.render(CPP_RNOH_PACKAGES_FACTORY_TEMPLATE, {
|
|
200
|
+
libraries: autolinkableLibraries,
|
|
201
|
+
}),
|
|
202
|
+
],
|
|
203
|
+
etsRNOHPackagesFactoryPathAndContent: [
|
|
204
|
+
input.etsRNOHPackagesFactoryPath,
|
|
205
|
+
mustache_1.default.render(ETS_RNOH_PACKAGES_FACTORY_TEMPLATE, {
|
|
206
|
+
libraries: autolinkableLibraries,
|
|
207
|
+
}),
|
|
208
|
+
],
|
|
209
|
+
cmakeAutolinkingPathAndContent: [
|
|
210
|
+
input.cmakeAutolinkingPath,
|
|
211
|
+
mustache_1.default.render(CMAKE_AUTOLINKING_TEMPLATE, {
|
|
212
|
+
libraries: autolinkableLibraries,
|
|
213
|
+
}),
|
|
214
|
+
],
|
|
215
|
+
ohPackagePathAndContent: [
|
|
216
|
+
input.ohPackagePathAndContent[0],
|
|
217
|
+
json5_1.default.stringify(Object.assign(Object.assign({}, ohPackage), { dependencies: Object.assign(Object.assign({}, unmanagedNativeDependencySpecifierByName), managedNativeDependencySpecifierByName) }), { space: 2, quote: '"' }) + '\n',
|
|
218
|
+
],
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
npmPackageNameToRNOHPackageClassName(fullNpmPackageName) {
|
|
222
|
+
if (fullNpmPackageName.startsWith('@')) {
|
|
223
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
224
|
+
.replace('@', '')
|
|
225
|
+
.split('/');
|
|
226
|
+
return case_1.default.pascal(scopeName) + case_1.default.pascal(packageName) + 'Package';
|
|
227
|
+
}
|
|
228
|
+
return case_1.default.pascal(fullNpmPackageName) + 'Package';
|
|
229
|
+
}
|
|
230
|
+
npmPackageNameToCMakeLibraryTargetName(fullNpmPackageName) {
|
|
231
|
+
if (fullNpmPackageName.startsWith('@')) {
|
|
232
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
233
|
+
.replace('@', '')
|
|
234
|
+
.split('/');
|
|
235
|
+
return 'rnoh__' + case_1.default.snake(scopeName) + '__' + case_1.default.snake(packageName);
|
|
236
|
+
}
|
|
237
|
+
return 'rnoh__' + case_1.default.snake(fullNpmPackageName);
|
|
238
|
+
}
|
|
239
|
+
npmPackageNameToOHPackageName(fullNpmPackageName) {
|
|
240
|
+
if (fullNpmPackageName.startsWith('@')) {
|
|
241
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
242
|
+
.replace('@', '')
|
|
243
|
+
.split('/');
|
|
244
|
+
return '@rnoh/' + case_1.default.kebab(scopeName) + '--' + case_1.default.kebab(packageName);
|
|
245
|
+
}
|
|
246
|
+
return '@rnoh/' + case_1.default.kebab(fullNpmPackageName);
|
|
247
|
+
}
|
|
248
|
+
saveAndLogOutput(output) {
|
|
249
|
+
const pathAndContentPairs = [];
|
|
250
|
+
pathAndContentPairs.push(output.etsRNOHPackagesFactoryPathAndContent);
|
|
251
|
+
pathAndContentPairs.push(output.cppRNOHPackagesFactoryPathAndContent);
|
|
252
|
+
pathAndContentPairs.push(output.cmakeAutolinkingPathAndContent);
|
|
253
|
+
pathAndContentPairs.push(output.ohPackagePathAndContent);
|
|
254
|
+
pathAndContentPairs.forEach(([path, content]) => {
|
|
255
|
+
this.fs.writeTextSync(path, content);
|
|
256
|
+
});
|
|
257
|
+
output.linkedLibraryNpmPackageNames.forEach((npmPackageName) => {
|
|
258
|
+
this.logger.info((styles) => `[${styles.green(styles.bold('link'))}] ${npmPackageName}`);
|
|
259
|
+
});
|
|
260
|
+
output.skippedLibraryNpmPackageNames.forEach((npmPackageName) => {
|
|
261
|
+
this.logger.warn((styles) => `[${styles.yellow(styles.bold('skip'))}] ${npmPackageName}`);
|
|
262
|
+
});
|
|
263
|
+
this.logger.info(() => '');
|
|
264
|
+
const sortedPathsRelativeToRoot = pathAndContentPairs
|
|
265
|
+
.map(([path]) => path.relativeTo(output.projectRootPath).toString())
|
|
266
|
+
.sort();
|
|
267
|
+
sortedPathsRelativeToRoot.forEach((pathStr) => {
|
|
268
|
+
this.logger.info((styles) => styles.gray(`• ${pathStr}`));
|
|
269
|
+
});
|
|
270
|
+
this.logger.info(() => '');
|
|
271
|
+
this.logger.info((styles) => `updated ${styles.green(styles.bold(sortedPathsRelativeToRoot.length))} file(s), linked ${styles.green(styles.bold(output.linkedLibraryNpmPackageNames.length))} libraries, skipped ${styles.yellow(styles.bold(output.skippedLibraryNpmPackageNames.length))} libraries`, { prefix: true });
|
|
272
|
+
this.logger.info(() => '');
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.Autolinking = Autolinking;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./Autolinking"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.CodegenError = void 0;
|
|
10
|
+
const core_1 = require("../../core");
|
|
11
|
+
class CodegenError extends core_1.DescriptiveError {
|
|
12
|
+
}
|
|
13
|
+
exports.CodegenError = CodegenError;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createEventNameFromEventHandlerName = void 0;
|
|
10
|
+
const CodegenError_1 = require("./CodegenError");
|
|
11
|
+
function createEventNameFromEventHandlerName(eventHandlerName) {
|
|
12
|
+
const eventName = eventHandlerName.replace('on', '');
|
|
13
|
+
if (eventName.length === 0) {
|
|
14
|
+
throw new CodegenError_1.CodegenError({
|
|
15
|
+
whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
|
|
16
|
+
whatCanUserDo: {
|
|
17
|
+
default: [
|
|
18
|
+
'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return eventName.charAt(0).toLowerCase() + eventName.slice(1);
|
|
24
|
+
}
|
|
25
|
+
exports.createEventNameFromEventHandlerName = createEventNameFromEventHandlerName;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.wrapWithQuotes = exports.getStringifiedTSDefaultValueFromPropTypeAnnotation = exports.TypeAnnotationToTS = void 0;
|
|
10
|
+
class TypeAnnotationToTS {
|
|
11
|
+
constructor(aliasPrefix = '') {
|
|
12
|
+
this.aliasPrefix = aliasPrefix;
|
|
13
|
+
}
|
|
14
|
+
convert(typeAnnotation) {
|
|
15
|
+
if (!typeAnnotation) {
|
|
16
|
+
return 'unknown';
|
|
17
|
+
}
|
|
18
|
+
switch (typeAnnotation.type) {
|
|
19
|
+
case 'BooleanTypeAnnotation':
|
|
20
|
+
return 'boolean';
|
|
21
|
+
case 'DoubleTypeAnnotation':
|
|
22
|
+
return 'number';
|
|
23
|
+
case 'FloatTypeAnnotation':
|
|
24
|
+
return 'number';
|
|
25
|
+
case 'Int32EnumTypeAnnotation':
|
|
26
|
+
return typeAnnotation.options.join(' | ');
|
|
27
|
+
case 'Int32TypeAnnotation':
|
|
28
|
+
return 'number';
|
|
29
|
+
case 'MixedTypeAnnotation':
|
|
30
|
+
return 'unknown';
|
|
31
|
+
case 'ReservedTypeAnnotation':
|
|
32
|
+
switch (typeAnnotation.name) {
|
|
33
|
+
case 'RootTag':
|
|
34
|
+
return 'Tag';
|
|
35
|
+
default:
|
|
36
|
+
return 'unknown';
|
|
37
|
+
}
|
|
38
|
+
case 'ReservedPropTypeAnnotation':
|
|
39
|
+
switch (typeAnnotation.name) {
|
|
40
|
+
case 'ColorPrimitive':
|
|
41
|
+
return 'ColorValue';
|
|
42
|
+
case 'DimensionPrimitive':
|
|
43
|
+
return 'unknown';
|
|
44
|
+
case 'EdgeInsetsPrimitive':
|
|
45
|
+
return 'unknown';
|
|
46
|
+
case 'ImageRequestPrimitive':
|
|
47
|
+
return 'unknown';
|
|
48
|
+
case 'ImageSourcePrimitive':
|
|
49
|
+
return 'unknown';
|
|
50
|
+
case 'PointPrimitive':
|
|
51
|
+
return 'unknown';
|
|
52
|
+
default:
|
|
53
|
+
return 'unknown';
|
|
54
|
+
}
|
|
55
|
+
case 'StringEnumTypeAnnotation':
|
|
56
|
+
return typeAnnotation.options
|
|
57
|
+
.map((option) => {
|
|
58
|
+
if (typeof option !== 'string') {
|
|
59
|
+
return option;
|
|
60
|
+
}
|
|
61
|
+
return wrapWithQuotes(option);
|
|
62
|
+
})
|
|
63
|
+
.join(' | ');
|
|
64
|
+
case 'StringTypeAnnotation':
|
|
65
|
+
return 'string';
|
|
66
|
+
case 'FunctionTypeAnnotation':
|
|
67
|
+
const { params, returnTypeAnnotation } = typeAnnotation;
|
|
68
|
+
const stringifiedArgs = params
|
|
69
|
+
.map((param) => `${param.name}: ${this.convert(param.typeAnnotation)}`)
|
|
70
|
+
.join(', ');
|
|
71
|
+
return `(${stringifiedArgs}) => ${this.convert(returnTypeAnnotation)}`;
|
|
72
|
+
case 'EnumDeclaration':
|
|
73
|
+
return typeAnnotation.name;
|
|
74
|
+
case 'GenericObjectTypeAnnotation':
|
|
75
|
+
return 'Object';
|
|
76
|
+
case 'TypeAliasTypeAnnotation':
|
|
77
|
+
return this.aliasPrefix + typeAnnotation.name;
|
|
78
|
+
case 'UnionTypeAnnotation':
|
|
79
|
+
return this.convertUnionMemberAnnotation(typeAnnotation.memberType);
|
|
80
|
+
case 'NumberTypeAnnotation':
|
|
81
|
+
return 'number';
|
|
82
|
+
case 'NullableTypeAnnotation':
|
|
83
|
+
return `null | ${this.convert(typeAnnotation.typeAnnotation)}`;
|
|
84
|
+
case 'ObjectTypeAnnotation':
|
|
85
|
+
return this.convertObjectTypeAnnotation(typeAnnotation);
|
|
86
|
+
case 'PromiseTypeAnnotation':
|
|
87
|
+
return `Promise<${this.convert(typeAnnotation.elementType)}>`;
|
|
88
|
+
case 'VoidTypeAnnotation':
|
|
89
|
+
return 'void';
|
|
90
|
+
case 'ArrayTypeAnnotation':
|
|
91
|
+
return `${this.convert(typeAnnotation.elementType)}[]`;
|
|
92
|
+
default:
|
|
93
|
+
return 'unknown';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
convertUnionMemberAnnotation(memberAnnotation) {
|
|
97
|
+
switch (memberAnnotation) {
|
|
98
|
+
case 'NumberTypeAnnotation':
|
|
99
|
+
return 'number';
|
|
100
|
+
case 'ObjectTypeAnnotation':
|
|
101
|
+
return 'Object';
|
|
102
|
+
case 'StringTypeAnnotation':
|
|
103
|
+
return 'string';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
convertObjectTypeAnnotation(objectTypeAnnotation) {
|
|
107
|
+
const props = objectTypeAnnotation.properties
|
|
108
|
+
.map((prop) => {
|
|
109
|
+
const maybeOptionalSymbol = prop.optional ? '?' : '';
|
|
110
|
+
return `${prop.name}${maybeOptionalSymbol}: ${this.convert(prop.typeAnnotation)}`;
|
|
111
|
+
})
|
|
112
|
+
.join(', ');
|
|
113
|
+
if (props.length === 0) {
|
|
114
|
+
return '{}';
|
|
115
|
+
}
|
|
116
|
+
return `{${props}}`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.TypeAnnotationToTS = TypeAnnotationToTS;
|
|
120
|
+
function getStringifiedTSDefaultValueFromPropTypeAnnotation(propTypeAnnotation) {
|
|
121
|
+
if ('default' in propTypeAnnotation && propTypeAnnotation.default !== null) {
|
|
122
|
+
if (typeof propTypeAnnotation.default === 'string') {
|
|
123
|
+
return wrapWithQuotes(propTypeAnnotation.default);
|
|
124
|
+
}
|
|
125
|
+
return String(propTypeAnnotation.default);
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
exports.getStringifiedTSDefaultValueFromPropTypeAnnotation = getStringifiedTSDefaultValueFromPropTypeAnnotation;
|
|
130
|
+
function wrapWithQuotes(str) {
|
|
131
|
+
if (str.includes("'")) {
|
|
132
|
+
return `"${str}"`;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return `'${str}'`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.wrapWithQuotes = wrapWithQuotes;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.UberSchema = void 0;
|
|
22
|
+
const core_1 = require("../../core");
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
const combine_js_to_schema_js_1 = __importDefault(require("@react-native/codegen/lib/cli/combine/combine-js-to-schema.js"));
|
|
25
|
+
const CodegenError_1 = require("./CodegenError");
|
|
26
|
+
function createRawUberSchemaFromSpecFilePaths(projectSourceFilePaths) {
|
|
27
|
+
return (0, combine_js_to_schema_js_1.default)(projectSourceFilePaths.map((p) => p.getValue()));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Contains component and turbo module (NativeModule) schemas. The "Uber" word is used here to highlight that SpecSchemas don't extend this class.
|
|
31
|
+
*/
|
|
32
|
+
class UberSchema {
|
|
33
|
+
static fromSpecFilePaths(specPaths) {
|
|
34
|
+
return new UberSchema(createRawUberSchemaFromSpecFilePaths(specPaths));
|
|
35
|
+
}
|
|
36
|
+
static fromCodegenConfig(codegenConfig) {
|
|
37
|
+
try {
|
|
38
|
+
return new UberSchema(createRawUberSchemaFromSpecFilePaths(codegenConfig.getSpecFilePaths()));
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (err instanceof Error) {
|
|
42
|
+
throw new CodegenError_1.CodegenError({
|
|
43
|
+
whatHappened: "Couldn't create the schema",
|
|
44
|
+
whatCanUserDo: {
|
|
45
|
+
default: [
|
|
46
|
+
`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}`,
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static fromProject(fs, projectRootPath, onShouldAcceptCodegenConfig) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const onShouldAcceptCodegenConfig_ = onShouldAcceptCodegenConfig !== null && onShouldAcceptCodegenConfig !== void 0 ? onShouldAcceptCodegenConfig : ((x) => true);
|
|
57
|
+
const packageJSON = core_1.PackageJSON.fromProjectRootPath(fs, projectRootPath, projectRootPath);
|
|
58
|
+
const acceptedCodegenConfigs = [];
|
|
59
|
+
const appCodegenConfigs = packageJSON.getCodegenConfigs();
|
|
60
|
+
for (const codegenConfig of appCodegenConfigs) {
|
|
61
|
+
if (onShouldAcceptCodegenConfig_(codegenConfig.getVersion(), packageJSON.name)) {
|
|
62
|
+
acceptedCodegenConfigs.push(codegenConfig);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
yield new core_1.ProjectDependenciesManager(fs, projectRootPath).forEachAsync((dependency) => {
|
|
66
|
+
const codegenConfigs = dependency.getCodegenConfigs();
|
|
67
|
+
for (const codegenConfig of codegenConfigs) {
|
|
68
|
+
if (onShouldAcceptCodegenConfig_(codegenConfig.getVersion(), dependency.readPackageJSON().name)) {
|
|
69
|
+
acceptedCodegenConfigs.push(codegenConfig);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
try {
|
|
74
|
+
return new UberSchema(createRawUberSchemaFromSpecFilePaths(acceptedCodegenConfigs.flatMap((codegenConfig) => codegenConfig.getSpecFilePaths())));
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (err instanceof Error) {
|
|
78
|
+
throw new CodegenError_1.CodegenError({
|
|
79
|
+
whatHappened: "Couldn't create the schema",
|
|
80
|
+
whatCanUserDo: {
|
|
81
|
+
default: [
|
|
82
|
+
`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}`,
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
constructor(schemaValue) {
|
|
92
|
+
this.schemaValue = schemaValue;
|
|
93
|
+
}
|
|
94
|
+
getValue() {
|
|
95
|
+
return this.schemaValue;
|
|
96
|
+
}
|
|
97
|
+
findAllSpecSchemasByType(schemaType) {
|
|
98
|
+
return Object.values(this.schemaValue.modules)
|
|
99
|
+
.filter((module) => module.type === schemaType)
|
|
100
|
+
.map((module) => module);
|
|
101
|
+
}
|
|
102
|
+
getSpecSchemaByFilenameMap() {
|
|
103
|
+
return Object.entries(this.schemaValue.modules).reduce((acc, [moduleName, moduleSchema]) => {
|
|
104
|
+
acc.set(moduleName, moduleSchema);
|
|
105
|
+
return acc;
|
|
106
|
+
}, new Map());
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.UberSchema = UberSchema;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./CodeGenerator"), exports);
|
|
24
|
+
__exportStar(require("./UberSchema"), exports);
|
|
25
|
+
__exportStar(require("./CodegenError"), exports);
|
|
26
|
+
__exportStar(require("./EventUtils"), exports);
|
|
27
|
+
__exportStar(require("./TypeAnnotationToTS"), exports);
|