env-sentinel
Version:
Zero-dependency tool that auto-validates .env files against schema.env, with optional fallback and secure warnings.
57 lines (56 loc) • 2.08 kB
JavaScript
import process from 'node:process';
import { handleInit, handleValidate, handleDocs } from './handlers/index.js';
import { parseArguments } from './parsers/parse-arguments.js';
import { DEFAULT_SCHEMA_FILE_NAME, DEFAULT_DOCS_FILE_NAME } from './constants.js';
import { handleLint } from './handlers/handle-lint.js';
import { log } from './utils/log.js';
export function run() {
const { command, file, schema, force, output } = parseArguments(process.argv, {
command: 'validate',
file: '.env',
schema: DEFAULT_SCHEMA_FILE_NAME,
force: false,
output: DEFAULT_DOCS_FILE_NAME,
});
try {
switch (command) {
case 'check':
console.warn('The "check" command is deprecated and will be removed in a future release. Please use "validate" instead.');
handleValidate(file, schema);
process.exit(0);
break;
case 'validate':
handleValidate(file, schema);
process.exit(0);
break;
case 'init':
handleInit(file, force);
process.exit(0);
break;
case 'lint':
case undefined:
handleLint(file);
process.exit(0);
break;
case 'docs':
handleDocs(schema, output);
process.exit(0);
break;
default:
console.log(`Unknown command: ${command}`);
console.log(`Usage: env-sentinel [init|validate|lint|docs] [--file FILE] [--schema FILE] [--output FILE]`);
process.exit(1);
}
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
log.error(errorMessage);
process.exit(1);
}
}
export * from './handlers/index.js';
export * from './parsers/index.js';
export * from './validate/index.js';
export * from './lint/index.js';
export * from './constants.js';
export * from './types.js';