-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
core.clj
46 lines (38 loc) · 1.73 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(ns polylith.clj.core.test-helper.core
(:require [clojure.pprint :as pp]
[clojure.string :as str]
[polylith.clj.core.file.interface :as file]
[polylith.clj.core.command.interface :as command]
[polylith.clj.core.user-input.interface :as user-input]
[polylith.clj.core.user-config.interface :as user-config]))
(def user-home "USER-HOME")
(def root-dir (atom nil))
(defn sub-dir [dir]
(str @root-dir "/" dir))
(defn test-setup-and-tear-down [function]
(let [path (file/create-temp-dir "polylith-root")]
(if path
(do
(reset! root-dir path)
(file/create-dir (sub-dir user-home)))
(throw (Exception. "Could not create temp directory")))
(function)
(file/delete-dir path)))
(defn execute-command [current-dir args]
(with-redefs [file/current-dir (fn [] (if (str/blank? current-dir)
@root-dir
(str @root-dir "/" current-dir)))
user-config/home-dir (fn [] (str @root-dir "/" user-home))]
(let [input (user-input/extract-params args)]
(command/execute-command input))))
(defn paths [dir]
(let [paths (-> dir sub-dir file/relative-paths)]
(set (filter #(not (str/starts-with? (str %) ".git/")) paths))))
(defn content [dir filename]
(str/split-lines (slurp (str (sub-dir dir) "/" filename))))
(defn update-dev-paths! [deps-file project-key path]
(let [content (-> deps-file file/read-file first)
paths (-> content :aliases project-key :extra-paths)
new-content (assoc-in content [:aliases project-key :extra-paths]
(conj paths path))]
(pp/pprint new-content (clojure.java.io/writer deps-file))))