Skip to content

Instantly share code, notes, and snippets.

@hiteshjasani
Last active March 21, 2018 14:58
Show Gist options
  • Save hiteshjasani/ca8876af156a707b5c8e596c33fa39f1 to your computer and use it in GitHub Desktop.
Save hiteshjasani/ca8876af156a707b5c8e596c33fa39f1 to your computer and use it in GitHub Desktop.
Enabling a cljs command line

Creating your own cljs command

Mike Fikes mentioned that he's suggested creating a cljs command for the command line that is similar to the current clj command. It sounds like a good idea that might take some time to get momentum. In the interim, you can create your own.

Option 1

Setup

Advantage is that it doesn't pollute your deps.edn for non-javascript work.

  1. Add an alias to ~/.bash_profile
alias cljs='clj -Sdeps "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.217\"}}}" -m cljs.main'
alias cljs.='clj -Sdeps "{:paths [\".\"] :deps {org.clojure/clojurescript {:mvn/version \"1.10.217\"}}}" -m cljs.main'

Usage

Run a simple command

cljs -re node -e "(+ 2 3)"

Get help

cljs --help

Run a program

Let's say you have a foo.cljs file with -main defined.

# foo.cljs
(ns foo)

(defn -main [& args]
  (println "hello world"))

Run it.

cljs. -re node -m foo

Run a script

Let's say you have a script named myscript.cljs.

# myscript.cljs
(defn do-something-cool []
  (println "hello world"))

(do-something-cool)

Run it.

cljs -re node myscript.cljs

Option 2

Disadvantage, will load the clojurescript.jar for all clj commands -- even non-javascript runs.

Setup

  1. Add clojurescript dep to ~/.clojure/deps.edn
  :deps {
    org.clojure/clojurescript {:mvn/version "1.10.217"}
  }
  1. Add an alias to ~/.bash_profile
alias cljs='clj -m cljs.main'

Usage

Run a simple command

cljs -re node -e "(+ 2 3)"

Get help

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