#!/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, 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}`);