-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbb.edn
43 lines (41 loc) · 2.64 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
{:paths ["src" "resources"]
:tasks {:requires ([babashka.fs :as fs]
[clojure.string :as str]
[clojure.java.io :as io]
[babashka.curl :as curl])
-input-dir "resources/inputs"
-load-template {:task (slurp (io/resource "template.clj"))}
-parse-day-args {:task (let [now (new java.util.Date)
year (.format (java.text.SimpleDateFormat. "yyyy") now)
day (.format (java.text.SimpleDateFormat. "d") now)]
(condp = (count *command-line-args*)
1 [(first *command-line-args*) year]
2 [(first *command-line-args*) (second *command-line-args*)]
[day year]))}
-download-input {:task (let [[day year] (run '-parse-day-args)
path (fs/path (run '-input-dir) year)
file-name (format "day%02d.txt" (Integer/parseInt day))
url (format "https://adventofcode.com/%s/day/%s/input" year day)
resp (curl/get url {:headers {"Cookie" (str "session=" (System/getenv "AOC_TOKEN"))
"User-Agent" (System/getenv "AOC_USER_AGENT")}})]
(when-not (fs/exists? path)
(fs/create-dir path))
(spit (str (fs/path path file-name)) (:body resp)))}
new-day {:doc "Create the next day from the template."
:depends [-download-input]
:task (let [[day year] (run '-parse-day-args)
day (format "%02d" (Integer/parseInt day))
template (run '-load-template)
path (fs/path "src" "solutions" year)
file-name (format "day%s.clj" day)]
(print (format "Creating template for %s/%s" day year))
;; Create the year path if missing
(when-not (fs/exists? path)
(fs/create-dir path))
(spit
(str (fs/path path file-name))
(-> template
(str/replace (re-pattern "YEAR") year)
(str/replace (re-pattern "DAY") day))))}
serve {:task (clojure "-M:serve")}
build {:task (clojure "-M:nextjournal/clerk")}}}