Get a fast starting REPL session with a ClojureScript library using Planck.
This is a draft of what will be eventually a blog post. Feedback is welcome.
It started by asking this question on StackOverflow. A good answer turned out to be Planck. This is how you solve it with Planck.
First, decide what dependencies Planck needs to load. This is easily done with boot
like this:
$ boot --dependencies org.clojars.micha/boot-cp ; load with-cp task that helps exporting minimal classpath to file
--dependencies com.andrewmcveigh/cljs-time:"0.4.0" ; load dependency you actually want to try
with-cp -w --file .classpath ; write classpath to a file `.classpath`
The list of dependencies is now written to .classpath
. You can re-use this file if your dependency hasn't changed.
Now we're ready to start the Planck REPL. It's fast! Even faster when you use the K
option which caches compiled ClojureScript.
$ planck -Kc `cat .classpath` -e "(require '[cljs-time.core :as t])" -r
cljs.user=> (str (t/plus (t/today) (t/days 100)))
"20161105"
To contain this in a script, I use for example a directory like this:
mkdir -p ~/bin/cljs-time/cljs-time
chmod +x ~/bin/cljs-time/cljs-time
export PATH="$PATH:$HOME/bin/cljs-time" # add this to .zshrc or equivalent
with the cljs-time
script:
#!/usr/bin/env bash
echo "Example: (str (t/plus (t/today) (t/days 100)))"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CP_FILE=$DIR/.classpath
if [ ! -f $CP_FILE ]; then
boot --dependencies org.clojars.micha/boot-cp \
--dependencies com.andrewmcveigh/cljs-time:"0.4.0" \
with-cp -w --file $CP_FILE
fi
CACHE_DIR=$DIR/.planck_cache
mkdir -p $CACHE_DIR
planck --cache=$CACHE_DIR -c `cat $CP_FILE` -e "(require '[cljs-time.core :as t])" -r
PS: In the future it's likely that boot show
can be used instead of the boot-cp
task to output dependencies. As of now the show
task includes a lot of boot dependencies, which can affect Planck's behavior. See this issue.