UNPKG

ts-bakery

Version:

Baked dependency injection for Typescript.

61 lines 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs"); const path = require("path"); const TsBakeryConfig_1 = require("./TsBakeryConfig"); const Paths_1 = require("../Util/Paths"); class TsBakeryConfigLoader { static load() { const configPath = TsBakeryConfigLoader.findConfigFile(); if (!configPath) { return { ...TsBakeryConfig_1.DEFAULT_TS_BAKERY_CONFIG }; } try { const configContent = fs.readFileSync(configPath, 'utf8'); const config = JSON.parse(configContent); return { ...TsBakeryConfig_1.DEFAULT_TS_BAKERY_CONFIG, ...config }; } catch (error) { throw new Error(`Failed to parse ts-bakery.json at ${configPath}: ${error.message}`); } } static getSourceRoot(config) { if (config?.sourceRoot) { return path.isAbsolute(config.sourceRoot) ? config.sourceRoot : path.resolve(Paths_1.default.ProjectRoot, config.sourceRoot); } // Fallback to current working directory return Paths_1.default.ProjectRoot; } static getConfigDirectory() { const configPath = TsBakeryConfigLoader.findConfigFile(); if (configPath) { return path.dirname(configPath); } // Fallback to current working directory if no config found return Paths_1.default.ProjectRoot; } static findConfigFile() { let currentDir = Paths_1.default.ProjectRoot; while (true) { const configPath = path.join(currentDir, TsBakeryConfigLoader.CONFIG_FILE_NAME); if (fs.existsSync(configPath)) { return configPath; } const parentDir = path.dirname(currentDir); if (parentDir === currentDir) { // Reached root directory break; } currentDir = parentDir; } return null; } } exports.default = TsBakeryConfigLoader; TsBakeryConfigLoader.CONFIG_FILE_NAME = 'ts-bakery.json'; //# sourceMappingURL=TsBakeryConfigLoader.js.map