aboutsummaryrefslogtreecommitdiff
path: root/challenge-131/tyler-wardhaugh/clojure/bb.edn
blob: 4cd11817b8b409741b5e439e8973d61a187af550 (plain)
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
{
 :paths ["src"]
 :deps {}
 
 :tasks
 {
  :requires ([clojure.java.io :as io]
             [clojure.edn :as edn]
             [babashka.fs :as fs])
  :init (do
          (defn get-first-form
            [file]
            (with-open [r (-> file fs/file io/reader)
                        pr (java.io.PushbackReader. r)]
              (edn/read pr)))

          (defn get-task-ns
            [task]
            (let [glob-target (format "src/tw/weekly/*/%s.clj" (name task))
                  file (->> glob-target (fs/glob ".") first)]
              (-> file get-first-form second str)))

          (defn run-task
            [task args]
            (let [clj-options (format "-M -m %s " (get-task-ns task))]
              (apply clojure clj-options args)))

          (defn run-task-bb
            [task args]
            (let [bb-cmd (format "bb -m %s " (get-task-ns task))]
              (apply shell bb-cmd args))))

  clean {:doc "Clean out temporary files"
         :task (run! fs/delete-tree [".nrepl-port" ".cpcache" ".lsp"])}

  generate-pom {:doc "Generate POM file"
                :task (clojure "-X:deps mvn-pom")}

  generate-jar {:doc "Generate JAR file"
                :depends [generate-pom]
                :task (clojure "-X:jar")}

  publish {:doc "Publish branch via git-push to REPO (default: origin)"
           :requires ([clojure.string :as str]
                      [babashka.process :as p :refer [process]])
           :task (let [repo (or (first *command-line-args*) "origin")
                       current-branch (-> (p/$ git branch --show-current)
                                          p/check
                                          :out
                                          slurp
                                          str/trim-newline)
                       cmd '[git push --force-with-lease --set-upstream]
                       args [repo current-branch]]
                   (-> (process (concat cmd args) {:inherit true})
                       p/check))}

  test {:doc "Run tests"
        :task (clojure "-X:test")}

  c**** {:doc "CHALLENGE TASKS"}

  task-1 {:doc "Run Task 1 (via clojure)"
          :task (run-task :t1 *command-line-args*)}

  task-1-bb {:doc "Run Task 1 (via Babashka)"
             :task (run-task-bb :t1 *command-line-args*)}

  task-2 {:doc "Run Task 2 (via clojure)"
          :task (run-task :t2 *command-line-args*)}

  task-2-bb {:doc "Run Task 2 (via Babashka)"
             :task (run-task-bb :t2 *command-line-args*)}

  both {:doc "Run both tasks (via clojure)"
        :task (do
                (println "Task 1:")
                (run 'task-1)
                (println "\nTask 2:")
                (run 'task-2))}

  both-bb {:doc "Run both tasks (via Babashka)"
           :task (do
                   (println "Task 1:")
                   (run 'task-1-bb)
                   (println "\nTask 2:")
                   (run 'task-2-bb))}

  }
}