Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions ElectronNET.CLI/Commands/StartElectronCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<Path> from ASP.NET Core Project.";
public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
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<CommandOption> CommandOptions { get; set; } = new List<CommandOption> ();

private string[] _args;

Expand All @@ -21,24 +24,35 @@ public StartElectronCommand(string[] args)
_args = args;
}

public Task<bool> ExecuteAsync()
{
return Task.Run(() =>
{
Console.WriteLine("Start Electron Desktop Application...");
private string _paramPath = "path";
private string _paramTarget = "target";

string aspCoreProjectPath = "";
public Task<bool> 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");
Expand All @@ -47,7 +61,7 @@ public Task<bool> 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);
Expand Down