33using System . IO ;
44using System . Runtime . InteropServices ;
55using System . Threading . Tasks ;
6+ using ElectronNET . CLI . Commands . Actions ;
67
78namespace ElectronNET . CLI . Commands
89{
@@ -33,86 +34,24 @@ public Task<bool> ExecuteAsync()
3334 desiredPlatform = _args [ 0 ] ;
3435 }
3536
37+ var platformInfo = GetTargetPlatformInformation . Do ( desiredPlatform ) ;
3638
3739
38- string netCorePublishRid = string . Empty ;
39- string electronPackerPlatform = string . Empty ;
40-
41- switch ( desiredPlatform )
40+ string tempPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "obj" , "desktop" , desiredPlatform ) ;
41+ if ( Directory . Exists ( tempPath ) == false )
4242 {
43- case "win" :
44- netCorePublishRid = "win-x64" ;
45- electronPackerPlatform = "win32" ;
46- break ;
47- case "osx" :
48- netCorePublishRid = "osx-x64" ;
49- electronPackerPlatform = "darwin" ;
50- break ;
51- case "linux" :
52- netCorePublishRid = "linux-x64" ;
53- electronPackerPlatform = "linux" ;
54- break ;
55- default :
56- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
57- {
58- desiredPlatform = "win" ;
59- netCorePublishRid = "win-x64" ;
60- electronPackerPlatform = "win32" ;
61- }
62- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
63- {
64- desiredPlatform = "osx" ;
65- netCorePublishRid = "osx-x64" ;
66- electronPackerPlatform = "darwin" ;
67- }
68- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
69- {
70- desiredPlatform = "linux" ;
71- netCorePublishRid = "linux-x64" ;
72- electronPackerPlatform = "linux" ;
73- }
74-
75- break ;
43+ Directory . CreateDirectory ( tempPath ) ;
7644 }
7745
78-
79- string tempPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "obj" , "desktop" , desiredPlatform ) ;
80-
8146 Console . WriteLine ( "Executing dotnet publish in this directory: " + tempPath ) ;
8247
8348 string tempBinPath = Path . Combine ( tempPath , "bin" ) ;
8449
85- Console . WriteLine ( $ "Build ASP.NET Core App for { netCorePublishRid } ...") ;
86-
87- ProcessHelper . CmdExecute ( $ "dotnet publish -r { netCorePublishRid } --output \" { tempBinPath } \" ", Directory . GetCurrentDirectory ( ) ) ;
50+ Console . WriteLine ( $ "Build ASP.NET Core App for { platformInfo . NetCorePublishRid } ...") ;
8851
52+ ProcessHelper . CmdExecute ( $ "dotnet publish -r { platformInfo . NetCorePublishRid } --output \" { tempBinPath } \" ", Directory . GetCurrentDirectory ( ) ) ;
8953
90- if ( Directory . Exists ( tempPath ) == false )
91- {
92- Directory . CreateDirectory ( tempPath ) ;
93- }
94-
95- EmbeddedFileHelper . DeployEmbeddedFile ( tempPath , "main.js" ) ;
96- EmbeddedFileHelper . DeployEmbeddedFile ( tempPath , "package.json" ) ;
97- EmbeddedFileHelper . DeployEmbeddedFile ( tempPath , "package-lock.json" ) ;
98-
99- string hostApiFolder = Path . Combine ( tempPath , "api" ) ;
100- if ( Directory . Exists ( hostApiFolder ) == false )
101- {
102- Directory . CreateDirectory ( hostApiFolder ) ;
103- }
104- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "ipc.js" , "api." ) ;
105- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "app.js" , "api." ) ;
106- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "browserWindows.js" , "api." ) ;
107- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "dialog.js" , "api." ) ;
108- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "menu.js" , "api." ) ;
109- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "notification.js" , "api." ) ;
110- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "tray.js" , "api." ) ;
111- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "webContents.js" , "api." ) ;
112- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "globalShortcut.js" , "api." ) ;
113- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "shell.js" , "api." ) ;
114- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "screen.js" , "api." ) ;
115- EmbeddedFileHelper . DeployEmbeddedFile ( hostApiFolder , "clipboard.js" , "api." ) ;
54+ DeployEmbeddedElectronFiles . Do ( tempPath ) ;
11655
11756 Console . WriteLine ( "Start npm install..." ) ;
11857 ProcessHelper . CmdExecute ( "npm install" , tempPath ) ;
@@ -137,8 +76,8 @@ public Task<bool> ExecuteAsync()
13776 Console . WriteLine ( "Executing electron magic in this directory: " + buildPath ) ;
13877
13978 // ToDo: Need a solution for --asar support
140- Console . WriteLine ( $ "Package Electron App for Platform { electronPackerPlatform } ...") ;
141- ProcessHelper . CmdExecute ( $ "electron-packager . --platform={ electronPackerPlatform } --arch=x64 --out=\" { buildPath } \" --overwrite", tempPath ) ;
79+ Console . WriteLine ( $ "Package Electron App for Platform { platformInfo . ElectronPackerPlatform } ...") ;
80+ ProcessHelper . CmdExecute ( $ "electron-packager . --platform={ platformInfo . ElectronPackerPlatform } --arch=x64 --out=\" { buildPath } \" --overwrite", tempPath ) ;
14281
14382 Console . WriteLine ( "... done" ) ;
14483
0 commit comments