All Projects → 417-72KI → BuildConfig.swift

417-72KI / BuildConfig.swift

Licence: MIT license
Android-like auto-generate configuration files for macOS/iOS

Programming Languages

swift
15916 projects
shell
77523 projects
ruby
36898 projects - #4 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to BuildConfig.swift

configmanager
Forget about configparser, YAML, or JSON parsers. Focus on configuration. NOT RECOMMENDED FOR USE (2019-01-26)
Stars: ✭ 15 (-50%)
Mutual labels:  json-configuration, yaml-configuration
portainer-stack-utils
CLI client for Portainer
Stars: ✭ 66 (+120%)
Mutual labels:  json-configuration, yaml-configuration
zsh-yarn-completions
Yarn completions for Z-shell that supports yarn workspaces
Stars: ✭ 35 (+16.67%)
Mutual labels:  autocomplete
bootstrap-5-autocomplete
autocomplete/typeahead js plugin for bootstrap v5
Stars: ✭ 79 (+163.33%)
Mutual labels:  autocomplete
react-search-autocomplete
A search box that filters the provided array of objects
Stars: ✭ 152 (+406.67%)
Mutual labels:  autocomplete
svelte-mapbox
MapBox Map and Autocomplete components for Svelte (or Vanilla JS)
Stars: ✭ 267 (+790%)
Mutual labels:  autocomplete
swoole-ide-helper-phar
Swoole IDE 自动补全,PHAR 包。
Stars: ✭ 14 (-53.33%)
Mutual labels:  autocomplete
S2s
Coding time Compile. A tool to write code fastest.
Stars: ✭ 254 (+746.67%)
Mutual labels:  autocomplete
choc-autocomplete
🏇 Autocomplete Component Package for Chakra UI
Stars: ✭ 286 (+853.33%)
Mutual labels:  autocomplete
hydra-zen
Pythonic functions for creating and enhancing Hydra applications
Stars: ✭ 165 (+450%)
Mutual labels:  yaml-configuration
shell.how
Explain shell commands using next-generation autocomplete Fig.
Stars: ✭ 237 (+690%)
Mutual labels:  autocomplete
PteroStats
PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and post it to your discord server
Stars: ✭ 122 (+306.67%)
Mutual labels:  yaml-configuration
combobox-nav
Attach combobox navigation behavior to <input> or <textarea>.
Stars: ✭ 76 (+153.33%)
Mutual labels:  autocomplete
react-autocomplete-tags
React Autocomplete Tags
Stars: ✭ 17 (-43.33%)
Mutual labels:  autocomplete
react-power-select
A highly composable & reusable select/autocomplete components
Stars: ✭ 63 (+110%)
Mutual labels:  autocomplete
search-ui
JavaScript library to develop Search UIs for the web
Stars: ✭ 16 (-46.67%)
Mutual labels:  autocomplete
bundle
Deprecated: WordPress plugin to enable plugin activation using a JSON, YAML or PHP file
Stars: ✭ 24 (-20%)
Mutual labels:  json-configuration
yamburger
YAML syntax got you down? That's a YAMBURGER!
Stars: ✭ 32 (+6.67%)
Mutual labels:  yaml-configuration
vue-thailand-address-autocomplete
🇹🇭 Autocomplete ที่อยู่ในประเทศไทย
Stars: ✭ 49 (+63.33%)
Mutual labels:  autocomplete
lua-complete
A Lua code completer
Stars: ✭ 21 (-30%)
Mutual labels:  autocomplete

BuildConfig.swift

Actions Status Version Platform GitHub release Swift Package Manager GitHub license

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

let config = BuildConfig.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 'BuildConfig.swift'
  • Add the following Run script build phase to your test target's Build Phases:

Example

if [ "${CONFIGURATION}" = 'Release' ]; then
  ENVIRONMENT='production'
else
  ENVIRONMENT='staging'
fi

"${PODS_ROOT}/BuildConfig.swift/buildconfigswift" -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 BuildConfig.plist and BuildConfig.generated.swift will be created.

  • Add $(SRCROOT)/BuildConfig.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 it's path.
  • Drag the new Run Script phase above the Compile Sources phase and below Check Pods Manifest.lock.

  • Build your project, in Finder you will now see a BuildConfig.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 *.generated.swift pattern to your .gitignore file to prevent unnecessary conflicts.

Manually

TODO: Future support.

What is BuildConfig.swift 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].