{:paths ["src" "resources"]
 :deps
 {io.lambdaforge/datalog-parser {:mvn/version "0.1.11"}
  me.tagaholic/dlint {:mvn/version "0.1.0"}}
 :tasks
 {:requires ([clojure.string :as str])

  copy-test-db
  {:requires ([cldwalker.logseq-query.util :as util]
              [babashka.fs :as fs])
   :doc "Copy test-notes db from ~/.logseq/graphs to test"
   :task (fs/copy
          (util/get-graph-path "test-notes")
          "test/cldwalker/logseq_query/test-notes.json"
          {:replace-existing true})}

  ;; Publish tasks copied from nbb
  publish {:doc "Bump to version, pushes tag and lets CI publish to npm."
           :task
           (let [version (or (first *command-line-args*)
                             (throw (ex-info "No version given!" {})))]
             (shell "npm version" version)
             (shell "git push --atomic origin main" (str "v" version)))}

  current-tag (->> (shell {:out :string} "git describe")
                   :out
                   str/trim
                   (re-matches (re-pattern "^v\\d+\\.\\d+\\.\\d+")))

  current-branch (->> (shell {:out :string} "git rev-parse --abbrev-ref HEAD")
                      :out
                      str/trim)

  ci:is-release {:depends [current-tag current-branch]
                 :task (and current-tag (= "main" current-branch))}

  ci:publish {:doc "Publishes release build to npm"
              :depends [ci:is-release]
              :task
              (if ci:is-release
                (do
                  (println "Releasing")
                  (shell "npm publish"))
                (println "Skipping release."))}}}
