import { globSync } from "glob"; import crypto from "crypto"; import { createReadStream } from "fs"; import { writeFile } from "fs/promises"; async function hashFile(path) { return new Promise((resolve) => { const stream = createReadStream(path); const hash = crypto.createHash(`sha1`); hash.setEncoding(`hex`); stream.on(`end`, () => { hash.end(); resolve(hash.read()); }); stream.pipe(hash); }); }; const skipFiles = [ `vtt.png`, `vtt-512.png`, `anvil.png`, `fvtt.icns`, `fvtt.ico`, `logo-scifi.png`, `logo-scifi-blank.png`, `LICENSE`, ]; const tagRenames = { weapons: `weapon`, wands: `wand`, swords: `sword`, cutlasses: `cutlass`, daggers: `dagger`, commodities: `commodity`, feathers: `feather`, dynamite: `explosive`, bomb: `explosive`, } const purgeTags = new Set([ // All of the colours `white`, `yellow`, `blue`, `red`, `green`, `black`, `brown`, `teal`, `silver`, `purple`, `gray`, `grey`, `orange`, `lime`, `crimson`, `magenta`, `gold`, `cyan`, `pink`, `tan`, `violet`, // Terms that just suck as tags `simple`, `ringed`, `hollow`, `guard`, `pressure`, `gas`, `fuse`, `cloth`, `sharp`, `worn`, ]); async function main() { const imageList = globSync(`foundry/public/icons/**/*`, { nodir: true }); const images = {}; for (const path of imageList) { if (skipFiles.some(file => path.endsWith(file))) continue; const hash = await hashFile(path); const filename = path.split(`/`).at(-1); const tags = new Set( path .replace(`foundry/public/icons/`, ``) .replace(/\.[a-z]+$/i, ``) .replaceAll(`-`, `/`) .split(`/`) .map(tag => tagRenames[tag] ?? tag) .filter(tag => !purgeTags.has(tag)) ); images[hash] = { name: filename, tags: Array.from(tags), artists: [`FVTT`], path: path.replace(`foundry/public/`, ``), external: true }; }; await writeFile( `importable/images.json`, JSON.stringify(images), ); }; main();