mirror of
https://github.com/logseq/logseq.git
synced 2026-04-29 16:36:27 +00:00
fix: correctly detect property type
for property values containing text and refs. Also allow import script to only import a file for testing. Part of LOG-2985
This commit is contained in:
23
deps/graph-parser/script/db_import.cljs
vendored
23
deps/graph-parser/script/db_import.cljs
vendored
@@ -6,6 +6,7 @@
|
||||
[datascript.core :as d]
|
||||
["path" :as node-path]
|
||||
["os" :as os]
|
||||
["fs" :as fs]
|
||||
["fs/promises" :as fsp]
|
||||
[nbb.core :as nbb]
|
||||
[babashka.cli :as cli]
|
||||
@@ -31,11 +32,15 @@
|
||||
(->> (common-graph/get-files dir)
|
||||
(mapv #(hash-map :rpath %)))))
|
||||
|
||||
(defn- <read-file
|
||||
[file]
|
||||
(p/let [s (fsp/readFile (:rpath file))]
|
||||
(str s)))
|
||||
|
||||
(defn- import-file-graph-to-db [file-graph-dir conn user-options]
|
||||
(p/let [*files (build-graph-files file-graph-dir)
|
||||
config-file (first (filter #(string/ends-with? (:rpath %) "logseq/config.edn") *files))
|
||||
_ (assert config-file "No 'logseq/config.edn' found for file graph dir")
|
||||
<read-file #(p/let [s (fsp/readFile (:rpath %))] (str s))
|
||||
;; TODO: Add :default-config option
|
||||
config (gp-exporter/import-config-file! conn config-file <read-file {:notify-user prn})
|
||||
files (remove-hidden-files file-graph-dir config *files)
|
||||
@@ -52,6 +57,15 @@
|
||||
(gp-exporter/import-logseq-files conn logseq-files <read-file {:notify-user prn})
|
||||
(gp-exporter/import-from-doc-files! conn doc-files <read-file import-options))))
|
||||
|
||||
(defn- import-files-to-db [file conn user-options]
|
||||
(let [import-options (gp-exporter/setup-import-options
|
||||
@conn
|
||||
{}
|
||||
user-options
|
||||
{:notify-user prn})
|
||||
files [{:rpath file}]]
|
||||
(gp-exporter/import-from-doc-files! conn files <read-file import-options)))
|
||||
|
||||
(def spec
|
||||
"Options spec"
|
||||
{:help {:alias :h
|
||||
@@ -78,9 +92,12 @@
|
||||
((juxt node-path/dirname node-path/basename) graph-dir'))
|
||||
[(node-path/join (os/homedir) "logseq" "graphs") db-graph-dir])
|
||||
file-graph' (node-path/join (or js/process.env.ORIGINAL_PWD ".") file-graph)
|
||||
conn (create-graph/init-conn dir db-name)]
|
||||
conn (create-graph/init-conn dir db-name)
|
||||
directory? (.isDirectory (fs/statSync file-graph'))]
|
||||
(p/do!
|
||||
(import-file-graph-to-db file-graph' conn (merge options {:graph-name db-name}))
|
||||
(if directory?
|
||||
(import-file-graph-to-db file-graph' conn (merge options {:graph-name db-name}))
|
||||
(import-files-to-db file-graph' conn (merge options {:graph-name db-name})))
|
||||
(when (:verbose options) (println "Transacted" (count (d/datoms @conn :eavt)) "datoms"))
|
||||
(println "Created graph" (str db-name "!")))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user