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

Fix for isue #29 #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ http://requirejs.org/docs/optimization.html#wholeproject

### Plugin Options

**runner**

Specifies which Javascript engine is used to execute the r.js optimizer. Can be either *rhino* or *nodejs*, defaults to *nodejs*.
When using *nodejs*, the plugin will try and detect the node executable. To customize the node executable's location, supply a path
to the executable using nodeJsFile

**nodeExecutable**

An optional path to a nodejs executable. This should not be needed if node is in the system path as 'node' or 'nodejs';
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<groupId>com.github.mcheely</groupId>
<artifactId>requirejs-maven-plugin</artifactId>
<name>RequireJS Maven Plugin</name>
<version>2.0.1-noquotes-SNAPSHOT</version>
<version>2.0.1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<url>http://github.com/mcheely/requirejs-maven-plugin</url>
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/com/github/mcheely/maven/requirejs/OptimizeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public class OptimizeMojo extends AbstractMojo {
*/
private boolean skip;

/**
* Defines which javascript engine to use. Possible values: rhino or nodejs.
*
* @parameter expression="${requirejs.optimize.runner}" default-value=nodejs
*/
private String runner = "nodejs";

/**
* Defines the location of the NodeJS executable to use.
*
Expand All @@ -100,7 +107,8 @@ public void execute() throws MojoExecutionException {
}

Runner runner;
String nodeCommand = getNodeJsPath();
String nodeCommand = getNodeCommand();

if (nodeCommand != null) {
getLog().info("Running with Node @ " + nodeCommand);
runner = new NodeJsRunner(nodeCommand);
Expand All @@ -109,7 +117,6 @@ public void execute() throws MojoExecutionException {
runner = new RhinoRunner();
}


try {
Optimizer builder = new Optimizer();
ErrorReporter reporter = new MojoErrorReporter(getLog(), true);
Expand All @@ -127,8 +134,20 @@ public void execute() throws MojoExecutionException {
throw new MojoExecutionException("r.js exited with an error.");
}
}
/**
* Returns the node command if node is available and it is the runner which should be used.
*
* @return the command or <code>null</code>
*/
private String getNodeCommand() {
if ("nodejs".equalsIgnoreCase(runner)) {
return getNodeJsPath();
}

return null;
}

@SuppressWarnings("rawtypes")
@SuppressWarnings("rawtypes")
public Map getPluginContext() {
return super.getPluginContext();
}
Expand Down