2026-08-16 11:03:25 +02:00
|
|
|
import fs from "node:fs";
|
|
|
|
|
import { ConfigError, loadConfig } from "../../lib/config/load";
|
|
|
|
|
import { isPortFree } from "../lib/network";
|
|
|
|
|
import { resolveConfigPath } from "../lib/paths";
|
|
|
|
|
|
|
|
|
|
export interface DoctorOptions {
|
|
|
|
|
config?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function doctorCommand(opts: DoctorOptions): Promise<void> {
|
|
|
|
|
const rows: [string, string][] = [];
|
|
|
|
|
|
|
|
|
|
rows.push(["Node.js", process.version]);
|
|
|
|
|
|
|
|
|
|
const configPath = resolveConfigPath(opts.config);
|
|
|
|
|
const exists = fs.existsSync(configPath);
|
2026-08-16 13:55:25 +02:00
|
|
|
rows.push([
|
|
|
|
|
"Config path",
|
|
|
|
|
`${configPath} ${exists ? "(exists)" : "(not found)"}`,
|
|
|
|
|
]);
|
2026-08-16 11:03:25 +02:00
|
|
|
|
|
|
|
|
if (exists) {
|
|
|
|
|
try {
|
|
|
|
|
const { config } = loadConfig(configPath);
|
|
|
|
|
const portFree = await isPortFree(config.server.host, config.server.port);
|
|
|
|
|
rows.push([
|
|
|
|
|
"Port available",
|
2026-08-16 13:55:25 +02:00
|
|
|
portFree
|
|
|
|
|
? "yes"
|
|
|
|
|
: `no (${config.server.host}:${config.server.port} in use)`,
|
2026-08-16 11:03:25 +02:00
|
|
|
]);
|
|
|
|
|
rows.push(["Scripts configured", String(config.scripts.length)]);
|
|
|
|
|
rows.push(["Auth enabled", String(config.auth.enabled)]);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (error instanceof ConfigError) {
|
|
|
|
|
rows.push(["Config", error.message]);
|
|
|
|
|
} else {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const labelWidth = Math.max(...rows.map(([label]) => label.length));
|
|
|
|
|
for (const [label, value] of rows) {
|
|
|
|
|
console.log(`${label.padEnd(labelWidth)} ${value}`);
|
|
|
|
|
}
|
|
|
|
|
}
|