Hive Hive
Sign in

Scaffold doesn’t support conditional file creation

GitHub issue · Open

Metadata
Source
tuist/tuist #6862
Updated
Jun 11, 2026
Domains
CLI
Details

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

Comments
EP
Ernest0-Production Oct 13, 2024

I also highlighted this problem. I hope it will be implemented one day😄 https://github.com/tuist/tuist/discussions/5508

The current workaround for me was to write a script wrapper around Tuist Scaffold that took arguments and passed them to environment variables before calling Tuist Scaffold. This way I could read the “attributes” on the basis of which conditional logic could be built, instead of using the built-in attribute mechanism.

F
fortmarek Oct 16, 2024

Hey 👋

I agree this would be a good addition.

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:

This would have been amazing but I’m not 100 % sure how you would achieve something like that. When compiling Template.swift, you would need to predefine variables from the CLI invocation – is that possible? Maybe. Worth exploring at least!

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).

If the above doesn’t work, then yeah, this is a good alternative.

H
hanrw Mar 27, 2025

+1

let appTemplate = Template(
description: "New App template",
attributes: [
nameAttribute,
.optional("platform", default: "ios"),
],
items: [
.directory(path: "Tuist", sourcePath: "../../ProjectDescriptionHelpers"),
]
)

the appTemplate would be run again in the future. should skip create the directory if it’s exist.

D
dosubot[bot] Mar 28, 2026

Hi, @DmitrySerovWise. I’m Dosu, and I’m helping the tuist team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You raised a request for Tuist Scaffold to support conditional file or directory creation based on attribute values.
  • Some community members shared workarounds using script wrappers to simulate conditional logic.
  • Others agreed on the enhancement but noted potential challenges in implementation.
  • There is interest in improving template flexibility, but no concrete solution or official support has been implemented yet.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of Tuist by commenting here to keep the discussion open.
  • Otherwise, this issue will be automatically closed in 7 days.

Thanks for your understanding and contribution!

L
linear[bot] Mar 28, 2026
D
DmitrySerovWise Mar 31, 2026

Issue still relevant, issue persists in 4.162.1

D
dosubot[bot] Mar 31, 2026

@pepicrft The user DmitrySerovWise has confirmed the issue is still relevant and persists in version 4.162.1. Could you please assist with this?