diff --git a/package.json b/package.json index dbece0c7..183d2de2 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "readline": "^1.3.0", "pushLDBtoYML": "node ./tools/pushLDBtoYML.mjs", "pullYMLtoLDB": "node ./tools/pullYMLtoLDB.mjs", - "pullYMLtoLDBBuild": "node ./tools/pullYMLtoLDBBuild.mjs", + "pullYMLtoLDBBuild": "node ./tools/pullYMLtoLDB.mjs --build", "createSymlink": "node ./tools/create-symlink.mjs", "setup:dev": "node ./tools/dev-setup.mjs" }, diff --git a/system.json b/system.json index 4972a395..fe1f63cb 100644 --- a/system.json +++ b/system.json @@ -4,7 +4,7 @@ "description": "An unofficial implementation of the Daggerheart system", "version": "1.2.7", "compatibility": { - "minimum": "13", + "minimum": "13.346", "verified": "13.351", "maximum": "13" }, diff --git a/tools/pullYMLtoLDB.mjs b/tools/pullYMLtoLDB.mjs index 52b0f0da..2326d94a 100644 --- a/tools/pullYMLtoLDB.mjs +++ b/tools/pullYMLtoLDB.mjs @@ -1,22 +1,26 @@ import { compilePack } from '@foundryvtt/foundryvtt-cli'; import readline from 'node:readline/promises'; import { promises as fs } from 'fs'; +import systemJSON from "../system.json" with { type: "json" }; const MODULE_ID = process.cwd(); -const yaml = false; -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout -}); +const answer = await (async () => { + if (process.argv.includes("--build")) return "overwrite"; -const answer = await rl.question( - 'You are about to overwrite your current database with the saved packs/json. Write "Overwrite" if you are sure. ', - function (answer) { - rl.close(); - return answer; - } -); + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + + return rl.question( + 'You are about to overwrite your current database with the saved packs/json. Write "Overwrite" if you are sure. ', + function (answer) { + rl.close(); + return answer; + } + ); +})(); if (answer.toLowerCase() === 'overwrite') { await pullToLDB(); @@ -32,7 +36,35 @@ async function pullToLDB() { for (const pack of packs) { if (pack === '.gitattributes') continue; console.log('Packing ' + pack); - await compilePack(`${MODULE_ID}/src/${pack}`, `${MODULE_ID}/${pack}`, { yaml }); + await compilePack(`${MODULE_ID}/src/${pack}`, `${MODULE_ID}/${pack}`, { yaml: false, transformEntry }); + } + + function transformEntry(entry) { + const stats = { + coreVersion: systemJSON.compatibility.minimum, + systemId: "daggerheart", + systemVersion: systemJSON.version, + }; + + entry._stats = { ...stats }; + for (const effect of entry.effects ?? []) { + effect._stats = { + compendiumSource: effect._stats?.compendiumSource ?? null, + ...stats + }; + } + for (const item of entry.items ?? []) { + item._stats = { + compendiumSource: item._stats?.compendiumSource ?? null, + ...stats + }; + for (const effect of item.effects ?? []) { + effect._stats = { + compendiumSource: effect._stats?.compendiumSource ?? null, + ...stats + }; + } + } } async function deepGetDirectories(distPath) { diff --git a/tools/pullYMLtoLDBBuild.mjs b/tools/pullYMLtoLDBBuild.mjs deleted file mode 100644 index 6c2b8c79..00000000 --- a/tools/pullYMLtoLDBBuild.mjs +++ /dev/null @@ -1,31 +0,0 @@ -import { compilePack } from '@foundryvtt/foundryvtt-cli'; -import { promises as fs } from 'fs'; - -const MODULE_ID = process.cwd(); -const yaml = false; - -const packs = await deepGetDirectories('./packs'); -console.log(packs); -for (const pack of packs) { - if (pack === '.gitattributes') continue; - console.log('Packing ' + pack); - await compilePack(`${MODULE_ID}/src/${pack}`, `${MODULE_ID}/${pack}`, { yaml }); -} - -async function deepGetDirectories(distPath) { - const dirr = await fs.readdir('src/' + distPath); - const dirrsWithSub = []; - for (let file of dirr) { - const stat = await fs.stat('src/' + distPath + '/' + file); - if (stat.isDirectory()) { - const deeper = await deepGetDirectories(distPath + '/' + file); - if (deeper.length > 0) { - dirrsWithSub.push(...deeper); - } else { - dirrsWithSub.push(distPath + '/' + file); - } - } - } - - return dirrsWithSub; -}