Flatten the repo: move everything out of app/ to the root
Now that the CLI and the Next.js app are one package, nesting it inside app/ served no purpose - the repo root itself becomes the published npm package. Merges app/.gitignore and app/README.md into the root versions, drops the now-duplicate app/LICENSE, and updates path references (README, docs/ARCHITECTURE.md, docs/CONFIG_REFERENCE.md, package.json's repository.directory) that assumed the app/ nesting. Also fixes a real bug this surfaced: the in-app docs viewer resolved docs/ relative to process.cwd(), which only worked by accident when the CLI happened to be invoked from app/'s parent directory. A first attempt at fixing it with import.meta.dirname broke instead, for the same cross-module-graph reason config-path resolution already documented - Next compiles Route Handlers through a separate module graph that doesn't preserve source-relative import.meta paths. Fixed by exposing the app root via TRIGGERSHELL_APP_ROOT (set once in server.ts, where import.meta *does* resolve correctly), the same pattern already used for TRIGGERSHELL_CONFIG_PATH. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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",
|
||||
description: "REST and WebSocket endpoints, auth, and request/response shapes.",
|
||||
file: "API.md",
|
||||
},
|
||||
{
|
||||
slug: "config",
|
||||
title: "Config Reference",
|
||||
description: "Every field in triggershell.yml: server, auth, scripts, and variables.",
|
||||
file: "CONFIG_REFERENCE.md",
|
||||
},
|
||||
];
|
||||
|
||||
export function getDocMeta(slug: string): DocMeta | undefined {
|
||||
return DOCS.find((doc) => doc.slug === slug);
|
||||
}
|
||||
|
||||
// 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).
|
||||
function docsDir(): string {
|
||||
const appRoot =
|
||||
process.env.TRIGGERSHELL_APP_ROOT ?? path.resolve(import.meta.dirname, "..", "..");
|
||||
return path.resolve(appRoot, "docs");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
Reference in New Issue
Block a user