From 52f55424aeab90536c5393a3bc70571dd45957da Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Sat, 4 Nov 2017 23:17:04 +0100 Subject: [PATCH] fixes https://github.com/ElectronNET/Electron.NET/issues/36 & https://github.com/ElectronNET/Electron.NET/issues/11 --- .../Actions/DeployEmbeddedElectronFiles.cs | 35 ++++++++ .../Actions/GetTargetPlatformInformation.cs | 68 +++++++++++++++ ElectronNET.CLI/Commands/BuildCommand.cs | 85 +++---------------- .../Commands/StartElectronCommand.cs | 27 ++---- 4 files changed, 120 insertions(+), 95 deletions(-) create mode 100644 ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs create mode 100644 ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs diff --git a/ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs b/ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs new file mode 100644 index 0000000..a0b7d4c --- /dev/null +++ b/ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace ElectronNET.CLI.Commands.Actions +{ + public static class DeployEmbeddedElectronFiles + { + public static void Do(string tempPath) + { + EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js"); + EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json"); + EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json"); + + string hostApiFolder = Path.Combine(tempPath, "api"); + if (Directory.Exists(hostApiFolder) == false) + { + Directory.CreateDirectory(hostApiFolder); + } + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "webContents.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "globalShortcut.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "shell.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api."); + } + } +} diff --git a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs new file mode 100644 index 0000000..a5cf151 --- /dev/null +++ b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +namespace ElectronNET.CLI.Commands.Actions +{ + public static class GetTargetPlatformInformation + { + public struct GetTargetPlatformInformationResult + { + public string DesiredPlatform { get; set; } + public string NetCorePublishRid { get; set; } + public string ElectronPackerPlatform { get; set; } + + } + + public static GetTargetPlatformInformationResult Do(string desiredPlatform) + { + string netCorePublishRid = string.Empty; + string electronPackerPlatform = string.Empty; + + switch (desiredPlatform) + { + case "win": + netCorePublishRid = "win-x64"; + electronPackerPlatform = "win32"; + break; + case "osx": + netCorePublishRid = "osx-x64"; + electronPackerPlatform = "darwin"; + break; + case "linux": + netCorePublishRid = "linux-x64"; + electronPackerPlatform = "linux"; + break; + default: + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + desiredPlatform = "win"; + netCorePublishRid = "win-x64"; + electronPackerPlatform = "win32"; + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + desiredPlatform = "osx"; + netCorePublishRid = "osx-x64"; + electronPackerPlatform = "darwin"; + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + desiredPlatform = "linux"; + netCorePublishRid = "linux-x64"; + electronPackerPlatform = "linux"; + } + + break; + } + + return new GetTargetPlatformInformationResult() + { + DesiredPlatform = desiredPlatform, + ElectronPackerPlatform = electronPackerPlatform, + NetCorePublishRid = netCorePublishRid + }; + } + } +} diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index fef7a0f..eefad72 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; +using ElectronNET.CLI.Commands.Actions; namespace ElectronNET.CLI.Commands { @@ -33,86 +34,24 @@ namespace ElectronNET.CLI.Commands desiredPlatform = _args[0]; } - - - string netCorePublishRid = string.Empty; - string electronPackerPlatform = string.Empty; - - switch (desiredPlatform) - { - case "win": - netCorePublishRid = "win-x64"; - electronPackerPlatform = "win32"; - break; - case "osx": - netCorePublishRid = "osx-x64"; - electronPackerPlatform = "darwin"; - break; - case "linux": - netCorePublishRid = "linux-x64"; - electronPackerPlatform = "linux"; - break; - default: - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - desiredPlatform = "win"; - netCorePublishRid = "win-x64"; - electronPackerPlatform = "win32"; - } - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - desiredPlatform = "osx"; - netCorePublishRid = "osx-x64"; - electronPackerPlatform = "darwin"; - } - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - desiredPlatform = "linux"; - netCorePublishRid = "linux-x64"; - electronPackerPlatform = "linux"; - } - - break; - } + var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform); string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform); - - Console.WriteLine("Executing dotnet publish in this directory: " + tempPath); - - string tempBinPath = Path.Combine(tempPath, "bin"); - - Console.WriteLine($"Build ASP.NET Core App for {netCorePublishRid}..."); - - ProcessHelper.CmdExecute($"dotnet publish -r {netCorePublishRid} --output \"{tempBinPath}\"", Directory.GetCurrentDirectory()); - - if (Directory.Exists(tempPath) == false) { Directory.CreateDirectory(tempPath); } - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js"); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json"); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json"); + Console.WriteLine("Executing dotnet publish in this directory: " + tempPath); - string hostApiFolder = Path.Combine(tempPath, "api"); - if (Directory.Exists(hostApiFolder) == false) - { - Directory.CreateDirectory(hostApiFolder); - } - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "webContents.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "globalShortcut.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "shell.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api."); + string tempBinPath = Path.Combine(tempPath, "bin"); + + Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}..."); + + ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\"", Directory.GetCurrentDirectory()); + + DeployEmbeddedElectronFiles.Do(tempPath); Console.WriteLine("Start npm install..."); ProcessHelper.CmdExecute("npm install", tempPath); @@ -137,8 +76,8 @@ namespace ElectronNET.CLI.Commands Console.WriteLine("Executing electron magic in this directory: " + buildPath); // ToDo: Need a solution for --asar support - Console.WriteLine($"Package Electron App for Platform {electronPackerPlatform}..."); - ProcessHelper.CmdExecute($"electron-packager . --platform={electronPackerPlatform} --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath); + Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}..."); + ProcessHelper.CmdExecute($"electron-packager . --platform={platformInfo.ElectronPackerPlatform} --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath); Console.WriteLine("... done"); diff --git a/ElectronNET.CLI/Commands/StartElectronCommand.cs b/ElectronNET.CLI/Commands/StartElectronCommand.cs index daeefc0..cd91527 100644 --- a/ElectronNET.CLI/Commands/StartElectronCommand.cs +++ b/ElectronNET.CLI/Commands/StartElectronCommand.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; +using ElectronNET.CLI.Commands.Actions; namespace ElectronNET.CLI.Commands { @@ -47,30 +48,12 @@ namespace ElectronNET.CLI.Commands Directory.CreateDirectory(tempPath); } + var platformInfo = GetTargetPlatformInformation.Do(string.Empty); + string tempBinPath = Path.Combine(tempPath, "bin"); - ProcessHelper.CmdExecute($"dotnet publish -r win-x64 --output \"{tempBinPath}\"", aspCoreProjectPath); + ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\"", aspCoreProjectPath); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js"); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json"); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json"); - - string hostApiFolder = Path.Combine(tempPath, "api"); - if (Directory.Exists(hostApiFolder) == false) - { - Directory.CreateDirectory(hostApiFolder); - } - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "webContents.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "globalShortcut.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "shell.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api."); - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api."); + DeployEmbeddedElectronFiles.Do(tempPath); Console.WriteLine("Start npm install..."); ProcessHelper.CmdExecute("npm install", tempPath);