Giter Site home page Giter Site logo

417-72ki / configurationplist Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 61 KB

Auto-generate configuration files for macOS/iOS

License: MIT License

Swift 97.01% Ruby 1.32% Makefile 1.66%
swift autocomplete yaml-configuration json-configuration ios-swift

configurationplist's Introduction

Caution!

ConfigurationPlist is renamed to BuildConfig.swift, and this repository will be EOL.
See https://github.com/417-72KI/BuildConfig.swift

ConfigurationPlist

Build Status Version Platform GitHub release Swift Swift Package Manager GitHub license

ConfigurationPlist is a tool to generate configuration files by merging yamls or jsons.

By splitting the file for each type of setting, it is possible to prevent conflicts of configuration files.

Also, by splitting the file for environment configurations, it will be easier to overwrite configurations for each environment.

Example

Base JSON file

{
    "API": {
        "domain": "http://localhost",
        "path": {
            "login": {
                "method": "POST",
                "path": "/login"
            },
            "getList": {
                "method": "GET",
                "path": "/list"
            }
        }
    }
}

Call above configuration

Vanilla

let file = Bundle.main.path(forResource: "Base", ofType: "json")!
let data = try! Data(contentsOf: URL(fileURLWithPath: filePath))
let config = try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
let api = config["API"] as! [String: Any]
let domain = api.domain as! String // "http://localhost"
let loginPath = (api.path as! [String: Any])["login"] as! [String: Any]
let path = loginPath.path // "/login"
let method = loginPath.method // "POST"

Using ConfigurationPlist

let config = AppConfig.default
let domain = config.API.domain // "http://localhost"
let path = config.API.path.login.path // "/login"
let method = config.API.path.login.method // "POST"

Installation

Common

  • Create directory for splitted configuration files, e.g. $PROJECT/Resources/Config.
  • If you use different settings for each environment, create .env into above directory.
  • You don't have to add above directory into project.

CocoaPods

  • Add the following line to your test target in your Podfile:
pod 'ConfigurationPlist'
  • Add the following Run script build phase to your test target's Build Phases:
if [ "${CONFIGURATION}" = 'Release' ]; then
  ENVIRONMENT='production'
else
  ENVIRONMENT='staging'
fi

"${PODS_ROOT}/ConfigurationPlist/configurationPlist" -e $ENVIRONMENT "$SRCROOT/$PROJECT/Resources/Config"

You can replace "$SRCROOT/$PROJECT/Resources/Config" to the relative path from project to the directory you created.

Also, you can add -o option with output path to specify where Config.plist and AppConfig.generated.swift will be created.

  • Add $(TEMP_DIR)/configurationplist-lastrun into Input Files in above Run script build phase.

  • Add $(SRCROOT)/Config.plist and $(SRCROOT)/AppConfig.generated.swift into Output Files in above Run script build phase.

    • If you set a path to output generated files by -o option, you have to change Output Files to those paths.
  • Drag the new Run Script phase above the Compile Sources phase and below Check Pods Manifest.lock
    If you are using R.swift, drag the new Run Script above the Run Script phase for R.swift and you can load with R.file.configPlist.

  • Build your project, in Finder you will now see a Config.plist and AppConfig.generated.swift in $SRCROOT or a path you set with -o option in above Run script build phase.

  • Drag them into your project.

Tip: Add the Config.plist pattern and the *.generated.swift pattern to your .gitignore file to prevent unnecessary conflicts.

Manually

TODO: Future support.

What is ConfigurationPlist doing?

  • Detect all yml/json files in $SRCROOT/$PROJECT/Resources/Config, exclude .env.
  • If the -e option is set and a file with the same name as that option exists in $SRCROOT/$PROJECT/Resources/Config/.env, only that file is read.
    For example, -e staging option means to read $SRCROOT/$PROJECT/Resources/Config/.env/staging.{yml/yaml/json}.
  • Parse above files as Swift.Dictionary.
  • Deep merge the above dictionaries.
  • Output merged dictionary as a plist file.

Libraries

License

Available under the MIT License.

configurationplist's People

Contributors

417-72ki avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

configurationplist's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.