Merge branch 'master' into bug/318-rename-clitool

This commit is contained in:
Robert Muehsig
2019-12-01 22:49:46 +01:00
committed by GitHub
58 changed files with 746 additions and 2449 deletions

View File

@@ -18,6 +18,7 @@ namespace ElectronNET.CLI.Commands.Actions
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "commandLine.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");

View File

@@ -72,9 +72,8 @@ namespace ElectronNET.CLI.Commands
ProcessHelper.CmdExecute("npm install", targetFilePath);
// run typescript compiler
string tscPath = Path.Combine(targetFilePath, "node_modules", ".bin");
// ToDo: Not sure if this runs under linux/macos
ProcessHelper.CmdExecute(@"tsc -p ../../", tscPath);
ProcessHelper.CmdExecute(@"npx tsc -p ../../", targetFilePath);
// search .csproj
Console.WriteLine($"Search your .csproj to add configure CopyToPublishDirectory to 'Never'");

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ElectronNET.CLI.Commands.Actions;
@@ -40,6 +41,7 @@ namespace ElectronNET.CLI.Commands
private string _paramAbsoluteOutput = "absolute-path";
private string _paramPackageJson = "package-json";
private string _paramForceNodeInstall = "install-modules";
private string _manifest = "manifest";
public Task<bool> ExecuteAsync()
{
@@ -50,6 +52,13 @@ namespace ElectronNET.CLI.Commands
SimpleCommandLineParser parser = new SimpleCommandLineParser();
parser.Parse(_args);
if (!parser.Arguments.ContainsKey(_paramTarget))
{
Console.WriteLine($"Error: missing '{_paramTarget}' argument.");
Console.WriteLine(COMMAND_ARGUMENTS);
return false;
}
var desiredPlatform = parser.Arguments[_paramTarget][0];
string specifiedFromCustom = string.Empty;
if (desiredPlatform == "custom" && parser.Arguments[_paramTarget].Length > 1)
@@ -72,7 +81,13 @@ namespace ElectronNET.CLI.Commands
if (Directory.Exists(tempPath) == false)
{
Directory.CreateDirectory(tempPath);
}
else
{
Directory.Delete(tempPath, true);
Directory.CreateDirectory(tempPath);
}
Console.WriteLine("Executing dotnet publish in this directory: " + tempPath);
@@ -105,21 +120,6 @@ namespace ElectronNET.CLI.Commands
Console.WriteLine("Start npm install...");
ProcessHelper.CmdExecute("npm install --production", tempPath);
Console.WriteLine("Start npm install electron-builder...");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Works proper on Windows...
ProcessHelper.CmdExecute("npm install electron-builder --global", tempPath);
}
else
{
// ToDo: find another solution or document it proper
// GH Issue https://github.com/electron-userland/electron-prebuilt/issues/48
Console.WriteLine("Electron Builder - make sure you invoke 'sudo npm install electron-builder --global' at " + tempPath + " manually. Sry.");
}
Console.WriteLine("ElectronHostHook handling started...");
string electronhosthookDir = Path.Combine(Directory.GetCurrentDirectory(), "ElectronHostHook");
@@ -130,13 +130,10 @@ namespace ElectronNET.CLI.Commands
DirectoryCopy.Do(electronhosthookDir, hosthookDir, true, new List<string>() { "node_modules" });
Console.WriteLine("Start npm install for hosthooks...");
ProcessHelper.CmdExecute("npm install --production", hosthookDir);
ProcessHelper.CmdExecute("npm install", hosthookDir);
// ToDo: Global TypeScript installation is needed for ElectronHostHook
//string tscPath = Path.Combine(tempPath, "node_modules", ".bin");
// ToDo: Not sure if this runs under linux/macos
ProcessHelper.CmdExecute(@"tsc -p . --sourceMap false", hosthookDir);
ProcessHelper.CmdExecute(@"npx tsc -p . --sourceMap false", hosthookDir);
}
Console.WriteLine("Build Electron Desktop Application...");
@@ -168,10 +165,18 @@ namespace ElectronNET.CLI.Commands
// ToDo: Make the same thing easer with native c# - we can save a tmp file in production code :)
Console.WriteLine("Create electron-builder configuration file...");
ProcessHelper.CmdExecute($"node build-helper.js", tempPath);
string manifestFileName = "electron.manifest.json";
if(parser.Arguments.ContainsKey(_manifest))
{
manifestFileName = parser.Arguments[_manifest].First();
}
ProcessHelper.CmdExecute($"node build-helper.js " + manifestFileName, tempPath);
Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}...");
ProcessHelper.CmdExecute($"electron-builder . --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=5.0.8 {electronParams}", tempPath);
ProcessHelper.CmdExecute($"npx electron-builder . --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=7.1.2 {electronParams}", tempPath);
Console.WriteLine("... done");

View File

@@ -16,26 +16,30 @@ namespace ElectronNET.CLI.Commands
public const string COMMAND_ARGUMENTS = "<Path> from ASP.NET Core Project.";
public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
private const string ConfigName = "electron.manifest.json";
private string[] _args;
private static SimpleCommandLineParser _parser = new SimpleCommandLineParser();
private static string ConfigName = "electron.manifest.json";
private const string DefaultConfigFileName = "electron.manifest.json";
public InitCommand(string[] args)
{
_args = args;
_parser.Parse(args);
}
private static string _aspCoreProjectPath = "project-path";
private static string _manifest = "manifest";
public Task<bool> ExecuteAsync()
{
return Task.Run(() =>
{
string aspCoreProjectPath = "";
if (_args.Length > 0)
if (_parser.Arguments.ContainsKey(_aspCoreProjectPath))
{
if (Directory.Exists(_args[0]))
string projectPath = _parser.Arguments[_aspCoreProjectPath].First();
if (Directory.Exists(projectPath))
{
aspCoreProjectPath = _args[0];
aspCoreProjectPath = projectPath;
}
}
else
@@ -45,7 +49,15 @@ namespace ElectronNET.CLI.Commands
var currentDirectory = aspCoreProjectPath;
Console.WriteLine("Adding our config file to your project...");
if(_parser.Arguments.ContainsKey(_manifest))
{
ConfigName = "electron.manifest." + _parser.Arguments[_manifest].First() + ".json";
Console.WriteLine($"Adding your custom {ConfigName} config file to your project...");
}
else
{
Console.WriteLine("Adding our config file to your project...");
}
var targetFilePath = Path.Combine(currentDirectory, ConfigName);
@@ -56,7 +68,7 @@ namespace ElectronNET.CLI.Commands
}
// Deploy config file
EmbeddedFileHelper.DeployEmbeddedFile(currentDirectory, ConfigName);
EmbeddedFileHelper.DeployEmbeddedFileToTargetFile(currentDirectory, DefaultConfigFileName, ConfigName);
// search .csproj
Console.WriteLine($"Search your .csproj to add the needed {ConfigName}...");
@@ -99,7 +111,32 @@ namespace ElectronNET.CLI.Commands
string launchSettingText = File.ReadAllText(launchSettingFile);
if (launchSettingText.Contains("\"executablePath\": \"electronize\"") == false)
if(_parser.Arguments.ContainsKey(_manifest))
{
string manifestName = _parser.Arguments[_manifest].First();
if(launchSettingText.Contains("start /manifest " + ConfigName) == false)
{
StringBuilder debugProfileBuilder = new StringBuilder();
debugProfileBuilder.AppendLine("profiles\": {");
debugProfileBuilder.AppendLine(" \"Electron.NET App - " + manifestName + "\": {");
debugProfileBuilder.AppendLine(" \"commandName\": \"Executable\",");
debugProfileBuilder.AppendLine(" \"executablePath\": \"electronize\",");
debugProfileBuilder.AppendLine(" \"commandLineArgs\": \"start /manifest " + ConfigName + "\",");
debugProfileBuilder.AppendLine(" \"workingDirectory\": \".\"");
debugProfileBuilder.AppendLine(" },");
launchSettingText = launchSettingText.Replace("profiles\": {", debugProfileBuilder.ToString());
File.WriteAllText(launchSettingFile, launchSettingText);
Console.WriteLine($"Debug profile added!");
}
else
{
Console.WriteLine($"Debug profile already existing");
}
}
else if (launchSettingText.Contains("\"executablePath\": \"electronize\"") == false)
{
StringBuilder debugProfileBuilder = new StringBuilder();
debugProfileBuilder.AppendLine("profiles\": {");

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ElectronNET.CLI.Commands.Actions;
@@ -21,19 +22,27 @@ namespace ElectronNET.CLI.Commands
_args = args;
}
private string _aspCoreProjectPath = "project-path";
private string _arguments = "args";
private string _manifest = "manifest";
public Task<bool> ExecuteAsync()
{
return Task.Run(() =>
{
Console.WriteLine("Start Electron Desktop Application...");
SimpleCommandLineParser parser = new SimpleCommandLineParser();
parser.Parse(_args);
string aspCoreProjectPath = "";
if (_args.Length > 0)
if (parser.Arguments.ContainsKey(_aspCoreProjectPath))
{
if (Directory.Exists(_args[0]))
string projectPath = parser.Arguments[_aspCoreProjectPath].First();
if (Directory.Exists(projectPath))
{
aspCoreProjectPath = _args[0];
aspCoreProjectPath = projectPath;
}
}
else
@@ -76,27 +85,37 @@ namespace ElectronNET.CLI.Commands
string hosthookDir = Path.Combine(tempPath, "ElectronHostHook");
DirectoryCopy.Do(electronhosthookDir, hosthookDir, true, new List<string>() { "node_modules" });
Console.WriteLine("Start npm install for hosthooks...");
Console.WriteLine("Start npm install for typescript & hosthooks...");
ProcessHelper.CmdExecute("npm install", hosthookDir);
string tscPath = Path.Combine(tempPath, "node_modules", ".bin");
// ToDo: Not sure if this runs under linux/macos
ProcessHelper.CmdExecute(@"tsc -p ../../ElectronHostHook", tscPath);
ProcessHelper.CmdExecute(@"npx tsc -p ../../ElectronHostHook", tempPath);
}
string arguments = "";
if (parser.Arguments.ContainsKey(_arguments))
{
arguments = string.Join(' ', parser.Arguments[_arguments]);
}
if (parser.Arguments.ContainsKey(_manifest))
{
arguments += " --manifest=" + parser.Arguments[_manifest].First();
}
string path = Path.Combine(tempPath, "node_modules", ".bin");
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
if (isWindows)
{
Console.WriteLine("Invoke electron.cmd - in dir: " + path);
ProcessHelper.CmdExecute(@"electron.cmd ""..\..\main.js""", path);
ProcessHelper.CmdExecute(@"electron.cmd ""..\..\main.js"" " + arguments, path);
}
else
{
Console.WriteLine("Invoke electron - in dir: " + path);
ProcessHelper.CmdExecute(@"./electron ""../../main.js""", path);
ProcessHelper.CmdExecute(@"./electron ""../../main.js"" " + arguments, path);
}
return true;

View File

@@ -2,19 +2,24 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AssemblyName>dotnet-electronize</AssemblyName>
<ToolCommandName>electronize</ToolCommandName>
<PackageType>DotnetCliTool</PackageType>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageOutputPath>..\artifacts</PackageOutputPath>
<PackageId>ElectronNET.CLI</PackageId>
<!-- Version 99 is just set for local development stuff to avoid a conflict with "real" packages on NuGet.org -->
<Version>99.0.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 Core.
This package contains the dotnet tooling to electronize your application.</Description>
<Description>
Building cross platform electron based desktop apps with .NET Core and ASP.NET Core.
This package contains the dotnet tooling to electronize your application.
</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/ElectronNET/Electron.NET/</PackageProjectUrl>
<RepositoryUrl>https://github.com/ElectronNET/Electron.NET/</RepositoryUrl>
@@ -22,7 +27,7 @@ This package contains the dotnet tooling to electronize your application.</Descr
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PackageTags>electron aspnetcore</PackageTags>
<PackageReleaseNotes>Changelog: https://github.com/ElectronNET/Electron.NET/blob/master/Changelog.md</PackageReleaseNotes>
<PackageIconUrl>https://raw.githubusercontent.com/ElectronNET/Electron.NET/master/assets/images/electron.net-logo-square.png</PackageIconUrl>
<PackageIcon>PackageIcon.png</PackageIcon>
<PackAsTool>true</PackAsTool>
</PropertyGroup>
@@ -31,72 +36,39 @@ This package contains the dotnet tooling to electronize your application.</Descr
<None Remove="ElectronHost\package.json" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile></DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="PackageIcon.png" Pack="true" PackagePath="\"/>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile></DocumentationFile>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\electron.manifest.json" Link="ElectronHost\electron.manifest.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\package.json" Link="ElectronHost\package.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\main.js" Link="ElectronHost\main.js" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\build-helper.js" Link="ElectronHost\build-helper.js" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\api\ipc.js" Link="ElectronHost\api\ipc.js" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\index.ts" Link="ElectronHost\ElectronHostHook\index.ts" />
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\connector.ts" Link="ElectronHost\ElectronHostHook\connector.ts" />
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\tsconfig.json" Link="ElectronHost\ElectronHostHook\tsconfig.json" />
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\package.json" Link="ElectronHost\ElectronHostHook\package.json" />
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\.gitignore" Link="ElectronHost\ElectronHostHook\.gitignore" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\connector.ts" Link="ElectronHost\ElectronHostHook\connector.ts" />
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\tsconfig.json" Link="ElectronHost\ElectronHostHook\tsconfig.json" />
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\package.json" Link="ElectronHost\ElectronHostHook\package.json" />
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\.gitignore" Link="ElectronHost\ElectronHostHook\.gitignore" />
<EmbeddedResource Include="..\ElectronNET.Host\splashscreen\index.html" Link="ElectronHost\splashscreen\index.html" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\api\app.js" Link="ElectronHost\api\app.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\browserWindows.js" Link="ElectronHost\api\browserWindows.js" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\api\commandLine.js" Link="ElectronHost\api\commandLine.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\dialog.js" Link="ElectronHost\api\dialog.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\menu.js" Link="ElectronHost\api\menu.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\notification.js" Link="ElectronHost\api\notification.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\tray.js" Link="ElectronHost\api\tray.js" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\api\globalShortcut.js" Link="ElectronHost\api\globalShortcut.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\screen.js" Link="ElectronHost\api\screen.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\shell.js" Link="ElectronHost\api\shell.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\webContents.js" Link="ElectronHost\api\webContents.js" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\api\clipboard.js" Link="ElectronHost\api\clipboard.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\autoUpdater.js" Link="ElectronHost\api\autoUpdater.js" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View File

@@ -29,5 +29,19 @@ namespace ElectronNET.CLI
streamFromEmbeddedFile.CopyTo(fileStream);
}
}
public static void DeployEmbeddedFileToTargetFile(string targetPath, string embeddedFile, string targetFile, string namespacePath = "")
{
using (var fileStream = File.Create(Path.Combine(targetPath, targetFile)))
{
var streamFromEmbeddedFile = GetTestResourceFileStream("ElectronHost." + namespacePath + embeddedFile);
if (streamFromEmbeddedFile == null)
{
Console.WriteLine("Error: Couldn't find embedded file: " + embeddedFile);
}
streamFromEmbeddedFile.CopyTo(fileStream);
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB