apryor6 / flaskerize

Python CLI build/dev tool for templated code generation and project modification. Think Angular schematics for Python.
BSD 3-Clause "New" or "Revised" License
122 stars 13 forks source link

Create extensible templates #6

Closed apryor6 closed 5 years ago

apryor6 commented 5 years ago

Ideation

We should move away from defining templates within the project itself towards a model where definitions can be provided by external sources. This should include the files/directories to be created, a schema file (JSON format?) defining the available parameters (including help messages, shortcut flags, type information).

I'm not set on a naming convention, but I am thinking that all templates/schematics (whatever we call them) would have names with a .template.<extension> syntax, i.e. my_resource.template.py that generates the my_resource.py using provided context parameters. The names of the files/directories must themselves be parameterized via the same mechanism as the code within them.

A very nice feature of Angular schematics that I would like here is a way for parameterization via function calls. This allows you to have a base name for a resource that gets reused in-kebob-format as well as lowerCamelCase or PascalCase where it makes sense. There are multiple ways to accomplish this same thing in Python, and I am not yet sure which is the best. Possibilities include:

Overwriting existing files

If a template file is to be created that already exists on the actual file system, there should be a flag and/or interactive prompt to prevent accidentally stepping on existing files. This would be a flaskerize-level switch and not provided at the schematic level for obvious reasons (perhaps --force or --overwrite)