Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to set environment variables #2

Merged
merged 3 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading