11using System ;
22using System . Collections . Generic ;
33using System . IO ;
4+ using System . Linq ;
45using System . Runtime . InteropServices ;
56using System . Threading . Tasks ;
67using ElectronNET . CLI . Commands . Actions ;
@@ -21,20 +22,36 @@ public BuildCommand(string[] args)
2122 _args = args ;
2223 }
2324
25+ private string _paramTarget = "target" ;
26+ private string _paramDotNetConfig = "dotnet-configuration" ;
27+ private string _paramElectronArch = "electron-arch" ;
28+ private string _paramElectronParams = "electron-params" ;
29+
2430 public Task < bool > ExecuteAsync ( )
2531 {
2632 return Task . Run ( ( ) =>
2733 {
2834 Console . WriteLine ( "Build Electron Application..." ) ;
2935
30- string desiredPlatform = "" ;
36+ SimpleCommandLineParser parser = new SimpleCommandLineParser ( ) ;
37+ parser . Parse ( _args ) ;
3138
32- if ( _args . Length > 0 )
39+ var desiredPlatform = parser . Arguments [ _paramTarget ] [ 0 ] ;
40+ string specifiedFromCustom = string . Empty ;
41+ if ( desiredPlatform == "custom" && parser . Arguments [ _paramTarget ] . Length > 1 )
3342 {
34- desiredPlatform = _args [ 0 ] ;
43+ specifiedFromCustom = parser . Arguments [ "target" ] [ 1 ] ;
3544 }
3645
37- var platformInfo = GetTargetPlatformInformation . Do ( desiredPlatform ) ;
46+ string configuration = "Release" ;
47+ if ( parser . Arguments . ContainsKey ( _paramDotNetConfig ) )
48+ {
49+ configuration = parser . Arguments [ _paramDotNetConfig ] [ 0 ] ;
50+ }
51+
52+ var platformInfo = GetTargetPlatformInformation . Do ( desiredPlatform , specifiedFromCustom ) ;
53+
54+ Console . WriteLine ( $ "Build ASP.NET Core App for { platformInfo . NetCorePublishRid } ...") ;
3855
3956
4057 string tempPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "obj" , "desktop" , desiredPlatform ) ;
@@ -47,9 +64,9 @@ public Task<bool> ExecuteAsync()
4764
4865 string tempBinPath = Path . Combine ( tempPath , "bin" ) ;
4966
50- Console . WriteLine ( $ "Build ASP.NET Core App for { platformInfo . NetCorePublishRid } ...") ;
67+ Console . WriteLine ( $ "Build ASP.NET Core App for { platformInfo . NetCorePublishRid } under { configuration } -Configuration ...") ;
5168
52- var resultCode = ProcessHelper . CmdExecute ( $ "dotnet publish -r { platformInfo . NetCorePublishRid } --output \" { tempBinPath } \" ", Directory . GetCurrentDirectory ( ) ) ;
69+ var resultCode = ProcessHelper . CmdExecute ( $ "dotnet publish -r { platformInfo . NetCorePublishRid } -c { configuration } - -output \" { tempBinPath } \" ", Directory . GetCurrentDirectory ( ) ) ;
5370
5471 if ( resultCode != 0 )
5572 {
@@ -93,8 +110,21 @@ public Task<bool> ExecuteAsync()
93110 Console . WriteLine ( "Executing electron magic in this directory: " + buildPath ) ;
94111
95112 // ToDo: Need a solution for --asar support
113+
114+ string electronArch = "x64" ;
115+ if ( parser . Arguments . ContainsKey ( _paramElectronArch ) )
116+ {
117+ electronArch = parser . Arguments [ _paramElectronArch ] [ 0 ] ;
118+ }
119+
120+ string electronParams = "" ;
121+ if ( parser . Arguments . ContainsKey ( _paramElectronParams ) )
122+ {
123+ electronParams = parser . Arguments [ _paramElectronParams ] [ 0 ] ;
124+ }
125+
96126 Console . WriteLine ( $ "Package Electron App for Platform { platformInfo . ElectronPackerPlatform } ...") ;
97- ProcessHelper . CmdExecute ( $ "electron-packager . --platform={ platformInfo . ElectronPackerPlatform } --arch=x64 --out=\" { buildPath } \" --overwrite", tempPath ) ;
127+ ProcessHelper . CmdExecute ( $ "electron-packager . --platform={ platformInfo . ElectronPackerPlatform } --arch={ electronArch } { electronParams } --out=\" { buildPath } \" --overwrite", tempPath ) ;
98128
99129 Console . WriteLine ( "... done" ) ;
100130
0 commit comments