forked from juxt/pack.alpha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_lambda.clj
75 lines (69 loc) · 2.17 KB
/
aws_lambda.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
72
73
74
75
(ns mach.pack.alpha.aws-lambda
(:require
[clojure.java.io :as io]
[clojure.string :as string]
[clojure.tools.cli :as cli]
[mach.pack.alpha.impl.tools-deps :as tools-deps]
[mach.pack.alpha.impl.elodin :as elodin]
[mach.pack.alpha.impl.vfs :as vfs]
[mach.pack.alpha.impl.lib-map :as lib-map]))
(defn write-zip
[{::tools-deps/keys [lib-map paths]} output]
(vfs/write-vfs
{:type :zip
:stream (io/output-stream output)}
(concat
(map
(fn [{:keys [path] :as all}]
{:input (io/input-stream path)
:path ["lib" (elodin/jar-name all)]})
(lib-map/lib-jars lib-map))
(map
(fn [{:keys [path lib] :as all}]
{:paths (vfs/files-path
(file-seq (io/file path))
(io/file path))
:path ["lib" (format "%s.jar" (elodin/directory-name all))]})
(lib-map/lib-dirs lib-map))
(mapcat
(fn [dir]
(let [root (io/file dir)]
(vfs/files-path
(file-seq root)
root)))
paths))))
(defn- usage
[summary]
(->>
["Usage: clj -m mach.pack.alpha.aws-lambda [options] <path/to/output.zip>"
""
"Options:"
summary
""
"output.zip is where to put the output zip. Leading directories will be created."]
(string/join \newline)))
(defn- error-msg [errors]
(str "The following errors occurred while parsing your command:\n\n"
(string/join \newline errors)))
(defn -main
[& args]
(let [{{:keys [help main]
:as options} :options
[jar-location] :arguments
:as parsed-opts} (cli/parse-opts
args
(concat tools-deps/cli-spec
[["-h" "--help" "show this help"]]))
errors (cond-> (:errors parsed-opts)
(not jar-location)
(conj "Output must be specified"))]
(cond
help
(println (usage (:summary parsed-opts)))
errors
(println (error-msg errors))
:else
(write-zip
(-> (tools-deps/slurp-deps options)
(tools-deps/parse-deps-map options))
jar-location))))