-
-
Save rlefevre/850b1147f0ca256bf65d6bb8a58f0bcb to your computer and use it in GitHub Desktop.
Add a package to your Elm 0.19.1 local cache directly from GitHub
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 | |
author=$1 | |
name=$2 | |
version=$3 | |
if [ "$#" -lt 3 ]; then | |
echo "usage: elm-cache-add.sh AUTHOR PACKAGE VERSION" | |
exit 1 | |
fi | |
if [ "$(elm --version)" != "0.19.1" ]; then | |
echo "Globally installed elm 0.19.1 is required" | |
exit 1 | |
fi | |
packages=~/.elm/0.19.1/packages | |
pkgdir=$packages/$author/$name/$version | |
if [ -d "$pkgdir" ]; then | |
echo "$author/$name@$version already installed" | |
exit 0 | |
fi | |
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 | |
} | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment