              (spit "builds/chenex-repl.clj" (str e#)))
          (catch Exception _ (lmain/abort (red-text "Chenex Error: enter the name of a chenex feature\n\n"))))))
 
+
+(defn- write-extension [f filetype]
+  (clojure.string/replace f #"\.cljx$" (str "." filetype)))
+
+(defn- mv-files [cljx out]
+  (map #(sh/sh "mv" % %2) cljx out))
+
+(defn- package
+  "Takes a filetype and sets all cljx files in the source-paths to it so they
+  can be consumed nicely by downstream projects. Use this if you're writing a
+  library with chenex."
+  [filetype project]
+  (if (or (nil? (some #(#{:clj :cljs} %) (map keyword filetype)))
+        (not= 1 (count filetype)))
+    (lmain/abort (red-text "Chenex Error: package requires either clj or cljs"))
+    (let [src (:source-paths project)
+          files (reduce #(into % (file-seq (File. %2))) [] src)
+          cljx? (fn [f]
+                  (re-find #"^(?:(?!#).)*\.cljx$" (str f)))
+          cljx-files (->> files
+                   (filter cljx?)
+                   (map str))
+          new-files (map #(write-extension % (first filetype)) cljx-files)]
+      (doall (mv-files cljx-files new-files)))))
+
+
 (defn chenex
   "Run the chenex compiler"
-  {:help-arglists '([compile build repl])
-   :subtasks [#'compile #'build #'repl]}
+  {:help-arglists '([compile build repl package])
+   :subtasks [#'compile #'build #'repl #'package]}
   ([project]
      (lmain/abort
       (lhelp/help-for "chenex")))

    (do (io/make-parents "builds/chenex-builds.clj")
        (spit "builds/chenex-builds.clj" loc#))))

(defn- repl
  "Sets a new target environment for the REPL iteractively. Enter the name
  of a chenex feature environement"

            [leiningen.core.main :as lmain]
            [leiningen.core.eval :refer (eval-in-project)]
            [clojure.pprint :refer [pprint]]
            [clojure.java.io :as io]
            [clojure.java.shell :as sh])
  (:refer-clojure :exclude [compile])
  (import java.io.File))

(defn- yellow-text [msg] (str "\033[33m" msg "\033[0m"))
(defn- red-text [msg] (str "\033[31m" msg "\033[0m"))
