UNPKG

@zburn/core

Version:

Core utilities for the ZBURN ecosystem.

40 lines (35 loc) 1.25 kB
const path = require('path'); const fs = require('fs'); let first_print = false; function loadConfig(filename = '.zburnrc.json') { let currentDir = process.cwd(); // Start from the current working directory const rootDir = path.parse(currentDir).root; // Get the root directory (e.g., '/', 'C:\') while (currentDir !== rootDir) { const configPath = path.join(currentDir, filename); if (fs.existsSync(configPath)) { try { if(!first_print) console.log(`Loading ZBURN config from: ${configPath}`); first_print = true; // Read and parse the JSON file const configContent = fs.readFileSync(configPath, 'utf8'); return JSON.parse(configContent); } catch (error) { console.error(`Error parsing ZBURN config file ${configPath}:`, error.message); return null; // Return null if parsing fails } } // Move up to the parent directory currentDir = path.dirname(currentDir); } console.log(`No ZBURN config file (${filename}) found in current or parent directories.`); return { pin_gateways: [], stimulate_gateways: [], pin_env_var: {}, cloudflare: {} }; } module.exports = { loadConfig };