diff --git a/commands/coldbox/watch-reinit.cfc b/commands/coldbox/watch-reinit.cfc index 2e225cb..c8abf1a 100644 --- a/commands/coldbox/watch-reinit.cfc +++ b/commands/coldbox/watch-reinit.cfc @@ -17,7 +17,8 @@ * * {code} * package set reinitWatchDelay=1000 - * package set reinitWatchPaths= "config/**.cfc,handlers/**.cfc,models/**.cfc,ModuleConfig.cfc" + * package set reinitWatchPaths="config/**.cfc,handlers/**.cfc,models/**.cfc,ModuleConfig.cfc" + * package set reinitWatchDirectory="../" * {code} * * This command will run in the foreground until you stop it. When you are ready to shut down the watcher, press Ctrl+C. @@ -33,14 +34,16 @@ component { variables.PATHS = "/config/**.cfc,/handlers/**.cfc,/models/**.cfc,/modules_app/**/*.cfc"; /** - * @paths Command delimited list of file globbing paths to watch relative to the working directory, defaults to **.cfc - * @delay How may milliseconds to wait before polling for changes, defaults to 500 ms + * @paths Command delimited list of file globbing paths to watch relative to the working directory, defaults to **.cfc + * @delay How may milliseconds to wait before polling for changes, defaults to 500 ms * @password Reinit password + * @directory Working directory to start watcher in **/ function run( string paths, number delay, - string password = "1" + string password = "1", + string directory ){ // Get watch options from package descriptor var boxOptions = packageService.readPackageDescriptor( getCWD() ); @@ -59,12 +62,13 @@ component { // Determine watching patterns, either from arguments or boxoptions or defaults var globbingPaths = arguments.paths ?: getOptionsWatchers() ?: variables.PATHS; - // handle non numeric config and put a floor of 150ms - var delayMs = max( - val( arguments.delay ?: boxOptions.reinitWatchDelay ?: variables.WATCH_DELAY ), - 150 - ); - var statusColors = { + var globArray = globbingPaths.listToArray(); + var theDirectory = arguments.directory ?: boxOptions.reinitWatchDirectory ?: getCWD(); + theDirectory = resolvePath( theDirectory ); + + // handle non numeric config + var delayMs = max( val( arguments.delay ?: boxOptions.reinitWatchDelay ?: variables.WATCH_DELAY ), variables.WATCH_DELAY ); + var statusColors = { "added" : "green", "removed" : "red", "changed" : "yellow" @@ -95,15 +99,19 @@ component { .greenLine( "---------------------------------------------------" ) .greenLine( "Watching the following files for a framework reinit" ) .greenLine( "---------------------------------------------------" ) - .greenLine( " " & globbingPaths ) + .line(); + globArray.each( (p) => print.greenLine( " " & p ) ); + print + .line() + .greenLine( " in directory: #theDirectory#" ) .greenLine( " Press Ctrl-C to exit " ) .greenLine( "---------------------------------------------------" ) .toConsole(); // Start watcher watch() - .paths( globbingPaths.listToArray() ) - .inDirectory( getCWD() ) + .paths( globArray ) + .inDirectory( theDirectory ) .withDelay( delayMs ) .onChange( function( changeData ){ // output file changes @@ -112,14 +120,8 @@ component { changeData[ status ].map( function( filePath ){ print .text( changetime, statusColors[ status ] ) - .text( - filePath, - statusColors[ status ] & "Bold" - ) - .text( - " " & status & " ", - statusColors[ status ] - ) + .text( filePath, statusColors[ status ] & "Bold" ) + .text( " " & status & " ", statusColors[ status ] ) .toConsole(); } ) }