2

I've just started using grunt-init. I have everything working. And I was wondering if there is a way to do conditional copy root files based on prompts which based on answers to previous prompts.

pigcan
  • 93
  • 1
  • 1
  • 6

1 Answers1

2

You can make use of the rename.json file via the docs.

The prop should be the path to the file you want to copy/not copy, and the value can be a template string with a conditional. For example, let's say you had two different main.js files, one empty and one with code you tend to re-use:

{
  "app/js/main-empty.js": "{% if (empty) { %}app/js/main.js{% } %}",
  "app/js/main-skeleton.js": "{% if (!empty) { %}app/js/main.js{% } %}"
}

The destpath checks the value of the props.empty variable from your template.js file, copies and renames correctly.

Here is a link to a gist showing the template.js and rename.js for that example.