From a508ab01d0fb04a44c0a6a1dd510207b2ca7135e Mon Sep 17 00:00:00 2001 From: Sam Ritchie Date: Tue, 18 Apr 2023 07:45:08 -0600 Subject: [PATCH] Add windows support to shadow.cljc (#30) --- CHANGELOG.md | 3 ++ dev/user.clj | 4 +-- .../mentat/clerk_utils/viewers.clj_kondo | 12 +++---- src/mentat/clerk_utils/build/shadow.clj | 32 ++++++++++++------- src/mentat/clerk_utils/css.clj | 6 ++-- src/mentat/clerk_utils/show.cljc | 11 +++---- 6 files changed, 40 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e256cf..ca8951d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ## [0.5.0] +- #30 adds better support for Windows by invoking `npm` using `npm.bat` when + appropriate. + - #29 converts `mentat.clerk-utils` to `cljc`. The CLJS side doesn't do anything, but this allows the require and macro calls to live inside `cljc` files. diff --git a/dev/user.clj b/dev/user.clj index 9104b61..8a21721 100644 --- a/dev/user.clj +++ b/dev/user.clj @@ -28,8 +28,8 @@ (b/serve! (merge defaults opts)))) -(def ^{:doc "Alias for [[mentat.clerk-utils.build/halt!]]."} - halt! +(def halt! + "Alias for [[mentat.clerk-utils.build/halt!]]." b/halt!) (defn build! diff --git a/resources/clj-kondo.exports/org.mentat/clerk-utils/hooks/mentat/clerk_utils/viewers.clj_kondo b/resources/clj-kondo.exports/org.mentat/clerk-utils/hooks/mentat/clerk_utils/viewers.clj_kondo index d892dc0..fd7ad57 100644 --- a/resources/clj-kondo.exports/org.mentat/clerk-utils/hooks/mentat/clerk_utils/viewers.clj_kondo +++ b/resources/clj-kondo.exports/org.mentat/clerk-utils/hooks/mentat/clerk_utils/viewers.clj_kondo @@ -20,14 +20,14 @@ [node] (= :unquote-splicing (:tag node))) -(def ^{:doc "Returns true if the supplied `node` is either of the unquote -forms (`:unquote` or `:unquote-splicing`, false otherwise.)"} - any-unquote? +(def any-unquote? + "Returns true if the supplied `node` is either of the unquote + forms (`:unquote` or `:unquote-splicing`, false otherwise.)" (some-fn unquote? unquote-splice?)) -(def ^{:doc "Returns true if the supplied `node` is a collection, ie, a list, - vector or map, false otherwise."} - coll-node? +(def coll-node? + "Returns true if the supplied `node` is a collection, ie, a list, + vector or map, false otherwise." (some-fn api/list-node? api/vector-node? api/map-node? set-node?)) (defn walk-node diff --git a/src/mentat/clerk_utils/build/shadow.clj b/src/mentat/clerk_utils/build/shadow.clj index 3786b78..8000975 100644 --- a/src/mentat/clerk_utils/build/shadow.clj +++ b/src/mentat/clerk_utils/build/shadow.clj @@ -1,6 +1,7 @@ (ns mentat.clerk-utils.build.shadow "Utilities for generating custom Clerk viewer CLJS builds via `shadow-cljs`." - (:require [clojure.java.shell :refer [sh]] + (:require [clojure.string] + [clojure.java.shell :refer [sh]] [shadow.cljs.devtools.config :as shadow.config] [shadow.cljs.devtools.server :as shadow.server] [shadow.cljs.devtools.server.runtime :as runtime] @@ -8,24 +9,33 @@ [shadow.cljs.devtools.server.npm-deps :as npm-deps] [shadow.cljs.devtools.api :as shadow.api])) -(def ^{:doc "Shadow version of the currently-loaded `shadow-cljs` dependency."} - shadow-version +(def ^:private windows? + (clojure.string/starts-with? + (System/getProperty "os.name") + "Windows")) + +(def npm-cmd + "System-specific NPM command, tuned for Windows or non-Windows." + (if windows? "npm.cmd" "npm")) + +(def shadow-version + "Shadow version of the currently-loaded `shadow-cljs` dependency." (shadow.util/find-version)) -(def ^{:doc "Schema for the NPM dependency for `shadow-cljs` associated with the - currently loaded `shadow-cljs` JVM library."} - shadow-npm-dep +(def shadow-npm-dep + "Schema for the NPM dependency for `shadow-cljs` associated with the + currently loaded `shadow-cljs` JVM library." {:id "shadow-cljs" :version shadow-version}) (def ^:no-doc build-id ::clerk) -(def ^{:doc "Output directory for our controlled `shadow-cljs` build."} - output-dir +(def output-dir + "Output directory for our controlled `shadow-cljs` build." ".clerk/shadow-cljs") -(def ^{:doc "Location of the generated JS code."} - js-path +(def js-path + "Location of the generated JS code." (str output-dir "/main.js")) (defn clerk-build-config @@ -77,7 +87,7 @@ (println "Running npm install...") (println (:out - (sh "npm" "install")))) + (sh npm-cmd "install")))) (npm-deps/install-deps {} deps))) diff --git a/src/mentat/clerk_utils/css.clj b/src/mentat/clerk_utils/css.clj index 05ce917..5468eae 100644 --- a/src/mentat/clerk_utils/css.clj +++ b/src/mentat/clerk_utils/css.clj @@ -6,9 +6,9 @@ ;; ## CSS Customization -(def ^{:doc "Stateful reference to a sequence of custom CSS sources to be - included in Clerk's page when it loads."} - custom-css +(def custom-css + "Stateful reference to a sequence of custom CSS sources to be + included in Clerk's page when it loads." (atom [])) (alter-var-root diff --git a/src/mentat/clerk_utils/show.cljc b/src/mentat/clerk_utils/show.cljc index 697dee3..3cb6e98 100644 --- a/src/mentat/clerk_utils/show.cljc +++ b/src/mentat/clerk_utils/show.cljc @@ -61,18 +61,17 @@ (comp hash stable-hash-form)) #?(:clj - (def ^{:no-doc true - :doc "This viewer takes function name generated by the macro body - of [[show-cljs]] and loads the results. + (def ^:no-doc loading-viewer + "This viewer takes function name generated by the macro body of [[show-cljs]] + and loads the results. If the cljs code is not ready, shows a loading marker under the class - `show-cljs-loading`. + `show-cljs-loading`. Once the CLJS code is ready, the cljs form is presented as either - a reagent form, if it's a vector and `:inspect true` is not set in the metadata - - a form passed to `sicmutils.clerk.render/inspect` otherwise."} - loading-viewer + - a form passed to `sicmutils.clerk.render/inspect` otherwise." {:transform-fn nextjournal.clerk/mark-presented :render-fn