Skip to content

Commit

Permalink
Added ignoreExitValue and execOverrides to NodeTask.
Browse files Browse the repository at this point in the history
  • Loading branch information
konrad-garus committed Feb 17, 2014
1 parent 50ee4f1 commit e3eee7c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -40,6 +40,25 @@ You can also add arguments, like this:
args = ['arg1', 'arg2']
}

`NodeTask` is a wrapper around the core `Exec` task. You can set the `ignoreExitValue` property on it:

task myScript(type: NodeTask) {
script = file('src/scripts/my.js')
ignoreExitValue = true
}

You can also customize all other values on the `ExecSpec` by passing a closure to `execOverrides`. It's executed last, possibly
overriding already set parameters.

task myScript(type: NodeTask) {
script = file('src/scripts/my.js')
execOverrides {
it.ignoreExitValue = true
it.workingDir = 'somewhere'
it.standardOutput = new FileOutputStream('logs/my.log')
}
}

When executing this for the first time, it will run a nodeSetup task that downloades NodeJS (for your platform) and
NPM (Node Package Manager) if on windows (other platforms include it into the distribution).

Expand Down
14 changes: 14 additions & 0 deletions src/main/groovy/com/moowork/gradle/node/exec/ExecRunner.groovy
Expand Up @@ -19,6 +19,10 @@ abstract class ExecRunner
def Object workingDir

def List<?> arguments = []

def boolean ignoreExitValue

def Closure execOverrides

public ExecRunner( final Project project )
{
Expand Down Expand Up @@ -49,6 +53,16 @@ abstract class ExecRunner
{
it.workingDir = this.workingDir
}

if ( this.ignoreExitValue != null )
{
it.ignoreExitValue = this.ignoreExitValue
}

if ( this.execOverrides != null )
{
this.execOverrides( it )
}
} )
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/groovy/com/moowork/gradle/node/task/NodeTask.groovy
Expand Up @@ -39,6 +39,16 @@ class NodeTask
this.runner.workingDir = value
}

void setIgnoreExitValue ( final boolean value )
{
this.runner.ignoreExitValue = value
}

void setExecOverrides ( final Closure closure )
{
this.runner.execOverrides = closure
}

@TaskAction
void exec()
{
Expand Down

0 comments on commit e3eee7c

Please sign in to comment.