chiark / gitweb /
wip await gen
[otter.git] / tsc-wrap
1 #!/bin/bash
2 set -e
3
4 out="$1"; shift
5 tsconfig="$1"; shift
6
7 files_json='['
8 for f in "$@"; do
9         files_json="${files_json}\"$f\", "
10 done
11 files_json="$files_json]"
12
13 our_tsconfig=".tsconfig.${out##*/}.json"
14
15 x () {
16     echo "+ $*" >&2;
17     "$@";
18 }
19
20 sed <"$tsconfig" >"$our_tsconfig" '/^ *"files":/ s#:.*#:'"$files_json"'#'
21
22 x tsc --outfile "$out.1.tmp" -p "$our_tsconfig" 2>&1 \
23 | perl -pe 's/\((\d+),(\d+)\):/:$1:$2:/' >&2
24 test "${PIPESTATUS[*]}" = "0 0"
25
26 sed    <"$out.1.tmp" '/^[a-z]/,$d' > "$out".tmp
27 echo "// autogenerated from $@"    >>"$out".tmp
28 sed    <"$1"         '/^[a-z]/,$d' >>"$out".tmp
29 sed -n <"$out.1.tmp" '/^[a-z]/,$p' >> "$out".tmp
30
31 mv -f "$out".tmp "$out"