{"id":14985626,"url":"https://github.com/e-sites/natrium","last_synced_at":"2025-05-12T14:47:43.414Z","repository":{"id":8479994,"uuid":"58546079","full_name":"e-sites/Natrium","owner":"e-sites","description":"A pre-build (Swift) script to alter your Xcode project at pre-build-time per environment, build configuration and target.","archived":false,"fork":false,"pushed_at":"2025-03-21T09:51:27.000Z","size":391336,"stargazers_count":146,"open_issues_count":2,"forks_count":15,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-12T08:20:15.007Z","etag":null,"topics":["carthage","cli","cli-app","cocoapods","environment","environment-variables","ios","ribbon","scheme","swift","swift-package-manager","swift5","swiftpm","xcode","xcodegen","xcodeproj","yml"],"latest_commit_sha":null,"homepage":"https://www.e-sites.nl","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/e-sites.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-11T13:13:04.000Z","updated_at":"2025-03-21T09:51:22.000Z","dependencies_parsed_at":"2024-09-11T19:52:04.111Z","dependency_job_id":"8d4a01a6-dd85-4125-af47-f691b0848a89","html_url":"https://github.com/e-sites/Natrium","commit_stats":{"total_commits":328,"total_committers":8,"mean_commits":41.0,"dds":"0.14329268292682928","last_synced_commit":"3daa573bde237ff2108891b19f5b9e3414bb3748"},"previous_names":[],"tags_count":108,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-sites%2FNatrium","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-sites%2FNatrium/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-sites%2FNatrium/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-sites%2FNatrium/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/e-sites","download_url":"https://codeload.github.com/e-sites/Natrium/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253758146,"owners_count":21959534,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["carthage","cli","cli-app","cocoapods","environment","environment-variables","ios","ribbon","scheme","swift","swift-package-manager","swift5","swiftpm","xcode","xcodegen","xcodeproj","yml"],"created_at":"2024-09-24T14:11:23.171Z","updated_at":"2025-05-12T14:47:43.387Z","avatar_url":"https://github.com/e-sites.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Natrium](Assets/logo.png)\n\nNatrium is part of the **[E-sites iOS Suite](https://github.com/e-sites/iOS-Suite)**.\n\n---\n\nA pre-build (Swift) script to alter your Xcode project at build-time per environment and build configuration.\n\n[![forthebadge](http://forthebadge.com/images/badges/made-with-swift.svg)](http://forthebadge.com) [![forthebadge](http://forthebadge.com/images/badges/built-with-swag.svg)](http://forthebadge.com)\n\n[![Platform](https://img.shields.io/cocoapods/p/Natrium.svg?style=flat)](https://cocoapods.org/pods/Natrium)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Natrium.svg)](https://cocoapods.org/pods/Natrium)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Travis-ci](https://travis-ci.com/e-sites/Natrium.svg?branch=main)](https://travis-ci.com/e-sites/Natrium)\n\n# TL;DR\n\nWith Natrium you can change this:\n\n```swift\n#if ENVIRONMENT_STAGING\n    let apiHost = \"mynice.staging-api.com\"\n    \n#elseif ENVIRONMENT_DEVELOPMENT\n    let apiHost = \"mynice.dev-api.com\"\n    \n#else\n    let apiHost = \"mynice.api.com\"\n#endif\n\nAlamofire.request(\"https://\\(apiHost)/items\").responseJSON { response in\n    // ...\n}\n```\n![Build configurations jungle](Assets/build-configurations.png)\n\nInto this:\n\n```swift\nlet apiHost = Natrium.Config.apiHost\n\nAlamofire.request(\"https://\\(apiHost)/items\").responseJSON { response in\n    // ...\n}\n```\n![Build configurations jungle](Assets/build-configurations-natrium.png)\n\n### 🧙‍♂️ With the magic of pre-action run scripts. 😱\n\n```shell\n\"${PROJECT_DIR}/Pods/Natrium/Natrium/natrium\" Production\n```\n\n# Migration\n\n### To v8.x\n- The location of the binary is changed from (for instance in Cocoapods) `Pods/Natrium/bin/natrium` to `Pods/Natrium/Natrium/natrium`\n- The location of the generated **Natrium.swift** is changed to (for instance in Cocoapods): `Pods/Natrium/Natrium/Natrium.swift`\n\n### To v7.x\n- `natrium install` is removed\n- Both `.natrium-env` and `.env` files can be used for environment variables\n- CLI no longer needs `--project` argument\n- No longer supports Objective-c, use v6.4.0 if you still need it.\n\n### To v6.x \nFor 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](#installation) guide.\n\n### From v5.x\nNatrium v5.x doesn't need a build phase script anymore.    \nOpen your `Build Phases` from your target settings and remove the `[Natrium] check` step.    \n    \nElse your build will fail during the script steps\n\n# Roadmap\n- [x] Swift 4.2 compatible\n- [x] Use swift instead of ruby\n- [x] Remove ImageMagick dependency\n- [x] Unit tests\n- [x] Different installation options (apart from CocoaPods)\n- [x] Better error handling / reporting\n\n# Installation\n\n- Swift Package Manager → [Read the instructions here](docs/INSTALL_SWIFTPM.md).\n- CocoaPods → [Read the instructions here](docs/INSTALL_COCOAPODS.md).\n- Carthage → [Read the instructions here](docs/INSTALL_CARTHAGE.md).\n- Manually → [Read the instructions here](docs/INSTALL_MANUALLY.md).\n- [XcodeGen](https://github.com/yonaskolb/XcodeGen) → [Read the instructions here](docs/INSTALL_XCODEGEN.md).\n\n# Implementation\n\n## Swift\nJust add `Natrium.swift` (from the designated location, see installation guide) to your project's target (do not copy).\n\n# Configuration\n\nConfiguration documentation can be found [here](docs/CONFIGURATION.md).\n\n# Usage\n\nThe example `.natrium.yml` as shown above, will result in the following Config.swift file:\n\n```swift\nimport Foundation\n\n/// Natrium.swift\n/// Autogenerated by natrium\n///\n/// - see: https://github.com/e-sites/Natrium\n\nenum Natrium {\n\n    enum Environment: String {\n        case staging = \"Staging\"\n        case production = \"Production\"\n    }\n\n    enum Configuration: String {\n        case debug = \"Debug\"\n        case release = \"Release\"\n        case adhoc = \"Adhoc\"\n    }\n\n    enum Config {\n        static let environment: Natrium.Environment = .staging\n        static let configuration: Natrium.Configuration = .debug\n        static let testVariableDouble: Double = 1.0\n        static let testVariableString: String = \"debugString\"\n        static let testVariableBoolean: Bool = false\n        static let testVariableInteger: Int = 125\n        static let testArray: [String] = [ \"StagingFoo\", \"StagingBar\" ]\n    }\n}\n```\n\nIt can be used like so:\n\n```swift\nclass MainViewController: UIViewController {\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        print(\"bundle identifier: \\(Bundle.main.bundleIdentifier!)\")\n        print(\"environment: \\(Natrium.Config.environment)\")\n    }\n}\n```\n\n**Result:**\n\n```\nbundle identifier: com.esites.app.staging\nenvironment: Staging\n```\n\n# Development\n\nRun\n \n```\nmake xcodeproj\n```\n\nand open `Natrium.xcodeproj`\n\n\n# Advanced\n\n\n## Logging\n\nIn the `Pods/Natrium/bin/` folder you can find `natrium.log` with the logs of the previous build. It might help you with debugging.\n\n## Environment variables\n\nIf you place `.env` in the root of your project. Natrium will use that fill to add environment variables to your already existing environment variables.\nThe `.env` file should have to following format:\n\n```\nKEY=VALUE\n```\n\nfor instance:\n\n```\nPRODUCTION_SECRET_API_TOKEN=3489uierhjkfbnvcx\nSTAGING_SECRET_API_TOKEN=iujk9qijs41\n```\n\nThis way you can use `#env(PRODUCTION_SECRET_API_TOKEN)` in your `.natrium.yml` file.\n\nFor CI/CD pipelines you can simply add those environment variables to your build pipeline (in travis or buddybuild for instance).\n\nBut if you want to use it for local (debug) builds, this file can be helpful.   \n⚠️ Don't forget to add `.env` to your `.gitignore`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe-sites%2Fnatrium","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fe-sites%2Fnatrium","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe-sites%2Fnatrium/lists"}