What problem or need do you have?
When using Tuist Scaffold, the API for template description assumes all files/directories (i.e. template items) actually get created. While this is useful for most usecases, sometimes it makes sense to create files/directories depending on the values of the attributes.
For example, suppose I want to support --hasTests boolean attribute for a template that creates a new app module.
When true, I want to be able to create some files for testing. Currently the items of the template don’t have conditions attached to them, or any way to evaluate the value passed to the scaffold invocation, to be able to control the template item list to include/exclude testing files.
The only exception is when the attribute is a String value used as a part of a file path string interpolation, because the paths are actually expanded in TemplateGenerator.swift:63.
Potential solution
I’m not sure what the ideal API should look like.
Maybe the Template.Item type can get a condition parameter, similar to how a TargetDependency can be constrained to different platforms. Within the condition, a boolean attribute might be passed (which is not possible with the current typing around these entities so will require a refactor).
Another way would be rethinking how attributes are consumed and expanded to allow the template code access to the attribute values, which means the desired effect can be achieved with a simple if:
if hasTestsAttribute.value { …. }
macOS version
14.7
Tuist version
4.29.1
Xcode version
16.0