https://github.com/dimaru/buildenvironment
Use dotenv files and environment variables in Xcode and Swift Package Manager projects.
https://github.com/dimaru/buildenvironment
ios linux macos obfuscation plugin spm spm-plugin swift swiftpm xcode xcode-plugin
Last synced: 8 months ago
JSON representation
Use dotenv files and environment variables in Xcode and Swift Package Manager projects.
- Host: GitHub
- URL: https://github.com/dimaru/buildenvironment
- Owner: DimaRU
- License: mit
- Created: 2024-09-22T07:51:45.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-10T16:19:42.000Z (about 1 year ago)
- Last Synced: 2025-04-15T00:43:09.328Z (8 months ago)
- Topics: ios, linux, macos, obfuscation, plugin, spm, spm-plugin, swift, swiftpm, xcode, xcode-plugin
- Language: Swift
- Homepage:
- Size: 637 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BuildEvironment
  
## Description
The BuildEvironment project lets you store your keys and secrets away from your repository. Secrets can be stored in the `.env` file or in environment variables. Simple lightweight and functional solution, platform agnostic.
## Usage
### With Swift package :
- Add the package dependency:
```swift
.package(url: "https://github.com/DimaRU/BuildEnvironment.git", from: "1.0.0"),
```
- Add plugin to the target:
```swift
plugins: [ .plugin(name: "BuildEnvPlugin", package: "BuildEnvironment") ]
```
- You may have add platform requirements:
```swift
platforms: [.macOS(.v11), .iOS(.v14), .watchOS(.v7), .tvOS(.v14)],
```
### With Xcode project:
- Add package dependency:
Don't add BuildEnv as a dependency to any target.

- Add plugin to the Target:

#### Add the`.env` and/or `buildenv.config` files to the root directory of your project.
One of the files must be added.
##### If only `.env` exist, code with default settings will be generated:
- enum name: `BuildEnvironment`
- enum access level: `public`
- encode: no
- variables will be taken from the `.env` file.
> [!caution]
> The `.env` file shouldn't be committed to git as it contains your secrets.
##### If your project contain `buildenv.config`:
- you can customize code generation options.
- environment variables can be added.
`buildenv.config` contains no secrets and can be added to the repository.
## Examples
### Single `.env` file
```bash
# Sample api key
apiKey = "123456"
```
Generated code:
```swift
// Code generated from .env file
// Don't edit! All changes will be lost.
public enum BuildEnvironment {
public static let apiKey: String = "123456"
}
```
### Both `.env` and `buildenv.config`
```
# Sample BuildEnvPlugin config file
# Generated enum name. Default: BuildEnvironment
name: BuildEnvironment
# Generated enum access level.
# Must be one of: public, package, internal. Default: public
access: internal
# Obfuscate data by encode: yes/no. Default: no
encode: yes
# Environment variable list.
# Format: swift_variable_name=$environment_variable_name
userName= $USER
homeDir= $HOME
```
Generated code:
```swift
// Code generated from .env file
// Don't edit! All changes will be lost.
enum BuildEnvironment {
static let userName: String = {
let encrypted: [UInt8] = [191, 121, 218, 23, 127, 221, 219, 20, 179, 99, 13, 164]
let count = encrypted.count / 2
return String(unsafeUninitializedCapacity: count) { ptr in
(0..