@@ -51,15 +51,18 @@ public Task<bool> ExecuteAsync()
51
51
{
52
52
return Task . Run ( ( ) =>
53
53
{
54
- Console . WriteLine ( "Build Electron Application..." ) ;
54
+ var parser = new SimpleCommandLineParser ( ) ;
55
55
56
- SimpleCommandLineParser parser = new SimpleCommandLineParser ( ) ;
56
+ Console . WriteLine ( "Build Electron Application..." ) ;
57
57
parser . Parse ( _args ) ;
58
58
59
59
//This version will be shared between the dotnet publish and electron-builder commands
60
- string version = null ;
60
+ var version = string . Empty ;
61
+
61
62
if ( parser . Arguments . ContainsKey ( _paramVersion ) )
63
+ {
62
64
version = parser . Arguments [ _paramVersion ] [ 0 ] ;
65
+ }
63
66
64
67
if ( ! parser . Arguments . ContainsKey ( _paramTarget ) )
65
68
{
@@ -69,23 +72,24 @@ public Task<bool> ExecuteAsync()
69
72
}
70
73
71
74
var desiredPlatform = parser . Arguments [ _paramTarget ] [ 0 ] ;
72
- string specifiedFromCustom = string . Empty ;
75
+ var specifiedFromCustom = string . Empty ;
76
+
73
77
if ( desiredPlatform == "custom" && parser . Arguments [ _paramTarget ] . Length > 1 )
74
78
{
75
79
specifiedFromCustom = parser . Arguments [ _paramTarget ] [ 1 ] ;
76
80
}
77
81
78
- string configuration = "Release" ;
82
+ var configuration = "Release" ;
83
+
79
84
if ( parser . Arguments . ContainsKey ( _paramDotNetConfig ) )
80
85
{
81
86
configuration = parser . Arguments [ _paramDotNetConfig ] [ 0 ] ;
82
87
}
83
88
84
89
var platformInfo = GetTargetPlatformInformation . Do ( desiredPlatform , specifiedFromCustom ) ;
85
-
86
90
Console . WriteLine ( $ "Build ASP.NET Core App for { platformInfo . NetCorePublishRid } ...") ;
87
91
88
- string tempPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "obj" , "desktop" , desiredPlatform ) ;
92
+ var tempPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "obj" , "desktop" , desiredPlatform ) ;
89
93
90
94
if ( Directory . Exists ( tempPath ) == false )
91
95
{
@@ -97,17 +101,13 @@ public Task<bool> ExecuteAsync()
97
101
Directory . CreateDirectory ( tempPath ) ;
98
102
}
99
103
100
-
101
104
Console . WriteLine ( "Executing dotnet publish in this directory: " + tempPath ) ;
102
105
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...") ;
104
108
105
- Console . WriteLine ( $ "Build ASP.NET Core App for { platformInfo . NetCorePublishRid } under { configuration } -Configuration...") ;
106
-
107
109
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";
111
111
112
112
// output the command
113
113
Console . ForegroundColor = ConsoleColor . Green ;
@@ -132,33 +132,16 @@ public Task<bool> ExecuteAsync()
132
132
File . Copy ( parser . Arguments [ _paramPackageJson ] [ 0 ] , Path . Combine ( tempPath , "package.json" ) , true ) ;
133
133
}
134
134
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 ) ) ;
141
136
142
137
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 ) ;
157
139
158
140
Console . WriteLine ( "Build Electron Desktop Application..." ) ;
159
141
160
142
// 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
+
162
145
if ( parser . Arguments . ContainsKey ( _paramAbsoluteOutput ) )
163
146
{
164
147
buildPath = parser . Arguments [ _paramAbsoluteOutput ] [ 0 ] ;
@@ -170,13 +153,15 @@ public Task<bool> ExecuteAsync()
170
153
171
154
Console . WriteLine ( "Executing electron magic in this directory: " + buildPath ) ;
172
155
173
- string electronArch = "x64" ;
156
+ var electronArch = "x64" ;
157
+
174
158
if ( parser . Arguments . ContainsKey ( _paramElectronArch ) )
175
159
{
176
160
electronArch = parser . Arguments [ _paramElectronArch ] [ 0 ] ;
177
161
}
178
162
179
- string electronParams = "" ;
163
+ var electronParams = string . Empty ;
164
+
180
165
if ( parser . Arguments . ContainsKey ( _paramElectronParams ) )
181
166
{
182
167
electronParams = parser . Arguments [ _paramElectronParams ] [ 0 ] ;
@@ -185,7 +170,7 @@ public Task<bool> ExecuteAsync()
185
170
// ToDo: Make the same thing easer with native c# - we can save a tmp file in production code :)
186
171
Console . WriteLine ( "Create electron-builder configuration file..." ) ;
187
172
188
- string manifestFileName = "electron.manifest.json" ;
173
+ var manifestFileName = "electron.manifest.json" ;
189
174
190
175
if ( parser . Arguments . ContainsKey ( _manifest ) )
191
176
{
@@ -194,14 +179,13 @@ public Task<bool> ExecuteAsync()
194
179
195
180
ProcessHelper . CmdExecute (
196
181
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 ) ;
199
184
200
- Console . WriteLine ( $ "Package Electron App for Platform { platformInfo . ElectronPackerPlatform } ...") ;
185
+ Console . WriteLine ( $ "Package Electron App for Platform { platformInfo . ElectronPackerPlatform } ...") ;
201
186
ProcessHelper . CmdExecute ( $ "npx electron-builder --config=./bin/electron-builder.json --{ platformInfo . ElectronPackerPlatform } --{ electronArch } -c.electronVersion=23.2.0 { electronParams } ", tempPath ) ;
202
187
203
188
Console . WriteLine ( "... done" ) ;
204
-
205
189
return true ;
206
190
} ) ;
207
191
}
@@ -216,21 +200,28 @@ private Dictionary<string, string> GetDotNetPublishFlags(SimpleCommandLineParser
216
200
217
201
if ( parser . Arguments . ContainsKey ( _paramVersion ) )
218
202
{
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
+ {
220
205
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
+ {
222
210
dotNetPublishFlags . Add ( "/p:ProductVersion" , parser . Arguments [ _paramVersion ] [ 0 ] ) ;
211
+ }
223
212
}
224
213
225
214
foreach ( var parm in parser . Arguments . Keys . Where ( key => key . StartsWith ( "p:" ) || key . StartsWith ( "property:" ) ) )
226
215
{
227
216
var split = parm . IndexOf ( '=' ) ;
217
+
228
218
if ( split < 0 )
229
219
{
230
220
continue ;
231
221
}
232
222
233
223
var key = $ "/{ parm . Substring ( 0 , split ) } ";
224
+
234
225
// normalize the key
235
226
if ( key . StartsWith ( "/property:" ) )
236
227
{
0 commit comments