BuildEvironment 项目允许您将密钥和秘密信息存储在版本控制仓库之外。 秘密信息可以存储在 .env
文件或环境变量中。 简单、轻量且实用的解决方案,与平台无关。
.package(url: "https://github.com/DimaRU/BuildEnvironment.git", from: "1.0.0"),
plugins: [ .plugin(name: "BuildEnvPlugin", package: "BuildEnvironment") ]
platforms: [.macOS(.v11), .iOS(.v14), .watchOS(.v7), .tvOS(.v14)],
必须添加其中一个文件。
BuildEnvironment
public
.env
文件中获取。注意
.env
文件不应提交到 git,因为它包含您的秘密信息。
buildenv.config
不包含秘密信息,可以添加到版本控制仓库中。
# Sample api key
apiKey = "123456"
生成的代码
// Code generated from .env file
// Don't edit! All changes will be lost.
public enum BuildEnvironment {
public static let apiKey: String = "123456"
}
# 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
生成的代码
// 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..<count).forEach { ptr[$0] = encrypted[$0] ^ encrypted[$0 + count] }
return count
}
}()
static let homeDir: String = {
let encrypted: [UInt8] = [245, 33, 241, 173, 4, 190, 7, 163, 71, 155, 203, 189, 211, 218, 116, 130, 200, 118, 205, 40, 199, 42, 242, 191, 207, 170]
let count = encrypted.count / 2
return String(unsafeUninitializedCapacity: count) { ptr in
(0..<count).forEach { ptr[$0] = encrypted[$0] ^ encrypted[$0 + count] }
return count
}
}()
static let apiKey: String = {
let encrypted: [UInt8] = [41, 83, 240, 172, 236, 228, 24, 97, 195, 152, 217, 210]
let count = encrypted.count / 2
return String(unsafeUninitializedCapacity: count) { ptr in
(0..<count).forEach { ptr[$0] = encrypted[$0] ^ encrypted[$0 + count] }
return count
}
}()
}
BuildEnvironment
目录swift run BuildEnvExample
欢迎提交 Pull Request。 对于重大更改,请先开设一个 Issue 讨论您想要更改的内容。
该项目基于 MIT 许可 - 详情请参阅 LICENSE 文件