浏览代码

enhance(dev): CLI built db graphs

have same config.edn as UI ones. Also improve over hack to add
additional config now that rewrite-clj is available
Gabriel Horner 5 月之前
父节点
当前提交
f896a774ed
共有 3 个文件被更改,包括 19 次插入6 次删除
  1. 1 0
      deps/db/deps.edn
  2. 2 0
      deps/db/nbb.edn
  3. 16 6
      deps/outliner/src/logseq/outliner/cli.cljs

+ 1 - 0
deps/db/deps.edn

@@ -12,6 +12,7 @@
   logseq/common                {:local/root "../common"}
   logseq/clj-fractional-indexing        {:git/url "https://github.com/logseq/clj-fractional-indexing"
                                          :sha     "7182b7878410f78536dc2b6df35ed32ef9cd6b61"}
+  borkdude/rewrite-edn {:mvn/version "0.4.9"}
   metosin/malli {:mvn/version "0.16.1"}
   medley/medley {:mvn/version "1.4.0"}}
 

+ 2 - 0
deps/db/nbb.edn

@@ -4,6 +4,8 @@
   {:local/root "../common"}
   medley/medley {:mvn/version "1.4.0"}
   metosin/malli {:mvn/version "0.16.1"}
+  ;; Used by db scripts with outliner.cli
+  borkdude/rewrite-edn {:mvn/version "0.4.9"}
   logseq/clj-fractional-indexing        {:git/url "https://github.com/logseq/clj-fractional-indexing"
                                          :sha     "7182b7878410f78536dc2b6df35ed32ef9cd6b61"}
   io.github.nextjournal/nbb-test-runner

+ 16 - 6
deps/outliner/src/logseq/outliner/cli.cljs

@@ -1,13 +1,15 @@
 (ns ^:node-only logseq.outliner.cli
   "Primary ns for outliner CLI fns"
-  (:require [clojure.string :as string]
+  (:require [borkdude.rewrite-edn :as rewrite]
+            [clojure.string :as string]
             [datascript.core :as d]
             [logseq.db.sqlite.create-graph :as sqlite-create-graph]
             [logseq.db.sqlite.build :as sqlite-build]
             [logseq.db.common.sqlite-cli :as sqlite-cli]
             [logseq.outliner.db-pipeline :as db-pipeline]
             ["fs" :as fs]
-            ["path" :as node-path]))
+            ["path" :as node-path]
+            [logseq.common.config :as common-config]))
 
 (defn- find-on-classpath [classpath rel-path]
   (some (fn [dir]
@@ -15,6 +17,15 @@
             (when (fs/existsSync f) f)))
         (string/split classpath #":")))
 
+(defn- pretty-print-merge
+  "Merge map into string while preversing whitespace"
+  [s m]
+  (-> (reduce (fn [acc [k v]]
+                (rewrite/assoc acc k v))
+              (rewrite/parse-string s)
+              m)
+      str))
+
 (defn- setup-init-data
   "Setup initial data same as frontend.handler.repo/create-db"
   [conn {:keys [additional-config classpath import-type]
@@ -23,11 +34,10 @@
         (cond-> (or (some-> (find-on-classpath classpath "templates/config.edn") fs/readFileSync str)
                     (do (println "Setting graph's config to empty since no templates/config.edn was found.")
                         "{}"))
+          true
+          (common-config/create-config-for-db-graph)
           additional-config
-          ;; TODO: Replace with rewrite-clj when it's available
-          (string/replace-first #"(:file/name-format :triple-lowbar)"
-                                (str "$1 "
-                                     (string/replace-first (str additional-config) #"^\{(.*)\}$" "$1"))))]
+          (pretty-print-merge additional-config))]
     (d/transact! conn (sqlite-create-graph/build-db-initial-data config-content {:import-type import-type}))))
 
 (defn init-conn