-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
core.clj
65 lines (53 loc) · 1.88 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(ns polylith.clj.core.common.core
(:require [clojure.string :as str]
[polylith.clj.core.util.interface :as util]
[polylith.clj.core.user-config.interface :as user-config]))
(defn ns-to-path [namespace]
(-> namespace
(str/replace "." "/")
(str/replace "-" "_")))
(defn path-to-ns [namespace]
(-> namespace
(str/replace "/" ".")
(str/replace "_" "-")))
(defn user-path [path]
(when path
(if (str/starts-with? path "~/")
(str (user-config/home-dir)
(subs path 1))
path)))
(defn absolute-path [path entity-root-path]
"entity-root-path will be passed in as e.g. 'components/invoicer' if a brick,
or 'projects/invocing' if a project, and nil if the development project
(dev lives at the root, so keep that path as it is)."
(when path
(if (or (nil? entity-root-path)
(str/starts-with? path "/"))
path
(if (str/starts-with? path "../../")
(subs path 6)
(str entity-root-path "/" path)))))
(defn sufix-ns-with-dot
"Makes sure the namespace ends with a dot (.)"
[top-namespace]
(if (str/ends-with? top-namespace ".")
top-namespace
(str top-namespace ".")))
(defn filter-clojure-paths [paths]
(filterv #(or (str/ends-with? % ".clj")
(str/ends-with? % ".cljc"))
paths))
(defn find-brick [name {:keys [components bases]}]
(let [bricks (concat components bases)]
(util/find-first #(= name (:name %)) bricks)))
(defn find-component [name components]
(util/find-first #(= name (:name %)) components))
(defn find-base [name bases]
(util/find-first #(= name (:name %)) bases))
(defn- =project [{:keys [name alias]} project]
(or (= project name)
(= project alias)))
(defn find-project [name projects]
(util/find-first #(=project % name) projects))
(defn color-mode [{:keys [color-mode]}]
(or color-mode (user-config/color-mode)))