mirror of
https://github.com/logseq/logseq.git
synced 2026-04-28 08:04:40 +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:
20
deps/db/script/diff_graphs.cljs
vendored
20
deps/db/script/diff_graphs.cljs
vendored
@@ -1,27 +1,13 @@
|
||||
(ns diff-graphs
|
||||
"A script that diffs two DB graphs through their sqlite.build EDN"
|
||||
(:require ["os" :as os]
|
||||
["path" :as node-path]
|
||||
[babashka.cli :as cli]
|
||||
(:require [babashka.cli :as cli]
|
||||
[clojure.data :as data]
|
||||
[clojure.pprint :as pprint]
|
||||
[clojure.string :as string]
|
||||
[logseq.common.config :as common-config]
|
||||
[logseq.db.common.sqlite-cli :as sqlite-cli]
|
||||
[logseq.db.sqlite.export :as sqlite-export]
|
||||
[nbb.core :as nbb]))
|
||||
|
||||
(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
|
||||
@@ -43,8 +29,8 @@
|
||||
(println (str "Usage: $0 GRAPH-NAME GRAPH-NAME2 [& ARGS] [OPTIONS]\nOptions:\n"
|
||||
(cli/format-opts {:spec spec})))
|
||||
(js/process.exit 1))
|
||||
conn (apply sqlite-cli/open-db! (get-dir-and-db-name graph-dir))
|
||||
conn2 (apply sqlite-cli/open-db! (get-dir-and-db-name graph-dir2))
|
||||
conn (apply sqlite-cli/open-db! (sqlite-cli/->open-db-args graph-dir))
|
||||
conn2 (apply sqlite-cli/open-db! (sqlite-cli/->open-db-args graph-dir2))
|
||||
export-options (select-keys options [:include-timestamps? :exclude-namespaces :exclude-built-in-pages?])
|
||||
export-map (sqlite-export/build-export @conn {:export-type :graph :graph-options export-options})
|
||||
export-map2 (sqlite-export/build-export @conn2 {:export-type :graph :graph-options export-options})
|
||||
|
||||
Reference in New Issue
Block a user