colab-asset-manager
v0.0.6
Published
Fingerprints a project's images and syncs them to a Bunny storage zone, writing the d8e-asset-manifest.json d8e reads.
Readme
colab-asset-manager
Fingerprints a project's images and syncs them to a Bunny storage zone, so images never live in
git and never need uploading by hand. Writes d8e-asset-manifest.json, which d8e
(1.2.0+) uses to point every reference at the CDN.
How it works
Run colab-asset-manager in a project root whenever you add, change or remove an image under src/asset/. It:
- Fingerprints each image from its content —
asset/hero-banner.webpis stored ascolab-asset-manager/hero-banner.3f2a9c1e.webp. Change the image and it gets a new name automatically, so it can be cached forever and a stale copy can never be served. - Uploads the ones the storage zone doesn't have yet (checksum-verified).
- Writes
d8e-asset-manifest.json: each image's path undersrc/and its CDN URL. Commit this file — it's a few KB. - Deletes files nobody references any more, 7 days after they stopped being referenced, so pages in browser caches, sent emails and older staging builds keep working in the meantime.
Code keeps referencing images normally (<img src="asset/hero-banner.webp">, url(../asset/hero-banner.webp)), so
local dev still works by opening src/. At deploy, d8e rewrites those references to the CDN URLs and leaves the
images out of dist/.
It only ever lists, uploads to and deletes inside the zone's colab-asset-manager/ folder — files uploaded by hand anywhere
else in the zone are never touched. Supported: avif, gif, jpeg, jpg, png, svg, webp.
It runs on your machine only, never at deploy: the storage key stays off Heroku and Vercel, and staging can't delete production's images.
Setup
1. Install
npm install -g colab-asset-manager@latest2. Add colab-asset-manager.json to the project root
{
"storageZone": "viking-gear",
"storageHost": "jh.storage.bunnycdn.com",
"cdnUrl": "https://viking-gear-pz.b-cdn.net"
}storageZone: the storage zone's name.storageHost: optional, defaults tostorage.bunnycdn.com(Frankfurt). Use the zone's primary region:uk.,ny.,la.,sg.,se.,br.,jh.(Johannesburg) orsyd.storage.bunnycdn.com.cdnUrl: the pull zone connected to that storage zone.
3. Gitignore the images
src/asset/**/*.avif
src/asset/**/*.gif
src/asset/**/*.jpeg
src/asset/**/*.jpg
src/asset/**/*.png
src/asset/**/*.svg
src/asset/**/*.webpIf the images are already committed, also run git rm -r --cached src/asset once (it keeps your local copies). Their
old versions stay in git history.
4. Set the storage key
BUNNY_STORAGE_KEY is the storage zone password: Bunny dashboard → Storage → your zone → FTP & API Access. Keep it in
your shell profile or a password manager — never in the repo.
Usage
colab-asset-manager --help # lists every flag
colab-asset-manager --pull # downloads the images the manifest lists into src/asset/ (no key needed)
colab-asset-manager --dry-run # shows what would be uploaded and deleted; changes nothing
colab-asset-manager # syncs and writes d8e-asset-manifest.jsonThe version is printed first, so you can tell which install is running.
Changing an image
- Fresh clone? Run
colab-asset-manager --pullfirst — images aren't in git, sosrc/asset/starts empty. - Replace, add or remove the file in
src/asset/(kebab-case names). Keeping the same name for a replacement is fine: the fingerprint changes anyway. Check it locally by openingsrc/. colab-asset-manager --dry-run, thencolab-asset-manager.- Commit
d8e-asset-manifest.json(plus any code change that references a new image) and deploy as usual.
If two people sync on different branches, d8e-asset-manifest.json conflicts on merge: pull both sets of images
into src/asset/ (--pull) and run colab-asset-manager again — it rebuilds the manifest from what's there.
Safety checks
- Nothing is deleted just because it's missing locally. If images the manifest lists aren't in
src/asset/(a fresh clone, a half-copied folder), syncing refuses and says to--pull. If you removed them on purpose, add--allow-removals. --pullnever overwrites a local file that differs from Bunny — that's usually a change that hasn't been uploaded yet. It only fills in missing ones, and checks each download against its fingerprint.- Deletions only happen inside the zone's
colab-asset-manager/folder, 7 days after a file stopped being referenced.
Limitations
- Bunny storage zones have one full-access password (plus a read-only one, which isn't enough to upload). Anyone who uploads needs the full one: share it through a password manager, and regenerate it in Bunny if someone leaves.
- Videos and other large files stay where they are (Mux / Bunny Stream).
Tests
npm test — Node's built-in test runner, no extra dependency. test/colab-asset-manager.test.js runs the real CLI
against fixture projects and a fake Bunny (test/fake-bunny.js, installed as the global fetch), so nothing reaches
the network and no key is needed.
Deploying to npm
- FIRST TIME ONLY: run
npm login - Bump the version in
package.json npm test- Run
npm publish
