mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-15 05:35:01 +00:00
62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ElectronNET.CLI.Commands
|
|
{
|
|
public class StartElectronCommand : ICommand
|
|
{
|
|
public const string COMMAND_NAME = "start";
|
|
public const string COMMAND_DESCRIPTION = "Start your ASP.NET Core Application with Electron.";
|
|
public const string COMMAND_ARGUMENTS = "<Path> from ASP.NET Core Project.";
|
|
public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
|
|
|
|
private string[] _args;
|
|
|
|
public StartElectronCommand(string[] args)
|
|
{
|
|
_args = args;
|
|
}
|
|
|
|
public Task<bool> ExecuteAsync()
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
Console.WriteLine("Start Electron Desktop Application...");
|
|
|
|
string aspCoreProjectPath = "";
|
|
|
|
if (_args.Length > 0)
|
|
{
|
|
if (Directory.Exists(_args[0]))
|
|
{
|
|
aspCoreProjectPath = _args[0];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
aspCoreProjectPath = Directory.GetCurrentDirectory();
|
|
}
|
|
|
|
string currentAssemblyPath = AppDomain.CurrentDomain.BaseDirectory;
|
|
string tempPath = Path.Combine(currentAssemblyPath, "Host");
|
|
ProcessHelper.CmdExecute("dotnet publish -r win10-x64 --output " + Path.Combine(tempPath, "bin"), aspCoreProjectPath);
|
|
|
|
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js");
|
|
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
|
|
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json");
|
|
|
|
Console.WriteLine("Start npm install...");
|
|
ProcessHelper.CmdExecute("npm install", tempPath);
|
|
ProcessHelper.CmdExecute("npm install electron@1.7.8", tempPath);
|
|
|
|
ProcessHelper.CmdExecute(@"electron.cmd ""..\..\main.js""", Path.Combine(tempPath, "node_modules", ".bin"));
|
|
|
|
return true;
|
|
});
|
|
}
|
|
}
|
|
}
|