Skip to content

Instantly share code, notes, and snippets.

@FiV0
Last active December 18, 2020 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FiV0/f3112a8b07e4cdfe9f5c7858354c74c1 to your computer and use it in GitHub Desktop.
Save FiV0/f3112a8b07e4cdfe9f5c7858354c74c1 to your computer and use it in GitHub Desktop.
Moving a namespace in a clj/cljs/cljc project with mranderson
;; 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)
@FiV0
Copy link
Author

FiV0 commented Dec 18, 2020

Credit for the snippet goes to @plexus.

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