-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartifactory-npm-query.cljs
executable file
·74 lines (62 loc) · 2.75 KB
/
artifactory-npm-query.cljs
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
#!/usr/bin/env nbb
;; Copyright (c) 2024, Viasat, Inc
;; Licensed under EPL 2.0
(ns artifactory-npm-query
(:require [clojure.pprint :refer [pprint]]
[promesa.core :as P]
[cljs-bean.core :refer [->clj]]
[viasat.util :refer [parse-opts Eprintln Eprn Epprint]]
[viasat.schema-print :refer [schema-print]]
[viasat.apis.artifactory :as art]
["dotenv$default" :as dotenv]))
(def usage "
Usage:
artifactory-npm-query [options] <repo> <module-names>...
Options:
--debug Debug output [env: DEBUG]
-v, --verbose Verbose output [env: VERBOSE]
--fields FIELDS Fields to print (comma or space separated)
--sort FIELD Sort using FIELD
--rsort FIELD Reverse sort using FIELD
--field-max FIELD_MAX Maximum field width (when not --verbose) [default: 100]
--no-headers Skip printing headers
--json Print full results as JSON (default)
--edn Print full results as EDN
--pretty Pretty print --json or --edn
--artifactory-base-url URL Artifactory base URL
[env: ARTIFACTORY_BASE_URL]
--artifactory-username USERNAME Artifactory username
[env: ARTIFACTORY_USERNAME]
--artifactory-identity-token TOKEN Artifactory identity token. If no username is
provided, then assume this is a bearer token.
[env: ARTIFACTORY_IDENTITY_TOKEN]")
(def MODULE-SCHEMA
{:fields [:name
:version
:description
:author
:main
:created
[:repository [:repository :url]]
[:shasum [:dist :shasum]]]})
(P/let
[_ (dotenv/config #js {:path ".secrets"})
opts (parse-opts usage (or *command-line-args* []))
{:keys [debug verbose repo module-names
artifactory-base-url artifactory-username artifactory-identity-token]} opts
_ (when debug
(Epprint {:opts opts})
(art/enable-debug))
auth-headers (art/get-auth-headers opts)
opts (assoc opts
:axios-opts {:headers auth-headers}
:artifactory-api (str artifactory-base-url "/api"))
schema MODULE-SCHEMA
modules (if (seq module-names)
module-names
(do
(Eprintln "Getting image names from repo:" repo)
(art/get-npm-modules repo opts)))
_ (Eprintln "Getting information (in parallel) for modules:" modules)
data (art/get-npm-full-modules repo modules opts)]
(schema-print data schema opts))