deps-new 2024-08-27

I need some pointers for something I'm trying to do with deps-new. For a #clojuredart project, you need to run a clj command after the template has copied the files, clj -M:cljd init. I would like the template to execute this task. I tried putting that code into the post-process-fn but nothing seems to be executed:

defn cljd-init "Init clojuredart file" [opts]
  (let [basis    (b/create-basis {:aliases [:init]})
        cmds     (b/java-command
                  {:basis      basis
                   :main      'clojure.main
                   :main-args ["-m" "cljd" "init"]})
        {:keys [exit]} (b/process cmds)]
    (when-not (zero? exit) (throw (ex-info "Init failed" {}))))
  opts)

(defn post-process-fn
  "Example post-process-fn handler.

  Can programmatically modify files in the generated project."
  [edn data]
  cljd-init
)
Any help greatly appreciated. (non-functional Github repo: https://github.com/gregorybleiker/cljd-templates)

@seancorfield thank you, calling the function helped. However, now I have the problem that the process is not running in the created directory (it's probably running in the template top level directory). Is there any way I can change the directory based on edn or data? And more generally: is this actually the correct deps-new way of launching a post-creation process?

I can't remember, off the topic of my head, whether the target directory is added to edn / data but I think it is. You may be the first to try the :post-process-fn approach... but, yes, this is the sort of thing I had in mind (I was originally planning to use it for creating Polylith workspaces and using poly itself to set things up once the bare minimum template had been created).

Looking at the code, :target-dir should be in the data argument passed in...

https://github.com/seancorfield/deps-new/blob/develop/doc/options.md -- I need to update that to make it clearer that several options have default values and all of those fields end up in the data argument passed around.

You're just returning the fn cljd-init from post-process-fn -- you're not calling it.

You want (cljd-init {}) or something similar (maybe build the opts from the edn and/or the data?).

@seancorfield just to double check: I actually have to spin up a new java process to run clj with a new main (cljd)? I'm unsure because the calling code is already a java/clojure process.

That's the easiest way, in the context of deps-new, since it already has tools.build as a dependency. Here's a fragment of my next.jdbc build.clj file running multi-version testing as a subprocess: https://github.com/seancorfield/next-jdbc/blob/develop/build.clj#L23-L33

👍 1