0

Context
I recently took over a Swift project which relies on git submodules. One of my first task was to clean up the project, which means removing submodules, using Swift Packages.

On my way doing this i encounter a tricky submodule. It contains swift files and a WebPack project that's loaded in a WebView. Currently the project that imports this submodule has a custom build phase that runs npm ci + npm build to build the WebPack and copy the files into the app.


Question:
When i switch to using a Swift Package it should manage this custom build phase on its own. Is it possible to run npm ci + npm build in a BuildToolPlugin?

My current state is trying to run a shell script which simply creates a file:

@main
struct TSPlugin: BuildToolPlugin {

    func createBuildCommands(context: PackagePlugin.PluginContext, target: PackagePlugin.Target) async throws -> [PackagePlugin.Command] {
        let tsPath = context.pluginWorkDirectory
                .appending (subpath: target.name)
                .appending (subpath: "Seatmap")
        print(tsPath)
        print("here1")
        let scriptPath = context.package.directory.appending(["..", "TSPlugin", "TEst.sh"])

        print("here2")
        return [
            .prebuildCommand(
                displayName: "Generating localized strings from source files",
                executable: scriptPath,
                arguments: [],
                outputFilesDirectory: tsPath
            )
        ]
    }
}
#!/bin/bash
echo "come on"
touch easypeasy.txt

I rebuilt this in a demo project: https://github.com/Deitsch/SwiftPluginDemo

Deitsch
  • 1,610
  • 14
  • 28

0 Answers0