mirror of
https://github.com/ZTatman/myst.git
synced 2026-11-21 04:17:59 +00:00
- Delete broken Dockerfile (referenced non-existent packages/service) - Delete unused @firebreak/shared package - Delete unused crypto.ts, aiofiles dependency, stale static assets - Delete .tmp/embargo-test/ scaffold with hardcoded secrets - Move packages/cli/ to cli/ (flat structure, no packages/ dir) - Rename myst config example and UI design doc - Update docs to fix stale path references (packages/service/*, Pico CSS, SQLModel) - Remove stale agents.md entries (process.exit, ORM session leak) - Clean up tsconfig references and pnpm workspace config
190 lines
4.5 KiB
TypeScript
190 lines
4.5 KiB
TypeScript
import path from "node:path";
|
|
|
|
import * as c from "yoctocolors";
|
|
import * as p from "@clack/prompts";
|
|
|
|
import { ENV_MAPPING, parseEnvFile, REQUIRED_KEYS } from "../utils/config.js";
|
|
import {
|
|
checkForgejoReachability,
|
|
checkRepoAccess,
|
|
} from "../utils/forgejo-checks.js";
|
|
import { CommandConfig } from "../cli-router.js";
|
|
|
|
interface VerifyOptions {
|
|
diagnostic?: boolean;
|
|
}
|
|
|
|
interface CheckResult {
|
|
name: string;
|
|
success: boolean;
|
|
message?: string;
|
|
}
|
|
|
|
function loadConfig(): Record<string, string> | null {
|
|
const envPath = path.join(process.cwd(), ".env");
|
|
|
|
try {
|
|
return parseEnvFile(envPath);
|
|
} catch (error) {
|
|
const err = error as NodeJS.ErrnoException;
|
|
if (err.code === "ENOENT") {
|
|
p.cancel(`${c.red("Error:")} .env file not found in ${process.cwd()}`);
|
|
process.exitCode = 1;
|
|
return null;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
function getMissingKeys(config: Record<string, string>): string[] {
|
|
const missing: string[] = [];
|
|
for (const key of REQUIRED_KEYS) {
|
|
if (!config[key]) {
|
|
missing.push(key.replace(/(?<=[a-z])(?=[A-Z])/g, "_").toUpperCase());
|
|
}
|
|
}
|
|
return missing;
|
|
}
|
|
|
|
function formatCheck(result: CheckResult): string {
|
|
const icon = result.success ? c.green("✓") : c.red("✗");
|
|
const msg = result.message ? ` ${result.message}` : "";
|
|
return `${icon} ${result.name}${msg}`;
|
|
}
|
|
|
|
async function runDiagnosticMode(
|
|
config: Record<string, string>,
|
|
missing: string[],
|
|
): Promise<void> {
|
|
const results: CheckResult[] = [];
|
|
|
|
if (missing.length > 0) {
|
|
results.push({
|
|
name: "Required config",
|
|
success: false,
|
|
message: `Missing: ${missing.join(", ")}`,
|
|
});
|
|
}
|
|
|
|
for (const [envKey, configKey] of Object.entries(ENV_MAPPING)) {
|
|
const value = config[configKey];
|
|
results.push({
|
|
name: envKey,
|
|
success: !!value,
|
|
message: value ? "configured" : "missing",
|
|
});
|
|
}
|
|
|
|
const forgejoResults = await runForgejoChecks(config);
|
|
const allResults = [...results, ...forgejoResults];
|
|
|
|
const lines = allResults.map(formatCheck);
|
|
|
|
p.note(lines.join("\n"), c.yellow("Results"));
|
|
|
|
const failures = allResults.filter((r) => !r.success);
|
|
if (failures.length > 0) {
|
|
p.outro(c.red(`${failures.length} issue(s) found`));
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
|
|
p.outro(c.green("All checks passed"));
|
|
}
|
|
|
|
async function runVerifyMode(
|
|
config: Record<string, string>,
|
|
missing: string[],
|
|
): Promise<void> {
|
|
if (missing.length > 0) {
|
|
p.cancel(
|
|
`${c.red("Error:")} Missing required env variables: ${missing.join(", ")}`,
|
|
);
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
|
|
const s = p.spinner();
|
|
s.start("Verifying Forgejo configuration");
|
|
|
|
const forgejoResults = await runForgejoChecks(config);
|
|
|
|
const firstFailure = forgejoResults.find((r) => !r.success);
|
|
if (firstFailure) {
|
|
s.stop(firstFailure.message);
|
|
p.cancel(formatCheck(firstFailure));
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
|
|
if (forgejoResults.length === 0) {
|
|
s.stop("No Forgejo configuration");
|
|
p.cancel(`${c.red("Error:")} Forgejo not configured`);
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
|
|
s.stop("Verification complete");
|
|
|
|
const [reachability, repoAccess] = forgejoResults;
|
|
|
|
p.note(
|
|
[formatCheck(reachability), formatCheck(repoAccess)].join("\n"),
|
|
c.yellow("Results"),
|
|
);
|
|
|
|
p.outro(c.green("Verification passed"));
|
|
}
|
|
|
|
async function runForgejoChecks(
|
|
config: Record<string, string>,
|
|
): Promise<CheckResult[]> {
|
|
const { forgejoBaseUrl, forgejoPat } = config;
|
|
|
|
if (!forgejoBaseUrl || !forgejoPat) {
|
|
return [];
|
|
}
|
|
|
|
const results: CheckResult[] = [];
|
|
|
|
const reachability = await checkForgejoReachability(forgejoBaseUrl);
|
|
results.push(reachability);
|
|
|
|
if (!reachability.success) {
|
|
return results;
|
|
}
|
|
|
|
const repoAccess = await checkRepoAccess(forgejoBaseUrl, forgejoPat);
|
|
results.push(repoAccess);
|
|
|
|
return results;
|
|
}
|
|
|
|
async function verifyCommand(opts: VerifyOptions): Promise<void> {
|
|
const isDiagnostic = opts.diagnostic ?? false;
|
|
p.intro(c.bold("firebreak verify"));
|
|
|
|
const config = loadConfig();
|
|
if (!config) {
|
|
return;
|
|
}
|
|
|
|
const missing = getMissingKeys(config);
|
|
|
|
if (isDiagnostic) {
|
|
await runDiagnosticMode(config, missing);
|
|
} else {
|
|
await runVerifyMode(config, missing);
|
|
}
|
|
}
|
|
|
|
export const commandConfig: CommandConfig = {
|
|
description: "Verify Firebreak configuration and connection to Forgejo",
|
|
options: {
|
|
diagnostic: {
|
|
type: "boolean",
|
|
description: "Show diagnostic information for all checks",
|
|
},
|
|
},
|
|
handler: verifyCommand,
|
|
};
|