Files
Electron.NET/ElectronNET.CLI/Commands/BuildCommand.cs

52 lines
2.1 KiB
C#
Raw Normal View History

2017-10-05 04:44:58 +02:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace ElectronNET.CLI.Commands
{
public class BuildCommand : ICommand
{
public const string COMMAND_NAME = "build";
public const string COMMAND_DESCRIPTION = "Build your Electron Application.";
public const string COMMAND_ARGUMENTS = "<Path> from ASP.NET Core Project.";
public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
public Task<bool> ExecuteAsync()
{
return Task.Run(() =>
{
Console.WriteLine("Build Windows Application...");
string currentAssemblyPath = AppDomain.CurrentDomain.BaseDirectory;
2017-10-05 21:28:47 +02:00
string tempPath = Path.Combine(currentAssemblyPath, "Host");
ProcessHelper.CmdExecute("dotnet publish -r win10-x64 --output " + Path.Combine(tempPath, "bin"), Directory.GetCurrentDirectory());
2017-10-05 04:44:58 +02:00
2017-10-05 21:28:47 +02:00
if (Directory.Exists(tempPath) == false)
2017-10-05 04:44:58 +02:00
{
2017-10-05 21:28:47 +02:00
Directory.CreateDirectory(tempPath);
2017-10-05 04:44:58 +02:00
}
2017-10-05 21:28:47 +02:00
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js");
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json");
2017-10-05 04:44:58 +02:00
Console.WriteLine("Start npm install...");
2017-10-05 21:28:47 +02:00
ProcessHelper.CmdExecute("npm install", tempPath);
2017-10-05 04:44:58 +02:00
2017-10-05 21:28:47 +02:00
Console.WriteLine("Start npm install electron-packager...");
ProcessHelper.CmdExecute("npm install electron-packager --global", tempPath);
2017-10-05 04:44:58 +02:00
2017-10-05 21:28:47 +02:00
Console.WriteLine("Build Electron Desktop Application...");
string buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop");
2017-10-05 22:08:36 +02:00
// Need a solution for --asar support
ProcessHelper.CmdExecute($"electron-packager . --platform=win32 --arch=x64 --electronVersion=1.7.8 --out=\"{buildPath}\" --overwrite", tempPath);
2017-10-05 04:44:58 +02:00
return true;
});
}
2017-10-05 21:28:47 +02:00
2017-10-05 04:44:58 +02:00
}
}