This commit is contained in:
Gregor Biswanger
2017-10-18 05:31:49 +02:00
10 changed files with 155 additions and 56 deletions

View File

@@ -5,6 +5,17 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageOutputPath>..\artifacts</PackageOutputPath>
<PackageId>ElectronNET.API</PackageId>
<Authors>Gregor Biswanger, Robert Muehsig</Authors>
<Company />
<Product>Electron.NET</Product>
<PackageLicenseUrl>https://github.com/GregorBiswanger/Electron.NET/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/GregorBiswanger/Electron.NET/</PackageProjectUrl>
<Description>Building cross platform electron based desktop apps with .NET Core and ASP.NET NET Core.
This package contains the API to access the "native" electron API.</Description>
<RepositoryUrl>https://github.com/GregorBiswanger/Electron.NET/</RepositoryUrl>
<PackageTags>electron aspnetcore</PackageTags>
<PackageReleaseNotes>#0.0.1
- alpha release</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>

View File

@@ -10,41 +10,77 @@ namespace ElectronNET.CLI.Commands
{
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 const string COMMAND_ARGUMENTS = "<Platform> to build (default is current OS, possible values are: win,osx,linux)";
public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
private string[] _args;
public BuildCommand(string[] args)
{
_args = args;
}
public Task<bool> ExecuteAsync()
{
return Task.Run(() =>
{
Console.WriteLine("Build Electron Application...");
string desiredPlatform = "";
if (_args.Length > 0)
{
desiredPlatform = _args[0];
}
string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop");
Console.WriteLine("Executing dotnet publish in this directory: " + tempPath);
string tempBinPath = Path.Combine(tempPath, "bin");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WriteLine("Build ASP.NET Core App for Windows...");
string netCorePublishRid = string.Empty;
string electronPackerPlatform = string.Empty;
ProcessHelper.CmdExecute($"dotnet publish -r win10-x64 --output \"{tempBinPath}\"", Directory.GetCurrentDirectory());
switch (desiredPlatform)
{
case "win":
netCorePublishRid = "win10-x64";
electronPackerPlatform = "win32";
break;
case "osx":
netCorePublishRid = "osx-x64";
electronPackerPlatform = "darwin";
break;
case "linux":
netCorePublishRid = "ubuntu-x64";
electronPackerPlatform = "linux";
break;
default:
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
netCorePublishRid = "win10-x64";
electronPackerPlatform = "win32";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
netCorePublishRid = "osx-x64";
electronPackerPlatform = "darwin";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
netCorePublishRid = "ubuntu-x64";
electronPackerPlatform = "linux";
}
break;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Console.WriteLine("Build ASP.NET Core App for OSX...");
Console.WriteLine($"Build ASP.NET Core App for {netCorePublishRid}...");
ProcessHelper.CmdExecute($"dotnet publish -r osx-x64 --output \"{tempBinPath}\"", Directory.GetCurrentDirectory());
}
ProcessHelper.CmdExecute($"dotnet publish -r {netCorePublishRid} --output \"{tempBinPath}\"", Directory.GetCurrentDirectory());
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Console.WriteLine("Build ASP.NET Core App for Linux (Ubuntu x64)...");
ProcessHelper.CmdExecute($"dotnet publish -r ubuntu-x64 --output \"{tempBinPath}\"", Directory.GetCurrentDirectory());
}
if (Directory.Exists(tempPath) == false)
{
@@ -90,26 +126,8 @@ namespace ElectronNET.CLI.Commands
Console.WriteLine("Executing electron magic in this directory: " + buildPath);
// ToDo: Need a solution for --asar support
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WriteLine("Package Electron App for Windows...");
ProcessHelper.CmdExecute($"electron-packager . --platform=win32 --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath);
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Console.WriteLine("Package Electron App for OSX...");
ProcessHelper.CmdExecute($"electron-packager . --platform=darwin --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath);
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Console.WriteLine("Package Electron App for Linux...");
ProcessHelper.CmdExecute($"electron-packager . --platform=linux --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath);
}
Console.WriteLine($"Package Electron App for Platform {electronPackerPlatform}...");
ProcessHelper.CmdExecute($"electron-packager . --platform={electronPackerPlatform} --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath);
Console.WriteLine("... done");

View File

@@ -17,11 +17,32 @@ namespace ElectronNET.CLI.Commands
private const string ConfigName = "electron.manifest.json";
private string[] _args;
public InitCommand(string[] args)
{
_args = args;
}
public Task<bool> ExecuteAsync()
{
return Task.Run(() =>
{
var currentDirectory = Directory.GetCurrentDirectory();
string aspCoreProjectPath = "";
if (_args.Length > 0)
{
if (Directory.Exists(_args[0]))
{
aspCoreProjectPath = _args[0];
}
}
else
{
aspCoreProjectPath = Directory.GetCurrentDirectory();
}
var currentDirectory = aspCoreProjectPath;
Console.WriteLine("Adding our config file to your project...");

View File

@@ -10,6 +10,18 @@
<PackageOutputPath>..\artifacts</PackageOutputPath>
<PackageId>ElectronNET.CLI</PackageId>
<Version>1.0.0</Version>
<Authors>Gregor Biswanger, Robert Muehsig</Authors>
<Product>Electron.NET</Product>
<Company />
<Description>Building cross platform electron based desktop apps with .NET Core and ASP.NET NET Core.
This package contains the dotnet tooling to electronize your application.</Description>
<PackageLicenseUrl>https://github.com/GregorBiswanger/Electron.NET/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/GregorBiswanger/Electron.NET/</PackageProjectUrl>
<RepositoryUrl>https://github.com/GregorBiswanger/Electron.NET/</RepositoryUrl>
<PackageTags>electron aspnetcore</PackageTags>
<PackageReleaseNotes>#0.0.1
- alpha release</PackageReleaseNotes>
<PackageIconUrl>https://raw.githubusercontent.com/GregorBiswanger/Electron.NET/master/assets/images/electron.net-logo-square.png</PackageIconUrl>
</PropertyGroup>
<ItemGroup>

View File

@@ -28,10 +28,10 @@ namespace ElectronNET.CLI
command = new StartElectronCommand(args.Skip(1).ToArray());
break;
case BuildCommand.COMMAND_NAME:
command = new BuildCommand();
command = new BuildCommand(args.Skip(1).ToArray());
break;
case InitCommand.COMMAND_NAME:
command = new InitCommand();
command = new InitCommand(args.Skip(1).ToArray());
break;
case "--help":
case "--h":

View File

@@ -1,2 +1,2 @@
rd /s /q %userprofile%\.nuget\packages\.tools\electronnet.cli 2>nul
rd /s /q %userprofile%\.nuget\packages\electronnet.cli 2>nul
rd /s /q %userprofile%\.nuget\packages\.tools\electronnet.cli
rd /s /q %userprofile%\.nuget\packages\electronnet.cli

View File

@@ -1,9 +1,45 @@
[![Electron.NET Logo](https://github.com/GregorBiswanger/Electron.NET/blob/master/assets/images/electron.net-logo.png)](https://github.com/GregorBiswanger/Electron.NET)
[![Build status](https://ci.appveyor.com/api/projects/status/u710d6hman5a4beb/branch/cli-etc?svg=true)](https://ci.appveyor.com/project/robertmuehsig/electron-net/branch/cli-etc)
Master: [![Build status](https://ci.appveyor.com/api/projects/status/u710d6hman5a4beb/branch/master?svg=true)](https://ci.appveyor.com/project/robertmuehsig/electron-net/branch/master)
Build cross platform desktop apps with .NET Core and ASP.NET NET Core.
# Usage:
* To communicate with the "native" (sort of native...) Electron API include the [ElectronNET.API NuGet package](https://www.nuget.org/packages/ElectronNET.API/) in your ASP.NET Core app.
* For the tooling you will need your dotnet-electronize package [ElectronNET.CLI NuGet package](https://www.nuget.org/packages/ElectronNET.CLI/). This package __must__ be referenced in the .csproj like this:
```
<ItemGroup>
<DotNetCliToolReference Include="ElectronNET.CLI" Version="*" />
</ItemGroup>
```
* Make sure you have node.js and on OSX/Ubuntu the electron-packager installed (via "sudo npm install electron-packager --global")
* In your ASP.NET Core folder run:
```
dotnet electronize init
```
* Now a electronnet.manifest.json should appear in your ASP.NET Core project
* Now run the following:
```
dotnet electronize build
```
* In your default setting we just build the application for the OS you are running (Windows builds Windows, OSX builds OSX etc.), but this can be changed with:
```
dotnet electronize build win
dotnet electronize build osx
dotnet electronize build linux
```
* The end result should be a electron app under your /bin/desktop folder
## Dev Notes:
Currently there are two main projects and a "WebApp" that serves as a demo playground.
@@ -13,11 +49,7 @@ Currently there are two main projects and a "WebApp" that serves as a demo playg
Both projects create their own nuget package. The resulting nuget packages are saved under "/artifacts".
__Currently__ the packages are just build with version 1.0.0. If you change something you need to clear the nuget cache under this directory (because the version number doesn't change):
%userprofile%\.nuget\packages
The solution contains a NuGet.config which points to the artifacts directory, so we can just use the produced NuGet packages without uploading to NuGet.org.
__Currently__ the packages are just build with version 1.0.0 on your machine. NuGet might pick the wrong version from its own cache, so please read the dev notes if you want to develop!
__ElectronNET.WebApp:__
@@ -27,16 +59,14 @@ The WebApp now has referenced the API NuGet package and via the .csproj referenc
<DotNetCliToolReference Include="ElectronNET.CLI" Version="*" />
</ItemGroup>
## Dev Notes: Usage
Navigate to the WebApp folder and type this in a command prompt:
dotnet electronize
# Dev Notes: Dev Workflow (at least for the CLI extension is this a must)
# Dev Notes: Dev Workflow
(at least for the CLI extension)
* Change something in the CLI project
* rebuild the project (a nuget package should now appear in the /artifacts directory)
* make sure there is no ElectronNET.CLI package in your %userprofile%\.nuget\packages cache with the same version
* execute dotnet restore in the WebApp
* execute dotnet restore in the WebApp
* execute dotnet electronize

View File

@@ -1,7 +1,4 @@
version: 1.0.{build}
branches:
only:
- cli-etc
image: Visual Studio 2017
build_script:
- cmd: buildAll.cmd

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@@ -0,0 +1,10 @@
echo "Start building Electron.NET dev stack..."
echo "Restore & Build API"
cd ElectronNet.API
dotnet restore
dotnet pack /p:PackageVersion=0.0.1 --output %~dp0artifacts
cd ..
echo "Restore & Build API"
cd ElectronNet.CLI
dotnet restore
dotnet pack /p:PackageVersion=0.0.1 --output %~dp0artifacts