mirror of
https://github.com/logseq/logseq.git
synced 2026-04-26 07:05:10 +00:00
enhance: bb task for creating graphs from EDN file
Converted inferred graph to an EDN file now that this task exists. Also merge last of tasks.create-graph to relevant ns so that external users can also create such tasks
This commit is contained in:
38
deps/db/script/create_graph.cljs
vendored
Normal file
38
deps/db/script/create_graph.cljs
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
(ns create-graph
|
||||
"An example script that creates a DB graph given a sqlite.build EDN file"
|
||||
(:require [logseq.outliner.db-pipeline :as db-pipeline]
|
||||
[clojure.string :as string]
|
||||
[clojure.edn :as edn]
|
||||
[datascript.core :as d]
|
||||
["path" :as node-path]
|
||||
["os" :as os]
|
||||
["fs" :as fs]
|
||||
[nbb.classpath :as cp]
|
||||
[nbb.core :as nbb]))
|
||||
|
||||
(defn- resolve-path
|
||||
"If relative path, resolve with $ORIGINAL_PWD"
|
||||
[path]
|
||||
(if (node-path/isAbsolute path)
|
||||
path
|
||||
(node-path/join (or js/process.env.ORIGINAL_PWD ".") path)))
|
||||
|
||||
(defn -main [args]
|
||||
(when (not= 2 (count args))
|
||||
(println "Usage: $0 GRAPH-DIR EDN-PATH")
|
||||
(js/process.exit 1))
|
||||
(let [[graph-dir edn-path] args
|
||||
[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])
|
||||
sqlite-build-edn (-> (resolve-path edn-path) fs/readFileSync str edn/read-string)
|
||||
conn (db-pipeline/init-conn dir db-name {:classpath (cp/get-classpath)})
|
||||
{:keys [init-tx block-props-tx]} (db-pipeline/build-blocks-tx sqlite-build-edn)]
|
||||
(println "Generating" (count (filter :block/name init-tx)) "pages and"
|
||||
(count (filter :block/content init-tx)) "blocks ...")
|
||||
(d/transact! conn init-tx)
|
||||
(d/transact! conn block-props-tx)
|
||||
(println "Created graph" (str db-name "!"))))
|
||||
|
||||
(when (= nbb/*file* (:file (meta #'-main)))
|
||||
(-main *command-line-args*))
|
||||
Reference in New Issue
Block a user