david-swift 97d086a7bb
All checks were successful
Deploy Docs / publish (push) Successful in 18s
SwiftLint / SwiftLint (push) Successful in 6s
Migrate to the Aparoksha Gitea instance
2024-10-07 14:58:15 +02:00

40 lines
1.2 KiB
Swift

//
// Plugin.swift
// Localized
//
// Created by david-swift on 02.03.24.
//
import Foundation
import PackagePlugin
/// The build tool plugin for generating Swift code from the `Localized.yml` file.
@main
struct Plugin: BuildToolPlugin {
/// Create the commands for generating the code.
/// - Parameters:
/// - context: The plugin context.
/// - target: The target.
/// - Returns: The commands.
func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] {
guard let target = target.sourceModule,
let inputFile = target.sourceFiles.first(
where: { ["Localized.yml", "Localized.yaml"].contains($0.url.lastPathComponent) }
) else {
return []
}
let outputFile = context.pluginWorkDirectoryURL.appending(path: "Localized.swift")
return [
.buildCommand(
displayName: "Generating Localized.swift",
executable: try context.tool(named: "Generation").url,
arguments: [inputFile.url.path, outputFile.path],
inputFiles: [inputFile.url],
outputFiles: [outputFile]
)
]
}
}