Shadow-cljs: refactor CLI args

Created on 15 Jun 2017  路  6Comments  路  Source: thheller/shadow-cljs

I'm thinking about refactoring the CLI options so that you can run multiple commands with one go.

Something that would reduce left to right maybe.

shadow-cljs --once a --start b --start c --repl c
  • build :a once
  • start dev mode for :b
  • start dev mode for :c
  • connect to repl for :c

Currently this would require running shadow-cljs 4 times. With --server this doesn't matter as much but I think it would be useful to be able to start multiple things at once.

Most helpful comment

I just finished the first pass of the CLI refactor. Pretty much all the old options are gone. Running the command now looks like

$ shadow-cljs
shadow-cljs - config: /Users/zilence/code/shadow-cljs/shadow-cljs.edn version: 1.0.20170618
shadow-cljs - connected to server

Please specify which action to run!

Usage:
  shadow-cljs <action> <zero or more build ids>

Supported actions are:

     compile - ...
       watch - ...
       check - ...
     release - ...
   node-repl - ...
   cljs-repl - ...
    clj-repl - ...
      server - ...

Options:
-----
      --npm      internal, used by the shadow-cljs npm package
      --debug
  -v, --verbose  verbose build log
  -h, --help
-----

Still need to write the docs for each action. Here are some example commands

# starts a server process, do this first so everything else is faster
shadow-cljs server

# assuming there is an :app build defined
shadow-cljs compile app
shadow-cljs watch app
shadow-cljs check app
shadow-cljs release app

# all of these can do more than one build
shadow-cljs compile build1 build2 build3

# this connects to a REPL for :app
shadow-cljs cljs-repl app

# node-repl (starts or connects)
shadow-cljs node-repl

# clojure repl
shadow-cljs cli-repl

All 6 comments

Rough outline of my plans so far

Compile 3 builds once and exit

shadow-cljs once a,b,c 
shadow-cljs release a,b,c 

Compile and watch 3 builds, stays alive until killed

shadow-cljs watch a,b,c

Connect to REPL of build c

shadow-cljs cljs-repl c

Start or connect to running node-repl that isn't tied to any build

shadow-cljs node-repl

Start background server so all other commands get faster (watch will act as server if none is running)

shadow-cljs server

Connect to CLJ REPL of server

shadow-cljs clj-repl

Questions

  • watch or dev or autobuild?
  • should server launch into a clj-repl or stay non-interactive?
  • should server allow additional commands? shadow-cljs server watch a,b,c?
  • should builds for watch|once|release be optional and default to "all"?

I was a CoffeeScript fan, I would vote for compile(--once) and watch(--dev). And by default it compiles.

https://github.com/jashkenas/coffeescript/blob/0b2d852f678694179e2d3f7e62e4ae256e60921f/src/command.coffee#L34

I just finished the first pass of the CLI refactor. Pretty much all the old options are gone. Running the command now looks like

$ shadow-cljs
shadow-cljs - config: /Users/zilence/code/shadow-cljs/shadow-cljs.edn version: 1.0.20170618
shadow-cljs - connected to server

Please specify which action to run!

Usage:
  shadow-cljs <action> <zero or more build ids>

Supported actions are:

     compile - ...
       watch - ...
       check - ...
     release - ...
   node-repl - ...
   cljs-repl - ...
    clj-repl - ...
      server - ...

Options:
-----
      --npm      internal, used by the shadow-cljs npm package
      --debug
  -v, --verbose  verbose build log
  -h, --help
-----

Still need to write the docs for each action. Here are some example commands

# starts a server process, do this first so everything else is faster
shadow-cljs server

# assuming there is an :app build defined
shadow-cljs compile app
shadow-cljs watch app
shadow-cljs check app
shadow-cljs release app

# all of these can do more than one build
shadow-cljs compile build1 build2 build3

# this connects to a REPL for :app
shadow-cljs cljs-repl app

# node-repl (starts or connects)
shadow-cljs node-repl

# clojure repl
shadow-cljs cli-repl

[email protected] includes this now. I could use some feedback if it is actually better than before.

I broke the zero-configuration hidden default :npm build and I'm not sure it worth adding back. Previously if you just ran shadow-cljs --once it compiled this "hidden" :npm build which didn't need to be in your config. shadow-cljs compile will complain if you don't give it a build id.

Currently you'd need to add this :npm build and run shadow-cljs compile npm.

{:source-paths ["src"]
 :builds
 {:npm {:target :npm-module
        :output-dir "node_modules/shadow-cljs"}}}

Any thoughts on what commands should do when you don't specify a build? Should it default to all or nothing?

How about allowing users to add an entry called :default? I don't see a real-world example though.

Not going to do the :default for now. It is ok to type shadow-cljs compile npm and the implicit npm build is back now so the config for this is optional. Just needs to be documented properly.

Was this page helpful?
0 / 5 - 0 ratings