Skip to content

Instantly share code, notes, and snippets.

@opsb
Last active November 4, 2021 18:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opsb/544c568bdbeb548548a104eaf207e4ce to your computer and use it in GitHub Desktop.
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)
#!/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