1
0

KISC arch init

This commit is contained in:
2026-10-11 14:36:51 +03:00
commit 8fb6c52e44
89 changed files with 10931 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import fs from "node:fs";
import path from "node:path";
import fg from "fast-glob";
function readFileSafe(filePath: string): string {
return fs.readFileSync(filePath, "utf-8");
}
export function getResource(archRoot: string, uri: string) {
// manifest://<domain>
if (uri.startsWith("manifest://")) {
const domain = uri.replace("manifest://", "");
const mf = path.join(archRoot, domain, "manifest.yaml");
if (!fs.existsSync(mf)) return { ok: false, error: `Not found: ${uri}` };
return { ok: true, uri, mimeType: "application/yaml", content: readFileSafe(mf) };
}
// views://<domain>/<viewfile-without-ext>
if (uri.startsWith("views://")) {
const rest = uri.replace("views://", "");
const [domain, viewName] = rest.split("/", 2);
const domainDir = path.join(archRoot, domain);
const matches = fg.sync([`views/${viewName}.md`], { cwd: domainDir, absolute: true });
if (!matches.length) return { ok: false, error: `Not found: ${uri}` };
return {
ok: true,
uri,
mimeType: "text/markdown",
content: readFileSafe(matches[0]!),
};
}
// register://<domain>/<relative-path>
if (uri.startsWith("register://")) {
const rest = uri.replace("register://", "");
const [domain, rel] = rest.split("/", 2);
const filePath = path.join(archRoot, domain, rel);
if (!fs.existsSync(filePath)) return { ok: false, error: `Not found: ${uri}` };
return { ok: true, uri, mimeType: "application/yaml", content: readFileSafe(filePath) };
}
return { ok: false, error: `Unsupported uri: ${uri}` };
}