diff --git a/bin/assets-sync.mjs b/bin/assets-sync.mjs new file mode 100755 index 0000000..99fca79 --- /dev/null +++ b/bin/assets-sync.mjs @@ -0,0 +1,39 @@ +#!/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})`); diff --git a/bin/vendor-sync.mjs b/bin/vendor-sync.mjs index 4214b18..93b1171 100644 --- a/bin/vendor-sync.mjs +++ b/bin/vendor-sync.mjs @@ -3,8 +3,8 @@ // 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`. -// Libraries not on npm (NPS plugins, Liberty style/sprite, fonts) stay -// hand-updated, see docs/third-party-notices.adoc. +// 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; diff --git a/docs/third-party-notices.adoc b/docs/third-party-notices.adoc index 4a73184..3ef5bbc 100644 --- a/docs/third-party-notices.adoc +++ b/docs/third-party-notices.adoc @@ -122,10 +122,14 @@ at runtime for the "Online" layer, and as a one-time vendored snapshot (`public/vendor/liberty-style/liberty.json`) that the "Offline" layer repoints at local data instead. Its icon sprite is vendored the same way, under `public/vendor/liberty-sprite/` (`ofm.json`/`ofm.png` + -`@2x` variants, from `tiles.openfreemap.org/sprites/`). Neither has -been re-checked against a specific upstream version pin the way the -table above does — re-fetch both from `tiles.openfreemap.org` if -Liberty's own style/sprite ever visibly drifts from what's vendored. +`@2x` variants, from `tiles.openfreemap.org/sprites/`). + +The Noto Sans glyphs and the Liberty style/sprite are pinned to git +commits (protomaps/basemaps-assets, hyperknot/openfreemap-styles) in +`bin/assets-sync.mjs`. Renovate bumps those pins and runs the script in +the same PR, so the new files arrive with it. A new openfreemap-styles +commit only triggers the sync, which then saves whatever style +`tiles.openfreemap.org` currently serves. `data/offline.pmtiles` (`lib/maptool/pmtiles_builder.rb`'s in-app regeneration, or the manual recipe in `docs/development.adoc`) is @@ -175,9 +179,8 @@ build step. Renovate (`renovate.json`) opens a PR per bump and its already contains the new files under `public/vendor/`. By hand: edit `package.json`, then `npm install && node bin/vendor-sync.mjs`. -Everything else under `public/vendor/` (NPS plugins, Liberty -style/sprite, fonts) isn't on npm or has no version to track — update -by hand and adjust this file. +The NPS plugins (patched, from an unmerged branch) and the National +Park typeface (no versioned source) are still updated by hand. go-pmtiles and Planetiler are pinned by `PMTILES_VERSION`/ `PLANETILER_VERSION` in the `Dockerfile`, which Renovate also bumps diff --git a/renovate.json b/renovate.json index fb1e6db..ad6893a 100644 --- a/renovate.json +++ b/renovate.json @@ -12,6 +12,15 @@ "fileFilters": ["public/vendor/**"], "executionMode": "branch" } + }, + { + "description": "Fonts and the Liberty style/sprite are pinned to git commits in bin/assets-sync.mjs, re-download them in the same PR", + "matchFileNames": ["bin/assets-sync.mjs"], + "postUpgradeTasks": { + "commands": ["node bin/assets-sync.mjs"], + "fileFilters": ["public/vendor/**"], + "executionMode": "branch" + } } ], "customManagers": [ @@ -23,6 +32,14 @@ "# renovate: datasource=(?\\S+) depName=(?\\S+)\\s+ARG \\S+_VERSION=(?\\S+)" ], "extractVersionTemplate": "^v?(?.*)$" + }, + { + "customType": "regex", + "description": "Git commit pins annotated with a `// renovate:` comment", + "managerFilePatterns": ["/^bin/assets-sync\\.mjs$/"], + "matchStrings": [ + "// renovate: datasource=(?\\S+) depName=(?\\S+) branch=(?\\S+)\\s+const \\w+ = \"(?[0-9a-f]{40})\"" + ] } ] }