Last active
October 18, 2015 06:55
-
-
Save sitepodmatt/6249d4a61562eb48f6db to your computer and use it in GitHub Desktop.
hacky bash script to pull clojure lein project deps into a local directory
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/bash | |
# require unzip | |
UNZIP=$(which unzip) | |
if [ $? -ne 0 ]; then | |
echo "Error: requires unzip command" | |
exit 1 | |
fi | |
# pull the first level dependencies from lein via some sed pain | |
deps=$(lein deps :tree | \ | |
sed -ne 's/^ \[\([-a-z.]\+\)\/\?\([-a-z.]\+\s\)\?.\+\?"\([0-9]\+\.[0-9]\+.[0-9]\+\)".*/\1 \2\3/gp') | |
REPO_PATH=~/.m2/repository | |
OUTPUT_PATH=depref | |
while read group artifact version; do | |
if [ -z "$version" ]; then | |
version="$artifact" | |
artifact="$group" | |
fi | |
echo -n "Group: $group " | |
echo -n "Artifact: $artifact " | |
echo "Version: $version" | |
jar_path="$REPO_PATH/${group/./\/}/$artifact/$version" | |
echo "Jar path: $jar_path" | |
if [ -d $jar_path ]; then | |
jar_file=$jar_path/*.jar | |
if [ -f $jar_file ]; then | |
jar_output_dest=$OUTPUT_PATH/$artifact | |
mkdir -p "$jar_output_dest" | |
echo "Outputting to $jar_output_dest" | |
unzip -oqq "$jar_file" "*.clj" "*.cljs" "*.cljx" "*.txt" "*.md" -x "META-INF/*" -d "$jar_output_dest" >/dev/null 2>&1 | |
fi | |
fi | |
done <<<"$deps" | |
# add directory to gitignore if exists and not already included | |
if [ -f .gitignore ]; then | |
grep -F "^${OUTPUT_PATH}/" .gitignore >/dev/null || echo "${OUTPUT_PATH}/" >> .gitignore | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment