cookieninja-generator / cookieninja

A cross-platform command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, C projects - a cookiecutter fork
BSD 3-Clause "New" or "Revised" License
68 stars 7 forks source link

Conditional files #61

Open OverkillGuy opened 1 year ago

OverkillGuy commented 1 year ago

Long-requested feature of cookiecutter: conditional file inclusion.

I wish to make a template that can generate a Kubernetes Helm chart, or don't, based on how comfortable people are with Kubernetes (or just fall-back to docker-compose file). To do this currently, I need to add a post-gen hook script that runs rm -r kubernetes_subfolder after generation, or something more elaborate[1].

I wish files or folders could be not included based on an if expression in filename: filename cli.py {% if cookiecutter.is_cli %} or {% if cookiecutter.kubernetes_scaffold%} k8s. Not fussy with the syntax, just wish it was in filename, not requiring a file deletion system.

[1]: My overcomplicated but "so elegant" solution, used here is to have all conditional files have sentinel content if they shouldn't be included see example, and in post-gen hook, fingerprint (sha256) the sentinel string, fingerprint all the expanded files, then delete the files with sentinel-string-hash.

OverkillGuy commented 1 year ago

This ticket and a few others I opened (and will open) are things I always wished cookiecutter could do, but the "advanced maturity" of the project was holding back massive changes of the sort.

Now that I see new blood injected in the project, I'm opening up the complaints department to write a bunch of feature requests! Hoping that's valuable to all, not just nagging =D

rafalkrupinski commented 1 year ago

copier can do it