mirror of
https://github.com/logseq/logseq.git
synced 2026-05-28 14:39:48 +00:00
enhance: properties graph script supports additional config
e.g. `-c '{:publishing/all-pages-public? true}'` to turn on publishing
by default
This commit is contained in:
@@ -24,22 +24,28 @@
|
||||
|
||||
(defn- setup-init-data
|
||||
"Setup initial data same as frontend.handler.repo/create-db"
|
||||
[conn]
|
||||
(let [config-content (or (some-> (find-on-classpath "templates/config.edn") fs/readFileSync str)
|
||||
(do (println "Setting graph's config to empty since no templates/config.edn was found.")
|
||||
"{}"))]
|
||||
[conn additional-config]
|
||||
(let [config-content
|
||||
(cond-> (or (some-> (find-on-classpath "templates/config.edn") fs/readFileSync str)
|
||||
(do (println "Setting graph's config to empty since no templates/config.edn was found.")
|
||||
"{}"))
|
||||
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"))))]
|
||||
(d/transact! conn (sqlite-create-graph/build-db-initial-data @conn config-content))))
|
||||
|
||||
(defn init-conn
|
||||
"Create sqlite DB, initialize datascript connection and sync listener and then
|
||||
transacts initial data"
|
||||
[dir db-name]
|
||||
[dir db-name & {:keys [additional-config]}]
|
||||
(fs/mkdirSync (node-path/join dir db-name) #js {:recursive true})
|
||||
;; Same order as frontend.db.conn/start!
|
||||
(let [conn (sqlite-db/open-db! dir db-name)]
|
||||
(cli-pipeline/add-listener conn)
|
||||
(ldb/create-default-pages! conn {:db-graph? true})
|
||||
(setup-init-data conn)
|
||||
(setup-init-data conn additional-config)
|
||||
conn))
|
||||
|
||||
(defn- translate-property-value
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
[logseq.common.util.page-ref :as page-ref]
|
||||
[logseq.db.frontend.property.type :as db-property-type]
|
||||
[clojure.string :as string]
|
||||
[clojure.edn :as edn]
|
||||
[datascript.core :as d]
|
||||
["path" :as node-path]
|
||||
["os" :as os]
|
||||
[babashka.cli :as cli]
|
||||
[nbb.core :as nbb]))
|
||||
|
||||
(defn- date-journal-title [date]
|
||||
@@ -163,15 +165,25 @@
|
||||
[:default :url :number :page :date]))
|
||||
(into {}))}))
|
||||
|
||||
(def spec
|
||||
"Options spec"
|
||||
{:help {:alias :h
|
||||
:desc "Print help"}
|
||||
:config {:alias :c
|
||||
:coerce edn/read-string
|
||||
:desc "EDN map to add to config.edn"}})
|
||||
|
||||
(defn -main [args]
|
||||
(when (not= 1 (count args))
|
||||
(println "Usage: $0 GRAPH-DIR")
|
||||
(js/process.exit 1))
|
||||
(let [graph-dir (first args)
|
||||
options (cli/parse-opts args {:spec spec})
|
||||
_ (when (or (nil? graph-dir) (:help options))
|
||||
(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 (create-graph/init-conn dir db-name)
|
||||
conn (create-graph/init-conn dir db-name {:additional-config (:config options)})
|
||||
blocks-tx (create-graph/create-blocks-tx
|
||||
@conn
|
||||
(create-init-data)
|
||||
|
||||
Reference in New Issue
Block a user