How to make my deps-new template more concise?

hi, I’m starting to develop a deps-new template and it seems like my template.edn could be more concise; this is all new to me though so I’d appreciate some feedback. The edn is

[["src/clj" "src/clj/{{top/file}}"
   {"template.clj" "{{main/file}}.clj"}]
  ["src/cljs" "src/cljs/{{top/file}}"
   {"template.cljs" "{{main/file}}.cljs"}]
  ["test/clj" "test/clj/{{top/file}}"
   {"template_test.clj" "{{main/file}}_test.clj"}]
  ["test/cljs" "test/cljs/{{top/file}}"
   {"template_test.cljs" "{{main/file}}_test.cljs"}]]

That copies this dir structure to the new project:


src/
 - clj/
   template.clj
 - cljs/
   template.cljs
test/
 - clj/
   template_test.clj
 - cljs/
   template_test.cljs

And substitutes in the project id/name. It looks like there should be a trick to do that in half as many LOC? Thanks for any advice!

The best thing you can do here IMO is to get rid of the clj/cljs separation. Just keep move it all a level up, directly to src. Such a separation bears no meaningful purpose but makes navigation worse, especially when you have shared code which you then have to put in cljc.

3 Likes

I’m using cider, so maybe this is a cider-centric question. In projects which have both clj and cljs content, I start two repls, one for “normal” clj and one for shadow-cljs. In cider, in sesman-browser I can then associate a specific directory (or file, or buffer, or project…) with an nrepl session, so that when I’m in a source file and I’m evaluating expressions, the expressions go to the correct repl.

If all the source files are in the same directory structure and mixed up, how do you achieve this seperation, @p-himik ?

1 Like

when I’m in a source file and I’m evaluating expressions, the expressions go to the correct repl.

Can’t this be decided based on the file extension? In general, you can’t evaluate code from .clj in a CLJS REPL, same for .cljs and a CLJ REPL. With .cljc it gets more complicated - you’d have to explicitly select the right REPL for each evaluation, I suppose. But that would be true even with directory separation.

how do you achieve this seperation, @p-himik ?

I’m not a frequent user of CLJS REPLs, so can’t really answer. But I imagine, I’d prefer a workflow where all forms that I evaluate get sent to the most recently used REPL, the “active” one.

From what I understand CIDER should send clj forms to the clj repl automatically. It might get complicated if you have multiple clj repls in a project for some reason.

@p-himik I like the idea of a flatter directory but I’ve never seen anyone structure a project like that, are there any other considerations/gotchas if you do?

I’ve never seen anyone structure a project like that

My experience is almost the opposite - I see both kinds of structure, but the flat one seemingly gets more and more prevalent. But that’s just my perception, I don’t have any actual data.

are there any other considerations/gotchas if you do?

None that I’m aware of.

2 Likes

If you feel like you have too much repetition, you can look at providing a :template-fn in your template as code that can expand the template.edn data – see deps-new/templates.md at develop · seancorfield/deps-new (github.com)

I have a similar setup but substitute shadow-cljs for figwheel, and on top of what you’ve written, there is also the issue of watching directories and hotloading files. I have separate src (for all .clj) and cljs-src (for .cljs and .cljc) files. If I put everything under just src then every time I save the any file, even .clj, it will trigger a compilation of all files.

From a management point of view, I also believe it’s much cleaner to keep the two separated.

1 Like

I second this. There is no reason to have any clj/cljs directory separation. The file extensions do that job adequateIy.

Ideally, you’ll want to use cljc too for code reuse purposes, which gets awkward when you suddenly need another directory structure just for that.