Fork me on GitHub
#deps-new
<
2023-04-10
>
practicalli-johnny11:04:53

Are there examples of code for programmatic transformation in deps-new , especially for the transform-fn that updates the :transform data ? There was some discussion in https://github.com/seancorfield/deps-new/issues/35 about helper functions. I have the basic idea of programmatic transformation from the docs and adding or updating keys in the template.edn file seems pretty straight forward via the data-fn So wondering if there examples of how to effectively work with the :transform [[,,,]] data. If anyone has created some helpers, that would be great to see. Also wondering if https://github.com/clj-commons/rewrite-clj is a useful library to help (seems relevant, but havent yet tried it) One thing that is not so clear from the docs is the difference between data and edn - although I added a println function to show the respective values in each when running the template (I am assuming data is keys from the template and edn is the template plus the project basis, maybe some other bits) I assume the simplest way is to have different files used as the source where code should be different based on a give option. It seems a more involved approach to rewrite template files, although depending on the changes this may make a simpler template to maintain I'm creating a number of declarative templates first, then will start looking for opportunities to refine the templates with programmatic transformation. Thanks.

seancorfield17:04:34

data is the substitution data -- the variables that are available to templates, either built-in or gathered from the command-line options -- data-fn is called with this value and whatever it returns is merged into the substitution data • edn is the template.edn structure itself -- template-fn is called with this value and the updated data structure (after calling data-fn and merging the result) and whatever it returns is used as the new template.edn structure

seancorfield17:04:15

If you have suggestions to make that clearer in the docs, feel free to create issues and/or pull requests. I'm assuming you read https://github.com/seancorfield/deps-new/blob/develop/doc/templates.md but it still wasn't clear?

practicalli-johnny22:04:40

Once I looked at what was being printed from data and edn when creating the project it was very clear what the distinction was and I understood specifically what was being described. Once I'm happy I've understood everything then I'll take another look at the deps-new docs. The docs are comprehensive, I just need to help my brain absorb what it all means... Thanks.

1
practicalli-johnny22:04:25

Is there a way to prevent .keep file from being added to the resources directory of a new project? Assuming I have a template that copies a file to resources, then I believe the .keep is redundant. I tried defining a declarative rule to only copy a config.edn.template to resources using the :only key, but .keep was also included in the new project along with the config.edn file

:transform
[["api" "src/{{top/file}}/api"
   {"system_admin_router.clj.template" "system_admin/router.clj"
    "system_admin_handler.clj.template" "system_admin/handler.clj"}]
  ["build" ""
   {"build.clj.template" "build.clj"
    "deps.edn.template"  "deps.edn"}]
  ["resources" "resources"
   {"config.edn.template" "config.edn"} :only]
  ["src" "src/{{top/file}}"
   {"middleware.clj.template" "middleware.clj"
    "parse_system.clj.template" "parse_system.clj"
    "router.clj.template" "router.clj"
    "service.clj.template" "{{main/file}}.clj"}]
  ["test" "test/{{top/file}}"
   {"service_test.clj.template" "{{main/file}}_test.clj"}]]
Am I missing something or should I raise an feature request to skip the .keep file when :only is used (or just not copied if another file is already there) I assume .keep is only used as otherwise resources would be empty.

seancorfield22:04:38

deps-new itself doesn't add .keep -- that comes from the template. If you don't want it, don't put it in your template?

seancorfield22:04:37

I suspect it's in your root folder? The entire contents of that are copied into the target folder first, then the :transform stuff is overlaid.

seancorfield22:04:23

I suspect your "build" transform will also need :only? Wasn't that the issue we discussed earlier...?

practicalli-johnny22:04:40

Ah yes, its in the root .. I missed that, sorry

practicalli-johnny22:04:32

The build directory is fine as there are mappings from the *.template files to the new file names. The original template files do not appear in the new project

seancorfield22:04:57

https://github.com/seancorfield/deps-new/commit/c4bbcfc40a102b5e73a387550fd7c375aa522079 was the commit where I added :only to more folders in the transform lists in the built-in templates, to avoid stray build.tmpl appearing in the root of the generated project...

practicalli-johnny22:04:29

Yes, that is curios that it was copying build.tmpl into the new project, but I dont get the same with build.edn.template... maybe I hadnt tried until I started using 0.5.1

practicalli-johnny22:04:10

I assume if there is a file mapping in a directory (other than root) then the original file is not copied. If that is not correct then I can add :only but it doesnt seem to be neccessary with 0.5.1. I can do some testing if this is incorrect behaviour

seancorfield23:04:47

The only thing that changed on 0.5.1 is that the built-in templates had :only added to them for folders where all files were explicitly mapped. But I am surprised that you are not seeing the .template files being copied (and left behind).

seancorfield23:04:21

Oh wait, I see why! The change was specifically for the template template, and it happened because there are multiple transforms on the build folder, targeting different sets of files.

seancorfield23:04:31

So, nothing to see, move along... 🙂

seancorfield23:04:57

You only need :only if you are processing a subset of the files from a given folder.

👍 2