Configure

0.2.0

Manages resources, local or remote, for your app or server-side framework.
LiveUI/Configure

What's New

Renamed to Configure

2018-05-28T18:07:14Z

Configure

Slack Jenkins Platforms Swift Package Manager Swift 4 Vapor 3

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 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.

.package(url: "https://github.com/LiveUI/Configure.git", .branch("master"))

Usage

Remote resources

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!

Other core packages

  • 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

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.

Description

  • Swift Tools 4.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 11:43:29 GMT-0900 (Hawaii-Aleutian Daylight Time)