UNPKG

@trapi/metadata

Version:

Generate REST-API metadata scheme from TypeScript Decorators.

54 lines 1.93 kB
"use strict"; /* * 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. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.softLoadTsconfig = exports.loadTSConfig = void 0; const locter_1 = require("locter"); const node_process_1 = __importDefault(require("node:process")); const node_path_1 = __importDefault(require("node:path")); const typescript_1 = require("typescript"); async function loadTSConfig(context = {}) { let fileName; let filePath; const cwd = context.cwd || node_process_1.default.cwd(); if (typeof context.name === 'string') { if (node_path_1.default.isAbsolute(context.name)) { filePath = context.name; } else { filePath = node_path_1.default.resolve(cwd, context.name); } fileName = node_path_1.default.basename(filePath); } else { fileName = 'tsconfig.json'; filePath = node_path_1.default.join(cwd, fileName); } const content = await (0, locter_1.load)(filePath); if (!(0, locter_1.isObject)(content)) { throw new Error('The tsconfig file is malformed.'); } if (typeof content.compilerOptions !== 'undefined') { const { options: compilerOptions } = (0, typescript_1.convertCompilerOptionsFromJson)(content.compilerOptions, cwd, fileName); content.compilerOptions = compilerOptions; } return content; } exports.loadTSConfig = loadTSConfig; async function softLoadTsconfig(context = {}) { try { return await loadTSConfig(context); } catch (e) { return {}; } } exports.softLoadTsconfig = softLoadTsconfig; //# sourceMappingURL=module.js.map