Skip to content

Instantly share code, notes, and snippets.

@vijaykiran
Forked from borkdude/planck-dependency.md
Created July 28, 2016 14:21
Show Gist options
  • Save vijaykiran/0d0d0c97ecb4c12ed1f58e1d01f5050f to your computer and use it in GitHub Desktop.
Save vijaykiran/0d0d0c97ecb4c12ed1f58e1d01f5050f 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.

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 you're 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

if [ ! -f .classpath ]; then
  boot --dependencies org.clojars.micha/boot-cp \
     --dependencies com.andrewmcveigh/cljs-time:"0.4.0" \
     with-cp -w --file .classpath
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CACHE_DIR=$DIR/.planck_cache

mkdir -p $CACHE_DIR

planck --cache=$CACHE_DIR -c `cat .classpath` -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 a lot of boot dependencies are included, which can affect Planck's behavior.

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