In projects with an established architecture, developers might want to bootstrap new components or features that are consistent with the project.
tuist scaffold you generate files, you can generate files from a template. You can define your own templates or use the ones that are vendored with Tuist. These are some scenarios where scaffolding might be useful:
- Create a new feature that follows a given architecture:
tuist scaffold viper --name MyFeature.
- Create new projects:
tuist scaffold feature-project --name Home
Tuist is not opinionated about the content of your templates, and what you use them for. They are only required to be in a specific directory, with a
Template.swift manifest file that describes it.
To define templates, you can run
tuist edit and then create a directory called
Tuist/Templates that represents your template. Templates need a manifest file,
name_of_template.swift that describes the template. So if you are creating a template called
framework, you should create a new directory
Tuist/Templates with a manifest file called
framework.swift that could look like this:
import ProjectDescription let nameAttribute: Template.Attribute = .required("name") let template = Template( description: "Custom template", attributes: [ nameAttribute, .optional("platform", default: "ios"), ], files: [ .string( path: "Project.swift", contents: "My template contents of name \(nameAttribute)" ), .file( path: "generated/Up.swift", templatePath: "generate.stencil" ), .directory( path: "destinationFolder", sourcePath: "sourceFolder" ), ])
After defining the template, we can use it from the
tuist scaffold name_of_template --name Name --platform macos
Since platform is an optional argument, we can also call the command without the
--platform macos argument.
You can also use
.directory which gives the possibility to copy entire folders to a given path.
Templates can import project description helpers. Just add
import ProjectDescriptionHelpers at the top, and extract reusable logic into the helpers.