Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixes #36 & #11
  • Loading branch information
robertmuehsig committed Nov 4, 2017
1 parent 85b80bf commit 52f5542
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 93 deletions.
35 changes: 35 additions & 0 deletions 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.");
}
}
}
68 changes: 68 additions & 0 deletions 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
};
}
}
}
81 changes: 10 additions & 71 deletions ElectronNET.CLI/Commands/BuildCommand.cs
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ElectronNET.CLI.Commands.Actions;

namespace ElectronNET.CLI.Commands
{
Expand Down Expand Up @@ -33,86 +34,24 @@ public Task<bool> 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);
Expand All @@ -137,8 +76,8 @@ public Task<bool> 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");
Expand Down
27 changes: 5 additions & 22 deletions ElectronNET.CLI/Commands/StartElectronCommand.cs
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ElectronNET.CLI.Commands.Actions;

namespace ElectronNET.CLI.Commands
{
Expand Down Expand Up @@ -47,30 +48,12 @@ public Task<bool> 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);
Expand Down

0 comments on commit 52f5542

Please sign in to comment.