@@ -51,15 +51,18 @@ public Task<bool> ExecuteAsync()
5151 {
5252 return Task . Run ( ( ) =>
5353 {
54- Console . WriteLine ( "Build Electron Application..." ) ;
54+ var parser = new SimpleCommandLineParser ( ) ;
5555
56- SimpleCommandLineParser parser = new SimpleCommandLineParser ( ) ;
56+ Console . WriteLine ( "Build Electron Application..." ) ;
5757 parser . Parse ( _args ) ;
5858
5959 //This version will be shared between the dotnet publish and electron-builder commands
60- string version = null ;
60+ var version = string . Empty ;
61+
6162 if ( parser . Arguments . ContainsKey ( _paramVersion ) )
63+ {
6264 version = parser . Arguments [ _paramVersion ] [ 0 ] ;
65+ }
6366
6467 if ( ! parser . Arguments . ContainsKey ( _paramTarget ) )
6568 {
@@ -69,23 +72,24 @@ public Task<bool> ExecuteAsync()
6972 }
7073
7174 var desiredPlatform = parser . Arguments [ _paramTarget ] [ 0 ] ;
72- string specifiedFromCustom = string . Empty ;
75+ var specifiedFromCustom = string . Empty ;
76+
7377 if ( desiredPlatform == "custom" && parser . Arguments [ _paramTarget ] . Length > 1 )
7478 {
7579 specifiedFromCustom = parser . Arguments [ _paramTarget ] [ 1 ] ;
7680 }
7781
78- string configuration = "Release" ;
82+ var configuration = "Release" ;
83+
7984 if ( parser . Arguments . ContainsKey ( _paramDotNetConfig ) )
8085 {
8186 configuration = parser . Arguments [ _paramDotNetConfig ] [ 0 ] ;
8287 }
8388
8489 var platformInfo = GetTargetPlatformInformation . Do ( desiredPlatform , specifiedFromCustom ) ;
85-
8690 Console . WriteLine ( $ "Build ASP.NET Core App for { platformInfo . NetCorePublishRid } ...") ;
8791
88- string tempPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "obj" , "desktop" , desiredPlatform ) ;
92+ var tempPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "obj" , "desktop" , desiredPlatform ) ;
8993
9094 if ( Directory . Exists ( tempPath ) == false )
9195 {
@@ -97,17 +101,13 @@ public Task<bool> ExecuteAsync()
97101 Directory . CreateDirectory ( tempPath ) ;
98102 }
99103
100-
101104 Console . WriteLine ( "Executing dotnet publish in this directory: " + tempPath ) ;
102105
103- string tempBinPath = Path . Combine ( tempPath , "bin" ) ;
106+ var tempBinPath = Path . Combine ( tempPath , "bin" ) ;
107+ Console . WriteLine ( $ "Build ASP.NET Core App for { platformInfo . NetCorePublishRid } under { configuration } -Configuration...") ;
104108
105- Console . WriteLine ( $ "Build ASP.NET Core App for { platformInfo . NetCorePublishRid } under { configuration } -Configuration...") ;
106-
107109 var dotNetPublishFlags = GetDotNetPublishFlags ( parser ) ;
108-
109- var command =
110- $ "dotnet publish -r { platformInfo . NetCorePublishRid } -c \" { configuration } \" --output \" { tempBinPath } \" { string . Join ( ' ' , dotNetPublishFlags . Select ( kvp => $ "{ kvp . Key } ={ kvp . Value } ") ) } --self-contained";
110+ var command = $ "dotnet publish -r { platformInfo . NetCorePublishRid } -c \" { configuration } \" --output \" { tempBinPath } \" { string . Join ( ' ' , dotNetPublishFlags . Select ( kvp => $ "{ kvp . Key } ={ kvp . Value } ") ) } --self-contained";
111111
112112 // output the command
113113 Console . ForegroundColor = ConsoleColor . Green ;
@@ -132,33 +132,16 @@ public Task<bool> ExecuteAsync()
132132 File . Copy ( parser . Arguments [ _paramPackageJson ] [ 0 ] , Path . Combine ( tempPath , "package.json" ) , true ) ;
133133 }
134134
135- var checkForNodeModulesDirPath = Path . Combine ( tempPath , "node_modules" ) ;
136-
137- if ( Directory . Exists ( checkForNodeModulesDirPath ) == false || parser . Contains ( _paramForceNodeInstall ) || parser . Contains ( _paramPackageJson ) )
138-
139- Console . WriteLine ( "Start npm install..." ) ;
140- ProcessHelper . CmdExecute ( "npm install --production" , tempPath ) ;
135+ ProcessHelper . CheckNodeModules ( tempPath , parser . Contains ( _paramForceNodeInstall ) || parser . Contains ( _paramPackageJson ) ) ;
141136
142137 Console . WriteLine ( "ElectronHostHook handling started..." ) ;
143-
144- string electronhosthookDir = Path . Combine ( Directory . GetCurrentDirectory ( ) , "ElectronHostHook" ) ;
145-
146- if ( Directory . Exists ( electronhosthookDir ) )
147- {
148- string hosthookDir = Path . Combine ( tempPath , "ElectronHostHook" ) ;
149- DirectoryCopy . Do ( electronhosthookDir , hosthookDir , true , new List < string > ( ) { "node_modules" } ) ;
150-
151- Console . WriteLine ( "Start npm install for hosthooks..." ) ;
152- ProcessHelper . CmdExecute ( "npm install" , hosthookDir ) ;
153-
154- // ToDo: Not sure if this runs under linux/macos
155- ProcessHelper . CmdExecute ( @"npx tsc -p . --sourceMap false" , hosthookDir ) ;
156- }
138+ ProcessHelper . BundleHostHook ( tempPath ) ;
157139
158140 Console . WriteLine ( "Build Electron Desktop Application..." ) ;
159141
160142 // Specifying an absolute path supercedes a relative path
161- string buildPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "desktop" ) ;
143+ var buildPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "desktop" ) ;
144+
162145 if ( parser . Arguments . ContainsKey ( _paramAbsoluteOutput ) )
163146 {
164147 buildPath = parser . Arguments [ _paramAbsoluteOutput ] [ 0 ] ;
@@ -170,13 +153,15 @@ public Task<bool> ExecuteAsync()
170153
171154 Console . WriteLine ( "Executing electron magic in this directory: " + buildPath ) ;
172155
173- string electronArch = "x64" ;
156+ var electronArch = "x64" ;
157+
174158 if ( parser . Arguments . ContainsKey ( _paramElectronArch ) )
175159 {
176160 electronArch = parser . Arguments [ _paramElectronArch ] [ 0 ] ;
177161 }
178162
179- string electronParams = "" ;
163+ var electronParams = string . Empty ;
164+
180165 if ( parser . Arguments . ContainsKey ( _paramElectronParams ) )
181166 {
182167 electronParams = parser . Arguments [ _paramElectronParams ] [ 0 ] ;
@@ -185,7 +170,7 @@ public Task<bool> ExecuteAsync()
185170 // ToDo: Make the same thing easer with native c# - we can save a tmp file in production code :)
186171 Console . WriteLine ( "Create electron-builder configuration file..." ) ;
187172
188- string manifestFileName = "electron.manifest.json" ;
173+ var manifestFileName = "electron.manifest.json" ;
189174
190175 if ( parser . Arguments . ContainsKey ( _manifest ) )
191176 {
@@ -194,14 +179,13 @@ public Task<bool> ExecuteAsync()
194179
195180 ProcessHelper . CmdExecute (
196181 string . IsNullOrWhiteSpace ( version )
197- ? $ "node build-helper.js { manifestFileName } "
198- : $ "node build-helper.js { manifestFileName } { version } ", tempPath ) ;
182+ ? $ "node dist/ build-helper.js { manifestFileName } "
183+ : $ "node dist/ build-helper.js { manifestFileName } { version } ", tempPath ) ;
199184
200- Console . WriteLine ( $ "Package Electron App for Platform { platformInfo . ElectronPackerPlatform } ...") ;
185+ Console . WriteLine ( $ "Package Electron App for Platform { platformInfo . ElectronPackerPlatform } ...") ;
201186 ProcessHelper . CmdExecute ( $ "npx electron-builder --config=./bin/electron-builder.json --{ platformInfo . ElectronPackerPlatform } --{ electronArch } -c.electronVersion=23.2.0 { electronParams } ", tempPath ) ;
202187
203188 Console . WriteLine ( "... done" ) ;
204-
205189 return true ;
206190 } ) ;
207191 }
@@ -216,21 +200,28 @@ private Dictionary<string, string> GetDotNetPublishFlags(SimpleCommandLineParser
216200
217201 if ( parser . Arguments . ContainsKey ( _paramVersion ) )
218202 {
219- if ( parser . Arguments . Keys . All ( key => ! key . StartsWith ( "p:Version=" ) && ! key . StartsWith ( "property:Version=" ) ) )
203+ if ( parser . Arguments . Keys . All ( key => ! key . StartsWith ( "p:Version=" ) && ! key . StartsWith ( "property:Version=" ) ) )
204+ {
220205 dotNetPublishFlags . Add ( "/p:Version" , parser . Arguments [ _paramVersion ] [ 0 ] ) ;
221- if ( parser . Arguments . Keys . All ( key => ! key . StartsWith ( "p:ProductVersion=" ) && ! key . StartsWith ( "property:ProductVersion=" ) ) )
206+ }
207+
208+ if ( parser . Arguments . Keys . All ( key => ! key . StartsWith ( "p:ProductVersion=" ) && ! key . StartsWith ( "property:ProductVersion=" ) ) )
209+ {
222210 dotNetPublishFlags . Add ( "/p:ProductVersion" , parser . Arguments [ _paramVersion ] [ 0 ] ) ;
211+ }
223212 }
224213
225214 foreach ( var parm in parser . Arguments . Keys . Where ( key => key . StartsWith ( "p:" ) || key . StartsWith ( "property:" ) ) )
226215 {
227216 var split = parm . IndexOf ( '=' ) ;
217+
228218 if ( split < 0 )
229219 {
230220 continue ;
231221 }
232222
233223 var key = $ "/{ parm . Substring ( 0 , split ) } ";
224+
234225 // normalize the key
235226 if ( key . StartsWith ( "/property:" ) )
236227 {
0 commit comments