Skip to content

Commit 258eeb3

Browse files
committed
Live debug output for the commands executed
1 parent 095a33f commit 258eeb3

File tree

3 files changed

+48
-31
lines changed

3 files changed

+48
-31
lines changed

buildFiles.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ function getBuildFiles(externalFiles) {
3838
return buildFiles
3939
}
4040

41-
42-
4341
module.exports = {
4442
getBuildFiles
4543
}

gradleCommand.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const {
22
spawnSync
33
} = require('child_process');
4-
const path = require('path')
5-
const {existsSync} = require('fs')
4+
const {
5+
existsSync
6+
} = require('fs')
67

78
function determineGradleCommand(debugLog) {
89
let gradleCommand = null

index.js

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ const {
2727
join
2828
} = require('path');
2929
const {
30-
spawnSync
30+
spawn
3131
} = require('child_process');
3232

33-
3433
const ReplaceVersion = require('./ReplaceVersion')
3534

3635
const {
@@ -57,33 +56,53 @@ if (!buildFiles.length) {
5756
return
5857
}
5958

60-
console.log('Checking for upgrades...\n')
59+
exports.debugLog = debugLog;
6160

62-
const gradleDependencyUpdateArgs = ['dependencyUpdates', '-DoutputFormatter=json', '-DoutputDir=build/dependencyUpdates']
63-
const gradleDependencyUpdateResolution = argv.resolution
64-
if (gradleDependencyUpdateResolution) {
65-
gradleDependencyUpdateArgs.push(`-Drevision=${gradleDependencyUpdateResolution}`)
66-
}
61+
async function executeCommandAndWaitForExitCode(command, args) {
62+
let commandExitCode
6763

68-
debugLog(`Executing command\n${gradleCommand} ${gradleDependencyUpdateArgs.join(' ')}\n`)
64+
const child = spawn(command, args);
65+
child.stdout.setEncoding('utf8');
66+
child.stdout.on('data', function (data) {
67+
debugLog(data);
68+
})
6969

70-
const gradleDependencyUpdateProcess = spawnSync(gradleCommand, gradleDependencyUpdateArgs);
70+
child.on('close', (code) => {
71+
commandExitCode = code
72+
})
7173

72-
if (gradleDependencyUpdateProcess.status !== 0) {
73-
informUserAboutInstallingUpdatePlugin();
74-
return
75-
}
74+
while (commandExitCode === undefined) {
75+
debugLog('Waiting for command to finish')
76+
await new Promise(resolve => setTimeout(resolve, 500));
77+
}
7678

77-
if (!buildFiles.length) {
78-
console.log('Unable to find build.gradle, build.gradle.kts or external build file.'.bgRed);
79-
return;
79+
return commandExitCode
8080
}
8181

82-
debugLog('Build files ' + buildFiles);
82+
(async () => {
83+
console.log('Checking for upgrades...\n')
8384

84-
exports.debugLog = debugLog;
85+
const gradleDependencyUpdateArgs = ['dependencyUpdates', '-DoutputFormatter=json', '-DoutputDir=build/dependencyUpdates']
86+
const gradleDependencyUpdateResolution = argv.resolution
87+
if (gradleDependencyUpdateResolution) {
88+
gradleDependencyUpdateArgs.push(`-Drevision=${gradleDependencyUpdateResolution}`)
89+
}
8590

86-
(async () => {
91+
debugLog(`Executing command\n${gradleCommand} ${gradleDependencyUpdateArgs.join(' ')}\n`)
92+
93+
let gradleDependencyUpdateProcessExitCode = await executeCommandAndWaitForExitCode(gradleCommand, gradleDependencyUpdateArgs)
94+
95+
if (gradleDependencyUpdateProcessExitCode !== 0) {
96+
informUserAboutInstallingUpdatePlugin(gradleDependencyUpdateProcessExitCode);
97+
return
98+
}
99+
100+
if (!buildFiles.length) {
101+
console.log('Unable to find build.gradle, build.gradle.kts or external build file.'.bgRed);
102+
return;
103+
}
104+
105+
debugLog('Build files ' + buildFiles);
87106

88107
debugLog(`Reading JSON report file\n`)
89108

@@ -117,10 +136,11 @@ exports.debugLog = debugLog;
117136
if (response.upgrades.some(it => it === 'gradle')) {
118137
console.log('Upgrading gradle wrapper')
119138
const upgradeArgs = ['wrapper', '--gradle-version=' + latestGradleRelease]
139+
120140
debugLog(`Executing command\n${gradleCommand}${upgradeArgs.join(' ')}\n`)
121-
const upgradeGradleWrapper = spawnSync(gradleCommand, upgradeArgs);
141+
let upgradeGradleWrapperExitCode = await executeCommandAndWaitForExitCode(gradleCommand, upgradeArgs)
122142

123-
if (upgradeGradleWrapper.status !== 0) {
143+
if (upgradeGradleWrapperExitCode !== 0) {
124144
console.log(`Error upgrading gradle wrapper (StatusCode=${upgradeGradleWrapper.status}).`.bgRed)
125145
console.log(upgradeGradleWrapper.stderr.toString().red)
126146
return
@@ -250,11 +270,10 @@ function findUpgradeJsonReportFiles() {
250270
return upgradeReportFiles;
251271
}
252272

253-
function informUserAboutInstallingUpdatePlugin() {
273+
function informUserAboutInstallingUpdatePlugin(exitCode) {
254274
const newestVersion = '0.28.0'
255275

256-
console.log(`Error executing gradle dependency updates (StatusCode=${gradleDependencyUpdateProcess.status})`.bgRed);
257-
console.log(gradleDependencyUpdateProcess.stderr.toString().red);
276+
console.log(`Error executing gradle dependency updates (StatusCode=${exitCode})`.bgRed);
258277
console.log(`\nIn case you haven't installed the gradle-versions-plugin (https://github.com/ben-manes/gradle-versions-plugin), put one of the following in your gradle build file:\n`);
259278
console.log(`Either Plugins block`);
260279
console.log(`
@@ -275,5 +294,4 @@ function informUserAboutInstallingUpdatePlugin() {
275294
276295
apply plugin: "com.github.ben-manes.versions"
277296
`.green);
278-
}
279-
297+
}

0 commit comments

Comments
 (0)