|
@@ -1,20 +1,28 @@
|
|
|
(ns ^:node-only logseq.cli.util
|
|
|
"CLI only util fns"
|
|
|
(:require ["path" :as node-path]
|
|
|
+ ["fs" :as fs]
|
|
|
[clojure.string :as string]
|
|
|
[logseq.cli.common.graph :as cli-common-graph]
|
|
|
[logseq.db.common.sqlite :as common-sqlite]
|
|
|
[nbb.error]
|
|
|
[promesa.core :as p]))
|
|
|
|
|
|
-(defn get-graph-dir
|
|
|
- [graph]
|
|
|
- (node-path/join (cli-common-graph/get-db-graphs-dir) (common-sqlite/sanitize-db-name graph)))
|
|
|
-
|
|
|
(defn ->open-db-args
|
|
|
"Creates args for sqlite-cli/open-db! given a graph. Similar to sqlite-cli/->open-db-args"
|
|
|
[graph]
|
|
|
- [(cli-common-graph/get-db-graphs-dir) (common-sqlite/sanitize-db-name graph)])
|
|
|
+ (cond
|
|
|
+ (and (fs/existsSync graph) (.isFile (fs/statSync graph)))
|
|
|
+ [graph]
|
|
|
+ (string/includes? graph "/")
|
|
|
+ ((juxt node-path/dirname node-path/basename) graph)
|
|
|
+ :else
|
|
|
+ [(cli-common-graph/get-db-graphs-dir) (common-sqlite/sanitize-db-name graph)]))
|
|
|
+
|
|
|
+(defn get-graph-path
|
|
|
+ "If graph is a file, return its path. Otherwise returns the graph's dir"
|
|
|
+ [graph]
|
|
|
+ (apply node-path/join (->open-db-args graph)))
|
|
|
|
|
|
(defn api-fetch [token method args]
|
|
|
(js/fetch "http://127.0.0.1:12315/api"
|