Document how server.mjs keeps the site up when an API is misconfigured and reports it on /api/health, the cache and CSP policy, the share API's synchronous reservation, the trust placed in X-Forwarded-For, the hooks main.jsx wires once, and how to run each script. The deploy script header now recalls that CI runs the copy installed on the server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
/**
|
|
* @file Génère les index JSON des listes de jeux (website/public/data/<jeu>/lists/index.json) à partir des fichiers
|
|
* éditables.
|
|
*
|
|
* Usage : npm run lists:index ; lancé automatiquement avant `npm run dev`, `npm run build` et `npm run check`.
|
|
* Attention : index.json est généré, ne pas le modifier à la main.
|
|
*/
|
|
|
|
import { access, readdir, readFile, writeFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
const DATA_DIRECTORY = "website/public/data";
|
|
|
|
function formatTitle(value) {
|
|
return String(value || "")
|
|
.replace(/\.json$/i, "")
|
|
.replace(/[_-]+/g, " ")
|
|
.replace(/\b\p{L}/gu, (letter) => letter.toUpperCase());
|
|
}
|
|
|
|
async function generateListIndex(directory) {
|
|
const entries = await readdir(directory, { withFileTypes: true });
|
|
const files = entries
|
|
.filter((entry) => entry.isFile() && entry.name.endsWith(".json") && entry.name !== "index.json")
|
|
.map((entry) => entry.name)
|
|
.sort((a, b) => a.localeCompare(b, "fr"));
|
|
|
|
const lists = await Promise.all(files.map(async (file) => {
|
|
const payload = JSON.parse(await readFile(path.join(directory, file), "utf8"));
|
|
const id = file.replace(/\.json$/i, "");
|
|
return {
|
|
id,
|
|
title: payload.titre || formatTitle(id),
|
|
file
|
|
};
|
|
}));
|
|
|
|
await writeFile(path.join(directory, "index.json"), `${JSON.stringify({ lists }, null, 2)}\n`);
|
|
}
|
|
|
|
async function findListDirectories() {
|
|
const entries = await readdir(DATA_DIRECTORY, { withFileTypes: true });
|
|
const directories = await Promise.all(entries
|
|
.filter((entry) => entry.isDirectory())
|
|
.map(async (entry) => {
|
|
const listDirectory = path.join(DATA_DIRECTORY, entry.name, "lists");
|
|
try {
|
|
await access(listDirectory);
|
|
return listDirectory;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}));
|
|
|
|
return directories.filter(Boolean);
|
|
}
|
|
|
|
const listDirectories = await findListDirectories();
|
|
await Promise.all(listDirectories.map(generateListIndex));
|