UNPKG

env-sentinel

Version:

Zero-dependency tool that auto-validates .env files against schema.env, with optional fallback and secure warnings.

22 lines (21 loc) 776 B
import fs, { readFileSync } from 'node:fs'; import { formatIssues } from './formatter.js'; export function validateFileExists(filePath, fileType) { if (!fs.existsSync(filePath)) { throw new Error(`${fileType} file not found: ${filePath}`); } } export function readEnvFile(envFilePath) { validateFileExists(envFilePath, '.env'); return readFileSync(envFilePath, 'utf-8'); } export function readSchemaFile(schemaFilePath) { validateFileExists(schemaFilePath, 'Schema'); return readFileSync(schemaFilePath, 'utf-8'); } export function handleResult(result, filePath, operation) { formatIssues(result.issues, filePath); if (operation === 'validate' && !result.isValid) { throw new Error(`Validation failed for ${filePath}`); } }