#!/bin/sh # # Usage: # sh build-fontkit.js.sh [] # defaults to ./fontkit-VERSION.js # # This script builds fontkit.js for a web browser as an ES module script. # Use the result like this: # # # We can't use esbuild but have to use parcel since fontkit relies on # parcel-specific features like executing nodejs fs.readFileSync at build time. # So first we build with parcel then use esbuild to minify the results. # There might be ways to streamline the parcel build process, but after 30 minutes # of reading their documentation I couldn't figure it out, thus the sed hacks. # set -e rm -rf /tmp/fontkit-build mkdir /tmp/fontkit-build pushd /tmp/fontkit-build >/dev/null cat < package.json { "name": "fontkit-build", "version": "1.0.0", "dependencies": { "buffer": "^6.0.3", "fontkit": "^2.0.2", "parcel": "^2.9.3", "esbuild": "^0.19.2" } } EOF npm install FONTKIT_VERSION=$(node -p 'require("./node_modules/fontkit/package.json").version') cat < index.html EOF ./node_modules/.bin/parcel build --no-optimize --no-cache index.html # strip away HTML sed -E 's/^\s*(:?