forked from logseq/marketplace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bb.edn
89 lines (80 loc) · 2.79 KB
/
bb.edn
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;; To use this: Install babashka - https://github.com/babashka/babashka#installation
{:tasks
{:requires ([cheshire.core :as json]
[clojure.pprint :as pprint])
:init
(do
(def default-fields [:id :author :repo])
(defn- plugins []
(-> "plugins.json" slurp (json/parse-string keyword) :packages))
(defn print-table [rows]
(pprint/print-table rows)
(println "Total:" (count rows) "rows"))
)
plugins
{:doc "List all plugins"
:task
(->> (plugins)
(mapv (fn [p] (select-keys p default-fields)))
print-table)}
non-theme-plugins
{:doc "List non theme plugins"
:task
(->> (plugins)
(remove :theme)
(mapv (fn [p] (select-keys p default-fields)))
print-table)}
theme-plugins
{:doc "List theme plugins"
:task
(->> (plugins)
(filter :theme)
(mapv (fn [p] (select-keys p default-fields)))
print-table)}
author-stats
{:doc "List stats by author"
:task
(->> (plugins)
(group-by :author)
(sort-by (comp count second) >)
(map (fn [[k v]] {:author k :plugin-count (count v)}))
print-table)}
plugin-stats
{:doc "List stats by plugin"
:task
(let [stats-map (-> "stats.json"
slurp
(json/parse-string keyword))
plugin->author (into {} (map (juxt :id :author) (plugins)))
stats (->> stats-map
(map (fn [[k v]]
{:plugin k
:author (plugin->author (name k))
:releases (count (:releases v))
:downloads (apply + (map (fn [v] (nth v 2)) (:releases v)))
:stargazers (:stargazers_count v)}))
(sort-by :downloads >))]
(print-table stats)
(println "Total Downloads:" (apply + (map :downloads stats))))}
validate-plugins
{:doc "Validate plugins.json"
:extra-deps {org.babashka/spec.alpha
{:git/url "https://github.com/babashka/spec.alpha"
:sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}}
:requires ([clojure.spec.alpha :as s])
:task
(let [plugins' (plugins)]
;; Define specs for valid plugins
(s/def :bb/title string?)
(s/def :bb/description string?)
(s/def :bb/author string?)
(s/def :bb/repo string?)
(s/def :bb/plugin (s/keys :req-un [:bb/title :bb/description
:bb/author :bb/repo]))
(s/def :bb/plugins (s/coll-of :bb/plugin))
(if-let [errors (s/explain-data :bb/plugins plugins')]
(do
(pprint/pprint {:errors (:clojure.spec.alpha/problems errors)
:message "Invalid plugins found"})
(System/exit 1))
(println "All plugins are valid!")))}}}