diff --git a/ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs b/ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs new file mode 100644 index 00000000..a0b7d4c3 --- /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 00000000..a5cf1514 --- /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 fef7a0f2..eefad720 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -3,6 +3,7 @@ using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; +using ElectronNET.CLI.Commands.Actions; namespace ElectronNET.CLI.Commands { @@ -33,86 +34,24 @@ public Task ExecuteAsync() desiredPlatform = _args[0]; } + var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform); - string netCorePublishRid = string.Empty; - string electronPackerPlatform = string.Empty; - - switch (desiredPlatform) + string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform); + if (Directory.Exists(tempPath) == false) { - 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; + Directory.CreateDirectory(tempPath); } - - 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()); + Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}..."); + ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.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"); - - 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); @@ -137,8 +76,8 @@ public Task ExecuteAsync() 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 daeefc04..cd91527b 100644 --- a/ElectronNET.CLI/Commands/StartElectronCommand.cs +++ b/ElectronNET.CLI/Commands/StartElectronCommand.cs @@ -4,6 +4,7 @@ using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; +using ElectronNET.CLI.Commands.Actions; namespace ElectronNET.CLI.Commands { @@ -47,30 +48,12 @@ public Task ExecuteAsync() Directory.CreateDirectory(tempPath); } - string tempBinPath = Path.Combine(tempPath, "bin"); - ProcessHelper.CmdExecute($"dotnet publish -r win-x64 --output \"{tempBinPath}\"", aspCoreProjectPath); + var platformInfo = GetTargetPlatformInformation.Do(string.Empty); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js"); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json"); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json"); + string tempBinPath = Path.Combine(tempPath, "bin"); + ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\"", aspCoreProjectPath); - 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);