Permalink
Browse files

Replace build script with 'lein run build'. Refs #34.

  • Loading branch information...
candera committed Jan 18, 2012
1 parent d8e3094 commit 4d0b892453dd0d120299192f10786a0d6f041ab9
Showing with 75 additions and 6 deletions.
  1. +1 −2 project.clj
  2. +39 −0 src/app/clj/one/sample/launchpad.clj
  3. +8 −3 src/app/clj/one/sample/prod_server.clj
  4. +27 −1 src/lib/clj/one/tools.clj
View
@@ -7,8 +7,7 @@
:dev-dependencies [[jline "0.9.94"]
[marginalia "0.7.0-SNAPSHOT"]
[lein-marginalia "0.7.0-SNAPSHOT"]]
- ;:main one.sample.prod-server
- ;:test-path "test"
+ :main ^:skip-aot one.sample.launchpad
:source-path "src/app/clj"
:extra-classpath-dirs ["lib/clojurescript/src/clj"
"lib/clojurescript/src/cljs"
@@ -0,0 +1,39 @@
+(ns one.sample.launchpad
+ "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.sample.config :as config]
+ [one.tools :as tools]
+ [one.sample.dev-server :as dev]
+ [one.sample.prod-server :as prod]
+ [clojure.java.io :as io]
+ [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))
+
+(defmulti command (fn [args] (first args)))
+
+(defmethod command "build" [_]
+ (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))
+
+(defmethod command nil [_]
+ (prod/run-server))
+
+(defn -main [& args]
+ (command args))
@@ -1,6 +1,6 @@
(ns one.sample.prod-server
"Production server serves the backend API. This is only required if
- there is a back end API."
+ there is a back end API."
(:use [ring.adapter.jetty :only (run-jetty)]
[ring.middleware.file :only (wrap-file)]
[ring.middleware.file-info :only (wrap-file-info)]
@@ -11,6 +11,10 @@
(def ^:private root "out/public")
+;; HACK: Something about the defroutes below requires that the
+;; out/public directory exist, or we get a compile error.
+(.mkdirs (java.io.File. "out/public"))
+
(defroutes app-routes
remote-routes
(-> (ANY "*" request (file-response "404.html" {:root root}))
@@ -20,5 +24,6 @@
(def ^:private app (-> app-routes
wrap-params))
-(defn -main [] (let [port (Integer/parseInt (get (System/getenv) "PORT" "8080"))]
- (run-jetty (var app) {:join? false :port port})))
+(defn run-server []
+ (let [port (Integer/parseInt (get (System/getenv) "PORT" "8080"))]
+ (run-jetty (var app) {:join? false :port port})))
View
@@ -2,7 +2,9 @@
"Support for building deployment artifacts for a project."
(:use [cljs.closure :only (build)]
[one.host-page :only (application-host)]
- [one.config :only (cljs-build-opts production-js)])
+ [one.config :only (cljs-build-opts production-js)]
+ [cljs.repl :only (repl)]
+ [cljs.repl.browser :only (repl-env)])
(:require [clojure.java.io :as io]))
(defn build-project
@@ -13,3 +15,27 @@
:optimizations :advanced
:output-to (str "out/" (production-js config))))
(spit "out/public/index.html" (application-host config :production)))
+
+(defn cljs-repl
+ "Start a ClojureScript REPL which can connect to the development
+ version of the application. The REPL will not work until the
+ development page connects to it, so you will need to either open or
+ refresh the development page after calling this function."
+ []
+ (repl (repl-env)))
+
+(defn copy-recursive-into
+ "Recursively copy the files in src to dest."
+ [src dest]
+ (doseq [file (remove #(.isDirectory %) (file-seq (io/file src)))]
+ (let [dest-file (io/file dest file)]
+ (.mkdirs (.getParentFile dest-file))
+ (io/copy file dest-file))))
+
+(defn delete
+ "Delete one or more files or directories. Directories are recursively
+ deleted."
+ [& paths]
+ (doseq [path paths
+ file (reverse (file-seq (io/file path)))]
+ (.delete file)))

0 comments on commit 4d0b892

Please sign in to comment.