UNPKG

@eventcatalog/notifier

Version:

CLI tool to detect EventCatalog changes and send notifications

60 lines 2.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadConfig = loadConfig; const fs_1 = require("fs"); const js_yaml_1 = __importDefault(require("js-yaml")); const dotenv_1 = __importDefault(require("dotenv")); const chalk_1 = __importDefault(require("chalk")); // Load environment variables dotenv_1.default.config(); function loadConfig(configPath) { const config = {}; if (configPath) { try { // Read the raw config file const configContent = (0, fs_1.readFileSync)(configPath, 'utf-8'); // Replace ${ENV_VAR} placeholders with actual environment variables const resolvedContent = configContent.replace(/\${([^}]+)}/g, (match, envVar) => { const value = process.env[envVar]; if (!value) { console.log(chalk_1.default.yellow('⚠'), `Environment variable ${chalk_1.default.cyan(envVar)} is not set`); return match; // Keep the placeholder if env var not found } return value; }); // Parse the resolved YAML const configFile = js_yaml_1.default.load(resolvedContent); Object.assign(config, configFile); // Validate required config validateConfig(config); } catch (error) { console.log(chalk_1.default.red('✗'), `Failed to load config file: ${chalk_1.default.cyan(configPath)}`, error); process.exit(1); } } return config; } // Optional: Add validation function validateConfig(config) { if (!config.version) { console.log(chalk_1.default.yellow('⚠'), 'No version specified in config, assuming 1.0.0'); config.version = '1.0.0'; } // Check if any webhooks are still placeholders if (config.owners) { Object.entries(config.owners).forEach(([ownerName, ownerConfig]) => { ownerConfig.channels?.forEach((channel, index) => { if (channel.webhook?.includes('${')) { console.log(chalk_1.default.red('✗'), `Owner ${chalk_1.default.cyan(ownerName)} channel ${chalk_1.default.cyan(index.toString())} has unresolved webhook placeholder: ${chalk_1.default.gray(channel.webhook)}`); console.log(chalk_1.default.red('✗'), 'Please set the required environment variables'); process.exit(1); } }); }); } } //# sourceMappingURL=config.js.map