Skip to content

Commit

Permalink
xcode command
Browse files Browse the repository at this point in the history
  • Loading branch information
loganwright committed Dec 6, 2018
1 parent 48434b3 commit bdb65d0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
60 changes: 59 additions & 1 deletion Sources/VaporToolbox/XcodeCommand.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
//import Vapor
import Vapor
import Globals

// TODO: Xcode Additions
// automatically add xcconfig
// swift package generate-xcodeproj --xcconfig-overrides Sandbox.xcconfig
//
// automatically add environment variables to project file, more work,
// but would be nice
//

// Generates an Xcode project
struct XcodeCommand: Command {
/// See `Command`.
var arguments: [CommandArgument] = []

/// See `Command`.
var options: [CommandOption] = []

/// See `Command`.
var help: [String] = ["Generates Xcode projects for SPM packages."]

/// See `Command`.
func run(using ctx: CommandContext) throws -> Future<Void> {
ctx.console.output("Generating Xcodeproj...")
let generateProcess = Process.asyncExecute(
"swift",
["package", "generate-xcodeproj"],
on: ctx.container
) { output in
switch output {
case .stderr(let err):
let str = String(bytes: err, encoding: .utf8) ?? "error"
ctx.console.output("Error:", style: .error, newLine: true)
ctx.console.output(str, style: .error, newLine: false)
case .stdout(let out):
let str = String(bytes: out, encoding: .utf8) ?? ""
ctx.console.output(str.consoleText(), newLine: false)
}
}

return generateProcess.map { val in
if val == 0 {
ctx.console.output(
"Generated Xcodeproj.",
style: .info,
newLine: true
)
try Shell.bash("open *.xcodeproj")
} else {
ctx.console.output(
"Failed to generate Xcodeproj.",
style: .error,
newLine: true
)
}
}
}
}

///// Generates an Xcode project for SPM packages.
//struct XcodeCommand: Command {
// /// See `Command`.
Expand Down
1 change: 1 addition & 0 deletions Sources/VaporToolbox/boot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public func boot() -> Future<Application> {

// for running quick exec tests
commands.use(Test(), as: "test")
commands.use(XcodeCommand(), as: "xcode")
services.register(commands)

return Application.asyncBoot(services: services)
Expand Down

0 comments on commit bdb65d0

Please sign in to comment.