diff --git a/project.clj b/project.clj index e3d372f..e02c3e6 100644 --- a/project.clj +++ b/project.clj @@ -4,12 +4,12 @@ :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :eval-in :leiningen - :plugins [[thomasa/mranderson "0.4.6"]] + :plugins [[thomasa/mranderson "0.4.7-SNAPSHOT"]] :java-source-paths ["java-src"] :javac-options ["-target" "1.6" "-source" "1.6"] :filespecs [{:type :bytes :path "mranderson/project.clj" :bytes ~(slurp "project.clj")}] :dependencies [^:source-dep [com.cemerick/pomegranate "0.3.0"] - ^:source-dep [org.clojure/tools.namespace "0.2.11"] + ^:source-dep [org.clojure/tools.namespace "0.3.0-alpha3"] ^:source-dep [me.raynes/fs "1.4.6"] [com.googlecode.jarjar/jarjar "1.3"]] :profiles {:dev {:dependencies [[org.clojure/clojure "1.7.0"]]}}) diff --git a/src/leiningen/source_deps.clj b/src/leiningen/source_deps.clj index 8904c59..cd9998f 100644 --- a/src/leiningen/source_deps.clj +++ b/src/leiningen/source_deps.clj @@ -14,8 +14,6 @@ (defn- zip-target-file [target-dir entry-path] - ;; remove leading slash in case some bonehead created a zip with absolute - ;; file paths in it. (let [entry-path (str/replace-first (str entry-path) #"^/" "")] (fs/file target-dir entry-path))) @@ -33,7 +31,9 @@ (->> entries (filter #(not (.isDirectory ^java.util.zip.ZipEntry %))) (map #(.getName %)) - (filter #(or (.endsWith % ".clj") (.endsWith % ".cljc"))))))) + (filter #(or (.endsWith % ".clj") + (.endsWith % ".cljc") + (.endsWith % ".cljs"))))))) (defn- cljfile->prefix [clj-file] (->> (str/split clj-file #"/") @@ -44,6 +44,7 @@ (->> clj-files (map cljfile->prefix) (remove #(str/blank? %)) + (remove #(= "clojure.core" %)) (reduce #(if (%1 %2) (assoc %1 %2 (inc (%1 %2))) (assoc %1 %2 1) ) {}) (filter #(< 1 (val %))) (map first) @@ -256,7 +257,7 @@ (doseq [file (clojure-source-files [srcdeps])] (update-deftypes file old-ns new-deftype))) ;; move actual ns-s - (move/move-ns old-ns new-ns srcdeps [srcdeps])) + (move/move-ns old-ns new-ns srcdeps (file->extension (str clj-file)) [srcdeps])) ;; a clj file without ns (when-not (= "project.clj" clj-file) (let [old-path (str "target/srcdeps/" clj-file) diff --git a/src/mranderson/move.clj b/src/mranderson/move.clj index c6fe17d..c7f5836 100644 --- a/src/mranderson/move.clj +++ b/src/mranderson/move.clj @@ -21,7 +21,8 @@ "} mranderson.move (:require [clojure.string :as str] - [clojure.java.io :as io]) + [clojure.java.io :as io] + [mranderson.util :as util]) (:import (java.io File FileNotFoundException))) (defn- update-file @@ -40,26 +41,27 @@ (str/replace "-" "_") (str/replace "." File/separator))) -(defn- find-file-for-sym [path sym] - (->> [".clj" ".cljc"] - (map #(io/file path (str (sym->file-name sym) %))) - (filter #(.exists %)) - first)) - (defn- sym->file [path sym extension] (io/file path (str (sym->file-name sym) extension))) -(defn- clojure-source-files [dirs] +(defn- update? [file extension-of-moved] + (let [file-ext (util/file->extension file) + all-extensions #{".cljc" ".cljs" ".clj"}] + (or + (and (= ".cljc" extension-of-moved) + (all-extensions file-ext)) + (= file-ext extension-of-moved) + (= file-ext ".cljc")))) + +(defn- clojure-source-files [dirs extension] (->> dirs (map io/file) (filter #(.exists ^File %)) (mapcat file-seq) (filter (fn [^File file] (and (.isFile file) - (or - (.endsWith (.getName file) ".clj") - (.endsWith (.getName file) ".cljc"))))) + (update? (str file) extension)))) (map #(.getCanonicalFile ^File %)))) (def ^:private symbol-regex @@ -82,10 +84,6 @@ new-name match))))) -(defn- file->extension - [file] - (re-find #"\.cljc?$" (str file))) - (defn move-ns-file "ALPHA: subject to change. Moves the .clj or .cljc source file (found relative to source-path) for the namespace named old-sym to a file for a @@ -93,9 +91,9 @@ WARNING: This function moves and deletes your source files! Make sure you have a backup or version control." - [old-sym new-sym source-path] - (if-let [old-file (find-file-for-sym source-path old-sym)] - (let [new-file (sym->file source-path new-sym (file->extension old-file))] + [old-sym new-sym extension source-path] + (if-let [old-file (sym->file source-path old-sym extension)] + (let [new-file (sym->file source-path new-sym extension)] (.mkdirs (.getParentFile new-file)) (io/copy old-file new-file) (.delete old-file) @@ -116,7 +114,7 @@ WARNING: This function modifies and deletes your source files! Make sure you have a backup or version control." - [old-sym new-sym source-path dirs] - (move-ns-file old-sym new-sym source-path) - (doseq [file (clojure-source-files dirs)] + [old-sym new-sym source-path extension dirs] + (move-ns-file old-sym new-sym extension source-path) + (doseq [file (clojure-source-files dirs extension)] (update-file file replace-ns-symbol old-sym new-sym))) diff --git a/src/mranderson/util.clj b/src/mranderson/util.clj index b344844..2c22dee 100644 --- a/src/mranderson/util.clj +++ b/src/mranderson/util.clj @@ -23,6 +23,7 @@ (and (.isFile file) (or (.endsWith file-name ".cljc") + (.endsWith file-name ".cljs") (.endsWith file-name ".clj"))))))))) ([dirs] (clojure-source-files-relative dirs nil))) @@ -113,3 +114,7 @@ (assert (string? v) (str "Something went wrong, version is not a string: " v)) v)) + +(defn file->extension + [file] + (re-find #"\.clj[cs]?$" file))