From a1aaabd588fb2d7283e05812e30a3c3c640ea83e Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Sun, 11 Feb 2018 22:24:12 +0100 Subject: [PATCH] test target stuff --- .../Actions/GetTargetPlatformInformation.cs | 41 ++++++++----------- ElectronNET.CLI/Commands/BuildCommand.cs | 16 +++++--- .../Commands/StartElectronCommand.cs | 2 +- ElectronNET.CLI/Program.cs | 1 - ElectronNET.CLI/SimpleCommandLineParser.cs | 38 +++++++++++++++++ buildAll.cmd | 12 +++--- buildAll.sh | 12 +++--- 7 files changed, 78 insertions(+), 44 deletions(-) create mode 100644 ElectronNET.CLI/SimpleCommandLineParser.cs diff --git a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs index f36df3f..856b77c 100644 --- a/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs +++ b/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs @@ -14,7 +14,7 @@ namespace ElectronNET.CLI.Commands.Actions } - public static GetTargetPlatformInformationResult Do(string desiredPlatform) + public static GetTargetPlatformInformationResult Do(string desiredPlatform, string specifiedPlatfromFromCustom) { string netCorePublishRid = string.Empty; string electronPackerPlatform = string.Empty; @@ -33,34 +33,27 @@ 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 (desiredPlatform.StartsWith("custom=")) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - + netCorePublishRid = "win-x64"; + electronPackerPlatform = "win32"; } - else + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - - 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"; - } + netCorePublishRid = "osx-x64"; + electronPackerPlatform = "darwin"; + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + netCorePublishRid = "linux-x64"; + electronPackerPlatform = "linux"; } - break; } diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index 133cd5c..d017b3d 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -28,13 +28,17 @@ namespace ElectronNET.CLI.Commands { Console.WriteLine("Build Electron Application..."); - var parsedArgs = _args - .Select(s => s.Split(new[] { ':' }, 1)) - .ToDictionary(s => s[0], s => s[1]); + SimpleCommandLineParser parser = new SimpleCommandLineParser(); + parser.Parse(_args); - var desiredPlatform = parsedArgs["/target"]; - - var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform); + var desiredPlatform = parser.Arguments["/target"][0]; + string specifiedFromCustom = string.Empty; + if (desiredPlatform == "custom" && parser.Arguments["/target"].Length > 1) + { + specifiedFromCustom = parser.Arguments["/target"][1]; + } + + var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform, specifiedFromCustom); Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}..."); 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/buildAll.cmd b/buildAll.cmd index a678d3f..b9b37e6 100755 --- a/buildAll.cmd +++ b/buildAll.cmd @@ -16,15 +16,15 @@ dotnet build echo "Invoke electronize build in WebApp Demo" -echo "-- win (dev-build)" -dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target:win +echo "/target win (dev-build)" +dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target win -echo "-- linux (dev-build)" -dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target:linux +echo "/target linux (dev-build)" +dotnet "../ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll" build /target linux :: 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..8a78c98 100755 --- a/buildAll.sh +++ b/buildAll.sh @@ -18,14 +18,14 @@ 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 # Be aware, that for non-electronnet-dev environments the correct # invoke command would be dotnet electronize ... \ No newline at end of file