-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.clj
71 lines (61 loc) · 1.96 KB
/
utils.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
66
67
68
69
70
71
(ns depo.utils
(:require [clojure.string :as s]
[clojure.xml :as xml]))
(defn create-identifier
[groupID artifactID dep-type]
(case dep-type
:map (str groupID "/" artifactID)
:vector (if (= groupID artifactID)
artifactID
(str groupID "/" artifactID))))
(defn create-keys
"- `config-path` - the full path to the config file as a string
Returns
- `:dependencies` for `:lein` and `:shadow`
- `:deps` for `:default`
"
[project-type]
(case project-type
(or :lein :shadow) :dependencies
:default :deps))
(defn get-project-type
"- `config-path` - the full path to the config file as a string
Returns
- `:shadow` for shadow-cljs.edn
- `:lein` for project.clj
- `:default` for everything else
"
[config-path]
(let [config-name (-> config-path
(s/split #"/")
(last))]
(case config-name
"shadow-cljs.edn" :shadow
"project.clj" :lein
:default)))
(defn parse
"Given a dependency string that follows the following schema
`[groupID/]artifactID[@version]`
Returns a map with the keys `:groupID`, `:artifactID`, `:version`
### Examples:
```clj
(parse \"reagent\")
; returns {:groupdID \"reagent\" :artifactID \"reagent\" :version nil}
(parse \"emotion-cljs@0.2.0\"'
; returns {:groupdID \"emotion-cljs\" :artifactID \"emotion-cljs\" :version 0.2.0}
```"
[arg]
(let [[group-artifact version] (if (s/includes? arg "@")
(s/split arg #"@")
[arg nil])
artifactID (last (s/split group-artifact #"/"))
groupID (if (s/includes? group-artifact "/")
(first (s/split group-artifact #"/"))
artifactID)]
{:groupID groupID
:artifactID artifactID
:version version}))
(defn xml->map
"Converts an xml string into Clojure map structure"
[doc]
(-> doc .getBytes java.io.ByteArrayInputStream. xml/parse))