-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathplugin.swift
63 lines (57 loc) · 1.57 KB
/
plugin.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import PackagePlugin
import Foundation
@main
struct FormatBuildPlugin {
static private let toolName = "swift-format"
func createBuildCommands(
pluginWorkDirectory: Path,
tool: PluginContext.Tool,
targetDirectory: Path
) -> [Command] {
let arguments = [
"format",
targetDirectory.string,
"--recursive",
"--parallel",
"--in-place",
"--configuration",
targetDirectory.appending(subpath: ".swift-format").string
]
return [
.prebuildCommand(
displayName: "Format Source Code",
executable: tool.path,
arguments: arguments,
environment: [:],
outputFilesDirectory: pluginWorkDirectory.appending(Self.toolName)
)
]
}
}
extension FormatBuildPlugin: BuildToolPlugin {
func createBuildCommands(
context: PackagePlugin.PluginContext,
target: PackagePlugin.Target
) async throws -> [PackagePlugin.Command] {
createBuildCommands(
pluginWorkDirectory: context.pluginWorkDirectory,
tool: try context.tool(named: Self.toolName),
targetDirectory: target.directory
)
}
}
#if canImport(XcodeProjectPlugin)
import XcodeProjectPlugin
extension FormatBuildPlugin: XcodeBuildToolPlugin {
func createBuildCommands(
context: XcodeProjectPlugin.XcodePluginContext,
target: XcodeProjectPlugin.XcodeTarget
) throws -> [PackagePlugin.Command] {
createBuildCommands(
pluginWorkDirectory: context.pluginWorkDirectory,
tool: try context.tool(named: Self.toolName),
targetDirectory: context.xcodeProject.directory
)
}
}
#endif