31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import type { Catalog, ServiceMetadata } from "../src/types.ts";
|
|
|
|
const here = import.meta.dir;
|
|
const repoRoot = join(here, "..", "..");
|
|
const servicesDir = join(repoRoot, "services");
|
|
|
|
const services: Catalog["services"] = [];
|
|
|
|
for (const name of readdirSync(servicesDir).sort()) {
|
|
if (!statSync(join(servicesDir, name), { throwIfNoEntry: false })?.isDirectory()) continue;
|
|
const metaPath = join(servicesDir, name, "metadata.json");
|
|
if (!statSync(metaPath, { throwIfNoEntry: false })?.isFile()) continue;
|
|
|
|
const meta = JSON.parse(readFileSync(metaPath, "utf8")) as ServiceMetadata;
|
|
services.push({
|
|
id: meta.id ?? name,
|
|
version: meta.version ?? "unknown",
|
|
path: `services/${name}/metadata.json`,
|
|
});
|
|
}
|
|
|
|
const catalog: Catalog = {
|
|
generatedAt: new Date().toISOString(),
|
|
services,
|
|
};
|
|
|
|
const out = join(servicesDir, "catalog.json");
|
|
writeFileSync(out, `${JSON.stringify(catalog, null, 2)}\n`, "utf8");
|
|
console.log(`Wrote ${out} with ${services.length} services.`);
|