Fork me on GitHub
#tools-deps
<
2018-08-28
>
richiardiandrea18:08:42

@seancorfield question about clj-new's generators - how do I handle the case where I want to modify a file in the project root, like a deps.edn?

richiardiandrea18:08:55

(and is it common/good practice?)

seancorfield18:08:14

@richiardiandrea That sounds like a nice enhancement -- to expose the prefix argument somehow. Feel free to open an issue.

seancorfield18:08:46

The main obstacle right now is that you can't specify the prefix (or any other parameters to generate-code under the hood), mostly because the command line processing isn't very sophisticated. Hence the open issue about looking at tools.cli for some of this.

👍 4
richiardiandrea19:08:48

@seancorfield sorry other question, can I build a template that accepts a single path in clj-new ?

seancorfield19:08:01

I'm not quite sure what you're asking there?

seancorfield19:08:39

If your template function accepts [name & args] instead of the default [name], then any additional arguments you provides on the command-line are passed in...

richiardiandrea19:08:32

it seems like I always receive an error directly from clj-new if I pass the project name as my-template-test for instance

seancorfield19:08:32

$ clj -Sdeps '{:deps {clj-new {:git/url "" :sha "108f27159501f8ce12564b398b0ea50def3892b1"}}}' -m clj-new.create template myt/thing
...
$ vi thing/src/clj/new/thing.clj # add & args and print them out
$ clj -Sdeps '{:deps {clj-new {:git/url "" :sha "108f27159501f8ce12564b398b0ea50def3892b1"} my/thing {:local/root "./thing"}}}' -m clj-new.create thing another.generated.thing with args
Generating fresh 'clj new' thing project.
args= (with args)
$ 

seancorfield19:08:43

clj-new does not accept a single-segment name

richiardiandrea19:08:55

oh ok that's what I feared

seancorfield19:08:59

It must either be a multi.segment.name or a qualified/name

seancorfield19:08:21

Phil always regretted allowing that bad practice for lein new 🙂

seancorfield19:08:45

You can always say my-template-test.core to get the Leiningen behavior.

richiardiandrea19:08:53

too bad because it feels natural for JS devs (which are my audience now)

richiardiandrea19:08:09

have to explain that 😄

seancorfield19:08:12

The docs say: > The project name should be a qualified Clojure symbol, where 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). An alternative is to use a multi-segment project name, such as foo.bar (the folder created will be called foo.bar and will contain src/foo/bar.clj).

seancorfield19:08:57

BTW, note above how I generated a template and then used it via :local/root 🙂 Gotta love the whole clj / deps.edn thing!

richiardiandrea19:08:17

yeah I am using the :local/root thing, it is a nice thing

richiardiandrea19:08:00

the thing is, JS users do not care/are used to the Java wait of packaging - therefore they consider it an additional burden..

richiardiandrea19:08:17

some people here at least 😄

richiardiandrea19:08:35

so the naming now for them feels Java-y

seancorfield19:08:56

JS people should learn the benefits of globally unique names 🙂

seancorfield19:08:15

I have zero sympathy! :rolling_on_the_floor_laughing:

richiardiandrea19:08:01

well, they have a group as well but very few people use it

seancorfield20:08:45

I will admit that when generating a new template, the qualified/multi-segment thing doesn't work as expected. If you use a qualified/name then the qualified part is ignored. If you use a multi.segment.name you get an illegal project (src/clj/new/multi.segment.name.clj). That's a bug that I haven't opened an issue for yet because there are restrictions on how template functions are named, including their namespace, so I'm not sure how best to resolve that conflict.

seancorfield20:08:14

The simplest solution would be to allow simple names for templates but... ¯\(ツ)

😺 4
richiardiandrea20:08:34

also I don't see any util to get only the myproj from something like my.long.group/myproj

seancorfield20:08:00

If you generate an actual project for my.long.group/myproj the qualifier part goes into the namespaces:

(! 978)-> clj -Sdeps '{:deps {clj-new {:git/url "" :sha "108f27159501f8ce12564b398b0ea50def3892b1"}}}' -m clj-new.create app my.long.group/myproj
Generating a project called myproj based on the 'app' template.

Tue Aug 28 13:13:34
(sean)-(jobs:0)-(~/clojure)
(! 979)-> tree myproj
myproj
|____.gitignore
|____.hgignore
|____CHANGELOG.md
|____deps.edn
|____doc
| |____intro.md
|____LICENSE
|____README.md
|____resources
| |____.keep
|____src
| |____my
| | |____long
| | | |____group
| | | | |____myproj.clj
|____test
| |____my
| | |____long
| | | |____group
| | | | |____myproj_test.clj

richiardiandrea21:08:06

uhm this does not seem to work in my template...I always get: Could not create directory /home/arichiardi/tmp/my.long.group/myproj. Maybe it already exists? Use -f / --force to overwrite it.. Super weird I am doing the same thing that your app is doing

richiardiandrea22:08:52

oh found the problem, :name is actually used by ->files! didn't expect that 😄

seancorfield20:08:29

That's how Leiningen and Boot work.

richiardiandrea20:08:40

yes that works but I would like to have {:project-name ...} in my data

richiardiandrea20:08:47

working on a patch

seancorfield20:08:09

{:project-name ...} in what data?

richiardiandrea20:08:00

the template data

richiardiandrea20:08:17

together with {:year ... :name ...}

seancorfield20:08:24

Ah, yes, the template generator could do with a lot of enhancements.

richiardiandrea20:08:54

this is something I really need, so patch will be coming

seancorfield20:08:00

The app generator has :name for (project-name name)

seancorfield20:08:30

You might consider sending a similar patch to boot-new since it's pretty much the same code, as I recall?

seancorfield20:08:16

The template already has :raw-name by the way -- which is the whole name.

seancorfield20:08:37

(but the template template does not have all that -- and it probably should https://github.com/seancorfield/clj-new/blob/master/src/clj/new/template/temp.clj )

richiardiandrea20:08:38

kk will see what I can do

richiardiandrea20:08:45

maybe I can just roll my own template

cfleming23:08:04

Am I correct in thinking that there’s no way right now to get the CLI to output the actual Java command that would be executed?

cfleming23:08:24

Is that cached, or is it only the classpath that’s cached?

cfleming23:08:08

Never mind, poking through the code, I see the .libs, .cp, .jvm and .main files.