1- import path from 'node:path' ;
2-
31import { api , StartOptions } from '@electron-forge/core' ;
42import { ElectronProcess } from '@electron-forge/shared-types' ;
5- import program from 'commander' ;
6- import fs from 'fs-extra' ;
3+ import { program } from 'commander' ;
74
85import './util/terminate' ;
6+ import packageJSON from '../package.json' ;
7+
98import workingDir from './util/working-dir' ;
109
1110( async ( ) => {
@@ -20,43 +19,46 @@ import workingDir from './util/working-dir';
2019
2120 let dir = process . cwd ( ) ;
2221 program
23- . version ( ( await fs . readJson ( path . resolve ( __dirname , '../package.json' ) ) ) . version , '-V, --version' , 'Output the current version' )
22+ . version ( packageJSON . version , '-V, --version' , 'Output the current version' )
2423 . arguments ( '[cwd]' )
2524 . option ( '-p, --app-path <path>' , "Override the path to the Electron app to launch (defaults to '.')" )
2625 . option ( '-l, --enable-logging' , 'Enable advanced logging. This will log internal Electron things' )
2726 . option ( '-n, --run-as-node' , 'Run the Electron app as a Node.JS script' )
2827 . option ( '--vscode' , 'Used to enable arg transformation for debugging Electron through VSCode. Do not use yourself.' )
2928 . option ( '-i, --inspect-electron' , 'Triggers inspect mode on Electron to allow debugging the main process. Electron >1.7 only' )
3029 . option ( '--inspect-brk-electron' , 'Triggers inspect-brk mode on Electron to allow debugging the main process. Electron >1.7 only' )
31- . helpOption ( '-h, --help' , 'Output usage information' )
30+ . addHelpText (
31+ 'after' ,
32+ `
33+ Any arguments found after "--" will be passed to the Electron app. For example...
34+
35+ $ npx electron-forge start /path/to/project --enable-logging -- -d -f foo.txt
36+
37+ ...will pass the arguments "-d -f foo.txt" to the Electron app.`
38+ )
39+ . passThroughOptions ( true ) // allows args to be passed down to the Electron executable
3240 . action ( ( cwd ) => {
3341 dir = workingDir ( dir , cwd ) ;
3442 } )
3543 . parse ( commandArgs ) ;
3644
37- program . on ( '--help' , ( ) => {
38- console . log ( ' Any arguments found after "--" will be passed to the Electron app, e.g.' ) ;
39- console . log ( '' ) ;
40- console . log ( ' $ electron-forge /path/to/project -l -- -d -f foo.txt' ) ;
41- console . log ( '' ) ;
42- console . log ( ' will pass the arguments "-d -f foo.txt" to the Electron app' ) ;
43- } ) ;
45+ const options = program . opts ( ) ;
4446
4547 const opts : StartOptions = {
4648 dir,
4749 interactive : true ,
48- enableLogging : ! ! program . enableLogging ,
49- runAsNode : ! ! program . runAsNode ,
50- inspect : ! ! program . inspectElectron ,
51- inspectBrk : ! ! program . inspectBrkElectron ,
50+ enableLogging : ! ! options . enableLogging ,
51+ runAsNode : ! ! options . runAsNode ,
52+ inspect : ! ! options . inspectElectron ,
53+ inspectBrk : ! ! options . inspectBrkElectron ,
5254 } ;
5355
54- if ( program . vscode && appArgs ) {
56+ if ( options . vscode && appArgs ) {
5557 // Args are in the format ~arg~ so we need to strip the "~"
5658 appArgs = appArgs . map ( ( arg ) => arg . substr ( 1 , arg . length - 2 ) ) . filter ( ( arg ) => arg . length > 0 ) ;
5759 }
5860
59- if ( program . appPath ) opts . appPath = program . appPath ;
61+ if ( options . appPath ) opts . appPath = options . appPath ;
6062 if ( appArgs ) opts . args = appArgs ;
6163
6264 const spawned = await api . start ( opts ) ;
0 commit comments