Skip to content

Commit

Permalink
Make it possible to set environment variables (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Aug 4, 2024
2 parents 814f344 + 2c663bd commit 52f1cb2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/diffplug/webtools/node/NodePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,7 +52,7 @@ public Extension(Project project) {
this.project = Objects.requireNonNull(project);
}

public TaskProvider<?> npm_run(String name, Action<Task> taskConfig) {
public TaskProvider<?> npm_run(String name, Action<NpmRunTask> taskConfig) {
return project.getTasks().register("npm_run_" + name, NpmRunTask.class, task -> {
task.taskName = name;
try {
Expand All @@ -76,12 +76,18 @@ public TaskProvider<?> npm_run(String name, Action<Task> taskConfig) {
@CacheableTask
public abstract static class NpmRunTask extends DefaultTask {
public String taskName;
private TreeMap<String, String> environment = new TreeMap<>();

@Input
public String getTaskName() {
return taskName;
}

@Input
public TreeMap<String, String> getEnvironment() {
return environment;
}

@Internal
public abstract Property<SetupCleanupNode> getSetup();

Expand All @@ -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);
}
}

Expand Down

0 comments on commit 52f1cb2

Please sign in to comment.