func createBuildCommands()

in Plugins/SwiftBuffetPlugin/Plugin.swift [6:28]


    func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
        // This plugin only runs for package targets that can have source files.
        guard let sourceFiles = target.sourceModule?.sourceFiles else { return [] }

        var commands: [Command] = []

        for sourceFile in sourceFiles {
            if sourceFile.path.extension == "proto" {
                let outputPath = context.pluginWorkDirectory.appending("\(sourceFile.path.stem).swift")
                commands.append(
                    .buildCommand(
                        displayName: "Generating Swift code for \(sourceFile.path.lastComponent)",
                        executable: try context.tool(named: "SwiftBuffet").path,
                        arguments: [sourceFile.path.string, outputPath.string],
                        inputFiles: [sourceFile.path],
                        outputFiles: [outputPath]
                    )
                )
            }
        }

        return commands
    }