Skip to content

Commit efb3142

Browse files
committed
Debug logging (defaults to false)
1 parent 241bbc6 commit efb3142

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Options:
4747
milestone or a release (default)
4848
* integration: selects the latest revision of the dependency
4949
module (such as SNAPSHOT) [string]
50+
--debug, -d Prints debugging information, such as commands executed and
51+
current status. [boolean] [Standard: false]
5052
--no-color Disables color output
5153
```
5254

index.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ var argv = require('yargs')
99
nargs: 1,
1010
demand: false
1111
})
12+
.option('debug', {
13+
alias: 'd',
14+
describe: 'Prints debugging information, such as commands executed and current status.',
15+
type: 'boolean',
16+
demand: false,
17+
default: false
18+
})
1219
.option('no-color', {
13-
describe: 'Disables color output'
20+
describe: 'Disables color output',
21+
nargs: 1,
22+
demand: false
1423
})
1524
.argv
1625

@@ -51,12 +60,16 @@ if (!gradleCommand) {
5160

5261
console.log('Checking for upgrades...\n')
5362

63+
const debug = argv.debug
64+
5465
const gduArgs = ['dependencyUpdates', '-DoutputFormatter=json', '-DoutputDir=build/dependencyUpdates']
5566
const gduResolution = argv.resolution
5667
if (gduResolution) {
5768
gduArgs.push(`-Drevision=${gduResolution}`)
5869
}
5970

71+
debugLog(`Executing command\n${gradleCommand} ${gduArgs.join(' ')}\n`)
72+
6073
const gdu = spawnSync(gradleCommand, gduArgs);
6174

6275
if (gdu.status !== 0) {
@@ -65,7 +78,7 @@ if (gdu.status !== 0) {
6578
console.log(gdu.stderr.toString().red)
6679

6780
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`)
68-
81+
6982
console.log(`Either Plugins block`)
7083
console.log(`
7184
plugins {
@@ -89,17 +102,28 @@ if (gdu.status !== 0) {
89102
return
90103
}
91104

105+
function debugLog (message) {
106+
if (debug) {
107+
console.log(message.blue)
108+
}
109+
}
110+
92111
(async () => {
93112

113+
debugLog(`Reading JSON report file\n`)
114+
94115
const upgradeReport = fs.readFileSync('build/dependencyUpdates/report.json');
95116
let dependencyUpdates = JSON.parse(upgradeReport);
96117
let outdatedDependencies = dependencyUpdates.outdated.dependencies
118+
debugLog(`Outdated dependencies parsed\n${JSON.stringify(outdatedDependencies)}\n\n`)
97119

98120
let choices = outdatedDependencies.map(it => {
99121
const newVersion = it.available.release || it.available.milestone || it.available.integration
100122
return { description: `Group ${it.group}`, title: `${it.name} - ${it.version} => ${newVersion}`, value: { group: it.group, name: it.name, oldVersion: it.version, version: newVersion } }
101123
})
102124

125+
debugLog(`Choices\n${JSON.stringify(choices)}\n\n`)
126+
103127
let currentGradleRelease = dependencyUpdates.gradle.running.version
104128
let latestGradleRelease = dependencyUpdates.gradle.current.version
105129

@@ -131,7 +155,9 @@ if (gdu.status !== 0) {
131155

132156
if (response.upgrades.some(it => it === 'gradle')) {
133157
console.log('Upgrading gradle wrapper')
134-
const upgradeGradleWrapper = spawnSync(gradleCommand, ['wrapper', '--gradle-version=' + latestGradleRelease]);
158+
const upgradeArgs = ['wrapper', '--gradle-version=' + latestGradleRelease]
159+
debugLog(`Executing command\n${gradleCommand}${upgradeArgs.join(' ')}\n`)
160+
const upgradeGradleWrapper = spawnSync(gradleCommand, upgradeArgs);
135161

136162
if (upgradeGradleWrapper.status !== 0) {
137163
console.log(`Error upgrading gradle wrapper (StatusCode=${upgradeGradleWrapper.status}).`.bgRed)
@@ -140,18 +166,22 @@ if (gdu.status !== 0) {
140166
}
141167
}
142168

169+
debugLog('Reading Gradle build file\n')
170+
143171
fs.readFile('build.gradle', function (err, buf) {
144172
let buildFileAsString = buf.toString()
145173

146174
response.upgrades.filter(it => it !== 'gradle').forEach(it => {
175+
debugLog(`Replacing version\n${JSON.stringify(it)}\n`)
147176
buildFileAsString = ReplaceVersion.replace(buildFileAsString, it)
148177
})
149178

179+
debugLog('Writing Gradle build file\n')
150180
fs.writeFile('build.gradle', buildFileAsString, 'utf8', function (err) {
151181
if (err) return console.log(`Unable to write gradle build file.\n${err}`.bgRed);
152182
});
153183

154184
});
155185

156186

157-
})();
187+
})();

0 commit comments

Comments
 (0)