-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from s0x/fix-path-issues
Set PATH variable for node, npm and yarn
- Loading branch information
Showing
12 changed files
with
436 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 73 additions & 8 deletions
81
src/main/groovy/com/moowork/gradle/node/npm/NpmSetupTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,98 @@ | ||
package com.moowork.gradle.node.npm | ||
|
||
import com.moowork.gradle.node.task.SetupTask | ||
import com.moowork.gradle.node.NodeExtension | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Internal | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.process.ExecResult | ||
|
||
/** | ||
* npm install that only gets executed if gradle decides so. | ||
**/ | ||
class NpmSetupTask | ||
extends NpmTask | ||
extends DefaultTask | ||
{ | ||
public final static String NAME = 'npmSetup' | ||
|
||
private NodeExtension config | ||
|
||
protected Iterable<?> args = [] | ||
|
||
private ExecResult result | ||
|
||
public NpmSetupTask() | ||
{ | ||
dependsOn( SetupTask.NAME ) | ||
|
||
this.group = 'Node' | ||
this.description = 'Setup a specific version of npm to be used by the build.' | ||
this.enabled = false | ||
} | ||
|
||
@Input | ||
public Set<String> getInput() | ||
{ | ||
def set = new HashSet<>() | ||
set.add( getConfig().download ) | ||
set.add( getConfig().npmVersion ) | ||
set.add( getConfig().npmWorkDir ) | ||
return set | ||
} | ||
|
||
this.project.afterEvaluate { | ||
getOutputs().dir( this.project.node.npmWorkDir ) | ||
setWorkingDir( this.project.node.nodeModulesDir ) | ||
@OutputDirectory | ||
public File getNpmDir() | ||
{ | ||
return getVariant().npmDir | ||
} | ||
|
||
@Internal | ||
ExecResult getResult() | ||
{ | ||
return this.result | ||
} | ||
|
||
@Internal | ||
protected getConfig() | ||
{ | ||
if ( this.config != null) | ||
{ | ||
return this.config | ||
} | ||
|
||
this.config = NodeExtension.get( this.project ) | ||
return this.config | ||
} | ||
|
||
@Internal | ||
protected getVariant() | ||
{ | ||
return getConfig().variant | ||
} | ||
|
||
@Internal | ||
void setArgs( final Iterable<?> value ) | ||
{ | ||
this.args = value | ||
} | ||
|
||
@TaskAction | ||
void exec() { | ||
def runner = new NpmExecRunner( this.project ) | ||
runner.arguments.addAll( this.args ) | ||
|
||
this.result = runner.execute() | ||
} | ||
|
||
void configureNpmVersion( String npmVersion ) | ||
void configureVersion( String npmVersion ) | ||
{ | ||
if ( !npmVersion.isEmpty() ) | ||
{ | ||
logger.debug( "Setting npmVersion to ${npmVersion}" ) | ||
setArgs( ['install', '--prefix', this.project.node.npmWorkDir, "npm@${npmVersion}"] ) | ||
setEnabled( true ) | ||
getInputs().property( 'npmVersion', npmVersion ) | ||
setArgs( ['install', '--global', '--prefix', getVariant().npmDir, "npm@${npmVersion}"] ) | ||
enabled = true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.