diff --git a/CHANGELOG.md b/CHANGELOG.md index 583e0b4..50bcc25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Webtools releases ## [Unreleased] +### Added +- Make it possible to set environment variables for npm run tasks. ([#2](https://github.com/diffplug/webtools/pull/2)) ## [1.0.0] - 2024-07-05 ### Fixed diff --git a/settings.gradle b/settings.gradle index 7e84ced..a949517 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,7 +10,7 @@ plugins { // https://github.com/diffplug/spotless/blob/main/plugin-gradle/CHANGES.md id 'com.diffplug.spotless' version '7.0.0.BETA1' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md - id 'com.diffplug.spotless-changelog' version '3.0.2' apply false + id 'com.diffplug.spotless-changelog' version '3.1.2' apply false // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.2.1' apply false // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md @@ -29,7 +29,7 @@ plugins { id 'dev.adamko.dokkatoo-html' version '2.3.1' apply false } blowdryerSetup { - github 'diffplug/blowdryer-diffplug', 'tag', '7.3.0' + github 'diffplug/blowdryer-diffplug', 'tag', '8.0.1' //devLocal '../blowdryer-diffplug' setPluginsBlockTo { it.file 'plugin.versions' diff --git a/src/main/java/com/diffplug/webtools/node/NodePlugin.java b/src/main/java/com/diffplug/webtools/node/NodePlugin.java index 03be667..258c44b 100644 --- a/src/main/java/com/diffplug/webtools/node/NodePlugin.java +++ b/src/main/java/com/diffplug/webtools/node/NodePlugin.java @@ -22,11 +22,11 @@ import java.nio.file.Files; import java.util.Collections; import java.util.Objects; +import java.util.TreeMap; import org.gradle.api.Action; import org.gradle.api.DefaultTask; import org.gradle.api.Plugin; import org.gradle.api.Project; -import org.gradle.api.Task; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.provider.Property; import org.gradle.api.tasks.CacheableTask; @@ -52,7 +52,7 @@ public Extension(Project project) { this.project = Objects.requireNonNull(project); } - public TaskProvider npm_run(String name, Action taskConfig) { + public TaskProvider npm_run(String name, Action taskConfig) { return project.getTasks().register("npm_run_" + name, NpmRunTask.class, task -> { task.taskName = name; try { @@ -76,12 +76,18 @@ public TaskProvider npm_run(String name, Action taskConfig) { @CacheableTask public abstract static class NpmRunTask extends DefaultTask { public String taskName; + private TreeMap environment = new TreeMap<>(); @Input public String getTaskName() { return taskName; } + @Input + public TreeMap getEnvironment() { + return environment; + } + @Internal public abstract Property getSetup(); @@ -95,7 +101,7 @@ public void npmCiRunTask() throws Exception { setup.start(getProjectDir().get().getAsFile()); // run the gulp task ProxyConfig proxyConfig = new ProxyConfig(Collections.emptyList()); - setup.factory().getNpmRunner(proxyConfig, null).execute("run " + taskName, null); + setup.factory().getNpmRunner(proxyConfig, null).execute("run " + taskName, environment); } }