Repository navigation
Coldbox Watch-Reinit Doesn't Recognize Webroot Setting in server.json #76
Copy link
Copy link
Closed
Description
Activity
Possible solution? Note that I added
getDefaultServerName()which also exists in thefwreinitcommand. Might want to pull that out as a UDF or base class method to avoid duplicated code.// commands/coldbox/watch-reinit.cfc function run( string paths, number delay, string password = "1", string directory, name = getDefaultServerName( getCWD() ) <-- new argument ){ // Get watch options from package descriptor var boxOptions = packageService.readPackageDescriptor( getCWD() ); var initPassword = arguments.password; var getOptionsWatchers = function(){ // Return to List if ( boxOptions.keyExists( "reinitWatchPaths" ) && boxOptions.reinitWatchPaths.len() ) { return ( isArray( boxOptions.reinitWatchPaths ) ? boxOptions.reinitWatchPaths.toList() : boxOptions.reinitWatchPaths ); } // should return null if not found return; } // Determine watching patterns, either from arguments or boxoptions or defaults var globbingPaths = arguments.paths ?: getOptionsWatchers() ?: variables.PATHS; 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" } // New: Use the new way to resolve server details var serverDetails = serverService.resolveServerDetails( { name : arguments.name, directory : getCWD() } ); var serverStatus = serverService.isServerRunning( serverDetails.serverInfo ); // Tabula rasa command( "cls" ).run(); // Check if the server is up, prompt if not to start it if ( !serverStatus ) { print .redBoldText( "Server Status: Stopped" ) .line() .toConsole(); var startServer = confirm( "Would you like to start it [y/n]?" ); if ( startServer ) { command( "start" ).run(); } else { return; } } // General Message about the globbing paths and its purpose print .greenLine( "---------------------------------------------------" ) .greenLine( "Watching the following files for a framework reinit" ) .greenLine( "---------------------------------------------------" ) .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( globArray ) .inDirectory( theDirectory ) .withDelay( delayMs ) .onChange( function( changeData ){ // output file changes var changetime = "[" & timeFormat( now(), "HH:mm:ss" ) & "] "; for ( status in changeData ) { changeData[ status ].map( function( filePath ){ print .text( changetime, statusColors[ status ] ) .text( filePath, statusColors[ status ] & "Bold" ) .text( " " & status & " ", statusColors[ status ] ) .toConsole(); } ) } // reinit the framework command( "coldbox reinit password=""#initPassword#"" showUrl=""false""" ).run(); } ) .start(); } /** * Tries to find the default server name from the server.json file in the current directory * note: This method is duplicated in fwreinit command... might want to pull out as shared UDF. * @directory The directory to look for the server.json file, defaults to the current working directory * * @return The server name if found, otherwise an empty string */ private function getDefaultServerName( directory = getCwd() ){ var serverInfo = serverService.getServerInfoByDiscovery( serverConfigFile = "server.json" ) return serverInfo.keyExists( "name" ) ? serverInfo.name : "" }- linked a pull request that will close this issueHonor server.json webroot server discovery in `coldbox watch-reinit` #77
on May 28, 2026
Similar to: #9
What are the steps to reproduce this issue?
coldbox watch-reinitin CommandboxWhat happens?
Console will display:
What were you expecting to happen?
The Coldbox-CLI should identify that the server is running in the webroot and watch the specified folder for changes.
Any other comments?
Discovered this when building a Coldbox module where the webroot lives in "test-harness", but I want to monitor the project root (the module's code) for changes so I can reinit the test-harness.