gruntwork-io / boilerplate

A tool for generating files and folders ("boilerplate") from a set of templates
https://www.gruntwork.io
Mozilla Public License 2.0
160 stars 12 forks source link

Add support for callbacks #18

Open brikis98 opened 7 years ago

brikis98 commented 7 years ago

To make boilerplate even more flexible and powerful, it would be great to support "callbacks" where you can provide arbitrary code to execute at specific times. For example, there could be a start callback that gets called just after Boilerplate gathers all variables but before it starts generating; a file callback called for each file and folder Boilerplate processes; and an end callback called after project generation is finished. The callbacks could be defined as simple shell commands in boilerplate.yml:

variables:
  - name: foo
  - name: bar

callbacks:
  start: echo "Boilerplate is generating files to $2 from templates in $1"
  file: echo "Boilerplate is processing file $1"
  end: echo "Boilerplate finished generating files in $2 from templates in $1"
josh-padnick commented 7 years ago

Can you give an example use case of this?

brikis98 commented 7 years ago

Sure. Let's say you're using boilerplate to generate a skeleton for a react.js project. Actually, here's an example of just such a template: https://github.com/Granze/react-starterify

You could package that template as a boilerplate template and use the callbacks as follows: