diff --git a/bb.edn b/bb.edn index 1e447d92f8..76e1ba171a 100644 --- a/bb.edn +++ b/bb.edn @@ -31,15 +31,32 @@ dev:app-watch logseq.tasks.dev.mobile/app-watch - dev:build-publishing - logseq.tasks.dev/build-publishing + -dev:build-publishing-frontend + logseq.tasks.dev/build-publishing-frontend + + dev:publishing-backend + logseq.tasks.dev/publishing-backend + + -dev:publishing-release + {:depends [-dev:build-publishing-frontend] + :doc "Build release publishing spa app given graph and output dirs" + :task (run 'dev:publishing-backend)} + + -dev:watch-publishing-frontend + logseq.tasks.dev/watch-publishing-frontend + + -dev:watch-publishing-backend + logseq.tasks.dev/watch-publishing-backend + + -dev:publishing-dev + {:depends [-dev:watch-publishing-frontend -dev:watch-publishing-backend] + :doc "Watch dev publishing spa app given graph and output dirs"} dev:publishing - {:depends [dev:build-publishing] - :doc "Build publishing spa app given graph and output dirs" - :task (apply shell {:dir "scripts"} - "yarn -s nbb-logseq -cp src -m logseq.tasks.dev.publishing" - (into ["static"] *command-line-args*))} + {:doc "Builds full publishing app given graph and output dirs. Append --dev to watch frontend" + :task (if ((set *command-line-args*) "--dev") + (run '-dev:publishing-dev {:parallel true}) + (run '-dev:publishing-release))} dev:npx-cap-run-ios logseq.tasks.dev.mobile/npx-cap-run-ios diff --git a/deps/publishing/src/logseq/publishing/export.cljs b/deps/publishing/src/logseq/publishing/export.cljs index 0ae51f3da7..4e986e78a3 100644 --- a/deps/publishing/src/logseq/publishing/export.cljs +++ b/deps/publishing/src/logseq/publishing/export.cljs @@ -42,10 +42,7 @@ (fs/symlinkSync (node-path/join source-static-dir "js" "publishing" "cljs-runtime") (node-path/join output-static-dir "js" "cljs-runtime"))) ;; remove publishing-dir - _ (when-not dev? (p/all (map (fn [file] - (fs/rmSync (node-path/join publishing-dir file))) - (fs/readdirSync publishing-dir)))) - _ (when-not dev? (fs/rmdirSync publishing-dir)) + _ (when-not dev? (fse/remove publishing-dir)) ;; remove source map files _ (p/all (map (fn [file] (fs/rmSync (node-path/join output-static-dir "js" (str file ".map")) #js {:force true})) diff --git a/docs/dev-practices.md b/docs/dev-practices.md index df29657918..356f937311 100644 --- a/docs/dev-practices.md +++ b/docs/dev-practices.md @@ -307,13 +307,20 @@ point out: ```sh # One time setup $ cd scripts && yarn install && cd - - # Build a release export + + # Build a release publishing app $ bb dev:publishing /path/to/graph-dir tmp/publish - # OR build a dev export with `clojure -M:cljs watch publishing` and then + + # OR build a dev publishing app that watches frontend changes $ bb dev:publishing /path/to/graph-dir tmp/publish --dev - # View the app in a browser - $ python3 -m http.server 8080 -d tmp/db-publish &; open http://localhost:8080 + # View the publishing app in a browser + $ python3 -m http.server 8080 -d tmp/publish &; open http://localhost:8080 + + # Rebuild the publishing backend for dev/release. + # Handy when making backend changes in deps/publishing or + # to test a different graph + $ bb dev:publishing-backend /path/graph-dir tmp/publish ``` diff --git a/scripts/src/logseq/tasks/dev.clj b/scripts/src/logseq/tasks/dev.clj index e3b9915d5b..d49fb48ac7 100644 --- a/scripts/src/logseq/tasks/dev.clj +++ b/scripts/src/logseq/tasks/dev.clj @@ -3,6 +3,7 @@ namespaces" (:require [babashka.process :refer [shell]] [babashka.fs :as fs] + [logseq.tasks.util :as task-util] [clojure.java.io :as io] [clojure.pprint :as pp] [clojure.edn :as edn])) @@ -37,8 +38,8 @@ (pp/pprint (edn/read-string (:out (shell {:out :string} "node ./static/gen-malli-kondo-config.js")))))] (spit config-edn config)))) -(defn build-publishing - "Builds release publishing asset when files have changed" +(defn build-publishing-frontend + "Builds frontend release publishing asset when files have changed" [& _args] (if-let [_files (and (not (System/getenv "SKIP_ASSET")) (seq (set (fs/modified-since (fs/file "static/js/publishing/main.js") @@ -47,3 +48,27 @@ (println "Building publishing js asset...") (shell "clojure -M:cljs release publishing")) (println "Publishing js asset is up to date"))) + +(defn publishing-backend + "Builds publishing backend and copies over supporting frontend assets" + [& args] + (apply shell {:dir "scripts"} + "yarn -s nbb-logseq -cp src -m logseq.tasks.dev.publishing" + (into ["static"] args))) + +(defn watch-publishing-frontend + [& _args] + (shell "clojure -M:cljs watch publishing")) + +(defn watch-publishing-backend + "Builds publishing backend once watch-publishing-frontend has built initial frontend" + [& args] + (let [start-time (java.time.Instant/now)] + (Thread/sleep 3000) + (loop [n 1000] + (if (and (fs/exists? "static/js/publishing/main.js") + (task-util/file-modified-later-than? "static/js/publishing/main.js" start-time)) + (apply publishing-backend args) + (do (println "Waiting for publishing frontend to build...") + (Thread/sleep 1000) + (recur (inc n))))))) \ No newline at end of file