-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgradleCommand.js
43 lines (35 loc) · 1.12 KB
/
gradleCommand.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { spawnSync } from "child_process";
import { existsSync } from "fs";
function determineGradleCommand(debugLog) {
let gradleCommand = null;
let gradleWrapper = false;
debugLog("Determining gradle command");
try {
const isWindows = process.platform === "win32";
debugLog("isWindows: " + isWindows);
const gradleWrapperFile = isWindows ? "gradlew.bat" : "gradlew";
debugLog(`Checking if wrapper file ${gradleWrapperFile} exists`);
if (existsSync(gradleWrapperFile)) {
debugLog("Wrapper file exists");
gradleCommand = (isWindows ? "" : "./") + gradleWrapperFile;
gradleWrapper = true;
} else {
debugLog("Wrapper file not found");
}
} catch (err) {
debugLog("Error trying to determine gradle command.");
debugLog(err);
}
if (!gradleCommand) {
const gradleVersion = spawnSync("gradle", ["--version"]);
if (gradleVersion.status === 0) {
gradleCommand = "gradle";
}
}
debugLog(`Determined gradle command: ${gradleCommand}, wrapper: ${gradleWrapper}`);
return {
gradleCommand,
gradleWrapper,
};
}
export { determineGradleCommand };