forked from vgeshel/one
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert all scripts to Leiningen. Refs #34.
- Loading branch information
Brenton Ashworth
committed
Jan 23, 2012
1 parent
e01b960
commit 578895b
Showing
18 changed files
with
191 additions
and
131 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ docs | |
/.lein-deps-sum | ||
*~ | ||
/.lein-failures | ||
/.lein-git-deps/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
web: lein run | ||
web: lein run -m script.serve |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,3 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
cd `dirname $0`/.. | ||
|
||
mkdir -p out | ||
|
||
echo "Creating out/public..." | ||
cp -a public out/ | ||
rm out/public/index.html | ||
rm out/public/design.html | ||
rm -rf out/public/javascripts/* | ||
|
||
source script/setup_classpath.sh | ||
|
||
echo "Create advanced compiled JavaScript..." | ||
java -server -cp $CLJSC_CP jline.ConsoleRunner clojure.main -e \ | ||
"(use 'one.tools) | ||
(use 'one.sample.config) | ||
(build-project config)" | ||
|
||
echo "[build complete]" | ||
|
||
lein run -m script.build |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lein run -m script.build |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
# This is here for convention. Many Emacs users have their | ||
# inferior-lisp-program set to script/repl. | ||
|
||
lein repl |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
# Start the production server which will serve the contents of | ||
# out/public and the API for the sample application. | ||
|
||
lein run -m script.serve |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(ns one.sample.repl | ||
"The starting namespace for the project. This is the namespace that | ||
users will land in when they start a Clojure REPL. It exists both to | ||
process commands passed on the command line (such as 'build') and to | ||
provide convenience functions like 'go'." | ||
(:use [clojure.repl]) | ||
(:require [one.tools :as tools] | ||
[one.sample.dev-server :as dev] | ||
[clojure.java.browse :as browse])) | ||
|
||
(defn go | ||
"Start a browser-connected REPL and launch a browser to talk to it." | ||
[] | ||
(dev/run-server) | ||
(future (Thread/sleep 3000) | ||
(browse/browse-url "http://localhost:8080/development")) | ||
(tools/cljs-repl)) | ||
|
||
(defn dev-server | ||
"Start the development server and open the host application in the | ||
default browser." | ||
[] | ||
(dev/run-server) | ||
(future (Thread/sleep 3000) | ||
(browse/browse-url "http://localhost:8080"))) | ||
|
||
(println) | ||
(println "Type (go) to launch the development server and setup a browser-connected REPL.") | ||
(println "Type (dev-server) to launch only the development server.") | ||
(println) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns script.build | ||
(:require [clojure.java.io :as io] | ||
[one.tools :as tools] | ||
[one.sample.config :as config])) | ||
|
||
(defn -main [] | ||
(println "Creating out/public...") | ||
(.mkdir (io/file "out")) | ||
(tools/copy-recursive-into "public" "out") | ||
(tools/delete "out/public/index.html" | ||
"out/public/design.html" | ||
"out/public/javascripts") | ||
(.mkdir (io/file "out/public/javascripts")) | ||
(println "Create advanced compiled JavaScript...") | ||
(tools/build-project config/config)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(ns script.serve | ||
(:require [one.sample.prod-server :as prod])) | ||
|
||
(defn -main [] | ||
(prod/run-server)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(ns leiningen.bootstrap | ||
(:require leiningen.deps | ||
leiningen.git-deps)) | ||
|
||
(defn bootstrap | ||
"Bootstrap the project by running lein deps and lein git-deps." | ||
[project] | ||
(leiningen.deps/deps project) | ||
(leiningen.git-deps/git-deps project)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
(ns leiningen.git-deps | ||
"How this works: It clones projects into .lein-git-deps/<whatever>. | ||
If the directory already exists, it does a git pull and git checkout." | ||
(:require [clojure.java.shell :as sh] | ||
[clojure.java.io :as io] | ||
[clojure.string :as string])) | ||
|
||
(def ^:private git-deps-dir ".lein-git-deps") | ||
|
||
(defn- directory-exists? | ||
"Return true if the specified directory exists." | ||
[dir] | ||
(.isDirectory (io/file dir))) | ||
|
||
(defn- penultimate | ||
"Return the second-to-last element of a collection." | ||
[coll] | ||
(last (butlast coll))) | ||
|
||
(defn- default-clone-dir | ||
"Given a git URL, return the directory it would clone into by default." | ||
[uri] | ||
(string/join "." (-> uri | ||
(string/split #"/") | ||
(last) | ||
(string/split #"\.") | ||
butlast))) | ||
|
||
(defn- exec | ||
"Run a command, throwing an exception if it fails, returning the | ||
result as with clojure.java.shell/sh." | ||
[& args] | ||
(let [{:keys [exit out err] :as result} (apply sh/sh args)] | ||
(if (zero? exit) | ||
result | ||
(throw | ||
(Exception. | ||
(format "Command %s failed with exit code %s\n%s\n%s" | ||
(apply str (interpose " " args)) | ||
exit | ||
out | ||
err)))))) | ||
|
||
(defn- git-clone | ||
"Clone the git repository at url into dir-name while working in | ||
directory working-dir." | ||
[url dir-name working-dir] | ||
(apply exec (remove nil? ["git" "clone" url (str dir-name) :dir working-dir]))) | ||
|
||
(defn- git-checkout | ||
"Check out the specified commit in dir" | ||
[commit dir] | ||
(println "Running git checkout " commit " in " (str dir)) | ||
(exec "git" "checkout" commit :dir dir)) | ||
|
||
(defn- detached-head? | ||
"Return true if the git repository in dir has HEAD detached." | ||
[dir] | ||
(let [{out :out} (exec "git" "branch" "--color=never" :dir dir) | ||
lines (string/split-lines out) | ||
current-branch (first (filter #(.startsWith % "*") lines))] | ||
(when-not current-branch | ||
(throw (Exception. "Unable to determine current branch"))) | ||
(= current-branch "* (no branch)"))) | ||
|
||
(defn- git-pull | ||
"Run 'git-pull' in directory dir, but only if we're on a branch. If | ||
HEAD is detached, we only do a fetch, not a full pull." | ||
[dir] | ||
(println "Running git pull on " (str dir)) | ||
(if (detached-head? dir) | ||
(do | ||
(println "Not on a branch, so fetching instead of pulling.") | ||
(exec "git" "fetch" :dir dir)) | ||
(exec "git" "pull" :dir dir))) | ||
|
||
(defn git-deps | ||
"A leiningen task that will pull dependencies in via git. | ||
Dependencies should be listed in project.clj under the | ||
:git-dependencies key in one of these three forms: | ||
:git-dependencies [;; First form: just a URL. | ||
[\"https://github.com/foo/bar.git\"] | ||
;; Second form: A URL and a ref, which can be anything | ||
;; you can specify for 'git checkout', like a commit ide | ||
;; or a branch name. | ||
[\"https://github.com/foo/baz.git\" | ||
\"329708b\"] | ||
;; Third form: A URL, a commit, and a map | ||
[\"https://github.com/foo/quux.git\" | ||
\"some-branch\" | ||
{:dir \"alternate-directory\"}]]" | ||
[project] | ||
(when-not (directory-exists? git-deps-dir) | ||
(.mkdir (io/file git-deps-dir))) | ||
(doseq [dep (:git-dependencies project)] | ||
(println "Setting up dependency for " dep) | ||
(let [[dep-url commit {clone-dir-name :dir}] dep | ||
commit (or commit "master") | ||
clone-dir-name (or clone-dir-name (default-clone-dir dep-url)) | ||
clone-dir (io/file git-deps-dir clone-dir-name)] | ||
(if (directory-exists? clone-dir) | ||
(git-pull clone-dir) | ||
(git-clone dep-url clone-dir-name git-deps-dir)) | ||
(git-checkout commit clone-dir)))) |