2026-08-16 00:54:15 +02:00
|
|
|
import fs from "node:fs";
|
|
|
|
|
import path from "node:path";
|
|
|
|
|
|
|
|
|
|
export interface DocMeta {
|
|
|
|
|
slug: string;
|
|
|
|
|
title: string;
|
|
|
|
|
description: string;
|
|
|
|
|
file: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const DOCS: DocMeta[] = [
|
|
|
|
|
{
|
|
|
|
|
slug: "api",
|
|
|
|
|
title: "API Reference",
|
2026-08-16 13:55:25 +02:00
|
|
|
description:
|
|
|
|
|
"REST and WebSocket endpoints, auth, and request/response shapes.",
|
2026-08-16 00:54:15 +02:00
|
|
|
file: "API.md",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
slug: "config",
|
|
|
|
|
title: "Config Reference",
|
2026-08-16 13:55:25 +02:00
|
|
|
description:
|
|
|
|
|
"Every field in triggershell.yml: server, auth, scripts, and variables.",
|
2026-08-16 00:54:15 +02:00
|
|
|
file: "CONFIG_REFERENCE.md",
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export function getDocMeta(slug: string): DocMeta | undefined {
|
|
|
|
|
return DOCS.find((doc) => doc.slug === slug);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-16 11:14:01 +02:00
|
|
|
// Resolved from TRIGGERSHELL_APP_ROOT (set once in server.ts), not `process.cwd()` or
|
|
|
|
|
// `import.meta.dirname` - this file is read from a Route Handler compiled through Next's own
|
|
|
|
|
// module graph, which is a separate module instantiation from server.ts and doesn't preserve
|
|
|
|
|
// source-relative `import.meta` paths (see the `globalThis` comment in `runner/events.ts`).
|
|
|
|
|
// Falls back to a source-relative resolution for contexts where server.ts never ran (e.g. tests).
|
2026-08-16 00:54:15 +02:00
|
|
|
function docsDir(): string {
|
2026-08-16 11:14:01 +02:00
|
|
|
const appRoot =
|
2026-08-16 13:55:25 +02:00
|
|
|
process.env.TRIGGERSHELL_APP_ROOT ??
|
|
|
|
|
path.resolve(import.meta.dirname, "..", "..");
|
2026-08-16 11:14:01 +02:00
|
|
|
return path.resolve(appRoot, "docs");
|
2026-08-16 00:54:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function readDocContent(doc: DocMeta): string | null {
|
|
|
|
|
const filePath = path.join(docsDir(), doc.file);
|
|
|
|
|
if (!fs.existsSync(/*turbopackIgnore: true*/ filePath)) return null;
|
|
|
|
|
return fs.readFileSync(/*turbopackIgnore: true*/ filePath, "utf-8");
|
|
|
|
|
}
|