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 …
Functionality
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!
Install
Just add following line package to your Package.swift file.
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)
Github resources
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)
String 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)
Run the installer
And when you are ready, run the installer
try ResourcesManager.default.run()
Further convenience methods
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.
Custom resource installers
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
}
}
Use with Vapor 3
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
}
}
Support
Join our Slack, channel #help-boost to … well, get help :)
Boost AppStore
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.
#
What is this even good for?!
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.
Functionality
Install
Just add following line package to your
Package.swift
file.Usage
Remote resources
Github resources
String resource
Run the installer
And when you are ready, run the installer
Further convenience methods
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.Custom resource installers
You can also create your own completely custom installers very easily by using one of the premade protocols, imagine something like this:
Use with Vapor 3
This package has no dependencies on purpose so a little trick to get into your
Resources
folder on Vapor 3 just give the Resource adestination
that could be made somehow like this:Support
Join our Slack, channel #help-boost to … well, get help :)
Boost AppStore
Core package for Boost, a completely open source enterprise AppStore written in Swift!
Other core packages
Code contributions
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.
Author
Ondrej Rafaj (@rafiki270 on Github, Twitter, LiveUI Slack and Vapor Slack)
License
See the LICENSE file for more info.