import { readFileSync, writeFileSync, copyFileSync } from "fs"; import { dirname, join } from 'path'; import { fileURLToPath } from 'url'; import glob from 'glob'; const __dirname = dirname(fileURLToPath(import.meta.url)); const genAuthors = (a) => { let authors = []; if (typeof a === "string") { authors = a.split(', '); } else if (Array.isArray(a)) { authors = a; }; return authors.map((x, i) => { if (typeof x === 'object') { // User object const pfp = ``; const name = `${x.n}`; //#${result.discriminator}`; return i > 1 ? pfp : pfp + name; } let idMatch = x.match(/(.*) \(([0-9]{17,18})\)/); // " ()" if (idMatch === null) return `${x}`; // "" return `${idMatch[1]}`; }).join(', '); }; const makeCard = (m) => { const authors = genAuthors(m.authors); return `
${authors}
${m.name}
${m.description}
${m.github.stars}
${m.version === '0' || m.version.toLowerCase().includes('auto') ? '' : `v${m.version}`}
`; } export default () => { let template = readFileSync(join(__dirname, 'template.html'), 'utf8'); const repos = glob.sync(join(global.distDir, '*.json')); let cards = []; let name = 'GooseMod Store'; let description = 'Browse GooseMod modules'; for (const repo of repos) { console.log(repo); const json = JSON.parse(readFileSync(repo, 'utf8')); if (repos.length === 1) { // 1 repo likely means a custom repo, so use that name and description name = json.meta.name; description = json.meta.description; } cards = cards.concat(json.modules); } cards = cards.sort((a, b) => a.name.localeCompare(b.name)).map((x) => makeCard(x)); template = template .replace('ALL_CARDS', cards.join('\n')) .replaceAll('NAME', name) .replaceAll('DESCRIPTION', description); writeFileSync(join(global.distDir, 'index.html'), template); copyFileSync(join(__dirname, 'NotoSans-Medium.ttf'), join(global.distDir, 'NotoSans-Medium.ttf')); };