Have you ever had an issue with SPM not supporting resources? How do you get your templates, demo files and I don't know what else from your submodules into your app?
Well, I hope Configure will make your experience with resource files a tiny bit easier.
No dependencies so will work with Vapor, Perfect, Kitura and others ...
- Install resources from a string
- Install resources from a github.com repo (un-authenticated)
- Install resources from a github.com repo (authenticated)
- Install resources from anywhere in the inter-the-web
- Override existing files on each run if needed
- Run your install script synchronously (good when you need stuff in before your app fully starts)
- Run your install script asynchronously
Note System is mainly designed for server-side-swift but will compile fine on any iOS/tvOS or macOS!
Just add following line package to your Package.swift
file.
.package(url: "https://github.com/LiveUI/Configure.git", .branch("master"))
let resource = BasicWebResource(
resourceUrl: "http://www.example.com/Resources/email-template.leaf",
destinationPath: "Resources/email-template.leaf" // Where to install the file to
)
try ResourcesManager.default.add(resource)
let resource = BasicGithubResource(
organization: "LiveUI",
repository: "YourRepo",
branch: "master",
path: "Resources/email-template.leaf",
destinationPath: "Resources/email-template.leaf" // Where to install the file to
)
try ResourcesManager.default.add(resource)
import Configure
// Create a string resource
let template = """
Hi #(user.firstname) #(user.lastname)
This is an email template for you
Bye,
LiveUI team!
"""
let resource = template.asResource(destination: "Resources/email-template.leaf")
try ResourcesManager.default.add(resource)
And when you are ready, run the installer
try ResourcesManager.default.run()
There is a plenty convenience methods to help you create your templates like the one previously mentioned asResource
on a string. There is one for a URL, an array or URL's and strings.
You can also create your own completely custom installers very easily by using one of the premade protocols, imagine something like this:
public struct ModelResource<T>: Resource where T: Codable {
/// Your model which conforms to Codable
public let model: T
/// Where the final file will be saved
public let destinationPath: String
/// Make the resource to be rewritten every time it runs
public var alwaysOverride: Bool {
return true
}
/// Converting to data
public func data() throws -> Data {
let data = try JSONEncoder().encode(model)
return data
}
/// Intializer
public init(model: T, destinationPath: String) {
self.model = model
self.destinationPath = destinationPath
}
}
This package has no dependencies on purpose so a little trick to get into your Resources
folder on Vapor 3 just give the Resource a destination
that could be made somehow like this:
extension Request {
/// Gives absolute path URL for the Resources folder
var resourcesUrl: URL {
let config = DirectoryConfig.detect()
var url: URL = URL(fileURLWithPath: config.workDir).appendingPathComponent("Resources")
return url
}
}
Join our Slack, channel #help-boost to ... well, get help :)
Core package for Boost, a completely open source enterprise AppStore written in Swift!
- Website: http://www.boostappstore.com
- Github: https://github.com/LiveUI/Boost
- BoostCore - AppStore core module
- ApiCore - API core module with users and team management
- MailCore - Mailing wrapper for multiple mailing services like MailGun, SendGrig or SMTP (coming)
- DBCore - Set of tools for work with PostgreSQL database
- VaporTestTools - Test tools and helpers for Vapor 3
We love PR’s, we can’t get enough of them ... so if you have an interesting improvement, bug-fix or a new feature please don’t hesitate to get in touch. If you are not sure about something before you start the development you can always contact our dev and product team through our Slack.
Ondrej Rafaj (@rafiki270 on Github, Twitter, LiveUI Slack and Vapor Slack)
See the LICENSE file for more info.