Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
function get-libs(){
if(test-path "lib"){
$jars = (ls lib -include *.jar -recur) | foreach { $_.FullName }
if($jars){
[String]::Join(";", $jars)
}
}
}
$VERSION="1.0.0-SNAPSHOT"
$lein_mvn_str = "{0}`\.m2`\repository`\leiningen`\leiningen`\{1}`\leiningen-{1}.jar"
$LEIN_JAR = [String]::Format($lein_mvn_str, $env:UserProfile, $VERSION)
$LIBS = (get-libs)
$CLASSPATH = "src;classes;$LIBS"
# this needs to exist before the JVM is launched apparently
if(-not (test-path "classes")){
[void](mkdir classes)
}
# If we are not running from a checkout
if((-not (test-path "classes\leiningen\core.class"))){
if((-not (test-path $LEIN_JAR)) -and ($args[0] -ne "self-install")){
write-error "Leiningen is not installed. Please run `"lein self-install`"."
exit 1
}
$CLASSPATH= "$CLASSPATH;$LEIN_JAR"
}
if ($DEBUG) {
write-host $CLASSPATH
}
if($args[0] -eq "test"){
$testDir = (get-item -erroraction SilentlyContinue "test").FullName
$CLASSPATH= $testDir + ";" + $CLASSPATH
}
# Deps need to run before the JVM launches for tasks that need them
if(($args[0] -eq "compile") -or ($args[0] -eq "jar") -or ($args[0] -eq "uberjar")){
if(-not $LIBS){
& $myInvocation.MyCommand deps skip-dev
}
}
$ESCAPED_ARGS = $args | foreach { $allArgs = "" } { $allArgs += "\`"$_\`" " } { $allArgs }
if($args[0] -eq "repl"){
java -cp $CLASSPATH clojure.main
} elseif($args[0] -eq "self-install"){
write-host "Downloading Leiningen now..."
$dir_path = split-path $LEIN_JAR
if(-not (test-path $dir_path)){
mkdir $dir_path
}
$LEIN_URL = "http://repo.technomancy.us/leiningen-$VERSION.jar"
$webClient = new-object System.Net.WebClient
$webClient.DownloadFile($LEIN_URL, $LEIN_JAR)
} else {
if($args.Length -eq 0){
write-host $myInvocation.MyCommand "missing task"
write-host "Usage:" $myInvocation.MyCommand "taskname"
}else {
java -client -cp $CLASSPATH clojure.main -e "(use 'leiningen.core) (main $ESCAPED_ARGS)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment