SPB Git

Repository Public

generate-model-logos.sh 2.9 KB 77 lines shellscript

1#!/bin/sh2# SP Notes Core3# File: Scripts/generate-model-logos.sh4# Description: Regenerates the model creator / route logos bundled in SPNotesFeatures from the web repository5#              (public/model-logos/*.svg + registry.json, single-colour 24×24 SVGs from simple-icons, CC0-1.0; the marks stay6#              trademarks of their owners). Output: Sources/SPNotesFeatures/Resources/ModelLogos.xcassets (one vector,7#              template-rendered image set per SVG file, compiled by actool under both `swift build` and xcodebuild) and8#              Resources/ModelLogosRegistry.json (the registry, read at run time to map a creator / route id to its9#              image and monogram). Read-only on the node. No WebKit anywhere: the SVGs are rendered by the asset catalogue.10#11# Author: Simon-Pierre Boucher12# Contact: contact@spboucher.ai13#14# Usage: Scripts/generate-model-logos.sh [source]15#   source = an scp location or a local directory (default: M4M64c:dev/note-next-int/public/model-logos)16set -eu1718root="$(cd "$(dirname "$0")/.." && pwd)"19source="${1:-M4M64c:dev/note-next-int/public/model-logos}"20resources="$root/Sources/SPNotesFeatures/Resources"21assets="$resources/ModelLogos.xcassets"22work="$(mktemp -d)"23trap 'rm -rf "$work"' EXIT2425if [ -d "$source" ]; then26    cp "$source"/*.svg "$source"/registry.json "$work"/27else28    scp -q "$source/*.svg" "$source/registry.json" "$work"/29fi30[ -f "$work/registry.json" ] || { echo "registry.json missing in $source" >&2; exit 1; }3132rm -rf "$assets"33mkdir -p "$assets"34printf '{\n  "info" : {\n    "author" : "xcode",\n    "version" : 1\n  }\n}\n' > "$assets/Contents.json"3536count=037for svg in "$work"/*.svg; do38    stem="$(basename "$svg" .svg)"39    set="$assets/ModelLogo-$stem.imageset"40    mkdir -p "$set"41    cp "$svg" "$set/$stem.svg"42    cat > "$set/Contents.json" <<JSON43{44  "images" : [45    {46      "filename" : "$stem.svg",47      "idiom" : "universal"48    }49  ],50  "info" : {51    "author" : "xcode",52    "version" : 153  },54  "properties" : {55    "preserves-vector-representation" : true,56    "template-rendering-intent" : "template"57  }58}59JSON60    count=$((count + 1))61done6263cp "$work/registry.json" "$resources/ModelLogosRegistry.json"6465# Every file named by the registry must exist as an image set.66python3 - "$resources/ModelLogosRegistry.json" "$assets" <<'PY'67import json, os, sys68registry = json.load(open(sys.argv[1]))69missing = sorted({e["file"] for e in registry["entries"] if not os.path.isdir(os.path.join(sys.argv[2], "ModelLogo-" + e["file"][:-4] + ".imageset"))})70fallback = registry.get("fallback", "generic.svg")71if not os.path.isdir(os.path.join(sys.argv[2], "ModelLogo-" + fallback[:-4] + ".imageset")): missing.append(fallback)72if missing:73    print("registry names files that were not found: " + ", ".join(missing), file=sys.stderr); sys.exit(1)74print("%d registry entries" % len(registry["entries"]))75PY76echo "$count image sets written to $assets"77
Files main
Menu

Theme