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 = []; for (const repo of repos) { const repoName = repo.split('/').pop().split('.')[0]; console.log(repo, repoName); const json = JSON.parse(readFileSync(repo, 'utf8')); console.log(json); 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')); writeFileSync(join(global.distDir, 'index.html'), template); copyFileSync(join(__dirname, 'NotoSans-Medium.ttf'), join(global.distDir, 'NotoSans-Medium.ttf')); };