Files
maptool/bin/assets-sync.mjs
T
randy f0f463d9b2
CI / check (push) Successful in 18s
CI / deploy (push) Successful in 22s
Update https://github.com/hyperknot/openfreemap-styles digest to 006ea57
2026-11-13 09:36:50 +01:00

40 lines
2.0 KiB
JavaScript
Executable File

#!/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 = "006ea5796803ba2df4330888836cb0a8f17473b4";
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})`);