Skip to content

Commit ee4379d

Browse files
committed
chore: add debug messages to peek startup arguments
1 parent e32bb1c commit ee4379d

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

src/index.js

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ chalk.level = 3;
210210
Debug > Print args
211211
*/
212212

213-
console.log( process.argv );
213+
Log.debug( '-- DEBUGGING ARGUMENTS --' );
214+
Log.debug( 'Full process.argv:', process.argv );
215+
Log.debug( 'Arguments after executable:', process.argv.slice( 2 ) );
216+
Log.debug( 'NODE_ENV from process.env:', process.env.NODE_ENV );
217+
Log.debug( '------------------------' );
214218

215219
/**
216220
Define > Electron Elements
@@ -232,7 +236,7 @@ let bDevTools = 0;
232236
let bHotkeysEnabled = 0;
233237
let bQuitOnClose = 0;
234238
let bWinHidden = 0;
235-
let appEnvironment = process.env.NODE_ENV || 'production';
239+
let appEnvironment = 'production'; // Will be set after argument parsing
236240
const bStartHidden = 0;
237241

238242
/**
@@ -947,12 +951,6 @@ function ready()
947951
// Initialize main process logging first
948952
initializeMainProcessLogging();
949953

950-
Log.info( `core`, chalk.yellow( `[initiate]` ), chalk.white( `: ` ),
951-
chalk.blueBright( `<msg>` ), chalk.gray( `Starting ${ appName }` ),
952-
chalk.blueBright( `<version>` ), chalk.gray( `${ appVer }` ),
953-
chalk.blueBright( `<electron>` ), chalk.gray( `${ appElectron }` ),
954-
chalk.blueBright( `<env>` ), chalk.gray( `${ appEnvironment }` ) );
955-
956954
/**
957955
new window
958956
*/
@@ -1316,41 +1314,69 @@ function ready()
13161314
--env set runtime environment (production, development, test)
13171315
*/
13181316

1317+
// initialize appEnvironment from NODE_ENV if set; otherwise use production
1318+
appEnvironment = process.env.NODE_ENV || 'production';
1319+
Log.debug( `Before Initialization - NODE_ENV: ${ process.env.NODE_ENV }` );
1320+
Log.debug( `Before Initialization - appEnvironment: ${ appEnvironment }` );
1321+
1322+
Log.debug( '-- Parse Arguments --' );
13191323
for ( let i = 0; i < process.argv.length; i++ )
13201324
{
1325+
Log.debug( `Processing arg[${ i }]: "${ process.argv[ i ] }"` );
1326+
13211327
if ( process.argv[ i ] === '--hidden' )
13221328
{
1329+
Log.debug( 'Setting bWinHidden = 1' );
13231330
bWinHidden = 1;
13241331
}
13251332
else if ( process.argv[ i ] === '--devtools' )
13261333
{
1334+
Log.debug( 'Setting bDevTools = 1' );
13271335
bDevTools = 1;
13281336
activeDevTools();
13291337
}
13301338
else if ( process.argv[ i ] === '--terminate' )
13311339
{
1340+
Log.debug( 'Setting bQuitOnClose = 1' );
13321341
bQuitOnClose = 1;
13331342
}
13341343
else if ( process.argv[ i ] === '--hotkeys' )
13351344
{
1345+
Log.debug( 'Setting bHotkeysEnabled = 1' );
13361346
bHotkeysEnabled = 1;
13371347
}
13381348
else if ( process.argv[ i ] === '--env' && i + 1 < process.argv.length )
13391349
{
13401350
const value = process.argv[ i + 1 ].toLowerCase();
1341-
if ( value === 'production' || value === 'development' || value === 'test' )
1351+
const validEnvironments = [ 'production', 'development', 'test' ];
1352+
1353+
Log.debug( `Found --env with value: "${ value }"` );
1354+
1355+
if ( validEnvironments.includes( value ) )
13421356
{
1357+
Log.debug( `Setting appEnvironment = ${ value }` );
13431358
appEnvironment = value;
1344-
process.env.NODE_ENV = value; // set NODE_ENV for consistency
1345-
i++; // skip the next arg since it is consumed as env value
1359+
process.env.NODE_ENV = value; // set NODE_ENV for consistency
1360+
i++; // skip the next arg since it is consumed as env value
13461361
}
13471362
else
13481363
{
13491364
console.warn( `Unknown environment: ${ value }, defaulting to production.` );
1365+
console.warn( `Valid environments: ${ validEnvironments.join( ', ' ) }` );
13501366
}
13511367
}
13521368
}
13531369

1370+
Log.debug( `Final appEnvironment: ${ appEnvironment }` );
1371+
Log.debug( `Final NODE_ENV: ${ process.env.NODE_ENV }` );
1372+
1373+
// log startup message
1374+
Log.info( `core`, chalk.yellow( `[initiate]` ), chalk.white( `: ` ),
1375+
chalk.blueBright( `<msg>` ), chalk.gray( `Starting ${ appName }` ),
1376+
chalk.blueBright( `<version>` ), chalk.gray( `${ appVer }` ),
1377+
chalk.blueBright( `<electron>` ), chalk.gray( `${ appElectron }` ),
1378+
chalk.blueBright( `<env>` ), chalk.gray( `${ appEnvironment }` ) );
1379+
13541380
/*
13551381
no topics are set; warn the user to set some
13561382
*/

0 commit comments

Comments
 (0)