From e169f6b810af4021c18ffbd8f9c3d556309d08e8 Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Sun, 8 Oct 2017 22:39:04 +0200 Subject: [PATCH 01/13] osx first test --- .vscode/launch.json | 28 ++++++++++++++++++++++++++++ .vscode/tasks.json | 16 ++++++++++++++++ NuGet.config | 2 ++ 3 files changed, 46 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ff9df19 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceRoot}/ElectronNET.CLI/bin/Debug/netcoreapp2.0/dotnet-electronize.dll", + "args": [], + "cwd": "${workspaceRoot}/ElectronNET.CLI", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..03e64bf --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,16 @@ +{ + "version": "0.1.0", + "command": "dotnet", + "isShellCommand": true, + "args": [], + "tasks": [ + { + "taskName": "build", + "args": [ + "${workspaceRoot}/ElectronNET.CLI/ElectronNET.CLI.csproj" + ], + "isBuildCommand": true, + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/NuGet.config b/NuGet.config index 01f8e3e..822deb3 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,6 +1,8 @@ + + From b1ad790c413fa4dbee228021bf76775681bf2abe Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Sun, 8 Oct 2017 22:53:17 +0200 Subject: [PATCH 02/13] condition for windows --- ElectronNET.API/ElectronNET.API.csproj | 2 +- ElectronNET.CLI/ElectronNET.CLI.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ElectronNET.API/ElectronNET.API.csproj b/ElectronNET.API/ElectronNET.API.csproj index 5c20f7f..a50addc 100644 --- a/ElectronNET.API/ElectronNET.API.csproj +++ b/ElectronNET.API/ElectronNET.API.csproj @@ -12,7 +12,7 @@ - + diff --git a/ElectronNET.CLI/ElectronNET.CLI.csproj b/ElectronNET.CLI/ElectronNET.CLI.csproj index f8dc6f7..35b831e 100644 --- a/ElectronNET.CLI/ElectronNET.CLI.csproj +++ b/ElectronNET.CLI/ElectronNET.CLI.csproj @@ -34,7 +34,7 @@ - + From 4903384bd456ceda91224ee57e35d80703b0c096 Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Sun, 8 Oct 2017 23:22:20 +0200 Subject: [PATCH 03/13] osx for aspnet? --- ElectronNET.CLI/Commands/BuildCommand.cs | 19 +++++++++++++++++-- ElectronNET.CLI/ProcessHelper.cs | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index c240da9..47c64d9 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Runtime.InteropServices; using System.Threading.Tasks; namespace ElectronNET.CLI.Commands @@ -16,14 +17,28 @@ namespace ElectronNET.CLI.Commands { return Task.Run(() => { - Console.WriteLine("Build Windows Application..."); + Console.WriteLine("Build Electron Application..."); string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop"); Console.WriteLine("Executing dotnet publish in this directory: " + tempPath); string tempBinPath = Path.Combine(tempPath, "bin"); - ProcessHelper.CmdExecute($"dotnet publish -r win10-x64 --output \"{tempBinPath}\"", Directory.GetCurrentDirectory()); + + bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + if (isWindows) + { + Console.WriteLine("Build ASP.NET Core App for Windows..."); + + ProcessHelper.CmdExecute($"dotnet publish -r win10-x64 --output \"{tempBinPath}\"", Directory.GetCurrentDirectory()); + } + else + { + Console.WriteLine("Build ASP.NET Core App for OSX..."); + + // ToDo: Linux... (or maybe via an argument, but this is just for development) + ProcessHelper.CmdExecute($"dotnet publish -r osx-x64 --output \"{tempBinPath}\"", Directory.GetCurrentDirectory()); + } if (Directory.Exists(tempPath) == false) { diff --git a/ElectronNET.CLI/ProcessHelper.cs b/ElectronNET.CLI/ProcessHelper.cs index 3263ba3..775a0c9 100644 --- a/ElectronNET.CLI/ProcessHelper.cs +++ b/ElectronNET.CLI/ProcessHelper.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Runtime.InteropServices; namespace ElectronNET.CLI { @@ -9,7 +10,19 @@ namespace ElectronNET.CLI { using (Process cmd = new Process()) { - cmd.StartInfo.FileName = "cmd.exe"; + bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + + if (isWindows) + { + cmd.StartInfo.FileName = "cmd.exe"; + } + else + { + // ToDo: Linux... + + cmd.StartInfo.FileName = "bash"; + } + cmd.StartInfo.RedirectStandardInput = true; cmd.StartInfo.RedirectStandardOutput = true; cmd.StartInfo.CreateNoWindow = true; From cfeb3dde1e87b646f134fdf935bee14cc858f0f3 Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Sun, 8 Oct 2017 23:08:24 +0200 Subject: [PATCH 04/13] osx compatibilty --- NuGet.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.config b/NuGet.config index 822deb3..9eb1b6d 100644 --- a/NuGet.config +++ b/NuGet.config @@ -3,7 +3,7 @@ - + \ No newline at end of file From 418efd8d49b9f502007e8f10e8e76080c1246ab4 Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Sun, 8 Oct 2017 23:56:04 +0200 Subject: [PATCH 05/13] dirty osx tricks --- ElectronNET.CLI/Commands/BuildCommand.cs | 27 +++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index 47c64d9..1663b38 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -60,14 +60,35 @@ namespace ElectronNET.CLI.Commands ProcessHelper.CmdExecute("npm install", tempPath); Console.WriteLine("Start npm install electron-packager..."); - ProcessHelper.CmdExecute("npm install electron-packager --global", tempPath); + + if (isWindows) + { + ProcessHelper.CmdExecute("npm install electron-packager --global", tempPath); + } + else + { + // ToDo: check if it is safe to use sudo npm... + Console.WriteLine("Electron Packager - make sure you invoke 'npm install electron - packager--global' at " + tempPath + " manually. Sry."); + } Console.WriteLine("Build Electron Desktop Application..."); string buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop"); Console.WriteLine("Executing electron magic in this directory: " + buildPath); - // Need a solution for --asar support - ProcessHelper.CmdExecute($"electron-packager . --platform=win32 --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath); + // ToDo: Need a solution for --asar support + if (isWindows) + { + Console.WriteLine("Package Electron App for Windows..."); + + ProcessHelper.CmdExecute($"electron-packager . --platform=win32 --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath); + } + else + { + Console.WriteLine("Package Electron App for Windows..."); + + // ToDo: Linux... (or maybe via an argument, but this is just for development) + ProcessHelper.CmdExecute($"electron-packager . --platform=darwin --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath); + } return true; }); From d75259e2a6e57a9094eaaa21804e669045eb2b2d Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Mon, 9 Oct 2017 00:13:04 +0200 Subject: [PATCH 06/13] small changes regarding osx build --- ElectronNET.CLI/Commands/BuildCommand.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index 1663b38..0182b6e 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -67,8 +67,9 @@ namespace ElectronNET.CLI.Commands } else { - // ToDo: check if it is safe to use sudo npm... - Console.WriteLine("Electron Packager - make sure you invoke 'npm install electron - packager--global' at " + tempPath + " manually. Sry."); + // ToDo: find another solution or document it proper + // GH Issue https://github.com/electron-userland/electron-prebuilt/issues/48 + Console.WriteLine("Electron Packager - make sure you invoke 'sudo npm install electron - packager--global' at " + tempPath + " manually. Sry."); } Console.WriteLine("Build Electron Desktop Application..."); @@ -84,7 +85,7 @@ namespace ElectronNET.CLI.Commands } else { - Console.WriteLine("Package Electron App for Windows..."); + Console.WriteLine("Package Electron App for OSX..."); // ToDo: Linux... (or maybe via an argument, but this is just for development) ProcessHelper.CmdExecute($"electron-packager . --platform=darwin --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath); From cd73d1464e5f91ca13a8a371160cc482b683ef8c Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Wed, 11 Oct 2017 23:18:55 +0200 Subject: [PATCH 07/13] osx fix --- ElectronNET.Host/main.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index 2045e43..fc469c1 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -70,10 +70,10 @@ app.on('window-all-closed', () => { } }); -app.on('activate', () => { +//app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. - if (win === null) { - createWindow(); - } -}); \ No newline at end of file +// if (win === null) { +// createWindow(); +// } +//}); \ No newline at end of file From fa666eda27ea131ffbdc0a58ff023e162fb19f92 Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Wed, 11 Oct 2017 23:29:58 +0200 Subject: [PATCH 08/13] linux support --- ElectronNET.CLI/Commands/BuildCommand.cs | 30 +++++++++++++++++------- ElectronNET.CLI/ProcessHelper.cs | 3 +-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index 0182b6e..9e0cc91 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -25,21 +25,27 @@ namespace ElectronNET.CLI.Commands string tempBinPath = Path.Combine(tempPath, "bin"); - bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - if (isWindows) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console.WriteLine("Build ASP.NET Core App for Windows..."); ProcessHelper.CmdExecute($"dotnet publish -r win10-x64 --output \"{tempBinPath}\"", Directory.GetCurrentDirectory()); } - else + + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Console.WriteLine("Build ASP.NET Core App for OSX..."); - // ToDo: Linux... (or maybe via an argument, but this is just for development) ProcessHelper.CmdExecute($"dotnet publish -r osx-x64 --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) { Directory.CreateDirectory(tempPath); @@ -61,8 +67,9 @@ namespace ElectronNET.CLI.Commands Console.WriteLine("Start npm install electron-packager..."); - if (isWindows) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { + // Works proper on Windows... ProcessHelper.CmdExecute("npm install electron-packager --global", tempPath); } else @@ -77,20 +84,27 @@ namespace ElectronNET.CLI.Commands Console.WriteLine("Executing electron magic in this directory: " + buildPath); // ToDo: Need a solution for --asar support - if (isWindows) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console.WriteLine("Package Electron App for Windows..."); ProcessHelper.CmdExecute($"electron-packager . --platform=win32 --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath); } - else + + if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Console.WriteLine("Package Electron App for OSX..."); - // ToDo: Linux... (or maybe via an argument, but this is just for development) 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); + } + return true; }); } diff --git a/ElectronNET.CLI/ProcessHelper.cs b/ElectronNET.CLI/ProcessHelper.cs index 775a0c9..605d0c8 100644 --- a/ElectronNET.CLI/ProcessHelper.cs +++ b/ElectronNET.CLI/ProcessHelper.cs @@ -18,8 +18,7 @@ namespace ElectronNET.CLI } else { - // ToDo: Linux... - + // works for OSX and Linux (at least on Ubuntu) cmd.StartInfo.FileName = "bash"; } From 32e2ba24f3c835933a012568de682ce4b002e008 Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Thu, 12 Oct 2017 22:31:51 +0200 Subject: [PATCH 09/13] swallow error message --- ElectronNET.API/devCleanup.cmd | 2 +- ElectronNET.CLI/devCleanup.cmd | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ElectronNET.API/devCleanup.cmd b/ElectronNET.API/devCleanup.cmd index 23931d4..1ea3754 100644 --- a/ElectronNET.API/devCleanup.cmd +++ b/ElectronNET.API/devCleanup.cmd @@ -1 +1 @@ -rd /s /q %userprofile%\.nuget\packages\electronnet.api +rd /s /q %userprofile%\.nuget\packages\electronnet.api 2>nul diff --git a/ElectronNET.CLI/devCleanup.cmd b/ElectronNET.CLI/devCleanup.cmd index 611fffc..803ea4f 100644 --- a/ElectronNET.CLI/devCleanup.cmd +++ b/ElectronNET.CLI/devCleanup.cmd @@ -1,2 +1,2 @@ -rd /s /q %userprofile%\.nuget\packages\.tools\electronnet.cli -rd /s /q %userprofile%\.nuget\packages\electronnet.cli +rd /s /q %userprofile%\.nuget\packages\.tools\electronnet.cli 2>nul +rd /s /q %userprofile%\.nuget\packages\electronnet.cli 2>nul From d099363fb97f4b108d778b6d3c0f1b105b30f27f Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Thu, 12 Oct 2017 22:44:07 +0200 Subject: [PATCH 10/13] ignore exit code --- ElectronNET.API/ElectronNET.API.csproj | 2 +- ElectronNET.CLI/ElectronNET.CLI.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ElectronNET.API/ElectronNET.API.csproj b/ElectronNET.API/ElectronNET.API.csproj index a50addc..04863a3 100644 --- a/ElectronNET.API/ElectronNET.API.csproj +++ b/ElectronNET.API/ElectronNET.API.csproj @@ -13,7 +13,7 @@ - + diff --git a/ElectronNET.CLI/ElectronNET.CLI.csproj b/ElectronNET.CLI/ElectronNET.CLI.csproj index 35b831e..410138e 100644 --- a/ElectronNET.CLI/ElectronNET.CLI.csproj +++ b/ElectronNET.CLI/ElectronNET.CLI.csproj @@ -35,7 +35,7 @@ - + From f3050b9dc452db4296cd2fc4476cfe1c1455122e Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Sun, 15 Oct 2017 00:08:15 +0200 Subject: [PATCH 11/13] init --- ElectronNET.CLI/Commands/BuildCommand.cs | 8 +- ElectronNET.CLI/Commands/InitCommand.cs | 93 +++++++++++++++++++ .../Commands/StartElectronCommand.cs | 8 +- ElectronNET.CLI/ElectronNET.CLI.csproj | 2 + ElectronNET.CLI/EmbeddedFileHelper.cs | 2 +- ElectronNET.CLI/Program.cs | 5 + ElectronNET.CLI/electronnet.json | 3 + ElectronNET.WebApp/ElectronNET.WebApp.csproj | 12 ++- ElectronNET.WebApp/electronnet.json | 3 + 9 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 ElectronNET.CLI/Commands/InitCommand.cs create mode 100644 ElectronNET.CLI/electronnet.json create mode 100644 ElectronNET.WebApp/electronnet.json diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index 9e0cc91..329a1a3 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -51,16 +51,16 @@ namespace ElectronNET.CLI.Commands Directory.CreateDirectory(tempPath); } - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js"); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json"); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json"); + EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js", "ElectronHost."); + EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json", "ElectronHost."); + EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json", "ElectronHost."); string hostApiFolder = Path.Combine(tempPath, "api"); if (Directory.Exists(hostApiFolder) == false) { Directory.CreateDirectory(hostApiFolder); } - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "ElectronHost.api."); Console.WriteLine("Start npm install..."); ProcessHelper.CmdExecute("npm install", tempPath); diff --git a/ElectronNET.CLI/Commands/InitCommand.cs b/ElectronNET.CLI/Commands/InitCommand.cs new file mode 100644 index 0000000..6cfbfe1 --- /dev/null +++ b/ElectronNET.CLI/Commands/InitCommand.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ElectronNET.CLI.Commands +{ + public class InitCommand : ICommand + { + public const string COMMAND_NAME = "init"; + public const string COMMAND_DESCRIPTION = "Creates the needed Electron.NET config for your Electron Application."; + public const string COMMAND_ARGUMENTS = " from ASP.NET Core Project."; + public static IList CommandOptions { get; set; } = new List(); + + private const string ConfigName = "electronnet.json"; + + public Task ExecuteAsync() + { + return Task.Run(() => + { + var currentDirectory = Directory.GetCurrentDirectory(); + + Console.WriteLine("Adding our config file to your project..."); + + var targetFilePath = Path.Combine(currentDirectory, ConfigName); + + if (File.Exists(targetFilePath)) + { + Console.WriteLine("Config file already in your project."); + return false; + } + + // Deploy config file + EmbeddedFileHelper.DeployEmbeddedFile(currentDirectory, ConfigName); + + // search .csproj + Console.WriteLine($"Search your .csproj to add the needed {ConfigName}..."); + var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault(); + + // update config file with the name of the csproj + // ToDo: If the csproj name != application name, this will fail + string text = File.ReadAllText(targetFilePath); + text = text.Replace("{{executable}}", Path.GetFileNameWithoutExtension(projectFile)); + File.WriteAllText(targetFilePath, text); + + Console.WriteLine($"Found your .csproj: {projectFile} - check for existing config or update it."); + + using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite)) + { + var xmlDocument = XDocument.Load(stream); + + var projectElement = xmlDocument.Descendants("Project").FirstOrDefault(); + if (projectElement == null || projectElement.Attribute("Sdk")?.Value != "Microsoft.NET.Sdk.Web") + { + Console.WriteLine($"Project file is not a compatible type of 'Microsoft.NET.Sdk.Web'. Your project: {projectElement?.Attribute("Sdk")?.Value}"); + return false; + } + + if (xmlDocument.ToString().Contains($"Content Update=\"{ConfigName}\"")) + { + Console.WriteLine($"{ConfigName} already in csproj."); + return false; + } + + Console.WriteLine($"{ConfigName} will be added to csproj."); + + string itemGroupXmlString = "" + + "" + + "PreserveNewest" + + "" + + ""; + + var newItemGroupForConfig = XElement.Parse(itemGroupXmlString); + xmlDocument.Root.Add(newItemGroupForConfig); + + stream.SetLength(0); + stream.Position = 0; + + xmlDocument.Save(stream); + + Console.WriteLine($"{ConfigName} added in csproj - happy electronizing!"); + } + + return true; + }); + } + + + } +} diff --git a/ElectronNET.CLI/Commands/StartElectronCommand.cs b/ElectronNET.CLI/Commands/StartElectronCommand.cs index c0e4995..541d832 100644 --- a/ElectronNET.CLI/Commands/StartElectronCommand.cs +++ b/ElectronNET.CLI/Commands/StartElectronCommand.cs @@ -49,16 +49,16 @@ namespace ElectronNET.CLI.Commands string tempBinPath = Path.Combine(tempPath, "bin"); ProcessHelper.CmdExecute($"dotnet publish -r win10-x64 --output \"{tempBinPath}\"", aspCoreProjectPath); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js"); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json"); - EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json"); + EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js", "ElectronHost."); + EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json", "ElectronHost."); + EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json", "ElectronHost."); string hostApiFolder = Path.Combine(tempPath, "api"); if (Directory.Exists(hostApiFolder) == false) { Directory.CreateDirectory(hostApiFolder); } - EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api."); + EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "ElectronHost.api."); Console.WriteLine("Start npm install..."); ProcessHelper.CmdExecute("npm install", tempPath); diff --git a/ElectronNET.CLI/ElectronNET.CLI.csproj b/ElectronNET.CLI/ElectronNET.CLI.csproj index 410138e..1078d20 100644 --- a/ElectronNET.CLI/ElectronNET.CLI.csproj +++ b/ElectronNET.CLI/ElectronNET.CLI.csproj @@ -15,6 +15,7 @@ + @@ -24,6 +25,7 @@ + diff --git a/ElectronNET.CLI/EmbeddedFileHelper.cs b/ElectronNET.CLI/EmbeddedFileHelper.cs index bcaa246..aa405e3 100644 --- a/ElectronNET.CLI/EmbeddedFileHelper.cs +++ b/ElectronNET.CLI/EmbeddedFileHelper.cs @@ -19,7 +19,7 @@ namespace ElectronNET.CLI { using (var fileStream = File.Create(Path.Combine(targetPath, file))) { - var streamFromEmbeddedFile = GetTestResourceFileStream("ElectronHost." + namespacePath + file); + var streamFromEmbeddedFile = GetTestResourceFileStream(namespacePath + file); streamFromEmbeddedFile.CopyTo(fileStream); } } diff --git a/ElectronNET.CLI/Program.cs b/ElectronNET.CLI/Program.cs index b851cdf..63caac0 100644 --- a/ElectronNET.CLI/Program.cs +++ b/ElectronNET.CLI/Program.cs @@ -4,9 +4,11 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; +using System.Xml.Linq; namespace ElectronNET.CLI { + class Program { static void Main(string[] args) @@ -28,6 +30,9 @@ namespace ElectronNET.CLI case BuildCommand.COMMAND_NAME: command = new BuildCommand(); break; + case InitCommand.COMMAND_NAME: + command = new InitCommand(); + break; case "--help": case "--h": case "help": diff --git a/ElectronNET.CLI/electronnet.json b/ElectronNET.CLI/electronnet.json new file mode 100644 index 0000000..653cc60 --- /dev/null +++ b/ElectronNET.CLI/electronnet.json @@ -0,0 +1,3 @@ +{ + "executable": "{{executable}}" +} \ No newline at end of file diff --git a/ElectronNET.WebApp/ElectronNET.WebApp.csproj b/ElectronNET.WebApp/ElectronNET.WebApp.csproj index 33d154c..5143f4d 100644 --- a/ElectronNET.WebApp/ElectronNET.WebApp.csproj +++ b/ElectronNET.WebApp/ElectronNET.WebApp.csproj @@ -1,14 +1,12 @@ + - netcoreapp2.0 win10-x64 - - @@ -20,8 +18,12 @@ - - + + + PreserveNewest + + + \ No newline at end of file diff --git a/ElectronNET.WebApp/electronnet.json b/ElectronNET.WebApp/electronnet.json new file mode 100644 index 0000000..4ada330 --- /dev/null +++ b/ElectronNET.WebApp/electronnet.json @@ -0,0 +1,3 @@ +{ + "executable": "ElectronNET.WebApp" +} \ No newline at end of file From 8d59cebfa0b5e6e9686bc4cfc81b4315ff84cc06 Mon Sep 17 00:00:00 2001 From: Robert Muehsig Date: Sun, 15 Oct 2017 00:08:32 +0200 Subject: [PATCH 12/13] todo added --- ElectronNET.Host/main.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index fc469c1..51db14f 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -48,6 +48,10 @@ function startAspCoreBackend(electronPort) { var binPath = path.join(__dirname, 'bin'); fs.readdir(binPath, (error, files) => { + + // ToDo: Read 'electronnet.json and use the exectuable' + // add '.exe' to the exectuable name on windows and leave as is on linux/mac and we are done + const exeFiles = files.filter((name) => name.indexOf('.exe') > -1); const exeFileName = exeFiles[0]; const apipath = path.join(binPath, exeFileName); From f2fe86c250f5039261338c456aa2a01634703cde Mon Sep 17 00:00:00 2001 From: Gregor Biswanger Date: Sun, 15 Oct 2017 21:56:56 +0200 Subject: [PATCH 13/13] implement execute binary file from manifest json file config --- ElectronNET.Host/main.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index 51db14f..5b2e0c1 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -1,5 +1,4 @@ const { app, BrowserWindow, Notification } = require('electron'); -const fs = require('fs'); const path = require('path'); const process = require('child_process').spawn; const portfinder = require('detect-port'); @@ -44,23 +43,22 @@ function startSocketApiBridge(port) { function startAspCoreBackend(electronPort) { portfinder(8000, (error, electronWebPort) => { loadURL = `http://localhost:${electronWebPort}` - const arguments = [`/electronPort=${electronPort}`, `/electronWebPort=${electronWebPort}`]; + const parameters = [`/electronPort=${electronPort}`, `/electronWebPort=${electronWebPort}`]; - var binPath = path.join(__dirname, 'bin'); - fs.readdir(binPath, (error, files) => { + const manifestFile = require("./bin/electronnet.json"); + let binaryFile = manifestFile.executable; + + const os = require("os"); + if(os.platform() === "win32") { + binaryFile = binaryFile + '.exe'; + } + + const binFilePath = path.join(__dirname, 'bin', binaryFile); + apiProcess = process(binFilePath, parameters); - // ToDo: Read 'electronnet.json and use the exectuable' - // add '.exe' to the exectuable name on windows and leave as is on linux/mac and we are done - - const exeFiles = files.filter((name) => name.indexOf('.exe') > -1); - const exeFileName = exeFiles[0]; - const apipath = path.join(binPath, exeFileName); - apiProcess = process(apipath, arguments); - - apiProcess.stdout.on('data', (data) => { - var text = data.toString(); - console.log(`stdout: ${data.toString()}`); - }); + apiProcess.stdout.on('data', (data) => { + var text = data.toString(); + console.log(`stdout: ${data.toString()}`); }); }); }