Skip to content

Instantly share code, notes, and snippets.

@rlefevre
Last active February 3, 2023 10:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rlefevre/850b1147f0ca256bf65d6bb8a58f0bcb to your computer and use it in GitHub Desktop.
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
#!/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