loreanvictor / tmplr

Automate Code Scaffolding
MIT License
26 stars 0 forks source link

Read values from a file? #9

Closed YuriGal closed 1 year ago

YuriGal commented 1 year ago

Is there a way to define a simple text file with key/value pairs for variable name/values and have recipe read values from that file? Or any other simple straightforward way to assign literal values to a variables? The idea is - when a repo is created from the template user just supplies their own literal values and runs the recipe that copies template files using this values for variables.

YuriGal commented 1 year ago

I think I found a way, thanks!

loreanvictor commented 1 year ago

@YuriGal may I ask how did you manage to achieve this?

YuriGal commented 1 year ago

After some trial and error I realized that tmplr kind of supports what I need already, and I can simply do something like

steps:
   - read: variable_1
     eval: 'value_1'
   - read: variable_2
     eval: 'value_2'
   # ...etc...
   - copy ./templates/fille1.tmplr.js
     to: ./src/file1.js
   - copy ./templates/fille2.tmplr.js
     to: ./src/file2.js
   # ...etc...