Files
2026-04-25 23:58:58 +03:00

55 lines
1.8 KiB
JavaScript

import { readdir, readFile, writeFile, stat } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import path from "node:path";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(__dirname, "..");
const PRESENCES_DIR = path.join(ROOT, "presences");
async function listPresences() {
const entries = await readdir(PRESENCES_DIR, { withFileTypes: true });
return entries.filter((e) => e.isDirectory()).map((e) => e.name);
}
async function readMetadata(presenceDir) {
return JSON.parse(await readFile(path.join(presenceDir, "metadata.json"), "utf8"));
}
async function ensureDistExists(presenceDir, slug) {
const distFile = path.join(presenceDir, "dist", "presence.js");
try {
await stat(distFile);
} catch {
throw new Error(`dist/presence.js missing for ${slug} — run "npm run build" first`);
}
}
async function main() {
const slugs = await listPresences();
const entries = [];
for (const slug of slugs) {
const dir = path.join(PRESENCES_DIR, slug);
const meta = await readMetadata(dir);
await ensureDistExists(dir, slug);
entries.push({
id: meta.id,
name: meta.name,
description: meta.description,
version: meta.version,
author: meta.author,
match: meta.match,
...(meta.icon ? { icon: meta.icon } : {}),
...(typeof meta.tickInterval === "number" ? { tickInterval: meta.tickInterval } : {}),
});
}
entries.sort((a, b) => a.id.localeCompare(b.id));
const index = {
generatedAt: new Date().toISOString(),
presences: entries,
};
await writeFile(path.join(ROOT, "index.json"), JSON.stringify(index, null, 2) + "\n");
console.log(`Wrote index.json (${entries.length} presence${entries.length === 1 ? "" : "s"})`);
}
await main();