Last active
March 21, 2020 19:06
-
-
Save akshaymankar/aaefa69c7a202a7aab85f58de1836bb8 to your computer and use it in GitHub Desktop.
Generate hie.yaml for a stack project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# requirements: yq, awk, stack | |
set -euo pipefail | |
echo "cradle:" | |
echo " stack:" | |
for pkg in `stack ide targets --stdout`; do | |
dir=$(echo $pkg | awk -F: '{print $1}') | |
type=$(echo $pkg | awk -F: '{print $2}') | |
name=$(echo $pkg | awk -F: '{print $3}') | |
package_yaml=$(find . -wholename "*/$dir/package.yaml") | |
if [[ "$type" == "lib" ]]; then | |
yq_cmd='.library["source-dirs"]' | |
elif [[ "$type" == "exe" ]]; then | |
yq_cmd=".executables[\"$name\"][\"source-dirs\"] // .executables[\"$name\"].main" | |
elif [[ "$type" == "test" ]]; then | |
yq_cmd=".tests[\"$name\"][\"source-dirs\"]" | |
fi | |
for src_dir in $(yq -r "[ $yq_cmd ] | flatten | .[]" "$package_yaml"); do | |
echo " - path: $(dirname "$package_yaml")/$src_dir" | |
echo " component: $pkg" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment