|
20 | 20 | import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
|
21 | 21 | import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
|
22 | 22 | import java.io.File;
|
| 23 | +import java.io.IOException; |
23 | 24 | import java.io.Serializable;
|
| 25 | +import java.nio.charset.StandardCharsets; |
24 | 26 | import java.nio.file.Files;
|
25 | 27 | import java.util.Collections;
|
26 | 28 |
|
27 | 29 | class SetupCleanupNode implements Serializable {
|
| 30 | + private static String nvmRc(File file) throws IOException { |
| 31 | + String str = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8).trim(); |
| 32 | + return "v" + str; |
| 33 | + } |
| 34 | + |
| 35 | + private static File findNvmRc(File projectDir) { |
| 36 | + File nvmRc = new File(projectDir, ".nvmrc"); |
| 37 | + if (nvmRc.exists()) { |
| 38 | + return nvmRc; |
| 39 | + } |
| 40 | + nvmRc = new File(projectDir.getParentFile(), ".nvmrc"); |
| 41 | + if (nvmRc.exists()) { |
| 42 | + return nvmRc; |
| 43 | + } |
| 44 | + throw new IllegalArgumentException("Could not find .nvmrc in " + projectDir + " or its parent."); |
| 45 | + } |
| 46 | + |
28 | 47 | public String nodeVersion;
|
29 | 48 | public String npmVersion;
|
30 | 49 | private File workingDir, installDir;
|
31 | 50 | @SuppressWarnings("unused") // used for serialized equality
|
32 | 51 | private byte[] packageLockJson;
|
33 | 52 |
|
34 | 53 | public void start(File projectDir) throws Exception {
|
| 54 | + nodeVersion = nvmRc(findNvmRc(projectDir)); |
| 55 | + npmVersion = "provided"; |
35 | 56 | workingDir = projectDir;
|
36 | 57 | installDir = new File(projectDir, "build/node-install");
|
37 | 58 | packageLockJson = Files.readAllBytes(workingDir.toPath().resolve("package-lock.json"));
|
|
0 commit comments