#!/usr/bin/env node const fs = require('node:fs') const path = require('node:path') const { parse } = require('yaml') const ymlPath = path.join(__dirname, "..", "data", "spells.yml"); const data = parse(fs.readFileSync(ymlPath, "utf8")); const columns = ["name", "cost", "targets", "duration"]; const myEscape = (s) => String(s ?? "") .replace(/&/g, "&") .replace(//g, ">"); const generateTable = (spells, class_) => { const rows = spells .filter((elem) => elem.class === class_) .map( (spell) => ` \n${columns.map((col) => ` ${myEscape(spell[col])}`).join("\n")}\n ${spell["description"]}`, ) .join("\n"); const headers = columns .map((col) => ` ${col.charAt(0).toUpperCase() + col.slice(1)}`) .join("\n"); return ` ${headers} ${rows}
`; }; ["arcanist", "chimerist", "elementalist", "entropist", "spiritist"].forEach( (class_) => { process.stdout.write(`

${class_} Spells

\n`) process.stdout.write(generateTable(data.spells, class_)); }, );