Last active
December 18, 2020 18:02
-
-
Save FiV0/f3112a8b07e4cdfe9f5c7858354c74c1 to your computer and use it in GitHub Desktop.
Moving a namespace in a clj/cljs/cljc project with mranderson
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
;; needed if you don't use leiningen | |
(do | |
(create-ns 'leiningen.core.main) | |
(intern 'leiningen.core.main 'warn #(apply println "[warn]" %&)) | |
(intern 'leiningen.core.main 'info #(apply println "[info]" %&)) | |
(intern 'leiningen.core.main 'debug #(apply println "[debug]" %&)) | |
(dosync (commute @#'clojure.core/*loaded-libs* conj 'leiningen.core.main))) | |
(require '[mranderson.move :as move]) | |
(require '[clojure.java.io :as io]) | |
(require '[clojure.string :as str]) | |
(defn munge-name [lib] | |
(.. (name lib) | |
(replace \- \_) | |
(replace \. \/))) | |
(defn ns-file [sym] | |
(io/file (some #(io/resource (str (munge-name sym) "." %)) ["clj" "cljc" "cljs"]))) | |
(defn ns-extension [ns-name] | |
(let [f (str (ns-file ns-name))] | |
(subs f (str/last-index-of f ".")))) | |
(move/move-ns | |
'io.your.app.logging ;; source namespace | |
'io.your.app.log ;; target namespace | |
(io/file "src") ;; where one can find your namespace | |
(ns-extension 'io.your.app.logging) | |
(list (io/file "src")) ;; all directories where namespaces should be renamed | |
nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit for the snippet goes to @plexus.