Git Product home page Git Product logo

e-sites / natrium Goto Github PK

View Code? Open in Web Editor NEW
144.0 8.0 15.0 379.73 MB

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

Home Page: https://www.e-sites.nl

License: MIT License

Ruby 1.79% Swift 94.59% Shell 0.65% Objective-C 0.62% HTML 0.49% Makefile 1.69% C 0.17%
xcode cocoapods scheme yml ribbon swift cli environment carthage swift-package-manager

natrium's Introduction

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

natrium's People

Contributors

basvankuijck avatar dangthaison91 avatar dependabot[bot] avatar mpsnp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

natrium's Issues

INFOPLIST_FILE path is not work

I have more than one build target, therefore the project will have 2 or more Infor.plist files.

But actual, infoPlistPath will be like: DemoProject/$(SRCROOT)/Info.plist. So Natrium cannot generate the Config.

I also define plist file path in .natrium.yml but seem that they are not to be used or maybe I using it in wrong way

plists:
  "DemoProject/Info.plist":
        CFBundleDisplayName:
            Dev: Dev Demo
            Staging: Staging Demo
            Production: Demo

    "DemoProject/Debug-Info.plist":
        CFBundleDisplayName:
            Dev: Dev Demo
            Staging: Staging Demo
            Production: Demo
  Cannot find Optional("//Volumes/DATA/DemoProject/$(SRCROOT)/DemoProject/Info.plist")

Carthage unable to install Natrium 7.2.4

I'm getting the following error when attempting to install Natrium with Carthage 0.34.0:

*** Downloading binary-only framework Natrium at "https://raw.githubusercontent.com/e-sites/Natrium/master/Res/Natrium.json"
*** xcodebuild output can be found in /var/folders/9_/zr5v6zq504d9xyxklvrtmp9w0000gn/T/carthage-xcodebuild.o9ZMhJ.log
Failed to read file or folder at /Users/myuser/Documents/myproject/Carthage/Build/iOS/Natrium.framework

My Cartfile:

binary "https://raw.githubusercontent.com/e-sites/Natrium/master/Res/Natrium.json" == 7.2.4

I ran it with the following command:
carthage update --platform iOS

Please note, I don't get this error when I try to install an older version of Natrium 6.1.1.

My setup:

  • MacOS Catalina 10.15.4
  • Xcode 11.4

Launch_screen_versioning is not optional

On version 6.1.2, launch_screen_versioning is not optional anymore. If it is not set, Natrium will produce error:

Version 6.1.2:

12/10/18, 1:01:06 AM -   [launch_screen_versioning]
12/10/18, 1:01:06 AM -     -empty-
12/10/18, 1:01:06 AM -   Missing 'path' parameter for 'launch_screen_versioning' key

Git LFS

Why don't you use Git LFS? Cause repository cloning is already a pain because of binaries in repo.

"Config.swift" file not generate

Hi,
I follow Carthage installation, after run Natrium installer (v6.0.0),
the .natrium folder just contain following files, Config.swift is missing.

To solve problem I've used v5.9.0

Variables don't have Array support?

I would like to create an array of Strings as my configuration variable. But it doesn't seem to work.

Am I doing something wrong, or arrays are not supported?
I've tried the following, it fails to create Natrium.swift

variables:
    listOfStuff: ["aaa", "bbb"]
    anotherList:
        - abc
        - efg

Thank you.

.natrium Directory is not created

I tried to integrate the Natrium using SPM, Manually and cocoapods as well.
The ".natrium.yml" file which i am having a different variable. Through cococapods the Natrium.swift file is generated under "Pods/Natrium/Natrium/Natrium.swift" path but the configuration which is generated is not as per my .yml file.
Also with SPM the step 4 the .natrium directory is not generated.

Build your project (⌘ + B or ⌘ + R).
Then open the .natrium directory from your project root and:

Add the Natrium.swift file to your projects target.
Add all the Natrium.*.xcconfig files to your project and do NOT add them to your target(s).

Tried to integrate the Natrium using SPM in demo project as well.

Below is the sample of .natrium.yml which i am using.

settings:
  stringType: "StaticString"
  
environments:
  - QA
  - Staging

variables:
  stripeKey:
      QA: "pk_test_***"
    Staging: "pk_test_***"
   
  graphQLEndpoint:
    Staging: "https://graph.preview.helfie.io/graphql"
    QA: "https://graph.development.helfie.ai/graphql"
    
  restAPIEndpoint:
    Staging: "https://helfie-core-ojhavw35wq-ts.a.run.app/v1/helfie"
    QA: "https://helfie-core-ojhavw35wq-ts.a.run.app/v1/helfie"
  authenticationEndpoint:
   
    Staging: "https://graph.preview.helfie.io/v1"
    QA: "https://graph.development.helfie.ai/v1"


plists:
"NatriumDemo/Info.plist":
        CFBundleDisplayName:
            Staging: App_staging
            Production: App
    "NatriumDemo/App.entitlements":
        "aps-environment":
            "*":
                Debug: "development"
                Release: "production"


xcassets

Is it possible to configure the inclusion and exclusion of different xcassets depending on environment or configuration?

Config different Capabilities based on environment

Hi is there a way to config Different Capabilities base on environment (Dev, Stagging, Production) (in my case is AppGroup) ?

Seem we should modify

plists:
    "NatriumExampleProject/Info.plist":
        CFBundleDisplayName:
            Staging: App_staging
            Production: App
    "NatriumExampleProject/App.entitlements":
        "aps-environment":
            "*":
                Debug: "development"
                Release: "production"

But what is the config for other capabilities? (AppGroup for example)?

AppIcon contents.json generation

Here is the problem: if i entirelly ignore and remove AppIcon.appiconset folder, then natrium fails to generate it. but if i commit only contents.json inside of it, natrium doesn't use ordering while generating this json, and it changes each time it is generated.

What's the best practice of using natrium with AppIcon?

plists in target specific

I think there's a bug with target specific.

If I use this configuration:

target_specific:
    target_name:
        plists:
            "plist_path":
                CFBundleDisplayName:
                    Mock: XXXX
                    Dev: BG dev
        variables:
            var_1: "var_1"
            var_2: "var_2"

I can't set CFBundleDisplayName, in fact log contains this:

03/07/2018, 19:45:05 -   [target_specific:target_name]
03/07/2018, 19:45:05 -     variables
03/07/2018, 19:45:05 -       var_1 = var_1
03/07/2018, 19:45:05 -       var_2 = var_2
03/07/2018, 19:45:05 -       plists
03/07/2018, 19:45:05 -         -empty-

Plists is empty, how to fix this?

Thanks.

"Config.swift" file not generate

Hi,
I follow Carthage installation, after run Natrium installer (v5.8.1),
the .natrium folder just contain following files, Config.swift is missing

ls .natrium 
total 32
-rw-r--r--  1 user  staff   661B Aug 26 12:55 NatriumConfig.h
-rw-r--r--  1 user  staff   772B Aug 26 12:55 NatriumConfig.m
-rw-r--r--  1 user  staff   140B Aug 26 12:55 natrium.lock
-rw-r--r--  1 user  staff   1.7K Aug 26 12:55 natrium.log

PRODUCT_BUNDLE_IDENTIFIER cannot be specify

.natrium.config file below

xcconfig:
    PRODUCT_BUNDLE_IDENTIFIER:
        Staging: com.my.app.staging
        Production: com.my.app.production

when i print bundleIdentifier in the runtime

print("bundle identifier: \(Bundle.main.bundleIdentifier!)")

every mode is print the same bundleIdentifier

Anyone help me to debug this issue?

Cannot change Bundle Identifier

Everything is changed for Info Plist and Natrium.swift, but PRODUCT_BUNDLE_IDENTIFIER is not changed in build settings. I will try with version 6.1.0.

- Version: 6.1.1

.natrium.yml:

settings:
  class_name: BuildConfiguration

environments:
  - Dev
  - Staging
  - Production

natrium_variables:
  BundleID:
    Dev: com.domain.XXX.dev
    Staging: com.domain.XXX.staging
    Production: com.domain.XXX

target_specific:
  Target_XXX:
    xcconfig:
      PRODUCT_BUNDLE_IDENTIFIER:
        Dev: "#{BundleID}"
        Staging: "#{BundleID}"
        Production: "#{BundleID}"

plists:
  "AppXXX/Configuration/AppXXX-Info.plist":
    CFBundleDisplayName:
      Dev: Dev AppXXX
      Staging: Staging AppXXX
      Production: AppXXX

- Natrium log:

[environments]
[5:38:46 PM]:       - Dev
[5:38:46 PM]:       - Staging
[5:38:46 PM]:       - Production
[5:38:46 PM]:    [settings]
[5:38:46 PM]:      class_name = BuildConfiguration
[5:38:46 PM]:    [target_specific:AppXXX]
[5:38:46 PM]:      xcconfig
[5:38:46 PM]:        PRODUCT_BUNDLE_IDENTIFIER = "com.domain.XXX"
[5:38:46 PM]:    [natrium_variables]
[5:38:46 PM]:      AppName = "AppName 1"
[5:38:46 PM]:    [plists]
[5:38:46 PM]:      AppXXX/Configuration/AppXXX-Info.plist
[5:38:46 PM]:        CFBundleDisplayName = Staging AppXXX
[5:38:46 PM]:      AppXXX/Configuration/AppXXX-Debug-Info.plist
[5:38:46 PM]:        CFBundleDisplayName = Staging XXX Debug

MANUALLY INSTALL didn't generate .natrium

Try to use manually install by dragging latest natrium bin file into project folder but it didn't generate .natrium folder or anything.

I tried the Cocoapods way and it works. But there is an error that is reported in #11

PS: Really nice ideas and helpful library.

Bool and Int values are not overridden per target

It seems that non String values are not overridden correctly

Simplified example:

variables:
    message: "hello"
    isDoSomething: false
    someNumber: 0

target_specific:
    MyTarget:
        variables:
            message: "yo"
            isDoSomething: true
            someNumber: 1

This produces:

open static let message: String = "yo"
open static let isDoSomething: Bool = false
open static let someNumber: Int = 0

Notice the string is overridden correctly, but the bool and int were not.

Natrium version 5.7.0
Installed with Carthage

Thank you

**target_specific** not inject Natrium variables

Natrium variable defines in configuration will not affect to target_specific. As I don't misunderstand the log, it shows that natrium_variables will be parsed after target_specific

- Version: 6.1.1

.natrium.yml:

settings:
  class_name: BuildConfiguration

environments:
  - Dev
  - Staging
  - Production

natrium_variables:
  BundleID:
    Dev: com.domain.XXX.dev
    Staging: com.domain.XXX.staging
    Production: com.domain.XXX

xcconfig:
  PRODUCT_BUNDLE_IDENTIFIER: ""

target_specific:
  Target_XXX:
    xcconfig:
      PRODUCT_BUNDLE_IDENTIFIER: "#{BundleID}"

- Natrium log:

12/9/18, 9:09:18 PM - Running Natrium installer (v6.1.1)
12/9/18, 9:09:18 PM - 
12/9/18, 9:09:18 PM - Parsing //Volumes/.../.natrium.yml
12/9/18, 9:09:18 PM -   [environments]
12/9/18, 9:09:18 PM -      - Dev
12/9/18, 9:09:18 PM -      - Staging
12/9/18, 9:09:18 PM -      - Production
12/9/18, 9:09:18 PM -   [settings]
12/9/18, 9:09:18 PM -     class_name = BuildConfiguration
12/9/18, 9:09:18 PM -   [target_specific:Target_XXX]
12/9/18, 9:09:18 PM -     xcconfig
12/9/18, 9:09:18 PM -       PRODUCT_BUNDLE_IDENTIFIER = #{BundleID}
12/9/18, 9:09:18 PM -   [natrium_variables]
12/9/18, 9:09:18 PM -     BundleID =  com.domain.XXX.dev
12/9/18, 9:09:18 PM -   [files]
12/9/18, 9:09:18 PM -     Firebase/GoogleService-Info.plist = Firebase/GoogleService-Info-DEV.plist
12/9/18, 9:09:19 PM -   [xcconfig]
12/9/18, 9:09:19 PM -     PRODUCT_BUNDLE_IDENTIFIER:* = #{BundleID}
12/9/18, 9:09:19 PM -   Natrium  Success!

Environment not generate as String

I have some environment variables for CI but Natrium not generate them as Swift String.

.env file:

  API_DOMAIN = 'https://api.domain.com'

natrium:

  variables:
  domain:
    Staging: "api.staging.id.vin"
    Production: "#env(API_DOMAIN)"

Natrium.swift:

class Natrium {

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

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

    class Config {
        static let domain: String = https://api.domain.com
    }
}

It should be Swift String with double quote "":

class Natrium {
    class Config {
        static let domain: String = "https://api.domain.com"
    }
}

Natrium should remove all xcconfig files before generate

When using Natrium, many times it implicitly failed at local but build still success cause xcconfig files already generated before. This often takes time to check why CI build failed and notice to check Natrium's log.

I'm not sure if once Natrium fails can it make Pre-Action fail the following Build will be failed? If not we can remove all xcconfig files before generating a new one.

v5.8.0 is not working with Carthage

Using Carthage with latest version 5.8.0 is not working.
The zip file is not a real zip file.

BTW - why Carthage build is using only zip instead supporting building from the project?

Not able to set PRODUCT_BUNDLE_IDENTIFIER.

I've used CocoaPods to install the framework. I'm not able to set the PRODUCT_BUNDLE_IDENTIFIER for different environments.

I've made sure that I've added the Pre-Actions in Scheme information.

I'm able to change Variables but not the PRODUCT_BUNDLE_IDENTIFIER

How can I specify array of dictionaries in plists value?

plists:
    "Resources/Info.plist":
        CFBundleURLTypes:
            - CFBundleURLSchemes:
                - "#{FacebookUrlScheme}"
              CFBundleTypeRole: "Editor"
            - CFBundleURLSchemes:
                - "#{GoogleUrlScheme}"
              CFBundleTypeRole: "Editor"

This code results in empty array. Am I doing something wrong?

Thanks.

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.