Skip to content

Instantly share code, notes, and snippets.

@akshaymankar
Last active March 21, 2020 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akshaymankar/aaefa69c7a202a7aab85f58de1836bb8 to your computer and use it in GitHub Desktop.
Save akshaymankar/aaefa69c7a202a7aab85f58de1836bb8 to your computer and use it in GitHub Desktop.
Generate hie.yaml for a stack project
#!/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