server/priv/docs/yue_Hant/guides/features/projects/plugins.md
Plugins are a tool to share and reuse Tuist artifacts across multiple projects. The following artifacts are supported:
Note that plugins are designed to be a simple way to extend Tuist's functionality. Therefore there are some limitations to consider:
If you need more flexibility, consider suggesting a feature for the tool or
building your own solution upon Tuist's generation framework,
TuistGenerator.
A project description helper plugin is represented by a directory containing a
Plugin.swift manifest file that declares the plugin's name and a
ProjectDescriptionHelpers directory containing the helper Swift files.
::: code-group
import ProjectDescription
let plugin = Plugin(name: "MyPlugin")
.
├── ...
├── Plugin.swift
├── ProjectDescriptionHelpers
└── ...
:::
If you need to share
<LocalizedLink href="/guides/features/projects/synthesized-files#resource-accessors">synthesized resource accessors</LocalizedLink> you can use this type of plugin. The plugin
is represented by a directory containing a Plugin.swift manifest file that
declares the plugin's name and a ResourceSynthesizers directory containing the
resource accessor template files.
::: code-group
import ProjectDescription
let plugin = Plugin(name: "MyPlugin")
.
├── ...
├── Plugin.swift
├── ResourceSynthesizers
├───── Strings.stencil
├───── Plists.stencil
├───── CustomTemplate.stencil
└── ...
:::
The name of the template is the camel case version of the resource type:
| Resource type | Template file name |
|---|---|
| Strings | Strings.stencil |
| Assets | Assets.stencil |
| Property Lists | Plists.stencil |
| Fonts | Fonts.stencil |
| Core Data | CoreData.stencil |
| Interface Builder | InterfaceBuilder.stencil |
| JSON | JSON.stencil |
| YAML | YAML.stencil |
When defining the resource synthesizers in the project, you can specify the plugin name to use the templates from the plugin:
let project = Project(resourceSynthesizers: [.strings(plugin: "MyPlugin")])
[!WARNING] Deprecated
Task plugins are deprecated. Check out this blog post if you are looking for an automation solution for your project.
Tasks are $PATH-exposed executables that are invocable through the tuist
command if they follow the naming convention tuist-<task-name>. In earlier
versions, Tuist provided some weak conventions and tools under tuist plugin to
build, run, test and archive tasks represented by executables in Swift
Packages, but we have deprecated this feature since it increases the maintenance
burden and complexity of the tool.
If you were using Tuist for distributing tasks, we recommend building your
ProjectAutomation.xcframework distributed with
every Tuist release to have access to the project graph from your logic with
let graph = try Tuist.graph(). The command uses sytem process to run the
tuist command, and return the in-memory representation of the project graph.arm64 and x86_64 in GitHub releases, and using
Mise as an installation tool. To instruct Mise on how
to install your tool, you'll need a plugin repository. You can use
Tuist's as a reference.tuist-{xxx} and users can install it by running mise install, they can run it either invoking it directly, or through tuist xxx.[!NOTE] The Future Of Projectautomation
We plan to consolidate the models of
ProjectAutomationandXcodeGraphinto a single backward-compatible framework that exposes the entirity of the project graph to the user. Moreover, we'll extract the generation logic into a new layer,XcodeGraphthat you can also use from your own CLI. Think of it as building your own Tuist.
To use a plugin, you'll have to add it to your project's
<LocalizedLink href="/references/project-description/structs/tuist">Tuist.swift</LocalizedLink>
manifest file:
import ProjectDescription
let tuist = Tuist(
project: .tuist(plugins: [
.local(path: "/Plugins/MyPlugin")
])
)
If you want to reuse a plugin across projects that live in different
repositories, you can push your plugin to a Git repository and reference it in
the Tuist.swift file:
import ProjectDescription
let tuist = Tuist(
project: .tuist(plugins: [
.git(url: "https://url/to/plugin.git", tag: "1.0.0"),
.git(url: "https://url/to/plugin.git", sha: "e34c5ba")
])
)
After adding the plugins, tuist install will fetch the plugins in a global
cache directory.
[!NOTE] No Version Resolution
As you might have noted, we don't provide version resolution for plugins. We recommend using Git tags or SHAs to ensure reproducibility.
[!TIP] Project Description Helpers Plugins
When using a project description helpers plugin, the name of the module that contains the helpers is the name of the plugin
swiftimport ProjectDescription import MyTuistPlugin let project = Project.app(name: "MyCoolApp", platform: .iOS)