Skip to content

Commit

Permalink
Fix formatting by running swiftformat on the output and applying thos…
Browse files Browse the repository at this point in the history
…e rules to the text

In the long run, it would be better for this code to construct a `Manifest` and then use `ManifestSourceGeneration` to generate the text
  • Loading branch information
abertelrud committed Mar 28, 2023
1 parent 807d96d commit 6340897
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
36 changes: 21 additions & 15 deletions Sources/Workspace/InitPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,20 @@ public final class InitPackage {
} else if packageType == .buildToolPlugin {
param += """
.plugin(
name: "\(typeName)",
capability: .buildTool()
),
name: "\(typeName)",
capability: .buildTool()
),
]
"""
} else if packageType == .commandPlugin {
param += """
.plugin(
name: "\(typeName)",
capability: .command(intent: .custom(verb: "\(typeName)", description: "prints hello world"))
),
name: "\(typeName)",
capability: .command(intent: .custom(
verb: "\(typeName)",
description: "prints hello world"
))
),
]
"""
} else if packageType == .macro {
Expand Down Expand Up @@ -398,24 +401,27 @@ public final class InitPackage {
import PackagePlugin
@main
"""
if packageType == .buildToolPlugin {
content += """
struct \(typeName): BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
print("Hello, World!")
return []
}
struct \(typeName): BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
print("Hello, World!")
return []
}
}
"""
}
else {
content += """
struct \(typeName): CommandPlugin {
func performCommand(context: PluginContext, arguments: [String]) async throws {
print("Hello, World!")
}
struct \(typeName): CommandPlugin {
func performCommand(context: PluginContext, arguments: [String]) async throws {
print("Hello, World!")
}
}
"""
}

Expand Down
3 changes: 2 additions & 1 deletion Tests/WorkspaceTests/InitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ class InitTests: XCTestCase {
XCTAssertFileExists(manifest)
let manifestContents: String = try localFileSystem.readFileContents(manifest)
XCTAssertMatch(manifestContents, .and(.contains(".plugin("), .contains("targets: [\"MyCommandPlugin\"]")))
XCTAssertMatch(manifestContents, .and(.contains(".plugin("), .contains("capability: .command(intent: .custom(verb")))
XCTAssertMatch(manifestContents, .and(.contains(".plugin("),
.and(.contains("capability: .command(intent: .custom("), .contains("verb: \"MyCommandPlugin\""))))

let source = path.appending("Plugins", "MyCommandPlugin.swift")
XCTAssertFileExists(source)
Expand Down

0 comments on commit 6340897

Please sign in to comment.