UNPKG

vde-layout

Version:

Terminal multiplexer layout management tool for VDE (Vibe Coding Development Environment)

117 lines 4.6 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigLoader = void 0; const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const os_1 = __importDefault(require("os")); const yaml = __importStar(require("yaml")); const errors_1 = require("../utils/errors"); class ConfigLoader { searchPaths; constructor(options = {}) { this.searchPaths = options.configPaths ?? this.buildDefaultSearchPaths(); } async loadYAML() { const filePath = await this.findConfigFile(); if (filePath === null) { throw new errors_1.ConfigError("Configuration file not found", errors_1.ErrorCodes.CONFIG_NOT_FOUND, { searchPaths: this.searchPaths, }); } try { const content = await fs_extra_1.default.readFile(filePath, "utf8"); return content; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new errors_1.ConfigError(`Failed to read configuration file`, errors_1.ErrorCodes.CONFIG_PERMISSION_ERROR, { filePath, error: errorMessage, }); } } async loadConfig() { const yamlContent = await this.loadYAML(); try { if (!yamlContent.trim()) { return { presets: {} }; } const parsed = yaml.parse(yamlContent); if (parsed === null || typeof parsed !== "object") { return { presets: {} }; } if (!("presets" in parsed) || typeof parsed.presets !== "object") { return { presets: {} }; } return parsed; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); const filePath = await this.findConfigFile(); throw new errors_1.ConfigError(`Failed to parse YAML configuration file`, errors_1.ErrorCodes.CONFIG_PARSE_ERROR, { filePath, parseError: errorMessage, }); } } async findConfigFile() { for (const searchPath of this.searchPaths) { if (await fs_extra_1.default.pathExists(searchPath)) { return searchPath; } } return null; } getSearchPaths() { return [...this.searchPaths]; } buildDefaultSearchPaths() { const paths = []; const vdeConfigPath = process.env.VDE_CONFIG_PATH; if (vdeConfigPath !== undefined) { paths.push(path_1.default.join(vdeConfigPath, "layout.yml")); } const homeDir = process.env.HOME ?? os_1.default.homedir(); const xdgConfigHome = process.env.XDG_CONFIG_HOME ?? path_1.default.join(homeDir, ".config"); paths.push(path_1.default.join(xdgConfigHome, "vde", "layout.yml")); return [...new Set(paths)]; } } exports.ConfigLoader = ConfigLoader; //# sourceMappingURL=loader.js.map