UNPKG

beathers

Version:

Beather is a lightweight SCSS library that serves as a comprehensive design system for your projects. It offers a structured and consistent approach to manage colors, fonts, and other design related variables, making it easier to maintain a cohesive visua

45 lines (44 loc) 1.54 kB
import fs from 'fs-extra'; import { pathToFileURL } from 'node:url'; import path from 'path'; const userConfigFiles = ['beathers.configs.js', 'beathers.configs.ts', 'beathers.configs.json']; function findConfigFile(basePath) { for (const filename of userConfigFiles) { const fullPath = path.join(basePath, filename); if (fs.existsSync(fullPath)) return fullPath; } return null; } async function loadJsOrTsConfig(filePath) { try { const absolutePath = path.resolve(filePath); const fileUrl = pathToFileURL(absolutePath).href; const module = await import(fileUrl); return module.default ?? module; } catch (error) { throw new Error(`Failed to load config from ${filePath}: ${error}`); } } function loadJsonConfig(filePath) { try { const content = fs.readFileSync(filePath, 'utf-8'); return JSON.parse(content); } catch (error) { throw new Error(`Failed to parse JSON config from ${filePath}: ${error}`); } } export async function LoadUserConfigs(projectPath) { const basePath = projectPath ?? process.cwd(); const configFilePath = findConfigFile(basePath); if (!configFilePath) return null; const extension = path.extname(configFilePath); if (extension === '.json') return loadJsonConfig(configFilePath); if (['.js', '.ts'].includes(extension)) return await loadJsOrTsConfig(configFilePath); throw new Error(`Unsupported config file format: ${extension}`); }