Basic pnpm execution task
This task simplifies the wiring of running pnpm exec on packages that are installed in the toolchain.
It is also easy to use as a base class for building your own specialised tasks.
build.gradle
import org.ysb33r.gradle.jse.pnpm.tasks.PnpmPrepareTask
import org.ysb33r.gradle.jse.pnpm.tasks.PnpmExecTask
import org.ysb33r.gradle.jse.pnpm.toolchains.JsePnpmToolchain
import org.ysb33r.gradle.jsecosystem.packages.PackageDescriptor
jsEcosystem {
toolchains {
pnpm(JsePnpmToolchain) {
withPnpmNode()
}
}
}
tasks.register('pnpmPrepare', PnpmPrepareTask) {
workdir = project.layout.buildDirectory.dir('myWorkdir')
toolchain = jsEcosystem.toolchains.named('pnpm', JsePnpmToolchain)
packages = project.provider { -> (1)
[
PackageDescriptor.of('downdoc', '1.2.3'),
PackageDescriptor.of('asciidoctor', 'cli', '4.5.6')
]
}
}
tasks.register('runDownDoc', PnpmExecTask) {
execSpec(tasks.named('pnpmPrepare', PnpmPrepareTask)) { (2) (3)
cmd {
command = 'downdoc' (4)
args '--postpublish' (5)
}
}
}
tasks.named('runDownDoc', PnpmExecTask) {
execSpec {
cnd {
args '-a', 'foo=bar' (6)
}
}
}
| 1 | Registers an execution task and associate it with a PnpmPrepareTask.
This makes the execution task depend on the preparation task and also inherits the toolchain and working directory. |
| 2 | Configures the execution specification once the association is done. |
| 3 | Set a command to be executed |
| 4 | Set any additional arguments.
With this example configuration, Gradle will effectively execute pnpm exec downdoc --postpublish. |
| 5 | Once the association between the execution task and a toolchain has been established, additional parameters can be configured. If the task is associated with another toolchain all configuration will be discarded and the task’s execution specification must be configured again. |