@@ -18,6 +18,13 @@ const argv = require('yargs')
1818 nargs : 1 ,
1919 demand : false
2020 } )
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+ } )
2128 . option ( 'debug' , {
2229 alias : 'd' ,
2330 describe : 'Prints debugging information, such as commands executed and current status.' ,
@@ -30,13 +37,6 @@ const argv = require('yargs')
3037 nargs : 1 ,
3138 demand : false
3239 } )
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- } )
4040 . argv
4141
4242const prompts = require ( 'prompts' ) ;
@@ -69,30 +69,37 @@ if (!gradleCommand) {
6969 return
7070}
7171
72- let buildFile
72+ const externalFiles = argv [ 'external-file' ]
73+ const debug = argv . debug
7374
74- const externalFile = argv [ 'external-file' ]
75+ let buildFiles = [ ]
7576
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' )
8491} else if ( fs . existsSync ( 'build.gradle.kts' ) ) {
85- buildFile = 'build.gradle.kts'
92+ buildFiles . push ( 'build.gradle.kts' )
8693}
8794
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 )
9097 return
9198}
9299
93- console . log ( 'Checking for upgrades...\n' )
100+ debugLog ( 'Build files ' + buildFiles )
94101
95- const debug = argv . debug
102+ console . log ( 'Checking for upgrades...\n' )
96103
97104const gduArgs = [ 'dependencyUpdates' , '-DoutputFormatter=json' , '-DoutputDir=build/dependencyUpdates' ]
98105const gduResolution = argv . resolution
@@ -234,22 +241,24 @@ function debugLog (message) {
234241 }
235242 }
236243
237- debugLog ( 'Reading Gradle build file\n' )
244+ buildFiles . forEach ( buildFile => {
245+ debugLog ( `Reading Gradle build file ${ buildFile } \n` )
238246
239- fs . readFile ( buildFile , function ( err , buf ) {
240- let buildFileAsString = buf . toString ( )
247+ fs . readFile ( buildFile , function ( err , buf ) {
248+ let buildFileAsString = buf . toString ( )
241249
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+ } )
246254
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+ } ) ;
251259
252- } ) ;
260+ } ) ;
261+ } )
253262
254263
255264} ) ( ) ;
0 commit comments