-
-
Notifications
You must be signed in to change notification settings - Fork 39
Description
Please summarize your feature request
Can it be straightforward to handle these scenarios?
Describe the functionality you're seeking in more detail
I found it somewhat complex to configure the Leaf root directory when run in the 3 scenarios I need:
- Xcode for local development
- "swift test" for CI testing
- With the Vapor Heroku build package with a monorepo
Specifically, these 3 scenarios seem to all require different leaf configurations. While the docs indicate that I can set the working directory of the scheme to solve the Xcode configuration, this doesn't really work for multiple developers who will have different directory structures. (As far as I can tell, using $(SRCROOT), $(PACKAGE_ROOT), etc don't work in the "working directory" option for a scheme).
The best solution I have so far is to put the .leaf files in the Resources directory so they will get copied to DerivedData for running in Xcode, but this doesn't work with SPM or Heroku (Leaf refuses to load from the .bin or .swift-bin directory).
So right now my code to configure Leaf looks like this:
private func getLeafRootDirectory(app: Application) -> String {
let pathFromPackage = "Sources/Resources/Templates"
let pathFromRoot = "Packages/SwiftBackend/Sources/Resources/Templates"
return if FileManager.default.fileExists(atPath: pathFromPackage) {
// When running from SPM use the path from the package root
pathFromPackage
} else if FileManager.default.fileExists(atPath: pathFromRoot) {
// When deployed on Linux use the path from the repo root
pathFromRoot
} else {
// When run from Xcode, the working directory is in DerivedData
Bundle.module.url(forResource: "OneOfMyTemplates", withExtension: "leaf")!.deletingLastPathComponent().directory
}
}
Have you considered any alternatives?
No response