From 9fd03b61107cb43bfc2e8536208728edef46e742 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Fri, 2 Oct 2015 11:44:34 -0600 Subject: [PATCH 1/2] Include node_modules/.bin in node exec path Also add 'executable' syntax sugar for NodeTask --- .../com/moowork/gradle/node/exec/NodeExecRunner.groovy | 7 ++++++- .../groovy/com/moowork/gradle/node/task/NodeTask.groovy | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/com/moowork/gradle/node/exec/NodeExecRunner.groovy b/src/main/groovy/com/moowork/gradle/node/exec/NodeExecRunner.groovy index df54058..25d4351 100644 --- a/src/main/groovy/com/moowork/gradle/node/exec/NodeExecRunner.groovy +++ b/src/main/groovy/com/moowork/gradle/node/exec/NodeExecRunner.groovy @@ -1,5 +1,6 @@ package com.moowork.gradle.node.exec +import com.moowork.gradle.node.NodeExtension import org.gradle.api.Project import org.gradle.process.ExecResult @@ -24,7 +25,11 @@ class NodeExecRunner nodeEnvironment << System.getenv() } - def nodeBinDirPath = this.variant.nodeBinDir.getAbsolutePath() + String nodeModulesBinPath = + project.extensions.findByType(NodeExtension).nodeModulesDir.absolutePath + '/node_modules/.bin' + + String nodeBinDirPath = + this.variant.nodeBinDir.getAbsolutePath() + File.pathSeparator + nodeModulesBinPath // Take care of Windows environments that may contain "Path" OR "PATH" - both existing // possibly (but not in parallel as of now) diff --git a/src/main/groovy/com/moowork/gradle/node/task/NodeTask.groovy b/src/main/groovy/com/moowork/gradle/node/task/NodeTask.groovy index e7149aa..a2cea3c 100644 --- a/src/main/groovy/com/moowork/gradle/node/task/NodeTask.groovy +++ b/src/main/groovy/com/moowork/gradle/node/task/NodeTask.groovy @@ -1,5 +1,6 @@ package com.moowork.gradle.node.task +import com.moowork.gradle.node.NodeExtension import com.moowork.gradle.node.exec.NodeExecRunner import org.gradle.api.DefaultTask import org.gradle.api.tasks.TaskAction @@ -27,6 +28,13 @@ class NodeTask this.script = value } + void setExecutable( final String execName ) + { + File modulesDir = project.extensions.findByType(NodeExtension).nodeModulesDir + setScript(new File(modulesDir, 'node_modules/.bin/' + execName)) + dependsOn( NpmInstallTask.NAME ) + } + void setArgs( final Iterable value ) { this.args = value From 1126dc04e509e4532a967d4504759014ea54e7a9 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 6 Oct 2015 15:12:20 -0600 Subject: [PATCH 2/2] Pass through exec closure delegate This allows calling ExecSpec methods directly from the execOverrides closure, just like when using exec { } from Gradle normally. --- src/main/groovy/com/moowork/gradle/node/exec/ExecRunner.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/groovy/com/moowork/gradle/node/exec/ExecRunner.groovy b/src/main/groovy/com/moowork/gradle/node/exec/ExecRunner.groovy index 405c416..3be6a05 100644 --- a/src/main/groovy/com/moowork/gradle/node/exec/ExecRunner.groovy +++ b/src/main/groovy/com/moowork/gradle/node/exec/ExecRunner.groovy @@ -61,6 +61,7 @@ abstract class ExecRunner if ( this.execOverrides != null ) { + this.execOverrides.setDelegate( getDelegate() ) this.execOverrides( it ) } } )