Skip to content

Commit 52f5542

Browse files
committed
fixes #36 & #11
1 parent 85b80bf commit 52f5542

File tree

4 files changed

+118
-93
lines changed

4 files changed

+118
-93
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
6+
namespace ElectronNET.CLI.Commands.Actions
7+
{
8+
public static class DeployEmbeddedElectronFiles
9+
{
10+
public static void Do(string tempPath)
11+
{
12+
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js");
13+
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
14+
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json");
15+
16+
string hostApiFolder = Path.Combine(tempPath, "api");
17+
if (Directory.Exists(hostApiFolder) == false)
18+
{
19+
Directory.CreateDirectory(hostApiFolder);
20+
}
21+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
22+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
23+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
24+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api.");
25+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
26+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
27+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");
28+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "webContents.js", "api.");
29+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "globalShortcut.js", "api.");
30+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "shell.js", "api.");
31+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api.");
32+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api.");
33+
}
34+
}
35+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Runtime.InteropServices;
4+
using System.Text;
5+
6+
namespace ElectronNET.CLI.Commands.Actions
7+
{
8+
public static class GetTargetPlatformInformation
9+
{
10+
public struct GetTargetPlatformInformationResult
11+
{
12+
public string DesiredPlatform { get; set; }
13+
public string NetCorePublishRid { get; set; }
14+
public string ElectronPackerPlatform { get; set; }
15+
16+
}
17+
18+
public static GetTargetPlatformInformationResult Do(string desiredPlatform)
19+
{
20+
string netCorePublishRid = string.Empty;
21+
string electronPackerPlatform = string.Empty;
22+
23+
switch (desiredPlatform)
24+
{
25+
case "win":
26+
netCorePublishRid = "win-x64";
27+
electronPackerPlatform = "win32";
28+
break;
29+
case "osx":
30+
netCorePublishRid = "osx-x64";
31+
electronPackerPlatform = "darwin";
32+
break;
33+
case "linux":
34+
netCorePublishRid = "linux-x64";
35+
electronPackerPlatform = "linux";
36+
break;
37+
default:
38+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
39+
{
40+
desiredPlatform = "win";
41+
netCorePublishRid = "win-x64";
42+
electronPackerPlatform = "win32";
43+
}
44+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
45+
{
46+
desiredPlatform = "osx";
47+
netCorePublishRid = "osx-x64";
48+
electronPackerPlatform = "darwin";
49+
}
50+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
51+
{
52+
desiredPlatform = "linux";
53+
netCorePublishRid = "linux-x64";
54+
electronPackerPlatform = "linux";
55+
}
56+
57+
break;
58+
}
59+
60+
return new GetTargetPlatformInformationResult()
61+
{
62+
DesiredPlatform = desiredPlatform,
63+
ElectronPackerPlatform = electronPackerPlatform,
64+
NetCorePublishRid = netCorePublishRid
65+
};
66+
}
67+
}
68+
}

ElectronNET.CLI/Commands/BuildCommand.cs

Lines changed: 10 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Runtime.InteropServices;
55
using System.Threading.Tasks;
6+
using ElectronNET.CLI.Commands.Actions;
67

78
namespace 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

ElectronNET.CLI/Commands/StartElectronCommand.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Runtime.InteropServices;
66
using System.Threading.Tasks;
7+
using ElectronNET.CLI.Commands.Actions;
78

89
namespace ElectronNET.CLI.Commands
910
{
@@ -47,30 +48,12 @@ public Task<bool> ExecuteAsync()
4748
Directory.CreateDirectory(tempPath);
4849
}
4950

50-
string tempBinPath = Path.Combine(tempPath, "bin");
51-
ProcessHelper.CmdExecute($"dotnet publish -r win-x64 --output \"{tempBinPath}\"", aspCoreProjectPath);
51+
var platformInfo = GetTargetPlatformInformation.Do(string.Empty);
5252

53-
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js");
54-
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
55-
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json");
53+
string tempBinPath = Path.Combine(tempPath, "bin");
54+
ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\"", aspCoreProjectPath);
5655

57-
string hostApiFolder = Path.Combine(tempPath, "api");
58-
if (Directory.Exists(hostApiFolder) == false)
59-
{
60-
Directory.CreateDirectory(hostApiFolder);
61-
}
62-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
63-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
64-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
65-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api.");
66-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
67-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
68-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");
69-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "webContents.js", "api.");
70-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "globalShortcut.js", "api.");
71-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "shell.js", "api.");
72-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api.");
73-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api.");
56+
DeployEmbeddedElectronFiles.Do(tempPath);
7457

7558
Console.WriteLine("Start npm install...");
7659
ProcessHelper.CmdExecute("npm install", tempPath);

0 commit comments

Comments
 (0)