Skip to content

Commit

Permalink
Add windows support to shadow.cljc (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
sritchie committed Apr 18, 2023
1 parent 696a1e8 commit a508ab0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 28 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions dev/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 21 additions & 11 deletions src/mentat/clerk_utils/build/shadow.clj
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
(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]
[shadow.cljs.devtools.server.util :as shadow.util]
[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
Expand Down Expand Up @@ -77,7 +87,7 @@
(println "Running npm install...")
(println
(:out
(sh "npm" "install"))))
(sh npm-cmd "install"))))

(npm-deps/install-deps {} deps)))

Expand Down
6 changes: 3 additions & 3 deletions src/mentat/clerk_utils/css.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions src/mentat/clerk_utils/show.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a508ab0

Please sign in to comment.