Skip to content

Commit 535029b

Browse files
committed
Read local env file
1 parent 5a911e3 commit 535029b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Plugins/VercelPackager/VercelOutput.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,13 @@ public struct VercelOutput {
8383
print("")
8484

8585
Task {
86+
var env = localEnvironment()
87+
env["LOCAL_LAMBDA_SERVER_ENABLED"] = "true"
88+
8689
try Shell.execute(
8790
executable: context.tool(named: "swift").path,
8891
arguments: ["run", "--package-path", projectDirectory.string],
89-
environment: ["LOCAL_LAMBDA_SERVER_ENABLED": "true"]
92+
environment: env
9093
)
9194
}
9295

@@ -151,6 +154,25 @@ extension VercelOutput {
151154
}
152155
return arguments[index + 1]
153156
}
157+
158+
public func localEnvironment() -> [String: String] {
159+
guard let data = fs.contents(atPath: projectDirectory.appending(".env").string) else {
160+
return [:]
161+
}
162+
guard let text = String(data: data, encoding: .utf8) else {
163+
return [:]
164+
}
165+
let lines = text.split(separator: "\n").map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
166+
var env: [String: String] = [:]
167+
for line in lines {
168+
guard line.starts(with: "#") == false else { continue }
169+
let parts = line.split(separator: "=", maxSplits: 1)
170+
let key = String(parts[0]).trimmingCharacters(in: .whitespacesAndNewlines)
171+
let value = parts[1].trimmingCharacters(in: .whitespacesAndNewlines).dropFirst().dropLast()
172+
env[key] = String(value)
173+
}
174+
return env
175+
}
154176
}
155177

156178
// MARK: - Products

0 commit comments

Comments
 (0)