From d698e33aea377c1bbc6e91b413a9d1f20646cd59 Mon Sep 17 00:00:00 2001 From: Callum Hutchinson Date: Tue, 15 Oct 2019 12:26:20 +0100 Subject: [PATCH] Added Target option for Start command Uses the same structure as the /target for BuildCommand, changes the path option to follow the same system /path . This allows for platform targeting when testing applications, which is necessary when using certain libraries. --- .../Commands/StartElectronCommand.cs | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/ElectronNET.CLI/Commands/StartElectronCommand.cs b/ElectronNET.CLI/Commands/StartElectronCommand.cs index ee661f2f..7ad3b222 100644 --- a/ElectronNET.CLI/Commands/StartElectronCommand.cs +++ b/ElectronNET.CLI/Commands/StartElectronCommand.cs @@ -11,8 +11,11 @@ public class StartElectronCommand : ICommand { public const string COMMAND_NAME = "start"; public const string COMMAND_DESCRIPTION = "Start your ASP.NET Core Application with Electron, without package it as a single exe. Faster for development."; - public const string COMMAND_ARGUMENTS = " from ASP.NET Core Project."; - public static IList CommandOptions { get; set; } = new List(); + public static string COMMAND_ARGUMENTS = "Optional: '/path' from ASP.NET Core Project." + Environment.NewLine + + "Optional: '/target' with params 'win/osx/linux' to build for a typical app or use 'custom' and specify .NET Core build config & electron build config" + Environment.NewLine + + " for custom target, check .NET Core RID Catalog and Electron build target/" + Environment.NewLine + + " e.g. '/target win' or '/target custom \"win7-x86;win32\"'"; + public static IList CommandOptions { get; set; } = new List (); private string[] _args; @@ -21,24 +24,35 @@ public StartElectronCommand(string[] args) _args = args; } - public Task ExecuteAsync() - { - return Task.Run(() => - { - Console.WriteLine("Start Electron Desktop Application..."); + private string _paramPath = "path"; + private string _paramTarget = "target"; - string aspCoreProjectPath = ""; + public Task ExecuteAsync () { + return Task.Run (() => { + Console.WriteLine ("Start Electron Desktop Application..."); - if (_args.Length > 0) - { - if (Directory.Exists(_args[0])) - { - aspCoreProjectPath = _args[0]; + SimpleCommandLineParser parser = new SimpleCommandLineParser (); + parser.Parse (_args); + + var desiredPlatform = string.Empty; + string specifiedFromCustom = string.Empty; + + if (parser.Arguments.ContainsKey (_paramTarget)) { + desiredPlatform = parser.Arguments[_paramTarget][0]; + if (desiredPlatform == "custom" && parser.Arguments[_paramTarget].Length > 1) { + specifiedFromCustom = parser.Arguments[_paramTarget][1]; } } - else - { - aspCoreProjectPath = Directory.GetCurrentDirectory(); + + string aspCoreProjectPath = ""; + + if (parser.Arguments.ContainsKey (_paramPath)) { + string pathTemp = parser.Arguments[_paramPath][0]; + if (Directory.Exists (pathTemp)) { + aspCoreProjectPath = pathTemp; + } + } else { + aspCoreProjectPath = Directory.GetCurrentDirectory (); } string tempPath = Path.Combine(aspCoreProjectPath, "obj", "Host"); @@ -47,7 +61,7 @@ public Task ExecuteAsync() Directory.CreateDirectory(tempPath); } - var platformInfo = GetTargetPlatformInformation.Do(string.Empty, string.Empty); + var platformInfo = GetTargetPlatformInformation.Do (desiredPlatform, specifiedFromCustom); string tempBinPath = Path.Combine(tempPath, "bin"); var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\"", aspCoreProjectPath);