mirror of
https://github.com/logseq/logseq.git
synced 2026-04-28 16:15:21 +00:00
enhance(dev): scripts can read or write db graphs as full path files
This allows for easier use of debugging graphs as they are exported by users as a file. Also DRYed up duplicated helper
This commit is contained in:
17
deps/db/script/export_graph.cljs
vendored
17
deps/db/script/export_graph.cljs
vendored
@@ -1,12 +1,9 @@
|
||||
(ns export-graph
|
||||
"A script that exports a graph to a sqlite.build EDN file"
|
||||
(:require ["fs" :as fs]
|
||||
["os" :as os]
|
||||
["path" :as node-path]
|
||||
[babashka.cli :as cli]
|
||||
[clojure.edn :as edn]
|
||||
[clojure.pprint :as pprint]
|
||||
[clojure.string :as string]
|
||||
[logseq.db.common.sqlite-cli :as sqlite-cli]
|
||||
[logseq.db.sqlite.export :as sqlite-export]
|
||||
[nbb.core :as nbb]))
|
||||
@@ -18,17 +15,6 @@
|
||||
path
|
||||
(node-path/join (or js/process.env.ORIGINAL_PWD ".") path)))
|
||||
|
||||
(defn- get-dir-and-db-name
|
||||
"Gets dir and db name for use with open-db! Works for relative and absolute paths and
|
||||
defaults to ~/logseq/graphs/ when no '/' present in name"
|
||||
[graph-dir]
|
||||
(if (string/includes? graph-dir "/")
|
||||
(let [resolve-path' #(if (node-path/isAbsolute %) %
|
||||
;; $ORIGINAL_PWD used by bb tasks to correct current dir
|
||||
(node-path/join (or js/process.env.ORIGINAL_PWD ".") %))]
|
||||
((juxt node-path/dirname node-path/basename) (resolve-path' graph-dir)))
|
||||
[(node-path/join (os/homedir) "logseq" "graphs") graph-dir]))
|
||||
|
||||
(def spec
|
||||
"Options spec"
|
||||
{:help {:alias :h
|
||||
@@ -54,8 +40,7 @@
|
||||
(println (str "Usage: $0 GRAPH-NAME [& ARGS] [OPTIONS]\nOptions:\n"
|
||||
(cli/format-opts {:spec spec})))
|
||||
(js/process.exit 1))
|
||||
[dir db-name] (get-dir-and-db-name graph-dir)
|
||||
conn (sqlite-cli/open-db! dir db-name)
|
||||
conn (apply sqlite-cli/open-db! (sqlite-cli/->open-db-args graph-dir))
|
||||
export-options (dissoc options :file)
|
||||
export-map (sqlite-export/build-export @conn {:export-type :graph :graph-options export-options})]
|
||||
(if (:file options)
|
||||
|
||||
Reference in New Issue
Block a user