publishing.cljs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. (ns publishing
  2. "Basic script for publishing from CLI"
  3. (:require ["path" :as node-path]
  4. [clojure.edn :as edn]
  5. [datascript.core :as d]
  6. [logseq.db.common.sqlite-cli :as sqlite-cli]
  7. [logseq.db.sqlite.util :as sqlite-util]
  8. [logseq.publishing :as publishing]
  9. [nbb.core :as nbb]))
  10. (defn- publish-db-graph [static-dir graph-dir output-path opts]
  11. (let [db-name (node-path/basename graph-dir)
  12. conn (sqlite-cli/open-db! (node-path/dirname graph-dir) db-name)
  13. repo-config (-> (d/q '[:find ?content
  14. :where [?b :file/path "logseq/config.edn"] [?b :file/content ?content]]
  15. @conn)
  16. ffirst
  17. edn/read-string)]
  18. (publishing/export @conn
  19. static-dir
  20. graph-dir
  21. output-path
  22. (merge opts {:repo (str sqlite-util/db-version-prefix db-name)
  23. :repo-config repo-config
  24. :ui/theme "dark"
  25. :ui/radix-color :cyan}))))
  26. (defn- resolve-path
  27. "If relative path, resolve with $ORIGINAL_PWD"
  28. [path]
  29. (if (node-path/isAbsolute path)
  30. path
  31. (node-path/join (or js/process.env.ORIGINAL_PWD ".") path)))
  32. (defn -main
  33. [args]
  34. (when (< (count args) 3)
  35. (println "Usage: $0 STATIC-DIR GRAPH-DIR OUT-DIR")
  36. (js/process.exit 1))
  37. (let [[static-dir graph-dir output-path] (map resolve-path args)
  38. options {:dev? (contains? (set args) "--dev")}]
  39. (publish-db-graph static-dir graph-dir output-path options)))
  40. (when (= nbb/*file* (nbb/invoked-file))
  41. (-main *command-line-args*))