-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from idrougge/colour
Add support for rewriting colour literals as well
- Loading branch information
Showing
7 changed files
with
358 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// plugin.swift | ||
// | ||
// | ||
// Created by Iggy Drougge on 2024-01-22. | ||
// | ||
|
||
import PackagePlugin | ||
import XcodeProjectPlugin | ||
import Foundation | ||
|
||
@main | ||
struct ColourPlugin: CommandPlugin, XcodeCommandPlugin { | ||
func performCommand(context: PluginContext, arguments: [String]) async throws { | ||
var argumentExtractor = ArgumentExtractor(arguments) | ||
let targetNames = argumentExtractor.extractOption(named: "target") | ||
let sourceModules = try context.package.targets(named: targetNames).compactMap(\.sourceModule) | ||
let files = sourceModules.flatMap { $0.sourceFiles(withSuffix: "swift") } | ||
let tool = try context.tool(named: "ResourceRewriterForXcode") | ||
let process = Process() | ||
process.executableURL = URL(fileURLWithPath: tool.path.string) | ||
process.arguments = CollectionOfOne("colours") + files.map(\.path.string) | ||
try process.run() | ||
process.waitUntilExit() | ||
|
||
switch (process.terminationReason, process.terminationStatus) { | ||
case (.exit, EXIT_SUCCESS): | ||
print("String literals were successfully rewritten as resources.") | ||
case (let reason, let status): | ||
Diagnostics.error("Process terminated with error: \(reason) (\(status))") | ||
} | ||
} | ||
|
||
func performCommand(context: XcodePluginContext, arguments: [String]) throws { | ||
let sourceFiles = context.xcodeProject.filePaths.filter { file in | ||
file.extension == "swift" | ||
} | ||
let tool = try context.tool(named: "ResourceRewriterForXcode") | ||
let process = Process() | ||
process.executableURL = URL(fileURLWithPath: tool.path.string) | ||
process.arguments = CollectionOfOne("colours") + sourceFiles.map(\.string) | ||
try process.run() | ||
process.waitUntilExit() | ||
|
||
switch (process.terminationReason, process.terminationStatus) { | ||
case (.exit, EXIT_SUCCESS): | ||
print("String literals were successfully rewritten as resources.") | ||
case (let reason, let status): | ||
Diagnostics.error("Process terminated with error: \(reason) (\(status))") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.