Skip to content

Instantly share code, notes, and snippets.

@opsb opsb/elm-cache-add.sh
Last active Jan 23, 2020

Embed
What would you like to do?
Pulls all elm.json dependencies from github and saves in local cache (requires jq to be installed)
#!/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
You can’t perform that action at this time.