@@ -45,15 +45,15 @@ const {
4545
4646if ( ! gradleCommand ) {
4747 console . log ( 'Unable to find Gradle Wrapper or Gradle CLI.' . bgRed )
48- return
48+ process . exit ( )
4949}
5050
5151const externalFiles = argv [ 'external-file' ] ;
52- const buildFiles = getBuildFiles ( externalFiles )
53- debugLog ( ' Build Files:\n' + buildFiles . join ( '\n' ) )
52+ const buildFiles = getBuildFiles ( externalFiles , debugLog )
53+ debugLog ( ` Build Files:\n ${ buildFiles . join ( '\n' ) } ` )
5454if ( ! buildFiles . length ) {
5555 console . log ( 'Unable to find build.gradle, build.gradle.kts or external build file.' . bgRed )
56- return
56+ process . exit ( )
5757}
5858
5959exports . debugLog = debugLog ;
@@ -76,6 +76,10 @@ async function executeCommandAndWaitForExitCode(command, args) {
7676 commandExitCode = code
7777 } )
7878
79+ child . on ( 'exit' , ( code ) => {
80+ commandExitCode = code
81+ } )
82+
7983 while ( commandExitCode === undefined ) {
8084 debugLog ( 'Waiting for command to finish' )
8185 await new Promise ( resolve => setTimeout ( resolve , 500 ) ) ;
@@ -99,16 +103,14 @@ async function executeCommandAndWaitForExitCode(command, args) {
99103
100104 if ( gradleDependencyUpdateProcessExitCode !== 0 ) {
101105 informUserAboutInstallingUpdatePlugin ( gradleDependencyUpdateProcessExitCode ) ;
102- return
106+ process . exit ( )
103107 }
104108
105109 if ( ! buildFiles . length ) {
106110 console . log ( 'Unable to find build.gradle, build.gradle.kts or external build file.' . bgRed ) ;
107- return ;
111+ process . exit ( )
108112 }
109113
110- debugLog ( 'Build files ' + buildFiles ) ;
111-
112114 debugLog ( `Reading JSON report file\n` )
113115
114116 const dependencyUpdates = findOutdatedDependencies ( ) ;
@@ -123,7 +125,7 @@ async function executeCommandAndWaitForExitCode(command, args) {
123125
124126 if ( ! choices . length ) {
125127 console . log ( 'Everything up to date.' )
126- return
128+ process . exit ( )
127129 }
128130
129131 const response = await prompts ( {
@@ -134,11 +136,11 @@ async function executeCommandAndWaitForExitCode(command, args) {
134136 } ) ;
135137
136138 if ( ! response . upgrades || ! response . upgrades . length ) {
137- console . log ( 'No upgrades select ' )
138- return
139+ console . log ( 'No upgrades selected ' )
140+ process . exit ( )
139141 }
140142
141- if ( response . upgrades . some ( it => it === 'gradle' ) ) {
143+ if ( latestGradleRelease && response . upgrades . some ( it => it === 'gradle' ) ) {
142144 console . log ( 'Upgrading gradle wrapper' )
143145 const upgradeArgs = [ 'wrapper' , '--gradle-version=' + latestGradleRelease ]
144146
@@ -148,7 +150,7 @@ async function executeCommandAndWaitForExitCode(command, args) {
148150 if ( upgradeGradleWrapperExitCode !== 0 ) {
149151 console . log ( `Error upgrading gradle wrapper (StatusCode=${ upgradeGradleWrapper . status } ).` . bgRed )
150152 console . log ( upgradeGradleWrapper . stderr . toString ( ) . red )
151- return
153+ process . exit ( )
152154 }
153155 }
154156
@@ -192,7 +194,7 @@ async function executeCommandAndWaitForExitCode(command, args) {
192194 writeFileSync ( buildFile , modifiedContent , 'utf8' ) ;
193195 } catch ( err ) {
194196 console . log ( `Unable to write gradle build file.\n${ err } ` . bgRed ) ;
195- return
197+ process . exit ( )
196198 }
197199
198200 } , buildFileContentMap )
@@ -238,9 +240,10 @@ function buildUpgradeChoicesForUser(outdatedDependencies, dependencyUpdates) {
238240 choices . sort ( ( a , b ) => a . title . localeCompare ( b . title ) ) ;
239241 debugLog ( `Choices\n${ JSON . stringify ( choices ) } \n\n` ) ;
240242
243+ let latestGradleRelease
241244 if ( dependencyUpdates . gradle ) {
242245 let currentGradleRelease = dependencyUpdates . gradle . running . version ;
243- let latestGradleRelease = dependencyUpdates . gradle . current . version ;
246+ latestGradleRelease = dependencyUpdates . gradle . current . version ;
244247 if ( gradleWrapper && currentGradleRelease !== latestGradleRelease ) {
245248 choices . unshift ( {
246249 title : `Gradle - ${ currentGradleRelease } => ${ latestGradleRelease } ` ,
0 commit comments