Skip to content

Commit

Permalink
Merge pull request #8 from homestar9/patch-1
Browse files Browse the repository at this point in the history
Applied Changes from CommandBox-1547 ticket
  • Loading branch information
lmajano authored Sep 14, 2024
2 parents f113d26 + 48ff709 commit 26cdb57
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions commands/coldbox/watch-reinit.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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() );
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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();
} )
}
Expand Down

0 comments on commit 26cdb57

Please sign in to comment.