carlos / todomvc-bakeoff Public

Clone
git clone https://amadan.net/carlos/todomvc-bakeoff

Plain git — no account needed to clone.

Download

Download this file

1#!/usr/bin/env bash
2# Writes Sources/TodoApp/Assets.swift: the shared TodoMVC CSS and this app's
3# static files, embedded byte for byte so the binary is the whole app.
4# tools/embed.sh <shared-dir> <static-dir> <out.swift>
5set -euo pipefail
6shared=$1 static=$2 out=$3
7tmp=$(mktemp "$out.XXXXXX")
8trap 'rm -f "$tmp"' EXIT
9literal() {
10 if grep -q '"""#' "$1"; then echo "embed.sh: $1 contains \"\"\"#" >&2; exit 1; fi
11 printf ' static let %s = #"""\n' "$2"
12 cat "$1"
13 # A raw multi-line literal drops the newline before its closing
14 # delimiter, so add one to keep the file's own final newline.
15 printf '\n"""#\n\n'
16}
17{
18 printf '// GENERATED by tools/embed.sh from shared/ and static/. Do not edit.\n\n'
19 printf 'enum Assets {\n'
20 literal "$shared/base.css" baseCSS
21 literal "$shared/index.css" indexCSS
22 literal "$static/app.css" appCSS
23 literal "$static/app.js" appJS
24 printf '}\n'
25} > "$tmp"
26if cmp -s "$tmp" "$out"; then exit 0; fi
27mv "$tmp" "$out"
28trap - EXIT
29