#!/usr/bin/env node // Re-downloads the vendored assets that aren't on npm, pinned to the git // commits below. Renovate bumps each pin (git-refs digest, see renovate.json) // and runs this as a postUpgradeTask, so its PR carries the new files. // Manually: bump a sha, then `node bin/assets-sync.mjs`. import { mkdirSync, writeFileSync } from "node:fs"; // renovate: datasource=git-refs depName=https://github.com/protomaps/basemaps-assets branch=main const BASEMAPS_ASSETS = "028c18f713baecad011301ff7a69acc39bcc2ae7"; // renovate: datasource=git-refs depName=https://github.com/hyperknot/openfreemap-styles branch=main const OPENFREEMAP_STYLES = "6e5361286c3e1eac7b7c89800ff63218297b5cfd"; const vendor = new URL("../public/vendor/", import.meta.url).pathname; async function get(url, to) { const res = await fetch(url); if (!res.ok) throw new Error(`${res.status} ${url}`); const body = Buffer.from(await res.arrayBuffer()); if (to) { mkdirSync(`${vendor}${to}`.replace(/\/[^/]+$/, ""), { recursive: true }); writeFileSync(`${vendor}${to}`, body); } return body; } const raw = `https://raw.githubusercontent.com/protomaps/basemaps-assets/${BASEMAPS_ASSETS}/fonts`; await get(`${raw}/OFL.txt`, "fonts/OFL.txt"); for (const font of ["Noto Sans Regular", "Noto Sans Italic", "Noto Sans Medium"]) for (const range of ["0-255", "256-511"]) await get(`${raw}/${encodeURIComponent(font)}/${range}.pbf`, `fonts/${font}/${range}.pbf`); // ponytail: OPENFREEMAP_STYLES only triggers the sync; what's fetched is the // style tiles.openfreemap.org serves right now (built from that repo), and the // sprite at whatever versioned path that style points to. const style = await get("https://tiles.openfreemap.org/styles/liberty", "liberty-style/liberty.json"); const sprite = JSON.parse(style).sprite; for (const suffix of [".json", ".png", "@2x.json", "@2x.png"]) await get(`${sprite}${suffix}`, `liberty-sprite/ofm${suffix}`); console.log(`synced (openfreemap-styles ${OPENFREEMAP_STYLES.slice(0, 7)}, sprite ${sprite})`);