Created
July 19, 2012 23:55
-
-
Save aviflax/3147740 to your computer and use it in GitHub Desktop.
Compile your CoffeeScript along with your Clojure
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
;;; Compile your CoffeeScript along with your Clojure | |
;; NOTE: For Clojure projects using Leiningen 1.7.x. | |
;; Instructions for Leiningen 2.0.x coming soon. | |
;; Step 1: add [robert/hooke "1.1.2"] to the :dev-dependencies option of your defproject call | |
;; Step 2: add the following code to the bottom of your project.clj: | |
(require ['robert.hooke :as 'hooke] | |
['leiningen.compile] | |
['clojure.java.io :as 'io] | |
['clojure.java.shell :as 'shell]) | |
;; hook to compile Coffeescript before Leiningen does stuff | |
(hooke/add-hook #'leiningen.compile/eval-in-project | |
(fn [eip & args] | |
(let [compiler-path "/usr/local/bin/coffee" ; adjust for your system | |
coffee-dir "resources/public" ; adjust for your project | |
shell-args [compiler-path "-c"] | |
coffee-files (->> (io/file coffee-dir) | |
(.listFiles ,,,) | |
(map #(.getPath %) ,,,) | |
(filter #(.endsWith % ".coffee") ,,,)) | |
result (apply shell/sh (concat shell-args coffee-files))] | |
(apply println (if (= (:exit result) 0) | |
(concat ["Compiled"] (interpose ", " coffee-files)) | |
["Error invoking CoffeeScript compiler:" result]))) | |
(apply eip args))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe it could be interesting for somebody: https://github.com/vbauer/lein-coffeescript