This repository has been archived by the owner on Dec 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
63 lines (49 loc) · 1.63 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
(ns cocoapods-acknowledgements-licenses.core
"Parse Apple Plist file with CocoaPods dependencies into clojure native map"
(:gen-class)
(:require
;;[clojure.spec.test.alpha :refer [instrument]]
[clojure.spec.alpha :as s]
[com.github.bdesham.clj-plist :refer [parse-plist]]))
;; Specs
(s/def ::nilable-str (s/nilable string?))
(s/def ::package ::nilable-str)
(s/def ::license ::nilable-str)
(s/def ::path string?)
(s/def ::options (s/map-of keyword? any?))
(s/def ::plist-item (s/map-of string? any?))
(s/def ::data
(s/cat :package ::package :license ::license))
(s/def ::package-data
(s/nilable (s/coll-of ::version)))
;; Const
(def key-specifiers "PreferenceSpecifiers")
(def key-package-name "Title")
(def key-license-name "License")
;; Helpers
(s/fdef plist-item->map
:args ::plist-item
:ret ::data)
(defn- plist-item->map
"Convert plist item map to proper format"
[item]
(let [package (get item key-package-name)
license (get item key-license-name)]
{:package package :license license}))
;; Entrypoint
(s/fdef plist->data
:args (s/cat
:path ::path
:options ::options)
:ret ::data)
(defn plist->data
"Parse Plist into vector of {:package PACKAGE :license LICENSE} maps"
[path options]
(let [{:keys [skip-header skip-footer] :or {skip-header true skip-footer true}} options
parsed-plist (parse-plist path)
deps (get parsed-plist key-specifiers)
formatted (map plist-item->map deps)
formatted' (if skip-header (rest formatted) formatted)
formatted'' (if skip-footer (butlast formatted') formatted')]
formatted''))
;; (instrument `plist->data)