Skip to content

Instantly share code, notes, and snippets.

@felixSchl
Last active March 15, 2020 21:16
Show Gist options
  • Save felixSchl/167678b0c76539138cac82ebba1b02cb to your computer and use it in GitHub Desktop.
Save felixSchl/167678b0c76539138cac82ebba1b02cb to your computer and use it in GitHub Desktop.
Emacs 'M-x compile' compatible 'purs compile' output (spago only)
#!/bin/bash
# compilation-mode compatible spago build output
set -eo pipefail
root=$(git rev-parse --show-toplevel)
PATH=$root/node_modules/.bin:$PATH
output=$(spago 3>&2 2>&1 1>&3 --quiet build -u --json-errors || { :; })
n_errors=$(jq <<< "$output" '.errors | length')
n_warnings=$(jq <<< "$output" '.warnings | length')
if [[ "$n_warnings" -gt 0 ]]; then
echo "${n_warnings} warning(s):"
jq --arg root "$root" -r <<< "$output" '.warnings[] | "Warning " + $root + "/" + .filename + " " + (.position.startLine|tostring) + ": " + .message'
fi
if [[ "$n_errors" -gt 0 ]]; then
echo "${n_errors} error(s):"
jq --arg root "$root" -r <<< "$output" '.errors[] | "Error " + $root + "/" + .filename + " " + (.position.startLine|tostring) + ": " + .message'
exit 1
fi
if [[ "$1" == test ]]; then
spago test
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment