use of org.eclipse.n4js.binaries.nodejs.NodeBinaryLocatorHelper in project n4js by eclipse.
the class UpdateShippedCode method runNpmInstall.
private static void runNpmInstall(File workingDirectory) {
// Initialize DI
Injector injector = N4JSStandaloneSetup.doSetup();
final NodeBinaryLocatorHelper locator = injector.getInstance(NodeBinaryLocatorHelper.class);
final NodeProcessBuilder nodeProcessBuilder = injector.getInstance(NodeProcessBuilder.class);
println("Running \"" + N4JSGlobals.NPM_INSTALL + "\" in folder \"" + workingDirectory + "\"");
final String npmBinaryPath = locator.findNodePath();
if (npmBinaryPath == null || npmBinaryPath.isEmpty()) {
println("");
println("Could not identify location of node.");
println("!!! IMPORTANT !!!");
println("You have to manually run \"" + N4JSGlobals.NPM_INSTALL + "\" in folder " + workingDirectory);
println("");
return;
}
println("Identified npm path at: " + npmBinaryPath);
try {
String npm = npmBinaryPath + File.separator + N4JSGlobals.NPM;
final String[] cmd = new String[] { npm, "install" };
println("Invoking: " + String.join(" ", cmd));
println(" in working directory: " + workingDirectory);
ProcessBuilder pb = nodeProcessBuilder.getNpmInstallProcessBuilder(workingDirectory, "", true);
final Process p = pb.start();
p.waitFor();
println(N4JSGlobals.NPM_INSTALL + " finished.");
} catch (Throwable th) {
println("Error while running \"" + N4JSGlobals.NPM_INSTALL + "\"");
th.printStackTrace();
throw new RuntimeException(th);
}
}
Aggregations