Last active
November 4, 2021 18:43
-
-
Save opsb/544c568bdbeb548548a104eaf207e4ce to your computer and use it in GitHub Desktop.
Pulls all elm.json dependencies from github and saves in local cache (requires jq to be installed)
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
#!/bin/sh | |
set -e | |
if [ "$(elm --version)" != "0.19.1" ]; then | |
echo "Globally installed elm 0.19.1 is required" | |
exit 1 | |
fi | |
export packages=~/.elm/0.19.1/packages | |
invalid_archive () { | |
echo "Invalid archive: $author/$name@$version does not seem to exist" | |
cd | |
rm -f $pkgdir/archive.zip | |
rmdir $pkgdir $packages/$author/$name $packages/$author 2> /dev/null | |
exit 1 | |
} | |
install_dependency() { | |
author=$(echo $1 | cut -f1 -d/) | |
name=$(echo $1 | cut -f2 -d/) | |
version=$(echo $1 | cut -f3 -d/) | |
pkgdir=$packages/$author/$name/$version | |
if [ -d "$pkgdir" ]; then | |
echo "$author/$name@$version already installed" | |
exit 0 | |
fi | |
echo "Installing $author/$name@$version" | |
mkdir -p "$pkgdir" | |
cd "$pkgdir" | |
curl -sL -o archive.zip "https://github.com/$author/$name/zipball/$version/" | |
unzip -qn archive.zip 2> /dev/null || invalid_archive | |
rm archive.zip | |
dir=$(ls -d $author-$name*) | |
if [ -d "$dir" ]; then | |
mv $dir/src $dir/LICENSE $dir/README.md $dir/elm.json . | |
elm make --docs=docs.json || true | |
rm -r elm-stuff | |
rm -r $dir | |
fi | |
} | |
export -f install_dependency | |
cat elm.json | jq -r '[.dependencies.direct, .dependencies.indirect] | add | to_entries | map([.key, .value] | join("/")) | .[]' | xargs -I{} bash -c 'install_dependency "{}"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment