Message de bienvenue
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import path from "node:path"
|
||||
import fs from "node:fs"
|
||||
|
||||
import { buildPacks } from "./pack-builder.mjs"
|
||||
import { buildPacks, SYSTEM_PACK_DEFINITIONS } from "./pack-builder.mjs"
|
||||
|
||||
const rootDir = path.resolve(import.meta.dirname, "..")
|
||||
const packageJson = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"))
|
||||
@@ -10,6 +10,7 @@ const systemJson = JSON.parse(fs.readFileSync(path.join(rootDir, "system.json"),
|
||||
await buildPacks({
|
||||
sourceRoot: path.join(rootDir, "packs-src"),
|
||||
outputRoot: path.join(rootDir, "packs"),
|
||||
packDefinitions: SYSTEM_PACK_DEFINITIONS,
|
||||
documentSystemId: systemJson.id,
|
||||
documentSystemVersion: packageJson.version,
|
||||
coreVersion: String(systemJson.compatibility?.verified ?? systemJson.compatibility?.minimum ?? ""),
|
||||
|
||||
+115
-26
@@ -4,7 +4,7 @@ import crypto from "node:crypto"
|
||||
|
||||
import { Level } from "level"
|
||||
|
||||
export const PACK_DEFINITIONS = [
|
||||
export const CONTENT_PACK_DEFINITIONS = [
|
||||
{ sourceFile: "armes.json", outputFolder: "armes", type: "Item" },
|
||||
{ sourceFile: "armures.json", outputFolder: "armures", type: "Item" },
|
||||
{ sourceFile: "equipements.json", outputFolder: "equipements", type: "Item" },
|
||||
@@ -16,6 +16,11 @@ export const PACK_DEFINITIONS = [
|
||||
{ sourceFile: "sortileges.json", outputFolder: "sortileges", type: "Item" },
|
||||
]
|
||||
|
||||
export const SYSTEM_PACK_DEFINITIONS = [
|
||||
...CONTENT_PACK_DEFINITIONS,
|
||||
{ sourceFile: "aide-systeme.json", outputFolder: "aide-systeme", type: "JournalEntry" },
|
||||
]
|
||||
|
||||
function slugId(input) {
|
||||
const hash = crypto.createHash("sha256").update(input).digest()
|
||||
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
@@ -26,41 +31,122 @@ function slugId(input) {
|
||||
return id
|
||||
}
|
||||
|
||||
function toPackDocument(entry, index, {
|
||||
function createDocumentStats({
|
||||
documentSystemId,
|
||||
documentSystemVersion,
|
||||
coreVersion,
|
||||
createdTime,
|
||||
lastModifiedBy = "Copilot",
|
||||
} = {}) {
|
||||
return {
|
||||
systemId: documentSystemId,
|
||||
systemVersion: documentSystemVersion,
|
||||
coreVersion,
|
||||
createdTime,
|
||||
modifiedTime: createdTime,
|
||||
lastModifiedBy,
|
||||
compendiumSource: null,
|
||||
duplicateSource: null,
|
||||
exportSource: null,
|
||||
}
|
||||
}
|
||||
|
||||
function toItemPackDocument(entry, index, options = {}) {
|
||||
const docId = slugId(`${entry.type}:${entry.name}`)
|
||||
return {
|
||||
name: entry.name,
|
||||
type: entry.type,
|
||||
img: entry.img ?? "icons/svg/item-bag.svg",
|
||||
system: entry.system ?? {},
|
||||
effects: Array.isArray(entry.effects) ? entry.effects : [],
|
||||
flags: entry.flags ?? {},
|
||||
_stats: {
|
||||
systemId: documentSystemId,
|
||||
systemVersion: documentSystemVersion,
|
||||
coreVersion,
|
||||
createdTime,
|
||||
modifiedTime: createdTime,
|
||||
lastModifiedBy,
|
||||
compendiumSource: null,
|
||||
duplicateSource: null,
|
||||
exportSource: null,
|
||||
},
|
||||
_id: docId,
|
||||
folder: null,
|
||||
sort: index * 1000,
|
||||
ownership: {
|
||||
default: 0,
|
||||
key: `!items!${docId}`,
|
||||
value: {
|
||||
name: entry.name,
|
||||
type: entry.type,
|
||||
img: entry.img ?? "icons/svg/item-bag.svg",
|
||||
system: entry.system ?? {},
|
||||
effects: Array.isArray(entry.effects) ? entry.effects : [],
|
||||
flags: entry.flags ?? {},
|
||||
_stats: createDocumentStats(options),
|
||||
_id: docId,
|
||||
folder: null,
|
||||
sort: index * 1000,
|
||||
ownership: {
|
||||
default: 0,
|
||||
},
|
||||
},
|
||||
embedded: [],
|
||||
}
|
||||
}
|
||||
|
||||
function toJournalPageDocument(entry, journalId, page, pageIndex, options = {}) {
|
||||
const pageId = slugId(`JournalEntryPage:${entry.name}:${page.name ?? page.title ?? pageIndex}`)
|
||||
return {
|
||||
_id: pageId,
|
||||
name: page.name ?? `Page ${pageIndex + 1}`,
|
||||
type: page.type ?? "text",
|
||||
title: {
|
||||
show: page.title?.show ?? true,
|
||||
level: page.title?.level ?? 1,
|
||||
},
|
||||
text: {
|
||||
format: page.text?.format ?? 1,
|
||||
content: page.text?.content ?? "",
|
||||
},
|
||||
system: page.system ?? {},
|
||||
image: page.image ?? {},
|
||||
video: page.video ?? { controls: true, volume: 0.5 },
|
||||
src: page.src ?? null,
|
||||
category: page.category ?? null,
|
||||
sort: page.sort ?? pageIndex * 1000,
|
||||
ownership: page.ownership ?? { default: -1 },
|
||||
flags: page.flags ?? {},
|
||||
_stats: createDocumentStats(options),
|
||||
_key: `!journal.pages!${journalId}.${pageId}`,
|
||||
}
|
||||
}
|
||||
|
||||
function toJournalPackDocument(entry, index, options = {}) {
|
||||
const docId = slugId(`JournalEntry:${entry.name}`)
|
||||
const pages = Array.isArray(entry.pages)
|
||||
? entry.pages.map((page, pageIndex) => toJournalPageDocument(entry, docId, page, pageIndex, options))
|
||||
: []
|
||||
|
||||
return {
|
||||
key: `!journal!${docId}`,
|
||||
value: {
|
||||
name: entry.name,
|
||||
pages: pages.map((page) => page._id),
|
||||
ownership: entry.ownership ?? { default: 0 },
|
||||
flags: entry.flags ?? { core: {} },
|
||||
_stats: createDocumentStats(options),
|
||||
folder: null,
|
||||
sort: entry.sort ?? index * 1000,
|
||||
_id: docId,
|
||||
categories: Array.isArray(entry.categories) ? entry.categories : [],
|
||||
},
|
||||
embedded: pages.map((page) => ({
|
||||
key: page._key,
|
||||
value: {
|
||||
name: page.name,
|
||||
type: page.type,
|
||||
title: page.title,
|
||||
text: page.text,
|
||||
system: page.system,
|
||||
image: page.image,
|
||||
video: page.video,
|
||||
src: page.src,
|
||||
category: page.category,
|
||||
sort: page.sort,
|
||||
ownership: page.ownership,
|
||||
flags: page.flags,
|
||||
_stats: page._stats,
|
||||
_id: page._id,
|
||||
},
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
function toPackDocument(entry, index, options = {}) {
|
||||
if (entry.type === "JournalEntry") return toJournalPackDocument(entry, index, options)
|
||||
return toItemPackDocument(entry, index, options)
|
||||
}
|
||||
|
||||
async function buildPack({
|
||||
sourcePath,
|
||||
outputPath,
|
||||
@@ -95,7 +181,10 @@ async function buildPack({
|
||||
createdTime,
|
||||
lastModifiedBy,
|
||||
})
|
||||
batch.put(`!items!${doc._id}`, JSON.stringify(doc))
|
||||
batch.put(doc.key, JSON.stringify(doc.value))
|
||||
for (const embedded of doc.embedded) {
|
||||
batch.put(embedded.key, JSON.stringify(embedded.value))
|
||||
}
|
||||
})
|
||||
await batch.write()
|
||||
} finally {
|
||||
@@ -106,7 +195,7 @@ async function buildPack({
|
||||
export async function buildPacks({
|
||||
sourceRoot,
|
||||
outputRoot,
|
||||
packDefinitions = PACK_DEFINITIONS,
|
||||
packDefinitions = SYSTEM_PACK_DEFINITIONS,
|
||||
documentSystemId,
|
||||
documentSystemVersion,
|
||||
coreVersion,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs"
|
||||
import path from "node:path"
|
||||
|
||||
import { PACK_DEFINITIONS, buildPacks } from "./pack-builder.mjs"
|
||||
import { CONTENT_PACK_DEFINITIONS, SYSTEM_PACK_DEFINITIONS, buildPacks } from "./pack-builder.mjs"
|
||||
|
||||
const systemRoot = path.resolve(import.meta.dirname, "..")
|
||||
const targetRoot = path.resolve(
|
||||
@@ -20,10 +20,11 @@ const richFieldMap = Object.fromEntries(
|
||||
Object.entries(systemManifest.documentTypes?.Item ?? {}).map(([type, data]) => [type, data.htmlFields ?? []]),
|
||||
)
|
||||
const coreVersion = String(systemManifest.compatibility?.verified ?? systemManifest.compatibility?.minimum ?? "")
|
||||
const basePackDefinitions = PACK_DEFINITIONS.map((pack) => ({
|
||||
const basePackDefinitions = CONTENT_PACK_DEFINITIONS.map((pack) => ({
|
||||
...pack,
|
||||
outputFolder: `base-${pack.outputFolder}`,
|
||||
}))
|
||||
const contentPackNames = new Set(CONTENT_PACK_DEFINITIONS.map((pack) => pack.outputFolder))
|
||||
|
||||
function setDeepValue(target, propertyPath, value) {
|
||||
const segments = String(propertyPath || "").split(".").filter(Boolean)
|
||||
@@ -142,6 +143,11 @@ function ensureTargetModuleScaffold() {
|
||||
],
|
||||
},
|
||||
packs: (systemManifest.packs ?? []).map((pack) => ({
|
||||
// The base content module only mirrors content packs, not system journals or utility packs.
|
||||
...pack,
|
||||
}))
|
||||
.filter((pack) => contentPackNames.has(pack.name))
|
||||
.map((pack) => ({
|
||||
...pack,
|
||||
name: `base-${pack.name}`,
|
||||
path: `packs/base-${pack.name}`,
|
||||
@@ -201,7 +207,7 @@ pruneStalePackDirectories(targetPacksRoot, basePackDefinitions)
|
||||
await buildPacks({
|
||||
sourceRoot: systemSourceRoot,
|
||||
outputRoot: path.join(systemRoot, "packs"),
|
||||
packDefinitions: PACK_DEFINITIONS,
|
||||
packDefinitions: SYSTEM_PACK_DEFINITIONS,
|
||||
documentSystemId: systemManifest.id,
|
||||
documentSystemVersion: systemPackage.version,
|
||||
coreVersion,
|
||||
|
||||
Reference in New Issue
Block a user