Compatibility
- 0.2.0 and master5.35.25.15.04.2
- 0.2.0 and masteriOSmacOS(Intel)macOS(ARM)LinuxtvOSwatchOS
Manages resources, local or remote, for your app or server-side framework.
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 ...
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!
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.