[ANN] clj-new -- creating new Clojure projects using the clj CLI

520 views
Skip to first unread message

Sean Corfield

unread,
Apr 17, 2018, 11:06:16 PM4/17/18
to Clojure Mailing List

clj-new -- https://github.com/seancorfield/clj-new

 

This will generate new projects for you, either based on `clj`, or from any existing Leiningen or Boot template (or, I hope in the future, `clj-template` projects!).

 

You'll probably want to add clj-new as an alias in your ~/.clojure/deps.edn like this:

 

{:aliases

{:new {:extra-deps {seancorfield/clj-new

                     {:git/url "https://github.com/seancorfield/clj-new"

                      :sha "492bb2e7ad7373a8b5958124a86cddc4c7a123d5"}}

        :main-opts ["-m" "clj-new.create"]}}

...}

 

Create a basic application:

 

    clj -A:new app myname/myapp

    cd myapp

    clj -m myname.myapp

 

Run the tests:

 

    clj -A:test:runner

 

Yes, the `deps.edn` generated from the `app` (and `lib`) built-in template includes aliases to include your `test` folder, add `test.check` as a dependency, and bring in and run Cognitect's `test-runner`

 

The project name should either be a qualified Clojure symbol or a multi-segment name -- single segment project names are not allowed!

 

For a qualified Clojure symbol, the first part is typically your GitHub account name or your organization's domain reversed, e.g., `com.acme`, and the second part is the "local" name for your project (and is used as the name of the folder in which the project is created).

 

For a multi-segment project name, such as `foo.bar`, the folder that will be created would be called `foo.bar` and will contain `src/foo/bar.clj`.

 

Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

 

Didier

unread,
Apr 18, 2018, 1:33:55 PM4/18/18
to Clojure
Hum, cool.

First time I realize that clj could become the npm of Clojure.

Couldn't you pull leiningen down from it in a similar fashion? And have a lein alias?

Sean Corfield

unread,
Apr 18, 2018, 9:33:39 PM4/18/18
to clo...@googlegroups.com

Well, clj-new will use Leiningen as a library if you ask it to create you a new project from a Leiningen template:

 

                clj -A:new figwheel my.fig.project

 

It depends on [leiningen-core “2.7.1”] to render figwheel/lein-template (a lot of Leiningen templates seem to reach into the innards of Leiningen for various things). That doesn’t get you the lein shell script, however (which you can’t get as a dependency), but you can do a lot of things just with leiningen-core. For another example of using Leiningen itself as a library, see http://seancorfield.github.io/blog/2017/11/17/boot-localrepo/ where I show how to start a Boot REPL with (the whole of) Leiningen as a dependency and a Leiningen plugin, and then run lein commands from the REPL (still no shell script!).

 

If you ask clj-new to create a project from a Boot template, it will can do that out-of-the-box (since it is basically a fork of boot/new without any of the Boot dependencies):

 

                clj -A:new simple-yada-template simple.yada

 

(that will cause boot/new 0.5.2 to be downloaded, but only as a transitive dependency of simple-yada-template/boot-template).

 

Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

 


From: clo...@googlegroups.com <clo...@googlegroups.com> on behalf of Didier <did...@gmail.com>
Sent: Wednesday, April 18, 2018 10:33:55 AM
To: Clojure
Subject: [ANN] clj-new -- creating new Clojure projects using the clj CLI
 
Hum, cool.

First time I realize that clj could become the npm of Clojure.

Couldn't you pull leiningen down from it in a similar fashion? And have a lein alias?

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Didier

unread,
Apr 19, 2018, 3:18:08 AM4/19/18
to Clojure
Ah, awesome.

I guess I'm starting to think, it would be great if clj supported something like:

clj --install alias-name alias-url

So maybe in a repo, you could put a file of a given convention in the root with a common name. Clj could pull it, it would contain a clj alias in it, and clj would auto add it to your deps.edn file as an alias. You could add a -g option to add it to your global deps.edn, if you wanted to "install" it globally.

Nothing else would happen.

But then, you could run your newly "installed" clojure program by doing:

clj -A:alias-name args ...

If you omit the alias name, it could default to something specified in the alias file.

What that alias url resolves too, I'm not sure. I'm thinking a git url to an alias-install.edn file which contains something like:

{:default-alias-name alias-map-to-add-as-an-alias}

And similarly, you could add:

clj --uninstall alias-name

And it would remove the alias from your deps.edn, or if given -g, from your global deps.edn config.

Ideally, it would remember the alias-url in the deps.edn file, so you could run:

clj --update alias-name

Maybe there could even be a kind of global url repo, with a list of registered alias names, so one could do:

clj --install alias-name

And it would know where to pull the alias-install.edn file from based on some global repo of distributed Clojure programs.

I'd love this. Would seem like a pretty great way to deliver Clojure programs, which does not require any bash script, adding anything to your PATH, or having to edit a file.

So for clj-new, ideally one could do:

clj --install -g clj-new

And clj would take care of adding the alias for it in my global deps.edn.

But at the very least, without the alias registry, once could simply do:


Which would auto-install the alias from a top level alias-install.edn file inside the repo.

Something of the sort.

Alan Moore

unread,
Apr 19, 2018, 3:21:25 AM4/19/18
to Clojure
Nice... this looks super helpful, thanks!

Alan

Arnout Roemers

unread,
Apr 19, 2018, 4:50:16 AM4/19/18
to Clojure
Nice work! Another addition to the CLI tools ecosystem.

Maybe worth mentioning that a oneliner may suffice, for those just wanting to try it out without altering the global deps.edn:

clj -Sdeps '{:deps {seancorfield/clj-new {:git/url "https://github.com/seancorfield/clj-new" :sha "492bb2e7ad7373a8b5958124a86cddc4c7a123d5"}}}' -m clj-new.create ...


Sean Corfield

unread,
Apr 19, 2018, 1:39:09 PM4/19/18
to clo...@googlegroups.com

I had the one-liner in an earlier version of the README but decided it was unreadable (a single long line is hard to read when it scrolls so much).

 

Maybe I’ll put it back somewhere in there…

 

Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

 


From: clo...@googlegroups.com <clo...@googlegroups.com> on behalf of Arnout Roemers <goo...@company.romeinszoon.nl>
Sent: Thursday, April 19, 2018 1:50:16 AM
To: Clojure
Subject: Re: [ANN] clj-new -- creating new Clojure projects using the clj CLI
 
Nice work! Another addition to the CLI tools ecosystem.

Maybe worth mentioning that a oneliner may suffice, for those just wanting to try it out without altering the global deps.edn:

clj -Sdeps '{:deps {seancorfield/clj-new {:git/url "https://github.com/seancorfield/clj-new" :sha "492bb2e7ad7373a8b5958124a86cddc4c7a123d5"}}}' -m clj-new.create ...


John Newman

unread,
Apr 19, 2018, 2:01:12 PM4/19/18
to Clojure
These are nice ideas... Sort of like nmp. But you could implement this yourself as a lib and stick it behind a `clj -A:install ...` tool.

@dominicm (on clojurians.slack) has build an "injector" tool into pack, which you could reimplement into something that you're describing: https://github.com/juxt/pack.alpha/blob/master/src/mach/pack/alpha/inject.clj

Who knows, maybe if some of these aliases get super popular and standardized, we can convince Alex to fold some of them into the tools over time :)

V/r

John 

John

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.

Tim Visher

unread,
Apr 20, 2018, 8:12:46 AM4/20/18
to Clojure
On Thu, Apr 19, 2018 at 1:38 PM, Sean Corfield <se...@corfield.org> wrote:

I had the one-liner in an earlier version of the README but decided it was unreadable (a single long line is hard to read when it scrolls so much).

 

Maybe I’ll put it back somewhere in there…


Might I suggest:

```
clj -Sdeps '{:deps
              {seancorfield/clj-new
                {:git/url "https://github.com/seancorfield/clj-new"
                 :sha "492bb2e7ad7373a8b5958124a86cddc4c7a123d5"}}}' \
  -m clj-new.create \
  app \
  bibbity.bobbity.boo
```

It copy/pastes just fine. :)

Sean Corfield

unread,
Apr 20, 2018, 3:29:51 PM4/20/18
to clo...@googlegroups.com

Alright, added command-line usage back into the README! Talk about “peer pressure” 😊

 

Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

 


From: clo...@googlegroups.com <clo...@googlegroups.com> on behalf of Tim Visher <tim.v...@gmail.com>
Sent: Friday, April 20, 2018 5:11:53 AM

To: Clojure
Subject: Re: [ANN] clj-new -- creating new Clojure projects using the clj CLI
--

Gregg Reynolds

unread,
Apr 20, 2018, 3:32:34 PM4/20/18
to clo...@googlegroups.com


On Fri, Apr 20, 2018, 2:29 PM Sean Corfield <se...@corfield.org> wrote:

Alright, added command-line usage back into the README! Talk about “peer pressure” 😊

...


"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Apparently you are alive and well!

Very well done, btw.

G
Reply all
Reply to author
Forward
0 new messages