Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active August 4, 2016 02:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save borkdude/8d43941031518a0a85f9732c270b119a to your computer and use it in GitHub Desktop.
Save borkdude/8d43941031518a0a85f9732c270b119a to your computer and use it in GitHub Desktop.
Fast REPL session with a cljs library using Planck

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment