Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Approach for programmatic transformation #3

Closed
practicalli-johnny opened this issue Apr 10, 2023 · 1 comment
Closed

Approach for programmatic transformation #3

practicalli-johnny opened this issue Apr 10, 2023 · 1 comment
Assignees

Comments

@practicalli-johnny
Copy link
Contributor

practicalli-johnny commented Apr 10, 2023

How to effectively work with the seancorfield/deps-new programmatic transformation

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

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)

data-fn

updating keys in the overall template.edn file seems pretty straight forward via the data-fn

Very basic example that creates another key/value based on the value of an existing value in the template

(defn data-fn
  "Transform key/value pairs in the template
  Return: hash-map to be merged into the data by deps-new"
  [data]
  ;; returning nil means no changes to options data
  (when (= (data :component) "integrant")
    {:integrant-repl true})
 )

transform-fn

Effective ways to transform the :transform [[,,,]] data based on the template.edn key/values

Are there helpers that simplify transforming the [[ ,,, ]] structure

Libraries to review

References:
https://clojurians.slack.com/archives/C019ZQSPYG6/p1681126973615799

#21

@practicalli-johnny
Copy link
Contributor Author

Created a src/practicalli/rules.clj file to define declarative rule sets that will be returned instead of the default :transform data structure in the template.edn file for a specific template.

The template-edn function uses the substitution data to decide which rule set to return

(cond
    (= :donut (data :component))     (assoc edn :transform rules/donut)
    (= :integrant (data :component)) (assoc edn :transform rules/integrant)
    :else edn)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

1 participant