mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-29 20:27:05 -06:00
build(web): copy web fonts with cargo xtask, not sh
Replace the Trunk post_build hook packaging/web/copy-fonts.sh with `cargo xtask web-fonts` (xtask/src/web_fonts.rs), so the web build only needs trunk, the wasm32 target and cargo, with no POSIX shell, and works the same on Windows. The new task reuses crates/text/build/web_fonts.rs for list parsing and URLs, so build.rs and the copier can't disagree on fonts/<sha16>/<file>. It still does nothing without CRAFT_FONTS_DIR, checks each file's SHA-256 against the manifest, and copies the licence next to each face. A listed face that an older craft-fonts checkout lacks is now skipped with a warning, as build.rs does, instead of failing the build. A relative CRAFT_FONTS_DIR is resolved from the workspace root. Update the references in Trunk.toml, fonts.rs, build.rs, craft_fonts.rs and web-fonts.txt, and document the web build's requirements in docs/development.md. Add tests for the copy, a hash mismatch and the no-op case. Signed-off-by: Ahmed Moussa <moussa.ahmed95@gmail.com>
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Trunk post_build hook (apps/vectorcraft-web/Trunk.toml): copy the craft-fonts faces listed in
|
||||
# crates/text/web-fonts.txt from $CRAFT_FONTS_DIR into the site, each at
|
||||
# fonts/<first 16 hex digits of its SHA-256>/<file> with its licence beside it: the URLs
|
||||
# crates/text/build.rs puts in WEB_FONTS. A no-op without CRAFT_FONTS_DIR.
|
||||
set -eu
|
||||
[ -n "${CRAFT_FONTS_DIR:-}" ] || exit 0
|
||||
: "${TRUNK_STAGING_DIR:?run me as a Trunk post_build hook (TRUNK_STAGING_DIR unset)}"
|
||||
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
LIST="$ROOT/crates/text/web-fonts.txt"
|
||||
MANIFEST="$CRAFT_FONTS_DIR/fonts/manifest.txt"
|
||||
[ -f "$MANIFEST" ] || { echo "copy-fonts: $MANIFEST not found" >&2; exit 1; }
|
||||
|
||||
sha256() {
|
||||
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1
|
||||
else shasum -a 256 "$1" | cut -d' ' -f1; fi
|
||||
}
|
||||
|
||||
grep -v '^[[:space:]]*#' "$LIST" | grep -v '^[[:space:]]*$' | while IFS= read -r line; do
|
||||
family=$(printf '%s\n' "$line" | awk -F' [|] ' '{print $2}')
|
||||
style=$(printf '%s\n' "$line" | awk -F' [|] ' '{print $3}')
|
||||
row=$(awk -F' [|] ' -v f="$family" -v s="$style" '$1 == f && $2 == s { print $3 "|" $6 "|" $7; exit }' "$MANIFEST")
|
||||
[ -n "$row" ] || { echo "copy-fonts: $family $style is not in $MANIFEST" >&2; exit 1; }
|
||||
file=${row%%|*}; rest=${row#*|}; licence=${rest%%|*}; sha=${rest#*|}
|
||||
got=$(sha256 "$CRAFT_FONTS_DIR/$file")
|
||||
[ "$got" = "$sha" ] || { echo "copy-fonts: $file: sha256 $got, manifest says $sha" >&2; exit 1; }
|
||||
dest="$TRUNK_STAGING_DIR/fonts/$(printf '%s' "$sha" | cut -c1-16)"
|
||||
mkdir -p "$dest"
|
||||
cp "$CRAFT_FONTS_DIR/$file" "$dest/"
|
||||
cp "$CRAFT_FONTS_DIR/$licence" "$dest/"
|
||||
done
|
||||
Reference in New Issue
Block a user