import * as path from "path" ; import yargs from "yargs" ; yargs . command ( [ "app" , "compile" , "*" ] , "Compile application" , yargs => yargs , argv => build ( "app" ) ) . command ( [ "main" ] , "Compile main process" , yargs => yargs , argv => build ( "main" ) ) . command ( [ "renderer" ] , "Compile renderer process" , yargs => yargs , argv => build ( "renderer" ) ) . command ( [ "dll" ] , "Compile DLL bundles" , yargs => yargs , argv => build ( "renderer.dll" ) ) . command ( [ "dev" ] , "Run a development mode" , yargs => yargs , argv => runInDevMode ( ) ) . argv ; function build ( configFile ) { const args = process . argv ; const sliceIndex = args . length > 2 && ! args [ 2 ] . startsWith ( "-" ) ? 3 : 2 ; const extraWebpackArgs = sliceIndex < args . length ? args . slice ( sliceIndex ) : [ ] ; args . length = 2 ; if ( ! extraWebpackArgs . some ( it => it . includes ( "--env.production" ) ) ) { args . push ( "--env.production" ) ; } args . push ( "--progress" ) ; args . push ( ... extraWebpackArgs ) ; args . push ( "--config" , path . join ( __dirname , ".." , `webpack.${ configFile }.config.js` ) ) ; require ( "yargs" ) ( args . slice ( 2 ) ) ; require ( require . resolve ( "webpack-cli" ) ) ; } function runInDevMode ( ) { require ( "./dev/dev-runner" ) ; }