From: Ian Jackson Date: Sun, 4 Oct 2020 23:44:44 +0000 (+0100) Subject: refactor tsc compilation X-Git-Tag: otter-0.2.0~747 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=1a7404998e2dc5a74327020a7c9c32826d1d1570;p=otter.git refactor tsc compilation Signed-off-by: Ian Jackson --- diff --git a/.gitignore b/.gitignore index 2dd99c4f..1fb4a99e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ templates/CC-BY-SA-4.0 save/lock /library/*/*.usvg *.tmp -.tsconfig.json +.tsconfig.*.json diff --git a/Makefile b/Makefile index 4bb4c94c..c16606f6 100644 --- 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 \ - '/^ *"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 index 00000000..47586e94 --- /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"