Hive Hive
Sign in

Allow custom “context” values in ResourceSynthesizer Stencil templates

GitHub issue · Open

Metadata
Source
tuist/tuist #7747
Updated
Jun 11, 2026
Domains
Generated projects
Details

Why is this needed?

Stencil templates allows resolution of custom parameters of any kind, and many of them are already passed from Tuist via SwiftGen when using ResourceSynthesizers. However, I’ve found the need of having some layer of customization in either default Tuist templates and custom ones

Example: the Files template takes an accessModifier (public or implicitly internal when omitted) that cannot be set anywhere in any ProjectDescription. This and other default parameters are hardcoded at the end of this generator

This - in my opinion - is a limit to a feature that can help developers writing better custom architectures for their apps.

Steps to address the need

We should declare some Context object (I’d say a dictionary similar to the ones in use with plist, build settings and entitlements) that can take arbitrary parameters that will be passed down until the SwiftGenKit integration.

In ProjectDescription.ResourceSynthesizer we should add this Context parameter to every existing method, defaulting to an empty one when not needed.

Every in-between object should be changed accordingly.

When merging the customized Context with the default Tuist one, the customized values should overwrite the defaults.

Nothing should change for anyone already using synthesizers.

We should also add a new fixture that test this new feature OR change the existing one for resource synthesizers to be enriched with this new context.

Comments
S
stefanomondino Jun 26, 2025

Note: there’s already a parserOptions parameter that is a SwiftGen strictly-related element (it confused me at first, because it’s a dictionary as well). What I’m aiming here is to be able to write a Stencil template containing something like this

// .. other stuff
let someTest = "{{myCustomValue}}"
// ... more stuff

and then being able to declare a synthesizer like .files(extensions: ["json"], context: ["myCustomValue": "Tuist FTW"])

so that my synthesized file will look like

// .. other stuff
let someTest = "Tuist FTW"
// ... more stuff