Gestion de paquetage, aide intégrée et message de bienvenue
Release Creation / build (release) Successful in 59s

This commit is contained in:
2026-05-01 00:37:01 +02:00
parent 06b0ff7f78
commit 7d218f4a0a
41 changed files with 1524 additions and 54 deletions
+51
View File
@@ -0,0 +1,51 @@
import { compilePack, extractPack } from "@foundryvtt/foundryvtt-cli";
import { promises as fs } from "node:fs";
import path from "node:path";
const ROOT_DIR = process.cwd();
export class CompendiumsManager {
static async packToDistDir(srcDir = "packs_src", distDir = "packs", mode = "json") {
const yaml = mode === "yaml";
const packs = await fs.readdir(path.join(ROOT_DIR, srcDir));
for (const pack of packs) {
if (pack.startsWith(".")) continue;
const sourcePath = path.join(ROOT_DIR, srcDir, pack);
const targetPath = path.join(ROOT_DIR, distDir, pack);
await fs.rm(targetPath, { recursive: true, force: true });
console.log(`Packing ${pack}`);
await compilePack(sourcePath, targetPath, { yaml });
}
}
static async unpackToSrcDir(srcDir = "packs_src", distDir = "packs", mode = "json") {
const yaml = mode === "yaml";
const packs = await fs.readdir(path.join(ROOT_DIR, distDir));
for (const pack of packs) {
if (pack.startsWith(".")) continue;
const sourcePath = path.join(ROOT_DIR, distDir, pack);
const targetPath = path.join(ROOT_DIR, srcDir, pack);
await fs.mkdir(targetPath, { recursive: true });
const existingFiles = await fs.readdir(targetPath);
for (const file of existingFiles) {
await fs.unlink(path.join(targetPath, file));
}
console.log(`Unpacking ${pack}`);
await extractPack(sourcePath, targetPath, {
yaml,
transformName: (doc) => CompendiumsManager.transformName(doc, yaml)
});
}
}
static transformName(doc, yaml) {
const safeName = (doc.name ?? doc._id ?? "document").replace(/[^a-zA-Z0-9_-]+/g, "_");
const type = doc._key?.split("!")[1] ?? doc.type ?? "document";
const extension = yaml ? "yml" : "json";
return `${type}_${safeName}_${doc._id}.${extension}`;
}
}