mirror of
https://github.com/logseq/logseq.git
synced 2026-02-01 14:43:56 +00:00
chore: remove unused file ns graph-parser.cli
This commit is contained in:
2
deps/graph-parser/.carve/ignore
vendored
2
deps/graph-parser/.carve/ignore
vendored
@@ -1,6 +1,4 @@
|
||||
;; For CLI
|
||||
logseq.graph-parser.cli/parse-graph
|
||||
;; For CLI
|
||||
logseq.graph-parser.mldoc/ast-export-markdown
|
||||
;; API
|
||||
logseq.graph-parser.mldoc/link?
|
||||
|
||||
8
deps/graph-parser/README.md
vendored
8
deps/graph-parser/README.md
vendored
@@ -11,14 +11,12 @@ frontend and commandline functionality.
|
||||
## API
|
||||
|
||||
This library is under the parent namespace `logseq.graph-parser`. This library
|
||||
provides two main namespaces for parsing, `logseq.graph-parser` and
|
||||
`logseq.graph-parser.cli`. `logseq.graph-parser/parse-file` is the main fn for
|
||||
the frontend. `logseq.graph-parser.cli/parse-graph` is the main fn for node.js
|
||||
CLIs.
|
||||
provides two main namespaces for parsing, `logseq.graph-parser`.
|
||||
`logseq.graph-parser/parse-file` is the main fn for the frontend.
|
||||
|
||||
## Usage
|
||||
|
||||
See `logseq.graph-parser.cli-test` and [nbb-logseq example
|
||||
See [nbb-logseq example
|
||||
scripts](https://github.com/logseq/nbb-logseq/tree/main/examples) for example
|
||||
usage.
|
||||
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
(ns ^:node-only logseq.graph-parser.cli
|
||||
"For file graphs, primary ns to parse graphs with node.js based CLIs"
|
||||
(:require ["fs" :as fs]
|
||||
["path" :as path]
|
||||
[clojure.edn :as edn]
|
||||
[logseq.common.config :as common-config]
|
||||
[logseq.common.graph :as common-graph]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.graph-parser :as graph-parser]
|
||||
[logseq.graph-parser.db :as gp-db]))
|
||||
|
||||
(defn- slurp
|
||||
"Return file contents like clojure.core/slurp"
|
||||
[file]
|
||||
(str (fs/readFileSync file)))
|
||||
|
||||
(defn- remove-hidden-files [dir config files]
|
||||
(if (seq (:hidden config))
|
||||
(->> files
|
||||
(map #(assoc % ::rel-path (path/relative dir (:file/path %))))
|
||||
((fn [files] (common-config/remove-hidden-files files config ::rel-path)))
|
||||
(map #(dissoc % ::rel-path)))
|
||||
files))
|
||||
|
||||
(defn- build-graph-files
|
||||
"Given a graph directory, return absolute, allowed file paths and their contents in preparation
|
||||
for parsing"
|
||||
[dir* config]
|
||||
(let [dir (path/resolve dir*)]
|
||||
(->> (common-graph/get-files dir)
|
||||
(map #(hash-map :file/path %))
|
||||
graph-parser/filter-files
|
||||
(remove-hidden-files dir config)
|
||||
(mapv #(assoc % :file/content (slurp (:file/path %)))))))
|
||||
|
||||
(defn- read-config
|
||||
"Reads repo-specific config from logseq/config.edn"
|
||||
[dir]
|
||||
(let [config-file (str dir "/" common-config/app-name "/config.edn")]
|
||||
(if (fs/existsSync config-file)
|
||||
(-> config-file fs/readFileSync str edn/read-string)
|
||||
{})))
|
||||
|
||||
(defn- parse-files
|
||||
[conn files {:keys [config] :as options}]
|
||||
(let [extract-options (merge {:date-formatter (common-config/get-date-formatter config)
|
||||
:user-config config
|
||||
:filename-format (or (:file/name-format config) :legacy)}
|
||||
(select-keys options [:verbose]))]
|
||||
(mapv
|
||||
(fn [{:file/keys [path content]}]
|
||||
(let [{:keys [ast]}
|
||||
(let [parse-file-options
|
||||
(merge {:extract-options
|
||||
(assoc extract-options
|
||||
:block-pattern (common-config/get-block-pattern (common-util/get-format path)))}
|
||||
(:parse-file-options options))]
|
||||
(graph-parser/parse-file conn path content parse-file-options))]
|
||||
{:file path :ast ast}))
|
||||
files)))
|
||||
|
||||
(defn parse-graph
|
||||
"Parses a given graph directory and returns a datascript connection and all
|
||||
files that were processed. The directory is parsed as if it were a new graph
|
||||
as it can't assume that the metadata in logseq/ is up to date. Directory is
|
||||
assumed to be using git. This fn takes the following options:
|
||||
* :verbose - When enabled prints more information during parsing. Defaults to true
|
||||
* :files - Specific files to parse instead of parsing the whole directory
|
||||
* :conn - Database connection to use instead of creating new one
|
||||
* :parse-file-options - Options map to pass to graph-parser/parse-file"
|
||||
([dir]
|
||||
(parse-graph dir {}))
|
||||
([dir options]
|
||||
(let [config (read-config dir)
|
||||
files (or (:files options) (build-graph-files dir config))
|
||||
conn (or (:conn options) (gp-db/start-conn))
|
||||
_ (when-not (:files options) (println "Parsing" (count files) "files..."))
|
||||
asts (parse-files conn files (merge options {:config config}))]
|
||||
{:conn conn
|
||||
:files (map :file/path files)
|
||||
:asts asts})))
|
||||
@@ -1,31 +0,0 @@
|
||||
(ns ^:node-only logseq.graph-parser.cli-test
|
||||
(:require [cljs.test :refer [deftest is testing]]
|
||||
[clojure.string :as string]
|
||||
[datascript.core :as d]
|
||||
[logseq.graph-parser.cli :as gp-cli]
|
||||
[logseq.graph-parser.test.docs-graph-helper :as docs-graph-helper]))
|
||||
|
||||
;; Integration test that test parsing a large graph like docs
|
||||
(deftest ^:integration parse-graph
|
||||
(let [graph-dir "test/resources/docs-0.10.12"
|
||||
_ (docs-graph-helper/clone-docs-repo-if-not-exists graph-dir "v0.10.12")
|
||||
{:keys [conn files asts]} (gp-cli/parse-graph graph-dir {:verbose false})]
|
||||
|
||||
(docs-graph-helper/docs-graph-assertions @conn graph-dir files)
|
||||
|
||||
(testing "Additional counts"
|
||||
(is (= 58149 (count (d/datoms @conn :eavt))) "Correct datoms count"))
|
||||
|
||||
(testing "Asts"
|
||||
(is (seq asts) "Asts returned are non-zero")
|
||||
(is (= files (map :file asts))
|
||||
"There's an ast returned for every file processed")
|
||||
(is (empty? (remove #(or
|
||||
(seq (:ast %))
|
||||
;; edn files don't have ast
|
||||
(string/ends-with? (:file %) ".edn")
|
||||
;; logseq files don't have ast
|
||||
;; could also used common-config but API isn't public yet
|
||||
(string/includes? (:file %) (str graph-dir "/logseq/")))
|
||||
asts))
|
||||
"Parsed files shouldn't have empty asts"))))
|
||||
@@ -1,9 +1,6 @@
|
||||
(ns logseq.graph-parser.mldoc-test
|
||||
(:require [cljs.test :refer [testing deftest are is]]
|
||||
[clojure.string :as string]
|
||||
[logseq.graph-parser.cli :as gp-cli]
|
||||
[logseq.graph-parser.mldoc :as gp-mldoc]
|
||||
[logseq.graph-parser.test.docs-graph-helper :as docs-graph-helper]
|
||||
[logseq.graph-parser.text :as text]))
|
||||
|
||||
(deftest test-link
|
||||
@@ -134,34 +131,4 @@ line 4"]
|
||||
\t line 2
|
||||
\t line 3
|
||||
\tline 4"]
|
||||
(gp-mldoc/remove-indentation-spaces s 3 false))))))
|
||||
|
||||
(deftest ^:integration test->edn
|
||||
(let [graph-dir "test/resources/docs-0.10.12"
|
||||
_ (docs-graph-helper/clone-docs-repo-if-not-exists graph-dir "v0.10.12")
|
||||
files (#'gp-cli/build-graph-files graph-dir {})
|
||||
asts-by-file (->> files
|
||||
(map (fn [{:file/keys [path content]}]
|
||||
(let [format (if (string/ends-with? path ".org")
|
||||
:org :markdown)]
|
||||
[path
|
||||
(gp-mldoc/->edn content
|
||||
(gp-mldoc/default-config format))])))
|
||||
(into {}))]
|
||||
(is (= {"Custom" 62,
|
||||
"Displayed_Math" 2,
|
||||
"Drawer" 1,
|
||||
"Example" 22,
|
||||
"Footnote_Definition" 2,
|
||||
"Heading" 6764,
|
||||
"Hiccup" 9,
|
||||
"List" 25,
|
||||
"Paragraph" 629,
|
||||
"Properties" 85,
|
||||
"Property_Drawer" 510,
|
||||
"Quote" 28,
|
||||
"Raw_Html" 18,
|
||||
"Src" 82,
|
||||
"Table" 8}
|
||||
(->> asts-by-file (mapcat val) (map ffirst) frequencies))
|
||||
"AST node type counts")))
|
||||
(gp-mldoc/remove-indentation-spaces s 3 false))))))
|
||||
22
deps/publishing/script/publishing.cljs
vendored
22
deps/publishing/script/publishing.cljs
vendored
@@ -1,29 +1,13 @@
|
||||
(ns publishing
|
||||
"Basic script for publishing from CLI"
|
||||
(:require ["fs" :as fs]
|
||||
["path" :as node-path]
|
||||
(:require ["path" :as node-path]
|
||||
[clojure.edn :as edn]
|
||||
[datascript.core :as d]
|
||||
[logseq.db.common.sqlite-cli :as sqlite-cli]
|
||||
[logseq.db.sqlite.util :as sqlite-util]
|
||||
[logseq.graph-parser.cli :as gp-cli]
|
||||
[logseq.publishing :as publishing]
|
||||
[nbb.core :as nbb]))
|
||||
|
||||
(defn- get-db [graph-dir]
|
||||
(let [{:keys [conn]} (gp-cli/parse-graph graph-dir {:verbose false})] @conn))
|
||||
|
||||
(defn- publish-file-graph [static-dir graph-dir output-path options]
|
||||
(let [repo-config (-> (node-path/join graph-dir "logseq" "config.edn") fs/readFileSync str edn/read-string)]
|
||||
(publishing/export (get-db graph-dir)
|
||||
static-dir
|
||||
graph-dir
|
||||
output-path
|
||||
(merge options {:repo (node-path/basename graph-dir)
|
||||
:repo-config repo-config
|
||||
:ui/theme "dark"
|
||||
:ui/radix-color :purple}))))
|
||||
|
||||
(defn- publish-db-graph [static-dir graph-dir output-path opts]
|
||||
(let [db-name (node-path/basename graph-dir)
|
||||
conn (sqlite-cli/open-db! (node-path/dirname graph-dir) db-name)
|
||||
@@ -56,9 +40,7 @@
|
||||
(js/process.exit 1))
|
||||
(let [[static-dir graph-dir output-path] (map resolve-path args)
|
||||
options {:dev? (contains? (set args) "--dev")}]
|
||||
(if (sqlite-cli/db-graph-directory? graph-dir)
|
||||
(publish-db-graph static-dir graph-dir output-path options)
|
||||
(publish-file-graph static-dir graph-dir output-path options))))
|
||||
(publish-db-graph static-dir graph-dir output-path options)))
|
||||
|
||||
(when (= nbb/*file* (nbb/invoked-file))
|
||||
(-main *command-line-args*))
|
||||
Reference in New Issue
Block a user