diff --git a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs index a5cf151..856b77c 100644 --- a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs +++ b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs @@ -9,13 +9,12 @@ namespace ElectronNET.CLI.Commands.Actions { public struct GetTargetPlatformInformationResult { - public string DesiredPlatform { get; set; } public string NetCorePublishRid { get; set; } public string ElectronPackerPlatform { get; set; } } - public static GetTargetPlatformInformationResult Do(string desiredPlatform) + public static GetTargetPlatformInformationResult Do(string desiredPlatform, string specifiedPlatfromFromCustom) { string netCorePublishRid = string.Empty; string electronPackerPlatform = string.Empty; @@ -34,22 +33,24 @@ namespace ElectronNET.CLI.Commands.Actions netCorePublishRid = "linux-x64"; electronPackerPlatform = "linux"; break; + case "custom": + var splittedSpecified = specifiedPlatfromFromCustom.Split(';'); + netCorePublishRid = splittedSpecified[0]; + electronPackerPlatform = splittedSpecified[1]; + 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"; } @@ -59,7 +60,6 @@ namespace ElectronNET.CLI.Commands.Actions return new GetTargetPlatformInformationResult() { - DesiredPlatform = desiredPlatform, ElectronPackerPlatform = electronPackerPlatform, NetCorePublishRid = netCorePublishRid }; diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index b9866c9..6e0308d 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; using ElectronNET.CLI.Commands.Actions; @@ -21,20 +22,36 @@ namespace ElectronNET.CLI.Commands _args = args; } + private string _paramTarget = "target"; + private string _paramDotNetConfig = "dotnet-configuration"; + private string _paramElectronArch = "electron-arch"; + private string _paramElectronParams = "electron-params"; + public Task ExecuteAsync() { return Task.Run(() => { Console.WriteLine("Build Electron Application..."); - string desiredPlatform = ""; + SimpleCommandLineParser parser = new SimpleCommandLineParser(); + parser.Parse(_args); - if (_args.Length > 0) + var desiredPlatform = parser.Arguments[_paramTarget][0]; + string specifiedFromCustom = string.Empty; + if (desiredPlatform == "custom" && parser.Arguments[_paramTarget].Length > 1) { - desiredPlatform = _args[0]; + specifiedFromCustom = parser.Arguments["target"][1]; } - var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform); + string configuration = "Release"; + if (parser.Arguments.ContainsKey(_paramDotNetConfig)) + { + configuration = parser.Arguments[_paramDotNetConfig][0]; + } + + var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform, specifiedFromCustom); + + Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}..."); string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform); @@ -47,9 +64,9 @@ namespace ElectronNET.CLI.Commands string tempBinPath = Path.Combine(tempPath, "bin"); - Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}..."); + Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid} under {configuration}-Configuration..."); - var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\"", Directory.GetCurrentDirectory()); + var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c {configuration} --output \"{tempBinPath}\"", Directory.GetCurrentDirectory()); if (resultCode != 0) { @@ -93,8 +110,21 @@ namespace ElectronNET.CLI.Commands Console.WriteLine("Executing electron magic in this directory: " + buildPath); // ToDo: Need a solution for --asar support + + string electronArch = "x64"; + if (parser.Arguments.ContainsKey(_paramElectronArch)) + { + electronArch = parser.Arguments[_paramElectronArch][0]; + } + + string electronParams = ""; + if (parser.Arguments.ContainsKey(_paramElectronParams)) + { + electronParams = parser.Arguments[_paramElectronParams][0]; + } + Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}..."); - ProcessHelper.CmdExecute($"electron-packager . --platform={platformInfo.ElectronPackerPlatform} --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath); + ProcessHelper.CmdExecute($"electron-packager . --platform={platformInfo.ElectronPackerPlatform} --arch={electronArch} {electronParams} --out=\"{buildPath}\" --overwrite", tempPath); Console.WriteLine("... done"); diff --git a/ElectronNET.CLI/Commands/StartElectronCommand.cs b/ElectronNET.CLI/Commands/StartElectronCommand.cs index 355d3cc..48e0fba 100644 --- a/ElectronNET.CLI/Commands/StartElectronCommand.cs +++ b/ElectronNET.CLI/Commands/StartElectronCommand.cs @@ -48,7 +48,7 @@ namespace ElectronNET.CLI.Commands Directory.CreateDirectory(tempPath); } - var platformInfo = GetTargetPlatformInformation.Do(string.Empty); + var platformInfo = GetTargetPlatformInformation.Do(String.Empty, String.Empty); string tempBinPath = Path.Combine(tempPath, "bin"); var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\"", aspCoreProjectPath); diff --git a/ElectronNET.CLI/Program.cs b/ElectronNET.CLI/Program.cs index 87032cb..c053a58 100644 --- a/ElectronNET.CLI/Program.cs +++ b/ElectronNET.CLI/Program.cs @@ -7,7 +7,6 @@ using System.Text; namespace ElectronNET.CLI { - class Program { static void Main(string[] args) diff --git a/ElectronNET.CLI/SimpleCommandLineParser.cs b/ElectronNET.CLI/SimpleCommandLineParser.cs new file mode 100644 index 0000000..e5cf86e --- /dev/null +++ b/ElectronNET.CLI/SimpleCommandLineParser.cs @@ -0,0 +1,38 @@ +using System.Collections.Generic; + +namespace ElectronNET.CLI +{ + public class SimpleCommandLineParser + { + public SimpleCommandLineParser() + { + Arguments = new Dictionary(); + } + public IDictionary Arguments { get; private set; } + public void Parse(string[] args) + { + var currentName = ""; + var values = new List(); + foreach (var arg in args) + { + if (arg.StartsWith("/")) + { + if (currentName != "") + Arguments[currentName] = values.ToArray(); + values.Clear(); + currentName = arg.Substring(1); + } + else if (currentName == "") + Arguments[arg] = new string[0]; + else + values.Add(arg); + } + if (currentName != "") + Arguments[currentName] = values.ToArray(); + } + public bool Contains(string name) + { + return Arguments.ContainsKey(name); + } + } +} \ No newline at end of file diff --git a/ElectronNET.sln b/ElectronNET.sln index ce70b61..9ca181a 100644 --- a/ElectronNET.sln +++ b/ElectronNET.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27004.2002 +VisualStudioVersion = 15.0.27130.2024 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronNET.WebApp", "ElectronNET.WebApp\ElectronNET.WebApp.csproj", "{7C048379-401C-4345-B5E7-BE232DEA8157}" EndProject @@ -32,6 +32,8 @@ Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "ElectronNET.Host", "Electro EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2914CCF7-27C2-42AE-849A-2F0C1BC7CDFA}" ProjectSection(SolutionItems) = preProject + buildAll.cmd = buildAll.cmd + buildAll.sh = buildAll.sh buildReleaseNuGetPackages.cmd = buildReleaseNuGetPackages.cmd EndProjectSection EndProject diff --git a/buildAll.cmd b/buildAll.cmd index a1dd47f..3899395 100755 --- a/buildAll.cmd +++ b/buildAll.cmd @@ -16,15 +16,24 @@ dotnet build echo "Invoke electronize build in WebApp Demo" -echo "-- win (dev-build)" -dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build win -echo "-- linux (dev-build)" -dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build linux +echo "/target xxx (dev-build)" +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 " + + +echo "/target win (dev-build)" +dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target win + +echo "/target linux (dev-build)" +dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target linux + +echo "/target custom win7-x86;win32 (dev-build)" +dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target custom win7-x86;win32 + :: Be aware, that for non-electronnet-dev environments the correct :: invoke command would be dotnet electronize ... :: Not supported on Windows Systems, because of SymLinks... -:: echo "-- osx" -:: dotnet electronize build osx +:: echo "/target osx" +:: dotnet electronize build /target osx diff --git a/buildAll.sh b/buildAll.sh index 6d6ace8..4141a10 100755 --- a/buildAll.sh +++ b/buildAll.sh @@ -18,14 +18,17 @@ dotnet restore dotnet build echo "Invoke electronize build in WebApp Demo" -echo "-- win (dev-build)" -dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build win +echo "/target win (dev-build)" +dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target win -echo "-- linux (dev-build)" -dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build linux +echo "/target linux (dev-build)" +dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target linux -echo "-- osx (dev-build)" -dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build osx +echo "/target osx (dev-build)" +dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target osx + +echo "/target custom win7-x86;win32 (dev-build)" +dotnet "$dir/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target custom "win7-x86;win32" # Be aware, that for non-electronnet-dev environments the correct -# invoke command would be dotnet electronize ... \ No newline at end of file +# invoke command would be dotnet electronize ...