Skip to content

Commit 98e9bcd

Browse files
Merge pull request #100 from ElectronNET/params
Params
2 parents 3137d58 + eee2a3e commit 98e9bcd

File tree

8 files changed

+110
-29
lines changed

8 files changed

+110
-29
lines changed

ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ public static class GetTargetPlatformInformation
99
{
1010
public struct GetTargetPlatformInformationResult
1111
{
12-
public string DesiredPlatform { get; set; }
1312
public string NetCorePublishRid { get; set; }
1413
public string ElectronPackerPlatform { get; set; }
1514

1615
}
1716

18-
public static GetTargetPlatformInformationResult Do(string desiredPlatform)
17+
public static GetTargetPlatformInformationResult Do(string desiredPlatform, string specifiedPlatfromFromCustom)
1918
{
2019
string netCorePublishRid = string.Empty;
2120
string electronPackerPlatform = string.Empty;
@@ -34,22 +33,24 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform)
3433
netCorePublishRid = "linux-x64";
3534
electronPackerPlatform = "linux";
3635
break;
36+
case "custom":
37+
var splittedSpecified = specifiedPlatfromFromCustom.Split(';');
38+
netCorePublishRid = splittedSpecified[0];
39+
electronPackerPlatform = splittedSpecified[1];
40+
break;
3741
default:
3842
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
3943
{
40-
desiredPlatform = "win";
4144
netCorePublishRid = "win-x64";
4245
electronPackerPlatform = "win32";
4346
}
4447
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
4548
{
46-
desiredPlatform = "osx";
4749
netCorePublishRid = "osx-x64";
4850
electronPackerPlatform = "darwin";
4951
}
5052
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
5153
{
52-
desiredPlatform = "linux";
5354
netCorePublishRid = "linux-x64";
5455
electronPackerPlatform = "linux";
5556
}
@@ -59,7 +60,6 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform)
5960

6061
return new GetTargetPlatformInformationResult()
6162
{
62-
DesiredPlatform = desiredPlatform,
6363
ElectronPackerPlatform = electronPackerPlatform,
6464
NetCorePublishRid = netCorePublishRid
6565
};

ElectronNET.CLI/Commands/BuildCommand.cs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using System.Runtime.InteropServices;
56
using System.Threading.Tasks;
67
using ElectronNET.CLI.Commands.Actions;
@@ -21,20 +22,36 @@ public BuildCommand(string[] args)
2122
_args = args;
2223
}
2324

25+
private string _paramTarget = "target";
26+
private string _paramDotNetConfig = "dotnet-configuration";
27+
private string _paramElectronArch = "electron-arch";
28+
private string _paramElectronParams = "electron-params";
29+
2430
public Task<bool> ExecuteAsync()
2531
{
2632
return Task.Run(() =>
2733
{
2834
Console.WriteLine("Build Electron Application...");
2935

30-
string desiredPlatform = "";
36+
SimpleCommandLineParser parser = new SimpleCommandLineParser();
37+
parser.Parse(_args);
3138

32-
if (_args.Length > 0)
39+
var desiredPlatform = parser.Arguments[_paramTarget][0];
40+
string specifiedFromCustom = string.Empty;
41+
if (desiredPlatform == "custom" && parser.Arguments[_paramTarget].Length > 1)
3342
{
34-
desiredPlatform = _args[0];
43+
specifiedFromCustom = parser.Arguments["target"][1];
3544
}
3645

37-
var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform);
46+
string configuration = "Release";
47+
if (parser.Arguments.ContainsKey(_paramDotNetConfig))
48+
{
49+
configuration = parser.Arguments[_paramDotNetConfig][0];
50+
}
51+
52+
var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform, specifiedFromCustom);
53+
54+
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}...");
3855

3956

4057
string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform);
@@ -47,9 +64,9 @@ public Task<bool> ExecuteAsync()
4764

4865
string tempBinPath = Path.Combine(tempPath, "bin");
4966

50-
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}...");
67+
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid} under {configuration}-Configuration...");
5168

52-
var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\"", Directory.GetCurrentDirectory());
69+
var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c {configuration} --output \"{tempBinPath}\"", Directory.GetCurrentDirectory());
5370

5471
if (resultCode != 0)
5572
{
@@ -93,8 +110,21 @@ public Task<bool> ExecuteAsync()
93110
Console.WriteLine("Executing electron magic in this directory: " + buildPath);
94111

95112
// ToDo: Need a solution for --asar support
113+
114+
string electronArch = "x64";
115+
if (parser.Arguments.ContainsKey(_paramElectronArch))
116+
{
117+
electronArch = parser.Arguments[_paramElectronArch][0];
118+
}
119+
120+
string electronParams = "";
121+
if (parser.Arguments.ContainsKey(_paramElectronParams))
122+
{
123+
electronParams = parser.Arguments[_paramElectronParams][0];
124+
}
125+
96126
Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}...");
97-
ProcessHelper.CmdExecute($"electron-packager . --platform={platformInfo.ElectronPackerPlatform} --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath);
127+
ProcessHelper.CmdExecute($"electron-packager . --platform={platformInfo.ElectronPackerPlatform} --arch={electronArch} {electronParams} --out=\"{buildPath}\" --overwrite", tempPath);
98128

99129
Console.WriteLine("... done");
100130

ElectronNET.CLI/Commands/StartElectronCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public Task<bool> ExecuteAsync()
4848
Directory.CreateDirectory(tempPath);
4949
}
5050

51-
var platformInfo = GetTargetPlatformInformation.Do(string.Empty);
51+
var platformInfo = GetTargetPlatformInformation.Do(String.Empty, String.Empty);
5252

5353
string tempBinPath = Path.Combine(tempPath, "bin");
5454
var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\"", aspCoreProjectPath);

ElectronNET.CLI/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace ElectronNET.CLI
99
{
10-
1110
class Program
1211
{
1312
static void Main(string[] args)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Collections.Generic;
2+
3+
namespace ElectronNET.CLI
4+
{
5+
public class SimpleCommandLineParser
6+
{
7+
public SimpleCommandLineParser()
8+
{
9+
Arguments = new Dictionary<string, string[]>();
10+
}
11+
public IDictionary<string, string[]> Arguments { get; private set; }
12+
public void Parse(string[] args)
13+
{
14+
var currentName = "";
15+
var values = new List<string>();
16+
foreach (var arg in args)
17+
{
18+
if (arg.StartsWith("/"))
19+
{
20+
if (currentName != "")
21+
Arguments[currentName] = values.ToArray();
22+
values.Clear();
23+
currentName = arg.Substring(1);
24+
}
25+
else if (currentName == "")
26+
Arguments[arg] = new string[0];
27+
else
28+
values.Add(arg);
29+
}
30+
if (currentName != "")
31+
Arguments[currentName] = values.ToArray();
32+
}
33+
public bool Contains(string name)
34+
{
35+
return Arguments.ContainsKey(name);
36+
}
37+
}
38+
}

ElectronNET.sln

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27004.2002
4+
VisualStudioVersion = 15.0.27130.2024
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronNET.WebApp", "ElectronNET.WebApp\ElectronNET.WebApp.csproj", "{7C048379-401C-4345-B5E7-BE232DEA8157}"
77
EndProject
@@ -32,6 +32,8 @@ Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "ElectronNET.Host", "Electro
3232
EndProject
3333
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2914CCF7-27C2-42AE-849A-2F0C1BC7CDFA}"
3434
ProjectSection(SolutionItems) = preProject
35+
buildAll.cmd = buildAll.cmd
36+
buildAll.sh = buildAll.sh
3537
buildReleaseNuGetPackages.cmd = buildReleaseNuGetPackages.cmd
3638
EndProjectSection
3739
EndProject

buildAll.cmd

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,24 @@ dotnet build
1616

1717
echo "Invoke electronize build in WebApp Demo"
1818

19-
echo "-- win (dev-build)"
20-
dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build win
2119

22-
echo "-- linux (dev-build)"
23-
dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build linux
20+
echo "/target xxx (dev-build)"
21+
dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target custom win7-x86;win32 /dotnet-configuration Debug /electron-arch ia32 /electron-params "--prune=true "
22+
23+
24+
echo "/target win (dev-build)"
25+
dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target win
26+
27+
echo "/target linux (dev-build)"
28+
dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target linux
29+
30+
echo "/target custom win7-x86;win32 (dev-build)"
31+
dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target custom win7-x86;win32
32+
2433

2534
:: Be aware, that for non-electronnet-dev environments the correct
2635
:: invoke command would be dotnet electronize ...
2736

2837
:: Not supported on Windows Systems, because of SymLinks...
29-
:: echo "-- osx"
30-
:: dotnet electronize build osx
38+
:: echo "/target osx"
39+
:: dotnet electronize build /target osx

buildAll.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ dotnet restore
1818
dotnet build
1919

2020
echo "Invoke electronize build in WebApp Demo"
21-
echo "-- win (dev-build)"
22-
dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build win
21+
echo "/target win (dev-build)"
22+
dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target win
2323

24-
echo "-- linux (dev-build)"
25-
dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build linux
24+
echo "/target linux (dev-build)"
25+
dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target linux
2626

27-
echo "-- osx (dev-build)"
28-
dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build osx
27+
echo "/target osx (dev-build)"
28+
dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target osx
29+
30+
echo "/target custom win7-x86;win32 (dev-build)"
31+
dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target custom "win7-x86;win32"
2932

3033
# Be aware, that for non-electronnet-dev environments the correct
31-
# invoke command would be dotnet electronize ...
34+
# invoke command would be dotnet electronize ...

0 commit comments

Comments
 (0)