A generator that allows access to environment variables and values defined in the properties file.
Installation:
Add a dependency to Package.swift
.
.package(url: "https://github.com/simorgh3196/swift-secret-keys", from: "0.1.0"),
Execution:
swift package plugin --allow-writing-to-package-directory secret-keys generate
Using Mint
Installation:
Add the following to your Mintfile
.
simorgh3196/[email protected]
Execution:
mint run secret-keys generate
secret-keys generate --help
USAGE: secret-keys generate [--config <config>] [--project <project>] [--verbose]
OPTIONS:
-c, --config <config> The path to the configuration file (default: .secretkeys.yml)
-p, --project <project> The path to the project root (default: .)
-v, --verbose Enables verbose log messages
--version Show the version.
-h, --help Show help information.
For a detailed example, see Example/CommandPluginExample.
-
Create a configuration file. (docs)
-
Set
exportType
in the Configuration File toswiftpm
. -
Run the
generate
command.<config:output> └── SecretKeys ├── .gitignore ├── Package.swift └── Sources ├── Keys │ ├── SecretKeys+Keys.swift # Specified in .gitignore by default │ └── SecretKeys.swift └── SecretValueDecoder └── SecretValueDecoder.swift
-
Add a dependency to your project.
.package(name: "SecretKeys", path: "Dependencies/SwiftPM/SecretKeys")
-
Create a configuration file. (docs)
-
Set
exportType
in the Configuration File tococoapods
. -
Run the
generate
command.<config:output> └── SecretKeys ├── .gitignore ├── Keys.podspec ├── SecretValueDecoder.podspec └── Sources ├── Keys │ ├── SecretKeys+Keys.swift # Specified in .gitignore by default │ └── SecretKeys.swift └── SecretValueDecoder └── SecretValueDecoder.swift
-
Add a dependency to your project.
pod 'Keys', :path => '<config:output>/SecretKeys' pod 'SecretValueDecoder', :path => '<config:output>/SecretKeys'
-
Create a configuration file. (docs)
-
Set
exportType
in the Configuration File tosourcesOnly
. -
Run the
generate
command.<config:output> └── SecretKeys ├── .gitignore ├── Keys │ └── Keys.generated.swift # Specified in .gitignore by default └── SecretValueDecoder.generated.swift # Specified in .gitignore by default
-
Add swift codes to your project targets.
.secretkeys.yml
# Select the export type from `swiftpm`, `cocoapods` or `sourcesOnly`. (Default: `swiftpm`)
exportType: swiftpm
# The path of output directory. (Default: `Dependencies`)
output: Dependencies
# In addition to environment variables, a properties file can be read.
envFile: .env
# Set the target according to the environment and other requirements that
# you want to use different build modes, etc.
targets:
SecretKeysDebug:
namespace: MySecretKeys # can override namespace (Default: `Keys`)
keys:
clientID:
name: CLIENT_ID_DEBUG
clientSecret:
name: CLIENT_SECRET_DEBUG
apiPath:
name: BASE_API_PATH
home:
name: HOME # can load environment variables
SecretKeysProduction:
keys:
clientID:
name: CLIENT_ID_PRODUCTION
config:
DEBUG: CLIENT_ID_ADHOC # can override `name` only when `#if DEBUG`
clientSecret:
name: CLIENT_SECRET_PRODUCTION
config:
DEBUG: CLIENT_SECRET_ADHOC
apiPath:
name: BASE_API_PATH