Skip to content

Commit

Permalink
add a script to resolve an elm import
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed May 14, 2020
1 parent 761edbe commit 2ed5fe1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions script/resolve-elm-import.sh
@@ -0,0 +1,36 @@
#!/usr/bin/env sh
set -euo pipefail

ELM_JSON="${1:-}"
NAME="${2:-}"
if test -z "$NAME"; then
echo "usage: $0 elm.json Name.Of.Module"
exit 1
fi

RELATIVE_PATH="$(echo $NAME | sed 's|\.|/|g').elm"

# look locally

for DIR in $(jq -r '.["source-directories"] | join(" ")' "$ELM_JSON"); do
FINAL="$DIR/$RELATIVE_PATH"
if test -f $FINAL; then
echo "$FINAL"
exit 0
fi
done

# look in elm-stuff

ELM_HOME="${ELM_HOME:-$HOME/.elm}"
ELM_VERSION="$(jq -r '.["elm-version"]' "$ELM_JSON")"

for PROJECT_VERSION_SRC in $(jq -r '.dependencies.direct | to_entries | map("\(.key)/\(.value)") | join(" ")' "$ELM_JSON"); do
FINAL="$ELM_HOME/$ELM_VERSION/packages/$PROJECT_VERSION_SRC/src/$RELATIVE_PATH"
if test -f $FINAL; then
echo "$FINAL"
exit 0
fi
done

exit 1

0 comments on commit 2ed5fe1

Please sign in to comment.