evagoras
05/30/2023, 3:26 PMserver.json
one can have a definition for lifecycle events, like
"scripts":{
"onServerInstall":"cfpm install mail"
}
How do I add more than one under the onServerInstall
? For example I need to run the above and also a custom registered module as a task runner mysites copyConfig app=myapp
.bdw429s
05/30/2023, 6:27 PM"scripts":{
"onServerInstall" : "command; another-commmand; as; many; as; you; like"
}
bdw429s
05/30/2023, 6:28 PMbdw429s
05/30/2023, 6:28 PM;
, &&
, and ||
) apply hereevagoras
05/30/2023, 6:29 PMbdw429s
05/30/2023, 6:30 PMbdw429s
05/30/2023, 6:30 PMbdw429s
05/30/2023, 6:31 PMevagoras
05/30/2023, 6:32 PMbdw429s
05/30/2023, 6:32 PM"scripts":{
"onServerInstall" : [
"command",
"another-commmand",
"as",
"many",
"as",
"you",
"like"
]
}
bdw429s
05/30/2023, 6:32 PMbdw429s
05/30/2023, 6:32 PMbdw429s
05/30/2023, 6:32 PMevagoras
05/30/2023, 6:33 PMbdw429s
05/30/2023, 6:33 PMbdw429s
05/30/2023, 6:33 PMevagoras
05/30/2023, 6:34 PMbdw429s
05/30/2023, 6:35 PMbdw429s
05/30/2023, 6:35 PMbdw429s
05/30/2023, 6:35 PMreload
command and then the changes will be picked up. It's like the fwreinit=1
for ColdBoxbdw429s
05/30/2023, 6:36 PMbdw429s
05/30/2023, 6:37 PMevagoras
05/30/2023, 6:39 PMbdw429s
05/30/2023, 6:39 PMcfml
folder over to my CommandBox home. That way I can hack on the core and then just commit when I'm doneevagoras
05/31/2023, 6:11 PMbox.json
file. Instead, I needed it in the server.json
.
I created a ticket for it:https://ortussolutions.atlassian.net/browse/COMMANDBOX-1591
I also have the code working locally, but I have been trying to push my branch to github and I keep getting auth failures. It's the first time pushing to the repo so please bear with me!
c:\dev\cf\commandbox>git push --set-upstream origin COMMANDBOX-1591-allow-the-server-scripts-in-server-json-to-use-an-array-for-each-key
remote: Permission to Ortus-Solutions/commandbox.git denied to evagoras.
fatal: unable to access '<https://github.com/Ortus-Solutions/commandbox.git/>': The requested URL returned error: 403
bdw429s
05/31/2023, 6:12 PMevagoras
05/31/2023, 6:12 PMbdw429s
05/31/2023, 6:12 PMbdw429s
05/31/2023, 6:12 PMevagoras
05/31/2023, 6:19 PMbdw429s
05/31/2023, 6:26 PMbox.json
change yesterday when we very first talked about this π
https://cfml.slack.com/archives/C06TSRXCJ/p1685471732684909?thread_ts=1685460406.193339&cid=C06TSRXCJevagoras
05/31/2023, 6:29 PMchainScripts
method fit better as a common util, so I can use it in the PackageService as well?bdw429s
05/31/2023, 6:30 PMbdw429s
05/31/2023, 6:30 PMbdw429s
05/31/2023, 6:31 PM;
is if someone has
"onSomething" : [
"!npm install",
"install"
]
then that becomes
!npm install; install
which will not work as EVERYTHING after the !
will get 'eaten' by the run
command and passed to the native shellbdw429s
05/31/2023, 6:31 PMnpm install; install
to the native shell, which isn't what you wantevagoras
05/31/2023, 6:32 PMbdw429s
05/31/2023, 6:33 PMif( isSimpleValue( thisScript ) ) {
thisScript = [ thisScript ];
}
and then always loopbdw429s
05/31/2023, 6:35 PMbdw429s
05/31/2023, 6:35 PMbdw429s
05/31/2023, 6:36 PMconfig set server.defaults.scripts.onServerStart="echo 'I run for every server ever!'"
bdw429s
05/31/2023, 6:36 PMserver set scripts.onServerStart="echo 'I only run for this server'"
evagoras
05/31/2023, 6:40 PM;
here so I figured I could do the same.
getDefaultServerJSON().scripts.each( (k,v)=>{
// Append existing scripts
if( serverJSONScripts.keyExists( k ) ) {
serverJSONScripts[ k ] &= '; ' & v;
// Merge missing ones
} else {
serverJSONScripts[ k ] = v;
}
} );
I will take another look and try it like you suggest, but not today πbdw429s
05/31/2023, 6:43 PMevagoras
05/31/2023, 6:43 PMbdw429s
05/31/2023, 6:49 PM// get server.json script, defaulting to empty array
var serverJSONScripts = serverJSONScripts[ scriptName ] ?: [];
// get server default script, defaulting to empty array
var serverDefaultScripts = getDefaultServerJSON().scripts[ scriptName ] ?: [];
// force both to be an array, if not already
if( isSimpleValue( serverJSONScripts ) ) {
serverJSONScripts = [ serverJSONScripts ];
}
if( isSimpleValue( serverDefaultScripts ) ) {
serverDefaultScripts = [ serverDefaultScripts ];
}
// Combine both arrays
var totalScripts = serverJSONScripts.append( serverDefaultScripts , true )
// Only set up env vars, if there's something to run
if( totalScripts.len() && systemSettings.getAllEnvironments().len() > 1 ) {
systemSettings.setDeepSystemSettings( interceptData );
}
totalScripts.each( (thisScript)=>{
// Run preXXX package script
runScript( 'pre#scriptName#', arguments.directory, true, interceptData );
consoleLogger.debug( '.' );
consoleLogger.warn( 'Running server script [#arguments.scriptName#].' );
consoleLogger.debug( '> ' & thisScript );
// Normally the shell retains the previous exit code, but in this case
// it's important for us to know if the scripts return a failing exit code without throwing an exception
shell.setExitCode( 0 );
// ... then run the script! (in the context of the package's working directory)
var previousCWD = shell.pwd();
<http://shell.cd|shell.cd>( arguments.directory );
shell.callCommand( thisScript );
<http://shell.cd|shell.cd>( previousCWD );
// If the script ran "exit"
if( !shell.getKeepRunning() ) {
// Just kidding, the shell can stay....
shell.setKeepRunning( true );
}
if( shell.getExitCode() != 0 ) {
throw( message='Server script returned failing exit code (#shell.getExitCode()#)', detail='Failing script: #arguments.scriptName#', type="commandException", errorCode=shell.getExitCode() );
}
// Run postXXX package script
runScript( 'post#scriptName#', arguments.directory, true, interceptData );
} )
if( !arguments.ignoreMissing && !totalScripts.len() ) {
consoleLogger.error( 'The script [#arguments.scriptName#] does not exist in this server.' );
}
bdw429s
05/31/2023, 6:49 PMrun-script foo
then we output an error if the foo
script didn't exist, otherwise we ignore it.bdw429s
05/31/2023, 6:50 PMevagoras
06/01/2023, 2:58 PMbdw429s
06/01/2023, 3:57 PM