Skip to content

Commit 1bcc9ed

Browse files
committed
Support server only
1 parent d15bee3 commit 1bcc9ed

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

Plugins/VercelPackager/Plugin.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ struct VercelPackager: CommandPlugin {
1313
func performCommand(context: PackagePlugin.PluginContext, arguments: [String]) async throws {
1414
Shell.prepare()
1515
let vercelOutput = VercelOutput(packageManager: packageManager, context: context, arguments: arguments)
16-
if vercelOutput.isDev {
17-
try await dev(vercelOutput)
16+
if vercelOutput.isServer {
17+
try await vercelOutput.proxyServer()
18+
} else if vercelOutput.isDev {
19+
try await vercelOutput.dev()
1820
} else {
1921
try await build(vercelOutput)
2022
}
@@ -25,11 +27,6 @@ struct VercelPackager: CommandPlugin {
2527
try await vercelOutput.build()
2628
if vercelOutput.isDeploy {
2729
try await vercelOutput.deploy()
28-
return
2930
}
3031
}
31-
32-
private func dev(_ vercelOutput: VercelOutput) async throws {
33-
try await vercelOutput.dev()
34-
}
3532
}

Plugins/VercelPackager/VercelOutput.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,7 @@ public struct VercelOutput {
9797
}
9898

9999
Task {
100-
try Shell.execute(
101-
executable: context.tool(named: "node").path,
102-
arguments: [
103-
projectDirectory.appending([".build", "checkouts", "Vercel", "Plugins", "VercelPackager", "Server", "server.cjs"]).string,
104-
port
105-
],
106-
environment: ["SWIFT_PROJECT_DIRECTORY": projectDirectory.string]
107-
)
100+
try await proxyServer()
108101
}
109102

110103
try await Task.sleep(nanoseconds: 3_000_000_000)
@@ -119,6 +112,17 @@ public struct VercelOutput {
119112
try await Task.sleep(nanoseconds: 1_000_000_000_000)
120113
}
121114
}
115+
116+
public func proxyServer() async throws {
117+
try Shell.execute(
118+
executable: context.tool(named: "node").path,
119+
arguments: [
120+
projectDirectory.appending([".build", "checkouts", "Vercel", "Plugins", "VercelPackager", "Server", "server.cjs"]).string,
121+
port
122+
],
123+
environment: ["SWIFT_PROJECT_DIRECTORY": projectDirectory.string]
124+
)
125+
}
122126
}
123127

124128
// MARK: - Arguments
@@ -136,6 +140,10 @@ extension VercelOutput {
136140
arguments.contains("dev") || arguments.contains("--dev")
137141
}
138142

143+
public var isServer: Bool {
144+
arguments.contains("server") || arguments.contains("--server")
145+
}
146+
139147
public var isDeploy: Bool {
140148
arguments.contains("deploy") || arguments.contains("--deploy")
141149
}

0 commit comments

Comments
 (0)