#!/usr/bin/env bash # Writes Sources/TodoApp/Assets.swift: the shared TodoMVC CSS and this app's # static files, embedded byte for byte so the binary is the whole app. # tools/embed.sh set -euo pipefail shared=$1 static=$2 out=$3 tmp=$(mktemp "$out.XXXXXX") trap 'rm -f "$tmp"' EXIT literal() { if grep -q '"""#' "$1"; then echo "embed.sh: $1 contains \"\"\"#" >&2; exit 1; fi printf ' static let %s = #"""\n' "$2" cat "$1" # A raw multi-line literal drops the newline before its closing # delimiter, so add one to keep the file's own final newline. printf '\n"""#\n\n' } { printf '// GENERATED by tools/embed.sh from shared/ and static/. Do not edit.\n\n' printf 'enum Assets {\n' literal "$shared/base.css" baseCSS literal "$shared/index.css" indexCSS literal "$static/app.css" appCSS literal "$static/app.js" appJS printf '}\n' } > "$tmp" if cmp -s "$tmp" "$out"; then exit 0; fi mv "$tmp" "$out" trap - EXIT