• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A pre-build (Swift) script to alter your Xcode project at pre-build-time per environment, build configuration and target.

Natrium

Natrium is part of the E-sites iOS Suite.


A pre-build (Swift) script to alter your Xcode project at build-time per environment and build configuration.

forthebadge forthebadge

Platform CocoaPods Compatible Carthage compatible Travis-ci

TL;DR

With Natrium you can change this:

#if ENVIRONMENT_STAGING
    let apiHost = "mynice.staging-api.com"
    
#elseif ENVIRONMENT_DEVELOPMENT
    let apiHost = "mynice.dev-api.com"
    
#else
    let apiHost = "mynice.api.com"
#endif

Alamofire.request("https://\(apiHost)/items").responseJSON { response in
    // ...
}

Build configurations jungle

Into this:

let apiHost = Natrium.Config.apiHost

Alamofire.request("https://\(apiHost)/items").responseJSON { response in
    // ...
}

Build configurations jungle

πŸ§™β€β™‚οΈ With the magic of pre-action run scripts. 😱

"${PROJECT_DIR}/Pods/Natrium/Natrium/natrium" Production

Migration

To v8.x

  • The location of the binary is changed from (for instance in Cocoapods) Pods/Natrium/bin/natrium to Pods/Natrium/Natrium/natrium
  • The location of the generated Natrium.swift is changed to (for instance in Cocoapods): Pods/Natrium/Natrium/Natrium.swift

To v7.x

  • natrium install is removed
  • Both .natrium-env and .env files can be used for environment variables
  • CLI no longer needs --project argument
  • No longer supports Objective-c, use v6.4.0 if you still need it.

To v6.x

For Natrium v6.x you need to manually import the Natrium.swift file to your project to make it work in the new xcode build system. Read the Installation guide.

From v5.x

Natrium v5.x doesn't need a build phase script anymore.
Open your Build Phases from your target settings and remove the [Natrium] check step.

Else your build will fail during the script steps

Roadmap

  • Swift 4.2 compatible
  • Use swift instead of ruby
  • Remove ImageMagick dependency
  • Unit tests
  • Different installation options (apart from CocoaPods)
  • Better error handling / reporting

Installation

Implementation

Swift

Just add Natrium.swift (from the designated location, see installation guide) to your project's target (do not copy).

Configuration

Configuration documentation can be found here.

Usage

The example .natrium.yml as shown above, will result in the following Config.swift file:

import Foundation

/// Natrium.swift
/// Autogenerated by natrium
///
/// - see: https://github.com/e-sites/Natrium

enum Natrium {

    enum Environment: String {
        case staging = "Staging"
        case production = "Production"
    }

    enum Configuration: String {
        case debug = "Debug"
        case release = "Release"
        case adhoc = "Adhoc"
    }

    enum Config {
        static let environment: Natrium.Environment = .staging
        static let configuration: Natrium.Configuration = .debug
        static let testVariableDouble: Double = 1.0
        static let testVariableString: String = "debugString"
        static let testVariableBoolean: Bool = false
        static let testVariableInteger: Int = 125
        static let testArray: [String] = [ "StagingFoo", "StagingBar" ]
    }
}

It can be used like so:

class MainViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        print("bundle identifier: \(Bundle.main.bundleIdentifier!)")
        print("environment: \(Natrium.Config.environment)")
    }
}

Result:

bundle identifier: com.esites.app.staging
environment: Staging

Development

Run

make xcodeproj

and open Natrium.xcodeproj

Advanced

Logging

In the Pods/Natrium/bin/ folder you can find natrium.log with the logs of the previous build. It might help you with debugging.

Environment variables

If you place .env in the root of your project. Natrium will use that fill to add environment variables to your already existing environment variables. The .env file should have to following format:

KEY=VALUE

for instance:

PRODUCTION_SECRET_API_TOKEN=3489uierhjkfbnvcx
STAGING_SECRET_API_TOKEN=iujk9qijs41

This way you can use #env(PRODUCTION_SECRET_API_TOKEN) in your .natrium.yml file.

For CI/CD pipelines you can simply add those environment variables to your build pipeline (in travis or buddybuild for instance).

But if you want to use it for local (debug) builds, this file can be helpful.
⚠️ Don't forget to add .env to your .gitignore

More Repositories

1

perimeter.js

Creates an invisible perimeter around a target element and monitors mouse breaches.
JavaScript
299
star
2

Bluetonium

Bluetooth mapping in Swift
Swift
165
star
3

Zepto-Builder

Zepto Builder will let you generate a custom version of Zepto that just includes the modules you need.
JavaScript
112
star
4

php-mysql-mysqli-wrapper

PHP
98
star
5

ESTimePicker

A custom time picker just like the Google Calendar Android App
Objective-C
86
star
6

ESArcProgressView

A progress view to be used within Apple Watch projects
Objective-C
80
star
7

ESDatePicker

A custom date picker similar like the date picker of the Sunrise app and the Google Calendar android app
Objective-C
31
star
8

tinymce-emmet-plugin

A TinyMCE plugin that provides an HTML editor including all Emmet features
JavaScript
24
star
9

magento-advanced-code-editor

An advanced code editor that'll make it much easier to write clean markup for CMS pages, static blocks, product pages and Transactional Emails.
JavaScript
19
star
10

Jsend

Ajax wrapper that handles JSON data exchange according to the non-official JSend spec
JavaScript
18
star
11

ESOpenSourceLicensesKit

A script to generate an HTML file of all the license files used with your CocoaPods Project
Swift
14
star
12

ingenico.css

An elegant front-end boilerplate that'll make it easier to cope with the default Ingenico payment view
HTML
13
star
13

UnityXcodeBridge

A step-by-step tutorial on how to make a bridge between Unity's C# and Xcode's Objective-C
12
star
14

iOS-Suite

The a part of the E-sites iOS library suite
9
star
15

Palladium

A lightweight framework to schedule and cancel local notifications.
Swift
9
star
16

gulp-frontend-tasks

A bundle of useful Gulp tasks to automate your front-end workflow
JavaScript
8
star
17

RxSwiftly

An E-sites collection of RxSwift extensions
Swift
7
star
18

PAPI

A lightweight jQuery plugin that makes working with the Postcode API (@postcodeapi) easy as pie.
HTML
6
star
19

Fluorine

A small UIView helper to create simple linear gradients
Swift
5
star
20

Aluminum

Applying the robot pattern to your UI XCTests
Swift
4
star
21

populate

A small yet useful jQuery plugin that populates <select> elements with option nodes. It will accept either an object literal, a HTML fragment or a serialized string
JavaScript
4
star
22

Erbium

Light weight tool for detecting the current device's capabilities
Swift
3
star
23

Cobalt

The E-sites Swift iOS API Client used for standard restful API's
Swift
3
star
24

Pipelines

A macOS statusbar app that monitors Buildkite builds
Swift
3
star
25

Oganesson

A small swift helper class for using an ObjectPool
Swift
3
star
26

ESFlatButton

A beveled flat button
Objective-C
3
star
27

MaterialDesignSpinner

An iOS activity spinner modeled after Google's Material Design Spinner
Swift
3
star
28

esl

ESL is our internally developed php-code library with commonly used functions.
PHP
3
star
29

Bismuth

FIFO queue handling
Swift
2
star
30

Dysprosium

Deallocation helper for runtime objects
Swift
2
star
31

Einsteinium

A collection of swift extensions
Swift
2
star
32

XcodeLocalizableStringsBuildScript

A shell script to show errors for any missing translations used by NSLocalizedString at runtime
Shell
2
star
33

require-matchmedia-plugin

Require.js plugin for loading files conditionally, based on matchMedia.
JavaScript
2
star
34

Bohrium

A small helper class to benchmark specific code parts at runtime
Swift
2
star
35

Radon

A lightweight commandline tool to automatically generate strong-typed image references.
Swift
2
star
36

Lithium

_The_ E-sites logging framework
Swift
2
star
37

swift-log-papertrail

Swift
2
star
38

PinFieldView

Entering PIN codes made easy
Swift
1
star
39

Dupnium

A small helper class for localization
Swift
1
star
40

ObjectPool

A small swift helper class for using an ObjectPool
Swift
1
star
41

swift-log-proxy

Swift
1
star
42

ESMonitor

A draggable system monitor inside your application. Shake to show.
Swift
1
star
43

Francium

A small library to use for your file system.
Swift
1
star
44

ESDateHelper

Helper category for making the usage of NSDates easier
Objective-C
1
star
45

fe-boilerplate-poc

Frontend developer boilerplate proof of concept
CSS
1
star