diff --git a/bb.edn b/bb.edn index 1be4cd7d9..1b2cdee83 100644 --- a/bb.edn +++ b/bb.edn @@ -4,7 +4,9 @@ {:git/url "https://github.com/babashka/spec.alpha" :sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"} logseq/bb-tasks - {:local/root "deps/bb-tasks"} + #_{:local/root "../bb-tasks"} + {:git/url "https://github.com/logseq/bb-tasks" + :git/sha "4b3e623fb475cacb992425aa9dac770d6dd63e38"} logseq/graph-parser {:local/root "deps/graph-parser"}} :pods @@ -32,7 +34,10 @@ logseq.tasks.dev/lint nbb:watch - logseq.bb-tasks.nbb.watch/watch-dir + logseq.bb-tasks.nbb.watch/watch + + nbb:portal-watch + logseq.bb-tasks.nbb.watch/portal-watch test:load-namespaces-with-nbb logseq.tasks.nbb/load-compatible-namespaces diff --git a/deps/bb-tasks/README.md b/deps/bb-tasks/README.md deleted file mode 100644 index d1523441b..000000000 --- a/deps/bb-tasks/README.md +++ /dev/null @@ -1,33 +0,0 @@ -## Description - -Library of reusable https://github.com/babashka/babashka tasks - -## Install - -Add a git dependency to your `bb.edn`: - -```clojure -:deps -{logseq/bb-tasks -{:git/url "https://github.com/logseq/logseq" - :git/sha "FILL IN" - :deps/root "deps/bb-tasks"}} -``` - -## Usage - -### nbb:watch - -Given a graph directory and an nbb script, the nbb script will run when either the -script or a file in the directory is saved. - -For example, from root of logseq repo, run the following: - -``` -$ bb nbb:watch /path/to/graph deps/graph-parser/examples/parse_file.cljs -Watching /path/to/graph ... -``` - -See [this demo -clip](https://www.loom.com/share/20debb49fdd64e77ae83056289750b0f) to see it in -action. diff --git a/deps/bb-tasks/bb.edn b/deps/bb-tasks/bb.edn deleted file mode 100644 index a37ef82c3..000000000 --- a/deps/bb-tasks/bb.edn +++ /dev/null @@ -1,6 +0,0 @@ -{:paths ["src"] - :pods - {org.babashka/fswatcher {:version "0.0.3"}} - :tasks - {nbb:watch - logseq.bb-tasks.nbb.watch/watch-dir}} diff --git a/deps/bb-tasks/deps.edn b/deps/bb-tasks/deps.edn deleted file mode 100644 index b338280ba..000000000 --- a/deps/bb-tasks/deps.edn +++ /dev/null @@ -1,2 +0,0 @@ -;; Allows for this lib to be pulled in as a gitlib -{} diff --git a/deps/bb-tasks/src/logseq/bb_tasks/nbb/watch.clj b/deps/bb-tasks/src/logseq/bb_tasks/nbb/watch.clj deleted file mode 100644 index 7c92e7d51..000000000 --- a/deps/bb-tasks/src/logseq/bb_tasks/nbb/watch.clj +++ /dev/null @@ -1,35 +0,0 @@ -(ns logseq.bb-tasks.nbb.watch - "To use tasks in this ns, first install nbb-logseq: -`npm install -g @logseq/nbb-logseq`" - (:require [pod.babashka.fswatcher :as fw] - [babashka.tasks :refer [shell]] - [babashka.classpath :as classpath])) - -(def last-file (atom nil)) - -(defn- run-script - [nbb-script dir file] - (shell "nbb-logseq -cp" (classpath/get-classpath) nbb-script dir file)) - -(defn watch-dir - "Watch a graph dir and nbb script and run nbb script when either changes. -Nbb takes graph dir and last modified graph file. -NOTE: If the script fails, the watcher stops watching" - [& args] - (when-not (= 2 (count args)) - (throw (ex-info "Usage: $0 DIR NBB-SCRIPT" {}))) - (let [[dir nbb-script] args] - (println "Watching" dir "...") - (fw/watch dir - (fn [event] - ;; Don't use :chmod as it sometimes triggers twice on osx - (when (#{:write|chmod :write} (:type event)) - (run-script nbb-script dir (:path event)) - (reset! last-file (:path event)))) - {:recursive true}) - ;; Get live-editing experience by re-parsing last file - (fw/watch nbb-script - (fn [event] - (when (#{:write|chmod :write} (:type event)) - (run-script nbb-script dir @last-file)))) - (deref (promise)))) diff --git a/deps/graph-parser/examples/parse_file.cljs b/deps/graph-parser/examples/parse_file.cljs deleted file mode 100644 index fcea4aeca..000000000 --- a/deps/graph-parser/examples/parse_file.cljs +++ /dev/null @@ -1,52 +0,0 @@ -(ns parse-file - (:require [logseq.graph-parser.cli :as gp-cli] - [clojure.pprint :as pprint] - [datascript.core :as d])) - -(defn- colorize-or-pretty-print - [results] - (if (zero? (.-status (gp-cli/sh ["which" "puget"] {}))) - (gp-cli/sh ["puget"] {:input (pr-str results) - :stdio ["pipe" "inherit" "inherit"]}) - (pprint/pprint results))) - -(defn- get-all-page-properties - [db] - (->> (d/q '[:find (pull ?b [*]) - :where - [?b :block/properties]] - db) - (map first) - (map (fn [m] (zipmap (keys (:block/properties m)) (repeat 1)))) - (apply merge-with +) - (into {}))) - -(defn- analyze-file - [db file] - (let [results (map first - (d/q '[:find (pull ?b [:db/id :block/content]) - :in $ ?path - :where - [?b :block/page ?page] - [?page :block/file ?file] - [?file :file/path ?path]] - db - file))] - (colorize-or-pretty-print results) - (println "Block count:" (count results)) - (println "Properties count:" (get-all-page-properties db)))) - -(defn -main - "Prints blocks for given file along with basic file stats" - [& args] - (when-not (= 2 (count args)) - (throw (ex-info "Usage: $0 DIR FILE" {}))) - (println "Parsing...") - (let [[dir file] args - {:keys [conn]} (gp-cli/parse-graph dir - {:verbose false - :files [{:file/path file - :file/content (gp-cli/slurp file)}]})] - (analyze-file @conn file))) - -(apply -main *command-line-args*) diff --git a/docs/dev-practices.md b/docs/dev-practices.md index ad64b00a1..4c6ab0c35 100644 --- a/docs/dev-practices.md +++ b/docs/dev-practices.md @@ -135,3 +135,9 @@ Specs should go under `src/main/frontend/spec/` and be compatible with clojure and clojurescript. See `frontend.spec.storage` for an example. By following these conventions, specs should also be usable by babashka. This is helpful as it allows for third party tools to be written with logseq's data model. + +## Development Tools + +There are some babashka tasks under `nbb:` which are useful for inspecting +database changes in realtime. See [these +docs](https://github.com/logseq/bb-tasks#logseqbb-tasksnbbwatch) for more info.