Executing Node.js script on multiple files

I have a set of OpenAPI spec YAML files that I want to run through the openapi-filter Node.js script. But this script can only operate on a single file at a time. So essentially the script needs to be executed once for each file.

I’m using the Gradle Node plugin to download, install, and run the script. This plugin has a NodeTask type that can be used to execute the script.

The list of files to operate on will come from the output of a copy task that does inline editing of the YAML contents that needs to happen before it goes through the Node script. So basically it will look like this:

tasks.register('modifyYaml', Copy) {
    from file("src/main/resources")
    into file("${buildDir}/modified")
    filter ...
}

tasks.register('filterYaml') {
    inputs.files modifyYaml
    outputs.dir file("${buildDir}/filtered")
}

Obviously this doesn’t have the part where the Node script would be executed because that’s the part I can’t figure out. From what I’ve read in the docs of the Gradle Node plugin I think you need to define a NodeTask that specifies the script to run and its input parameters.

So what’s the best way to take the list of files from the output of the copy task and turn it into a bunch of NodeTasks?