Skip to content

Instantly share code, notes, and snippets.

@aviflax
Created July 19, 2012 23:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aviflax/3147740 to your computer and use it in GitHub Desktop.
Save aviflax/3147740 to your computer and use it in GitHub Desktop.
Compile your CoffeeScript along with your Clojure
;;; 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)))
@vbauer
Copy link

vbauer commented Sep 7, 2014

Maybe it could be interesting for somebody: https://github.com/vbauer/lein-coffeescript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment