Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes lein_prefer script #179

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions bin/get_lein.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
#!/usr/bin/env node

var https = require("https"),
fs = require("fs");
var wget = require('wgetjs');

var lein_loc = __dirname + "/lein";

https.get("https://raw.github.com/technomancy/leiningen/stable/bin/lein", function(res) {
var body = "";
res.setEncoding("utf8");
res.on("data", function (chunk) {
body += chunk;
});
res.on("end", function () {
fs.writeFileSync(lein_loc, body);
});
}).on("error", function(e) {
console.log("HTTP error: " + e.message);
wget({
url: "https://raw.github.com/technomancy/leiningen/stable/bin/lein",
dest: __dirname + "/lein",
}, function(err) {
if (err) {
console.log(err.message);
}
});
69 changes: 30 additions & 39 deletions bin/lein_prefer
Original file line number Diff line number Diff line change
@@ -1,51 +1,42 @@
#!/usr/bin/env bash

LEIN_PREFER=`which lein`
LEIN2=`which lein2`

if [[ ! -z $LEIN2 ]]; then

LEIN_PREFER=$LEIN2

fi

if [[ ! -z $LEIN_PREFER ]]; then

LEIN_VER=`$LEIN_PREFER version`

fi
set -e

LEIN_PREFER=""
LEIN_VER=""
LEIN_VER1_PATTERN="^Leiningen\ 1\."

if [[ -z $LEIN_PREFER || $LEIN_VER =~ $LEIN_VER1_PATTERN ]]; then

export LEIN_HOME=`pwd`"/bin/.lein"

if [[ ! -d $LEIN_HOME ]]; then

mkdir $LEIN_HOME

BIN=$(cd `dirname $0`; pwd)

command_exists () {
type "$1" &>/dev/null
}

download_lein () {
"$BIN/get_lein.js"
chmod +x "$BIN/lein"
echo "$BIN/lein"
}

if command_exists lein2; then
LEIN_PREFER=lein2
elif command_exists lein; then
LEIN_PREFER=lein
elif [ ! -x "$LEIN_PREFER" ]; then
LEIN_PREFER="$BIN/lein"
fi

LEIN_PREFER=`pwd`"/bin/lein"

if [ -x "$LEIN_PREFER" ]; then
LEIN_VER=$("$LEIN_PREFER" version)
fi

if [[ ! -f $LEIN_PREFER ]]; then

echo "Leiningen v2 not found, downloading..."

./bin/get_lein.js

chmod +x $LEIN_PREFER

if [[ ! -x "$LEIN_PREFER" || "$LEIN_VER" =~ "$LEIN_VER1_PATTERN" ]]; then
>&2 echo "Leiningen v2 not found, downloading..."
>&2 download_lein
fi

if [[ ! -f $LEIN_PREFER ]]; then

echo "Failed to find or set up Leiningen"
exit 1

if [ ! -x "$LEIN_PREFER" ]; then
echo "Failed to find or set up Leiningen"
exit 1
fi

$LEIN_PREFER $@
"$LEIN_PREFER" $@
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
"url": "git://github.com/swannodette/mori.git"
},
"engines": {
"node": ">=0.8.22"
"node": ">=0.8.22"
},
"dependencies": {},
"devDependencies": {
"immutable": "3.5.0",
"jasmine-node": "1.7.0"
"jasmine-node": "1.7.0",
"wgetjs": "0.3.6"
},
"scripts": {
"build": "./scripts/build.sh",
Expand All @@ -48,6 +48,6 @@
"test": "jasmine-node spec"
},
"directories": {
"test": "./spec"
"test": "./spec"
}
}