chiark / gitweb /
refactor tsc compilation
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Oct 2020 23:44:44 +0000 (00:44 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Oct 2020 23:44:44 +0000 (00:44 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
.gitignore
Makefile
tsc-wrap [new file with mode: 0755]

index 2dd99c4ff846e6a674d8759d8c98042fdf7b510d..1fb4a99eafc940de7db7f3eb879f37fce80450f0 100644 (file)
@@ -6,4 +6,4 @@ templates/CC-BY-SA-4.0
 save/lock
 /library/*/*.usvg
 *.tmp
-.tsconfig.json
+.tsconfig.*.json
index 4bb4c94c278c90525c1c011aaa4e03f869c4da69..c16606f62b1a124084573980fc5e7c74c73689ec 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -80,13 +80,8 @@ $(CARGO_TARGET_DIR)/debug/server:
 $(CARGO_TARGET_DIR)/release/server:
        $(CARGO) build --release
 
-templates/script.js: tsconfig.json $(TS_SRC_FILES)
-       sed <tsconfig.json >.tsconfig.json \
-               '/^ *"files":/ s#:.*#:[$(foreach f,$(TS_SRC_FILES),"$f",)]#'
-       tsc --outfile $@.tmp -p .tsconfig.json 2>&1 \
-       | perl -pe 's/\((\d+),(\d+)\):/:$$1:$$2:/'; \
-       test "$${PIPESTATUS[*]}" = "0 0"
-       mv -f $@.tmp $@
+templates/script.js: tsc-wrap tsconfig.json $(TS_SRC_FILES)
+       ./tsc-wrap $@ tsconfig.json $(TS_SRC_FILES)
 
 DEPLOY_ARCH=x86_64-unknown-linux-musl
 DEPLOY_RELEASE=debug
diff --git a/tsc-wrap b/tsc-wrap
new file mode 100755 (executable)
index 0000000..47586e9
--- /dev/null
+++ b/tsc-wrap
@@ -0,0 +1,30 @@
+#!/bin/bash
+set -e
+
+out="$1"; shift
+tsconfig="$1"; shift
+
+files_json='['
+for f in "$@"; do
+       files_json="${files_json}\"$f\", "
+done
+files_json="$files_json]"
+
+our_tsconfig=".tsconfig.${out##*/}.json"
+
+x () {
+    echo "+ $*" >&2;
+    "$@";
+}
+
+sed <"$tsconfig" >"$our_tsconfig" '/^ *"files":/ s#:.*#:'"$files_json"'#'
+
+x tsc --outfile "$out.1.tmp" -p "$our_tsconfig" 2>&1 \
+| perl -pe 's/\((\d+),(\d+)\):/:$1:$2:/' >&2
+test "${PIPESTATUS[*]}" = "0 0"
+
+sed    <"$out.1.tmp" '/^[a-z]/,$d' > "$out".tmp
+sed    <"$1"         '/^[a-z]/,$d' >>"$out".tmp
+sed -n <"$out.1.tmp" '/^[a-z]/,$p' >> "$out".tmp
+
+mv -f "$out".tmp "$out"