Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active March 17, 2021 03:31
Show Gist options
  • Save mfikes/2511a401ce92ca5315fdd2907ae18081 to your computer and use it in GitHub Desktop.
Save mfikes/2511a401ce92ca5315fdd2907ae18081 to your computer and use it in GitHub Desktop.
Command to get a preview of cljs.main

Usage

Start up the new cljs.main with Node:

clj -Sdeps '{:deps {org.clojurescript {:git/url "https://github.com/clojure/clojurescript" :sha "3f4084efcb5cd92cceb8ca30765144691d8cfd7e"}}}' -m cljs.main -re node

The above works by specifying ClojureScript as a "git dep" and you can ensure that you are running the very latest by replacing the :sha value with the latest commit SHA at https://github.com/clojure/clojurescript.

Note that, while the above is rather verbose, if you have deps.edn set up, things can be as succinct as clj -m cljs.main or, if you have the released cljs.jar, as simple as java -jar cljs.jar.

What is This?

In short, it is the ClojureScript analog of clojure.main. It lets you run ClojureScript files, or start a REPL with -r, or evaluate an expression with -e, or run a namespace with -m. This has previously only been available for ClojureScript in Planck and Lumo, but cljs.main brings it to ClojureScript proper!

What's it good for? Well, if you want to fire up a REPL, it is now trivial. But you can also use it to, say, run tests in a ClojureScript test namespace, or even run a browser REPL and have it automatically compile your code as you view the results in a browser. (Much of the Quick Start guide will likely be updated to work in terms of it.)

The exciting thing is that, for a lot of simple use cases, there will no longer be any extensive setup requried.

Help Output

Usage: java -cp cljs.jar cljs.main [init-opt*] [main-opt] [arg*]

With no options or args, runs an interactive Read-Eval-Print Loop

init option:
   -d, --output-dir path      Set the output directory to use. If supplied,
                              cljsc_opts.edn in that directory will be used to
                              set ClojureScript compiler options
  -re, --repl-env             The REPL environment to use. Built-in supported
                              values: nashorn, node, browser, rhino. Defaults
                              to nashorn
   -t, --target name          The JavaScript target. Configures environment
                              bootstrap and defaults to browser. Supported
                              values: nodejs, nashorn, webworker, none

init options only for --main and --repl:
   -e, --eval string          Evaluate expressions in string; print non-nil
                              values
   -i, --init path            Load a file or resource
   -v, --verbose bool         If true, will enable ClojureScript verbose logging

init options only for --compile:
   -O, --optimizations level  Set optimization level, only effective with -c
                              main option. Valid values are: none, whitespace,
                              simple, advanced
   -o, --output-to file       Set the output compiled file
   -w, --watch path           Continuously build, only effective with -c main
                              option

main options:
   -                          Run a script from standard input
   -c, --compile ns           Compile a namespace. If -r / --repl present after
                              namespace will launch a REPL after the compile
                              completes
   -h, --help, -?             Print this help message and exit
   -m, --main ns              Call the -main function from a namespace with args
   -r, --repl                 Run a repl
   path                       Run a script from a file or resource

For --main and --repl:

  - Enters the user namespace
  - Binds *command-line-args* to a seq of strings containing command line
    args that appear after any main option
  - Runs all init options in order
  - Calls a -main function or runs a repl or script if requested

The init options may be repeated and mixed freely, but must appear before
any main option.

Paths may be absolute or relative in the filesystem or relative to
classpath. Classpath-relative paths have prefix of @ or @/
@whamtet
Copy link

whamtet commented Dec 17, 2018

Hi @mfikes,

Thanks for your great work here. In your shrimp / ambly example the repl argument is

clj -m cljs.main -co '{:analyze-path ["src"]}' -re ambly -r

what does the {:analyze-path ["src"]} argument do?

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