enhance: add a --dev mode to publishing that pairs with shadow's watch

This commit is contained in:
Gabriel Horner
2024-01-22 14:35:36 -05:00
parent 73cbcc5a1c
commit 7831476c70
4 changed files with 31 additions and 17 deletions

View File

@@ -20,7 +20,7 @@ can be passed:
* :db-graph? - Boolean which indicates if graph is db based
* :default-notification-fn - Configure how errors are reported when creating the export.
Default is to throw an exception when it occurs."
[db static-dir graph-dir output-dir {:keys [notification-fn]
[db static-dir graph-dir output-dir {:keys [notification-fn dev?]
:or {notification-fn default-notification-fn}
:as options}]
(let [options' (cond-> options
@@ -30,4 +30,5 @@ can be passed:
(assoc-in [:app-state :ui/radix-color] (:ui/radix-color options)))
{:keys [html asset-filenames]} (publish-html/build-html db options')]
(publish-export/create-export html static-dir graph-dir output-dir {:asset-filenames asset-filenames
:notification-fn notification-fn})))
:notification-fn notification-fn
:dev? dev?})))

View File

@@ -22,21 +22,30 @@
(defn- cleanup-js-dir
"Moves used js files to the correct dir and removes unused js files"
[output-static-dir]
[output-static-dir source-static-dir {:keys [dev?]}]
(let [publishing-dir (node-path/join output-static-dir "js" "publishing")]
(p/let [_ (p/all (map (fn [file]
(fs/rmSync (node-path/join output-static-dir "js" file) #js {:force true}))
js-files))
_ (when dev?
(fse/remove (node-path/join output-static-dir "js" "cljs-runtime")))
_ (p/all (map (fn [file]
(fs/renameSync
(node-path/join publishing-dir file)
(node-path/join output-static-dir "js" file)))
(if dev?
(fs/symlinkSync
(node-path/join source-static-dir "js" "publishing" file)
(node-path/join output-static-dir "js" file))
(fs/renameSync
(node-path/join publishing-dir file)
(node-path/join output-static-dir "js" file))))
js-files))
_ (when dev?
(fs/symlinkSync (node-path/join source-static-dir "js" "publishing" "cljs-runtime")
(node-path/join output-static-dir "js" "cljs-runtime")))
;; remove publishing-dir
_ (p/all (map (fn [file]
(fs/rmSync (node-path/join publishing-dir file)))
(fs/readdirSync publishing-dir)))
_ (fs/rmdirSync 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))
;; remove source map files
_ (p/all (map (fn [file]
(fs/rmSync (node-path/join output-static-dir "js" (str file ".map")) #js {:force true}))
@@ -90,7 +99,7 @@
_ (fs/writeFileSync (node-path/join output-static-dir "css" "custom.css") custom-css)
custom-js (if (fs/existsSync custom-js-path) (str (fs/readFileSync custom-js-path)) "")
_ (fs/writeFileSync (node-path/join output-static-dir "js" "custom.js") custom-js)
_ (cleanup-js-dir output-static-dir)]
_ (cleanup-js-dir output-static-dir static-dir options)]
(notification-fn {:type "success"
:payload (str "Export public pages and publish assets to " output-dir " successfully 🎉")}))
(p/catch (fn [error]

View File

@@ -320,10 +320,14 @@ point out:
```sh
# One time setup
$ cd scripts && yarn install && cd -
# Build the export
# Build a release export
$ bb dev:publishing /path/to/graph-dir tmp/publish
# OR build a dev export with `clojure -M:cljs watch publishing` and then
$ bb dev:publishing /path/to/graph-dir tmp/publish --dev
# View the app in a browser
$ open tmp/publish/index.html
$ python3 -m http.server 8080 -d tmp/db-publish &; open http://localhost:8080
```
There are also some tasks under `nbb:` which are useful for inspecting database

View File

@@ -21,7 +21,7 @@
output-path
{:repo-config repo-config :ui/theme "dark" :ui/radix-color :purple})))
(defn- publish-db-graph [static-dir graph-dir output-path]
(defn- publish-db-graph [static-dir graph-dir output-path opts]
(let [db-name (node-path/basename graph-dir)
conn (sqlite-db/open-db! (node-path/dirname graph-dir) db-name)
repo-config (-> (d/q '[:find ?content
@@ -33,16 +33,16 @@
static-dir
graph-dir
output-path
{:repo-config repo-config :db-graph? true :ui/theme "dark" :ui/radix-color :cyan})))
(merge opts {:repo-config repo-config :db-graph? true :ui/theme "dark" :ui/radix-color :cyan}))))
(defn -main
[& args]
(when-not (= 3 (count args))
(when (< (count args) 3)
(println "Usage: $0 STATIC-DIR GRAPH-DIR OUT-DIR")
(js/process.exit 1))
(let [[static-dir graph-dir output-path]
;; Offset relative paths since they are run in a different directory than user is in
(map #(if (node-path/isAbsolute %) % (node-path/resolve ".." %)) args)]
(if (sqlite-cli/db-graph-directory? graph-dir)
(publish-db-graph static-dir graph-dir output-path)
(publish-db-graph static-dir graph-dir output-path {:dev? (contains? (set args) "--dev")})
(publish-file-graph static-dir graph-dir output-path))))