Skip to content

Instantly share code, notes, and snippets.

@erikbasargin
Forked from Sorix/Package.swift
Created December 16, 2020 00:28
Show Gist options
  • Select an option

  • Save erikbasargin/29d152e374d05f905da51c7e436a714c to your computer and use it in GitHub Desktop.

Select an option

Save erikbasargin/29d152e374d05f905da51c7e436a714c to your computer and use it in GitHub Desktop.
Example of Package.swift with environment variables support
// swift-tools-version:4.0
import PackageDescription
#if os(Linux)
import Glibc
#else
import Darwin.C
#endif
enum Enviroment: String {
static let `default`: Enviroment = .development
case development, production
static func get() -> Enviroment {
if let envPointer = getenv("ENV_TYPE") {
let env = String(cString: envPointer)
return Enviroment(rawValue: env) ?? .default
} else {
return .default
}
}
}
var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/vapor/vapor.git", from: "3.1.0"),
.package(url: "https://github.com/Sorix/whirr-feedback-api-model", .branch("develop"))
]
var appTargetDependencies: [Target.Dependency] = ["Vapor", "FluentSQLite", "APIModel", "GooglePlaces"]
switch Enviroment.get() {
case .production:
dependencies.append(.package(url: "https://github.com/vapor/fluent-postgresql.git", from: "1.0.0"))
appTargetDependencies.append("FluentPostgreSQL")
case .development:
dependencies.append(.package(url: "https://github.com/vapor/fluent-sqlite.git", from: "3.0.0"))
appTargetDependencies.append("FluentSQLite")
}
let package = Package(
name: "backend",
dependencies: dependencies,
targets: [
.target(name: "GooglePlaces", dependencies: ["Vapor"]),
.target(name: "App", dependencies: appTargetDependencies),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: ["App"])
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment