@@ -18,6 +18,13 @@ const argv = require('yargs')
18
18
nargs : 1 ,
19
19
demand : false
20
20
} )
21
+ . option ( 'external-file' , {
22
+ alias : 'e' ,
23
+ describe : 'Points to a file where dependencies have been declared, e.g. gradle/dependencies.gradle. Option can be used multiple times.' ,
24
+ type : 'array' ,
25
+ nargs : 1 ,
26
+ demand : false
27
+ } )
21
28
. option ( 'debug' , {
22
29
alias : 'd' ,
23
30
describe : 'Prints debugging information, such as commands executed and current status.' ,
@@ -30,13 +37,6 @@ const argv = require('yargs')
30
37
nargs : 1 ,
31
38
demand : false
32
39
} )
33
- . option ( 'external-file' , {
34
- alias : 'e' ,
35
- describe : 'Points to a file where dependencies have been declared, e.g. gradle/dependencies.gradle.' ,
36
- type : 'string' ,
37
- nargs : 1 ,
38
- demand : false
39
- } )
40
40
. argv
41
41
42
42
const prompts = require ( 'prompts' ) ;
@@ -69,30 +69,37 @@ if (!gradleCommand) {
69
69
return
70
70
}
71
71
72
- let buildFile
72
+ const externalFiles = argv [ 'external-file' ]
73
+ const debug = argv . debug
73
74
74
- const externalFile = argv [ 'external-file' ]
75
+ let buildFiles = [ ]
75
76
76
- if ( externalFile ) {
77
- if ( ! fs . existsSync ( externalFile ) ) {
78
- console . log ( 'Unable to find ' + externalFile + ' file.' . bgRed )
79
- return
80
- }
81
- buildFile = externalFile
82
- } else if ( fs . existsSync ( 'build.gradle' ) ) {
83
- buildFile = 'build.gradle'
77
+ if ( externalFiles && externalFiles . length ) {
78
+ externalFiles . forEach ( externalFile => {
79
+ if ( ! fs . existsSync ( externalFile ) ) {
80
+ console . log ( 'Unable to find ' + externalFile + ' file.' . bgRed )
81
+ return
82
+ } else {
83
+ buildFiles . push ( externalFile )
84
+ }
85
+ } )
86
+
87
+ }
88
+
89
+ if ( fs . existsSync ( 'build.gradle' ) ) {
90
+ buildFiles . push ( 'build.gradle' )
84
91
} else if ( fs . existsSync ( 'build.gradle.kts' ) ) {
85
- buildFile = 'build.gradle.kts'
92
+ buildFiles . push ( 'build.gradle.kts' )
86
93
}
87
94
88
- if ( ! buildFile ) {
89
- console . log ( 'Unable to find a build.gradle or build.gradle.kts file.' . bgRed )
95
+ if ( ! buildFiles . length ) {
96
+ console . log ( 'Unable to find build.gradle, build.gradle.kts or external build file.' . bgRed )
90
97
return
91
98
}
92
99
93
- console . log ( 'Checking for upgrades...\n' )
100
+ debugLog ( 'Build files ' + buildFiles )
94
101
95
- const debug = argv . debug
102
+ console . log ( 'Checking for upgrades...\n' )
96
103
97
104
const gduArgs = [ 'dependencyUpdates' , '-DoutputFormatter=json' , '-DoutputDir=build/dependencyUpdates' ]
98
105
const gduResolution = argv . resolution
@@ -234,22 +241,24 @@ function debugLog (message) {
234
241
}
235
242
}
236
243
237
- debugLog ( 'Reading Gradle build file\n' )
244
+ buildFiles . forEach ( buildFile => {
245
+ debugLog ( `Reading Gradle build file ${ buildFile } \n` )
238
246
239
- fs . readFile ( buildFile , function ( err , buf ) {
240
- let buildFileAsString = buf . toString ( )
247
+ fs . readFile ( buildFile , function ( err , buf ) {
248
+ let buildFileAsString = buf . toString ( )
241
249
242
- response . upgrades . filter ( it => it !== 'gradle' ) . forEach ( it => {
243
- debugLog ( `Replacing version\n${ JSON . stringify ( it ) } \n` )
244
- buildFileAsString = ReplaceVersion . replace ( buildFileAsString , it )
245
- } )
250
+ response . upgrades . filter ( it => it !== 'gradle' ) . forEach ( it => {
251
+ debugLog ( `Replacing version\n${ JSON . stringify ( it ) } \n` )
252
+ buildFileAsString = ReplaceVersion . replace ( buildFileAsString , it )
253
+ } )
246
254
247
- debugLog ( ' Writing Gradle build file\n' )
248
- fs . writeFile ( buildFile , buildFileAsString , 'utf8' , function ( err ) {
249
- if ( err ) return console . log ( `Unable to write gradle build file.\n${ err } ` . bgRed ) ;
250
- } ) ;
255
+ debugLog ( ` Writing Gradle build file ${ buildFile } \n` )
256
+ fs . writeFile ( buildFile , buildFileAsString , 'utf8' , function ( err ) {
257
+ if ( err ) return console . log ( `Unable to write gradle build file.\n${ err } ` . bgRed ) ;
258
+ } ) ;
251
259
252
- } ) ;
260
+ } ) ;
261
+ } )
253
262
254
263
255
264
} ) ( ) ;
0 commit comments