@t1mmen/srtd
Version:
Supabase Repeatable Template Definitions (srtd): 🪄 Live-reloading SQL templates for Supabase DX. Make your database changes reviewable and migrations maintainable! 🚀
84 lines • 2.81 kB
JavaScript
/**
* Doctor command - Read-only diagnostic that validates SRTD setup
*/
import chalk from 'chalk';
import { Command } from 'commander';
import figures from 'figures';
import { SEPARATOR } from '../ui/constants.js';
import { renderBranding } from '../ui/index.js';
import { getConfig } from '../utils/config.js';
import { runAllChecks } from '../utils/doctorChecks.js';
import { findProjectRoot } from '../utils/findProjectRoot.js';
import { getErrorMessage } from '../utils/getErrorMessage.js';
/**
* Render check result as a formatted line
*/
function renderCheckResult(result) {
if (result.passed) {
console.log(chalk.green(`${figures.tick} ${result.name}`));
}
else {
console.log(chalk.red(`${figures.cross} ${result.name}`));
if (result.message) {
console.log(chalk.dim(` ${figures.arrowRight} ${result.message}`));
}
if (result.hint) {
console.log(chalk.cyan(` ${figures.info} ${result.hint}`));
}
}
}
/**
* Render horizontal separator
*/
function renderSeparator() {
console.log(chalk.dim(SEPARATOR));
}
/**
* Render summary line
*/
function renderSummary(results) {
const passed = results.filter(r => r.passed).length;
const failed = results.filter(r => !r.passed).length;
if (failed === 0) {
console.log(chalk.green(`${passed} checks passed, no issues found`));
}
else {
console.log(chalk.yellow(`${passed} checks passed, ${failed} ${failed === 1 ? 'issue' : 'issues'} found`));
}
}
export const doctorCommand = new Command('doctor')
.description('Validate SRTD setup and configuration')
.action(async () => {
let exitCode = 0;
try {
await renderBranding({ subtitle: 'Doctor' });
const projectRoot = await findProjectRoot();
const { config, warnings } = await getConfig(projectRoot);
console.log();
renderSeparator();
console.log();
// Run all checks
const results = await runAllChecks(projectRoot, config, warnings);
// Display results
for (const result of results) {
renderCheckResult(result);
}
console.log();
renderSeparator();
// Summary
renderSummary(results);
// Set exit code based on failures
const hasFailures = results.some(r => !r.passed);
exitCode = hasFailures ? 1 : 0;
}
catch (error) {
console.log();
console.log(chalk.red(`${figures.cross} Error running doctor:`));
console.log(chalk.red(getErrorMessage(error)));
exitCode = 1;
}
// Use process.exitCode to allow event loop to drain naturally
// This enables proper cleanup and makes testing easier
process.exitCode = exitCode;
});
//# sourceMappingURL=doctor.js.map