#!/usr/bin/env node // Vendors every NPS map symbol (22 px, black, standalone) from // nationalparkservice/symbol-library's jakecoolidge-revision-2024 branch // (PR #226, the newest artwork: a superset of npmap5-plugins' copy) into // one ES module, { name: "" }, cleaned to a bare viewBox and // fill="currentColor". Public domain (CC0). Pinned to a commit; to update, // change REF and run `node bin/nps-symbols-sync.mjs`. import { mkdirSync, writeFileSync } from "node:fs"; const REPO = "nationalparkservice/symbol-library"; const REF = "94f772a21b593f2cdb6d2a2b8a5cc4d3dc5e3a61"; const out = new URL("../public/vendor/nps-symbols/", import.meta.url).pathname; const tree = await (await fetch(`https://api.github.com/repos/${REPO}/git/trees/${REF}?recursive=1`)).json(); const files = tree.tree.map((t) => t.path).filter((p) => /^src\/standalone\/.+-black-22\.svg$/.test(p) && !p.includes("transparent")); const clean = (svg) => svg .replace(/<\?xml[^>]*>||<(style|title)[\s\S]*?<\/\1>/g, "") .replace(/<\w+[^>]*fill="none"[^>]*\/>/g, "") // invisible leftovers .replace(/\s(id|fill|class|style|enable-background|xml:space)="[^"]*"/g, "") .replace(/]*>/, '') .replace(/\s+/g, " ") .replace(/> <") .trim(); const symbols = {}; for (let i = 0; i < files.length; i += 6) { await Promise.all( files.slice(i, i + 6).map(async (path) => { const res = await fetch(`https://raw.githubusercontent.com/${REPO}/${REF}/${path}`); if (!res.ok) throw new Error(`${path}: ${res.status}`); symbols[path.match(/([^/]+)-black-22\.svg$/)[1]] = clean(await res.text()); }), ); } mkdirSync(out, { recursive: true }); writeFileSync( `${out}nps-symbols.mjs`, `// Generated by bin/nps-symbols-sync.mjs from ${REPO}@${REF.slice(0, 7)} (CC0).\nexport const NPS_SYMBOLS = {\n` + Object.keys(symbols) .sort() .map((name) => ` ${JSON.stringify(name)}: ${JSON.stringify(symbols[name])},\n`) .join("") + "};\n", ); console.log(`${Object.keys(symbols).length} symbols`);