Comments (3)
@Ernest0-Production
Manifests that contain logic that depends on the current directory is generally discouraged
This is required to automate some actions in my project
Could you share an example so that I can provide with a solution or path forward.
from tuist.
Could you share an example so that I can provide with a solution or path forward
Hello. I really wanted to be able to write a custom mechanism for automatically generating type-safe access to target resources via SwiftGen.
The limited API of Tuist with the resource synthesizer
did not really suit me, and I decided to add my own side effects to the project generation (tuist generate
):
- in the
Project.swift
file, when creating a target and if resources were available, I generated aResourceType+Generated.swift
file.
extension Target {
func feature(name: String) -> Target {
Target.target(
name: name,
scripts: {
let resourcesPaths: [String] = FileManager.shared.subpaths(in: <path/feature/resources>)
// some magic for filter resources by resource kind
let resources: [ResourceType: [Path]] = resourcesPaths.reduce(....)
return resources.map { resourceType, inputPaths in
TargetScript.pre(script: "swiftgen run \(resourceType) --input .... --output \(inputPaths.join(separator: " ")) ")
}
}()
)
}
}
- Before generating the project, I generated a checksum of the project file structure. If
ResourceType+Generated.swift
was deleted, and/or a new resource type appeared (localization or fonts, for example), then the user would invalidate the cache and recompile and run the manifest, causing my side effects to be called again.
I came to this decision because I tried many other right and wrong approaches. The reason for this is that it is important for me to have access to the code that I use to generate the project.
The ProjectAutomation
API is very limited and does not allow you to change the project. And using XcodeProj forces you to go down to a lower level, which does not seem very convenient.
from tuist.
Gotcha. As you noted, we'd love to expose an API for this because ProjectAutomation
is very limited. But before we get there, we want to implement a fully-fledged plugin system with great ergonomics.
Until that exists, I recommend taking a different approach where the manifests don't have side effects. If we open an API that implicitly accepts imperative code depending on file-system files, we'd be opening the door for for complexity in the manifests, and potentially the breakage of features that assume no side effect in those files.
Since your logic requires accessing the declaration of your project, you can implement a small CLI, maybe in an Xcode project, that imports the dynamic ProjectDescription.framework
framework distributed with your Tuist installation. Then you can have a generation pipeline that looks like this:
#!/usr/bin/bash
generation_tool # It's noop if nothing has changed
tuist generate
from tuist.
Related Issues (20)
- Removing a dependency breaks tuist generate. HOT 1
- Build settings from PackageSettings not work as expected
- Install by homebrew, and create project failed! HOT 4
- Specify output/destination for `generate` command. HOT 1
- Excluding an SPM Dependency from a build by reading a flag HOT 5
- <ExternalDependency> is not a valid configured external dependency HOT 2
- Tuist with dependency cycle failed to generate HOT 6
- Issue with enforceExplicitDependencies and Find Implicit Dependencies Checkbox Interaction
- OpenCV fails to compile in a mixed source project with resources due to conflicting NO macro definition HOT 2
- tuist test with swiftlint script occured No lintable files found at paths: '' error HOT 4
- watchOS and visionOS project init errors HOT 3
- Braze SDK can't load the resources HOT 2
- Firebase version 7.13.3 fails to build with Tuist projects HOT 1
- Tuist SPM tutorial doesnโt work correctly any more HOT 3
- Tuist prints out warnings when using Braze HOT 4
- Tuist cache should allow pre-built local cache to be sync with the cloud HOT 2
- Support passing `xcodebuild` arguments to `build` and `test`
- Headers not mapped from Umbrella header when productName is nil HOT 1
- How to Configure Different Bundle Identifiers Per Scheme in Tuist HOT 3
- Tuist does not allow for codesigning copied filies
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tuist.