Skip to content

Instantly share code, notes, and snippets.

@bartojs
Created December 3, 2015 01:51
Show Gist options
  • Save bartojs/851e5103b517549236dd to your computer and use it in GitHub Desktop.
Save bartojs/851e5103b517549236dd to your computer and use it in GitHub Desktop.
boot clj profile for fmt and lein tasks
(deftask fmt
"fmt file or dir using cljfmt (changes files)"
[f files VAL str "file(s) to format"]
(set-env! :dependencies '[[cljfmt "0.3.0"]])
(require 'cljfmt.core
'clojure.java.io)
(let [reformat-string (resolve 'cljfmt.core/reformat-string)
file (resolve 'clojure.java.io/file)
fmt-file (fn [f]
(println "formatting" (.getName f))
(spit f (reformat-string (slurp f))))
clj-file? (fn [f]
(and (.exists f) (.isFile f) (not (.isHidden f))
(contains? #{"clj" "cljs" "cljc" "cljx" "boot"}
(last (.split (.toLowerCase (.getName f)) "\\.")))))
f (file files)]
(when (.exists f)
(doall (map fmt-file (filter clj-file? (if (.isDirectory f) (file-seq f) [f])))))))
(deftask lein
"create a project.clj (for cursive)"
[]
(let [coords [(symbol (or (get-env :project) "boot-project")) (or (get-env :version) "0.1.0-SNAPSHOT")]
proj (into {} (keep #(if-let [x (get-env %)] [% x])
[:url :licence :description :dependencies]))
cljs? (.matches (pr-str (:dependencies proj)) ".*adzerk/boot-cljs .*")
projcljs (update-in proj [:dependencies] conj '[org.clojure/clojurescript "1.7.170"])]
(spit "project.clj" (cons 'defproject (apply concat coords (if cljs? projcljs proj))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment