@@ -9,8 +9,17 @@ var argv = require('yargs')
9
9
nargs : 1 ,
10
10
demand : false
11
11
} )
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
+ } )
12
19
. option ( 'no-color' , {
13
- describe : 'Disables color output'
20
+ describe : 'Disables color output' ,
21
+ nargs : 1 ,
22
+ demand : false
14
23
} )
15
24
. argv
16
25
@@ -51,12 +60,16 @@ if (!gradleCommand) {
51
60
52
61
console . log ( 'Checking for upgrades...\n' )
53
62
63
+ const debug = argv . debug
64
+
54
65
const gduArgs = [ 'dependencyUpdates' , '-DoutputFormatter=json' , '-DoutputDir=build/dependencyUpdates' ]
55
66
const gduResolution = argv . resolution
56
67
if ( gduResolution ) {
57
68
gduArgs . push ( `-Drevision=${ gduResolution } ` )
58
69
}
59
70
71
+ debugLog ( `Executing command\n${ gradleCommand } ${ gduArgs . join ( ' ' ) } \n` )
72
+
60
73
const gdu = spawnSync ( gradleCommand , gduArgs ) ;
61
74
62
75
if ( gdu . status !== 0 ) {
@@ -65,7 +78,7 @@ if (gdu.status !== 0) {
65
78
console . log ( gdu . stderr . toString ( ) . red )
66
79
67
80
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
+
69
82
console . log ( `Either Plugins block` )
70
83
console . log ( `
71
84
plugins {
@@ -89,17 +102,28 @@ if (gdu.status !== 0) {
89
102
return
90
103
}
91
104
105
+ function debugLog ( message ) {
106
+ if ( debug ) {
107
+ console . log ( message . blue )
108
+ }
109
+ }
110
+
92
111
( async ( ) => {
93
112
113
+ debugLog ( `Reading JSON report file\n` )
114
+
94
115
const upgradeReport = fs . readFileSync ( 'build/dependencyUpdates/report.json' ) ;
95
116
let dependencyUpdates = JSON . parse ( upgradeReport ) ;
96
117
let outdatedDependencies = dependencyUpdates . outdated . dependencies
118
+ debugLog ( `Outdated dependencies parsed\n${ JSON . stringify ( outdatedDependencies ) } \n\n` )
97
119
98
120
let choices = outdatedDependencies . map ( it => {
99
121
const newVersion = it . available . release || it . available . milestone || it . available . integration
100
122
return { description : `Group ${ it . group } ` , title : `${ it . name } - ${ it . version } => ${ newVersion } ` , value : { group : it . group , name : it . name , oldVersion : it . version , version : newVersion } }
101
123
} )
102
124
125
+ debugLog ( `Choices\n${ JSON . stringify ( choices ) } \n\n` )
126
+
103
127
let currentGradleRelease = dependencyUpdates . gradle . running . version
104
128
let latestGradleRelease = dependencyUpdates . gradle . current . version
105
129
@@ -131,7 +155,9 @@ if (gdu.status !== 0) {
131
155
132
156
if ( response . upgrades . some ( it => it === 'gradle' ) ) {
133
157
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 ) ;
135
161
136
162
if ( upgradeGradleWrapper . status !== 0 ) {
137
163
console . log ( `Error upgrading gradle wrapper (StatusCode=${ upgradeGradleWrapper . status } ).` . bgRed )
@@ -140,18 +166,22 @@ if (gdu.status !== 0) {
140
166
}
141
167
}
142
168
169
+ debugLog ( 'Reading Gradle build file\n' )
170
+
143
171
fs . readFile ( 'build.gradle' , function ( err , buf ) {
144
172
let buildFileAsString = buf . toString ( )
145
173
146
174
response . upgrades . filter ( it => it !== 'gradle' ) . forEach ( it => {
175
+ debugLog ( `Replacing version\n${ JSON . stringify ( it ) } \n` )
147
176
buildFileAsString = ReplaceVersion . replace ( buildFileAsString , it )
148
177
} )
149
178
179
+ debugLog ( 'Writing Gradle build file\n' )
150
180
fs . writeFile ( 'build.gradle' , buildFileAsString , 'utf8' , function ( err ) {
151
181
if ( err ) return console . log ( `Unable to write gradle build file.\n${ err } ` . bgRed ) ;
152
182
} ) ;
153
183
154
184
} ) ;
155
185
156
186
157
- } ) ( ) ;
187
+ } ) ( ) ;
0 commit comments