-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathAutoAddonPlugin.swift
More file actions
71 lines (65 loc) · 2.17 KB
/
AutoAddonPlugin.swift
File metadata and controls
71 lines (65 loc) · 2.17 KB
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
64
65
66
67
68
69
70
71
//
// AppAddonPlugin.swift
// LiveViewNative
//
// Created by Carson Katri on 3/6/25.
//
import PackagePlugin
import Foundation
@main
struct AutoAddonPlugin: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: any Target) async throws -> [Command] {
let tool = try context.tool(named: "AutoAddon")
let inputFiles = target.sourceModule?.sourceFiles
.filter({
(try? String(contentsOf: $0.url, encoding: .utf8))?
.contains("@LiveElement")
?? false
})
.map(\.url)
?? []
let outputFile = context.pluginWorkDirectoryURL.appending(path: "AutoAddon.swift")
return [
.buildCommand(
displayName: "Auto Addon",
executable: tool.url,
arguments: [
target.name,
outputFile.absoluteString
] + inputFiles.map(\.absoluteString),
environment: [:],
inputFiles: inputFiles,
outputFiles: [outputFile]
)
]
}
}
#if canImport(XcodeProjectPlugin)
import XcodeProjectPlugin
extension AutoAddonPlugin: XcodeBuildToolPlugin {
func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] {
let tool = try context.tool(named: "AutoAddon")
let inputFiles = target.inputFiles
.filter({
(try? String(contentsOf: $0.url, encoding: .utf8))?
.contains("@LiveElement")
?? false
})
.map(\.url)
let outputFile = context.pluginWorkDirectoryURL.appending(path: "AutoAddon.swift")
return [
.buildCommand(
displayName: "Auto Addon",
executable: tool.url,
arguments: [
target.displayName,
outputFile.absoluteString
] + inputFiles.map(\.absoluteString),
environment: [:],
inputFiles: inputFiles,
outputFiles: [outputFile]
)
]
}
}
#endif