@trapi/metadata
Version:
Generate REST-API metadata scheme from TypeScript Decorators.
51 lines • 1.77 kB
JavaScript
;
/*
* Copyright (c) 2023.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadPreset = void 0;
const locter_1 = require("locter");
const check_1 = require("./check");
const normalize_1 = require("./normalize");
async function loadPreset(input) {
const items = [];
const lookupPaths = (0, normalize_1.generatePresetLookupPaths)(input);
let allFailed = true;
for (let i = 0; i < lookupPaths.length; i++) {
try {
let moduleExport = await (0, locter_1.load)(lookupPaths[i]);
if (!(0, check_1.isPresetSchema)(moduleExport)) {
if ((0, check_1.isPresetSchema)(moduleExport.default)) {
moduleExport = moduleExport.default;
}
else {
continue;
}
}
items.push(...moduleExport.items);
const extendsPromises = [];
if (moduleExport.extends) {
for (let j = 0; j < moduleExport.extends.length; j++) {
extendsPromises.push(loadPreset(moduleExport.extends[j]));
}
}
const output = await Promise.all(extendsPromises);
for (let j = 0; j < output.length; j++) {
items.push(...output[j]);
}
allFailed = false;
}
catch (e) {
// do nothing ...
}
}
if (allFailed) {
throw new Error(`The preset ${input} could not be resolved.`);
}
return items;
}
exports.loadPreset = loadPreset;
//# sourceMappingURL=load.js.map