#!/usr/bin/env node // Copies the npm-managed frontend libraries from node_modules/ into // public/vendor/ (committed, served as-is, no bundler). package.json pins // the versions; Renovate bumps them and runs this as a postUpgradeTask so // its PR carries the new files too. Manually: `npm ci && node bin/vendor-sync.mjs`. // Assets not on npm: fonts and the Liberty style/sprite go through // bin/assets-sync.mjs, the NPS plugins are updated by hand. import { copyFileSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs"; const root = new URL("..", import.meta.url).pathname; const nm = (p) => `${root}node_modules/${p}`; const vendor = (p) => `${root}public/vendor/${p}`; const copy = (from, to) => copyFileSync(nm(from), vendor(to)); for (const f of ["maplibre-gl.css", "maplibre-gl.mjs", "maplibre-gl-shared.mjs", "maplibre-gl-worker.mjs"]) copy(`maplibre-gl/dist/${f}`, `maplibre-gl/${f}`); copy("pmtiles/dist/pmtiles.js", "pmtiles/pmtiles.js"); copy("maplibre-contour/dist/index.min.js", "maplibre-contour/maplibre-contour.min.js"); // Trailing sourceMappingURL dropped: the .map isn't vendored. writeFileSync( vendor("maplibre-gl-lanes/maplibre-gl-lanes.mjs"), readFileSync(nm("maplibre-gl-lanes/dist/maplibre-gl-lanes.mjs"), "utf8").replace(/\n\/\/# sourceMappingURL=.*\n?$/, "\n"), ); copy("maplibre-gl-lanes/LICENSE", "maplibre-gl-lanes/LICENSE"); copy("suncalc/index.js", "suncalc/suncalc.js"); copy("suncalc/LICENSE", "suncalc/LICENSE"); // Only the flags already vendored (the European subset), not all ~270. for (const f of readdirSync(vendor("flag-icons/1x1"))) copy(`flag-icons/flags/1x1/${f}`, `flag-icons/1x1/${f}`); // Material Design Icons: only the mdi* names public/js/ actually uses (the // whole set is ~3 MB), as one small ES module. Using another icon is just // naming it in the code and running this again. const mdi = await import(nm("@mdi/js/mdi.js")); const used = new Set(); for (const f of readdirSync(`${root}public/js`)) { if (f.endsWith(".js")) for (const [name] of readFileSync(`${root}public/js/${f}`, "utf8").matchAll(/\bmdi[A-Z]\w*/g)) used.add(name); } const missing = [...used].filter((name) => !mdi[name]); if (missing.length) throw new Error(`not in @mdi/js: ${missing.join(", ")}`); mkdirSync(vendor("mdi"), { recursive: true }); writeFileSync( vendor("mdi/mdi.mjs"), `// Generated by bin/vendor-sync.mjs from @mdi/js ${JSON.parse(readFileSync(nm("@mdi/js/package.json"), "utf8")).version}, Apache-2.0 (LICENSE).\n` + [...used].sort().map((name) => `export const ${name} = "${mdi[name]}";\n`).join(""), ); copy("@mdi/js/LICENSE", "mdi/LICENSE");