mirror of
https://github.com/logseq/logseq.git
synced 2026-04-29 08:26: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:
@@ -4,7 +4,6 @@
|
||||
NOTE: This script is also used in CI to confirm graph creation works"
|
||||
(:require ["fs" :as fs]
|
||||
["fs-extra$default" :as fse]
|
||||
["os" :as os]
|
||||
["path" :as node-path]
|
||||
[babashka.cli :as cli]
|
||||
[cljs.pprint :as pprint]
|
||||
@@ -18,7 +17,8 @@
|
||||
[logseq.db.frontend.property.type :as db-property-type]
|
||||
[logseq.outliner.cli :as outliner-cli]
|
||||
[nbb.classpath :as cp]
|
||||
[nbb.core :as nbb]))
|
||||
[nbb.core :as nbb]
|
||||
[logseq.db.common.sqlite-cli :as sqlite-cli]))
|
||||
|
||||
(defn- date-journal-title [date]
|
||||
(date-time-util/int->journal-title (date-time-util/date->int date) "MMM do, yyyy"))
|
||||
@@ -210,14 +210,15 @@
|
||||
(println (str "Usage: $0 GRAPH-NAME [OPTIONS]\nOptions:\n"
|
||||
(cli/format-opts {:spec spec})))
|
||||
(js/process.exit 1))
|
||||
[dir db-name] (if (string/includes? graph-dir "/")
|
||||
((juxt node-path/dirname node-path/basename) graph-dir)
|
||||
[(node-path/join (os/homedir) "logseq" "graphs") graph-dir])
|
||||
db-path (node-path/join dir db-name "db.sqlite")
|
||||
_ (when (fs/existsSync db-path)
|
||||
init-conn-args (sqlite-cli/->open-db-args graph-dir)
|
||||
db-name (if (= 1 (count init-conn-args)) (first init-conn-args) (second init-conn-args))
|
||||
db-path (apply node-path/join init-conn-args)
|
||||
;; Only remove the directory if the directory is being overwritten
|
||||
_ (when (and (= 2 (count init-conn-args)) (fs/existsSync db-path))
|
||||
(fse/removeSync db-path))
|
||||
conn (outliner-cli/init-conn dir db-name {:additional-config (:config options)
|
||||
:classpath (cp/get-classpath)})
|
||||
conn (apply outliner-cli/init-conn
|
||||
(conj init-conn-args {:additional-config (:config options)
|
||||
:classpath (cp/get-classpath)}))
|
||||
init-data (create-init-data)
|
||||
_ (when (:file options) (fs/writeFileSync (:file options) (with-out-str (pprint/pprint init-data))))
|
||||
{:keys [init-tx block-props-tx]} (outliner-cli/build-blocks-tx init-data)
|
||||
@@ -226,7 +227,6 @@
|
||||
(when (seq conflicting-names)
|
||||
(println "Error: Following names conflict -" (string/join "," conflicting-names))
|
||||
(js/process.exit 1))
|
||||
(println "DB dir: " (node-path/join dir db-name))
|
||||
(println "Generating" (count (filter :block/name init-tx)) "pages and"
|
||||
(count (filter :block/title init-tx)) "blocks ...")
|
||||
(d/transact! conn init-tx)
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
type logseq doesnt' support yet
|
||||
* schema.org assumes no cardinality. For now, only :node properties are given a :cardinality :many"
|
||||
(:require ["fs" :as fs]
|
||||
["os" :as os]
|
||||
["path" :as node-path]
|
||||
[babashka.cli :as cli]
|
||||
[clojure.edn :as edn]
|
||||
[clojure.set :as set]
|
||||
@@ -23,7 +21,8 @@
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[logseq.outliner.cli :as outliner-cli]
|
||||
[nbb.classpath :as cp]
|
||||
[nbb.core :as nbb]))
|
||||
[nbb.core :as nbb]
|
||||
[logseq.db.common.sqlite-cli :as sqlite-cli]))
|
||||
|
||||
(defn- get-comment-string
|
||||
[rdfs-comment renamed-pages]
|
||||
@@ -406,11 +405,11 @@
|
||||
(println (str "Usage: $0 GRAPH-NAME [OPTIONS]\nOptions:\n"
|
||||
(cli/format-opts {:spec spec})))
|
||||
(js/process.exit 1))
|
||||
[dir db-name] (if (string/includes? graph-dir "/")
|
||||
((juxt node-path/dirname node-path/basename) graph-dir)
|
||||
[(node-path/join (os/homedir) "logseq" "graphs") graph-dir])
|
||||
conn (outliner-cli/init-conn dir db-name {:additional-config (:config options)
|
||||
:classpath (cp/get-classpath)})
|
||||
init-conn-args (sqlite-cli/->open-db-args graph-dir)
|
||||
db-name (if (= 1 (count init-conn-args)) (first init-conn-args) (second init-conn-args))
|
||||
conn (apply outliner-cli/init-conn
|
||||
(conj init-conn-args {:additional-config (:config options)
|
||||
:classpath (cp/get-classpath)}))
|
||||
init-data (create-init-data (d/q '[:find [?name ...] :where [?b :block/name ?name]] @conn)
|
||||
options)
|
||||
{:keys [init-tx block-props-tx]} (outliner-cli/build-blocks-tx init-data)]
|
||||
|
||||
Reference in New Issue
Block a user