Content-Length: 1058945 | pFad | http://github.com/ElectronNET/Electron.NET/commit/f6d17406cd8d19a2af8095421a199edc6ed1a181

4E Cleanup and improvements · ElectronNET/Electron.NET@f6d1740 · GitHub
Skip to content

Commit f6d1740

Browse files
committed
Cleanup and improvements
1 parent 9e79665 commit f6d1740

File tree

17 files changed

+214
-199
lines changed

17 files changed

+214
-199
lines changed

src/ElectronNET.CLI/Commands/Actions/DirectoryCopy.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,55 @@ public static class DirectoryCopy
88
public static void Do(string sourceDirName, string destDirName, bool copySubDirs, List<string> ignoredSubDirs)
99
{
1010
// Get the subdirectories for the specified directory.
11-
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
11+
var dir = new DirectoryInfo(sourceDirName);
1212

1313
if (!dir.Exists)
1414
{
15-
throw new DirectoryNotFoundException(
16-
"Source directory does not exist or could not be found: "
17-
+ sourceDirName);
15+
throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName);
1816
}
1917

20-
DirectoryInfo[] dirs = dir.GetDirectories();
18+
var dirs = dir.GetDirectories();
19+
2120
// If the destination directory doesn't exist, create it.
2221
if (!Directory.Exists(destDirName))
2322
{
2423
Directory.CreateDirectory(destDirName);
2524
}
2625
else
2726
{
28-
DirectoryInfo targetDir = new DirectoryInfo(destDirName);
27+
var targetDir = new DirectoryInfo(destDirName);
2928

30-
foreach (FileInfo fileDel in targetDir.EnumerateFiles())
29+
foreach (var fileDel in targetDir.EnumerateFiles())
3130
{
3231
fileDel.Delete();
3332
}
34-
foreach (DirectoryInfo dirDel in targetDir.EnumerateDirectories())
33+
34+
foreach (var dirDel in targetDir.EnumerateDirectories())
3535
{
3636
dirDel.Delete(true);
3737
}
3838
}
3939

40-
41-
42-
4340
// Get the files in the directory and copy them to the new location.
44-
FileInfo[] files = dir.GetFiles();
45-
foreach (FileInfo file in files)
41+
var files = dir.GetFiles();
42+
43+
foreach (var file in files)
4644
{
47-
string temppath = Path.Combine(destDirName, file.Name);
45+
var temppath = Path.Combine(destDirName, file.Name);
4846
file.CopyTo(temppath, false);
4947
}
5048

5149
// If copying subdirectories, copy them and their contents to new location.
5250
if (copySubDirs)
5351
{
54-
foreach (DirectoryInfo subdir in dirs)
52+
foreach (var subdir in dirs)
5553
{
5654
if (ignoredSubDirs.Contains(subdir.Name))
5755
{
5856
continue;
5957
}
6058

61-
string temppath = Path.Combine(destDirName, subdir.Name);
59+
var temppath = Path.Combine(destDirName, subdir.Name);
6260
Do(subdir.FullName, temppath, copySubDirs, ignoredSubDirs);
6361
}
6462
}

src/ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ public struct GetTargetPlatformInformationResult
99
{
1010
public string NetCorePublishRid { get; set; }
1111
public string ElectronPackerPlatform { get; set; }
12-
1312
}
1413

1514
public static GetTargetPlatformInformationResult Do(string desiredPlatform, string specifiedPlatfromFromCustom)
1615
{
17-
string netCorePublishRid = string.Empty;
18-
string electronPackerPlatform = string.Empty;
16+
var netCorePublishRid = string.Empty;
17+
var electronPackerPlatform = string.Empty;
1918

2019
switch (desiredPlatform)
2120
{
@@ -60,7 +59,7 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri
6059
break;
6160
}
6261

63-
return new GetTargetPlatformInformationResult()
62+
return new GetTargetPlatformInformationResult
6463
{
6564
ElectronPackerPlatform = electronPackerPlatform,
6665
NetCorePublishRid = netCorePublishRid

src/ElectronNET.CLI/Commands/AddCommand.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class AddCommand : ICommand
1515
public const string COMMAND_ARGUMENTS = "hosthook";
1616
public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
1717

18-
1918
private string[] _args;
2019

2120
public AddCommand(string[] args)
@@ -41,15 +40,21 @@ public Task<bool> ExecuteAsync()
4140

4241
// Maybe ToDo: Adding the possiblity to specify a path (like we did in the InitCommand, but this would require a better command args parser)
4342
var currentDirectory = Directory.GetCurrentDirectory();
44-
var hostDistFolder = Path.Combine(currentDirectory, "dist");
43+
var hostFolder = Path.Combine(currentDirectory, "ElectronHostHook");
4544

46-
if (!Directory.Exists(hostDistFolder))
45+
if (!Directory.Exists(hostFolder))
4746
{
48-
Directory.CreateDirectory(hostDistFolder);
47+
Directory.CreateDirectory(hostFolder);
4948
}
5049

5150
// Deploy related files
52-
EmbeddedFileHelper.DeployEmbeddedFile(hostDistFolder, "host-hook.js", "dist.");
51+
EmbeddedFileHelper.DeployEmbeddedFile(hostFolder, "package.json", "hook.");
52+
EmbeddedFileHelper.DeployEmbeddedFile(hostFolder, "tsconfig.json", "hook.");
53+
EmbeddedFileHelper.DeployEmbeddedFile(hostFolder, ".gitignore", "hook.");
54+
EmbeddedFileHelper.DeployEmbeddedFile(hostFolder, "index.ts", "hook.");
55+
56+
Console.WriteLine($"Installing the dependencies ...");
57+
ProcessHelper.CheckNodeModules(hostFolder);
5358

5459
// search .csproj or .fsproj (.csproj has higher precedence)
5560
Console.WriteLine($"Search your .csproj/.fsproj to add configure CopyToPublishDirectory to 'Never'");
@@ -82,16 +87,15 @@ private static bool EditProjectFile(string projectFile)
8287

8388
if (projectElement == null || projectElement.Attribute("Sdk")?.Value != "Microsoft.NET.Sdk.Web")
8489
{
85-
Console.WriteLine(
86-
$"Project file is not a compatible type of 'Microsoft.NET.Sdk.Web'. Your project: {projectElement?.Attribute("Sdk")?.Value}");
90+
Console.WriteLine($"Project file is not a compatible type of 'Microsoft.NET.Sdk.Web'. Your project: {projectElement?.Attribute("Sdk")?.Value}");
8791
return false;
8892
}
8993

9094
var itemGroupXmlString = "<ItemGroup>" +
91-
"<Content Update=\"ElectronHostHook\\**\\*.*\">" +
92-
"<CopyToPublishDirectory>Never</CopyToPublishDirectory>" +
93-
"</Content>" +
94-
"</ItemGroup>";
95+
"<Content Update=\"ElectronHostHook\\**\\*.*\">" +
96+
"<CopyToPublishDirectory>Never</CopyToPublishDirectory>" +
97+
"</Content>" +
98+
"</ItemGroup>";
9599

96100
var newItemGroupForConfig = XElement.Parse(itemGroupXmlString);
97101
xmlDocument.Root.Add(newItemGroupForConfig);
@@ -109,7 +113,6 @@ private static bool EditProjectFile(string projectFile)
109113
{
110114
xmlDocument.Save(xw);
111115
}
112-
113116
}
114117

115118
Console.WriteLine($"Publish setting added in csproj/fsproj!");

src/ElectronNET.CLI/Commands/BuildCommand.cs

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@ public Task<bool> ExecuteAsync()
5151
{
5252
return Task.Run(() =>
5353
{
54-
Console.WriteLine("Build Electron Application...");
54+
var parser = new SimpleCommandLineParser();
5555

56-
SimpleCommandLineParser parser = new SimpleCommandLineParser();
56+
Console.WriteLine("Build Electron Application...");
5757
parser.Parse(_args);
5858

5959
//This version will be shared between the dotnet publish and electron-builder commands
60-
string version = null;
60+
var version = string.Empty;
61+
6162
if (parser.Arguments.ContainsKey(_paramVersion))
63+
{
6264
version = parser.Arguments[_paramVersion][0];
65+
}
6366

6467
if (!parser.Arguments.ContainsKey(_paramTarget))
6568
{
@@ -69,23 +72,24 @@ public Task<bool> ExecuteAsync()
6972
}
7073

7174
var desiredPlatform = parser.Arguments[_paramTarget][0];
72-
string specifiedFromCustom = string.Empty;
75+
var specifiedFromCustom = string.Empty;
76+
7377
if (desiredPlatform == "custom" && parser.Arguments[_paramTarget].Length > 1)
7478
{
7579
specifiedFromCustom = parser.Arguments[_paramTarget][1];
7680
}
7781

78-
string configuration = "Release";
82+
var configuration = "Release";
83+
7984
if (parser.Arguments.ContainsKey(_paramDotNetConfig))
8085
{
8186
configuration = parser.Arguments[_paramDotNetConfig][0];
8287
}
8388

8489
var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform, specifiedFromCustom);
85-
8690
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}...");
8791

88-
string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform);
92+
var tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform);
8993

9094
if (Directory.Exists(tempPath) == false)
9195
{
@@ -97,17 +101,13 @@ public Task<bool> ExecuteAsync()
97101
Directory.CreateDirectory(tempPath);
98102
}
99103

100-
101104
Console.WriteLine("Executing dotnet publish in this directory: " + tempPath);
102105

103-
string tempBinPath = Path.Combine(tempPath, "bin");
106+
var tempBinPath = Path.Combine(tempPath, "bin");
107+
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid} under {configuration}-Configuration...");
104108

105-
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid} under {configuration}-Configuration...");
106-
107109
var dotNetPublishFlags = GetDotNetPublishFlags(parser);
108-
109-
var command =
110-
$"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))} --self-contained";
110+
var command = $"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))} --self-contained";
111111

112112
// output the command
113113
Console.ForegroundColor = ConsoleColor.Green;
@@ -132,33 +132,16 @@ public Task<bool> ExecuteAsync()
132132
File.Copy(parser.Arguments[_paramPackageJson][0], Path.Combine(tempPath, "package.json"), true);
133133
}
134134

135-
var checkForNodeModulesDirPath = Path.Combine(tempPath, "node_modules");
136-
137-
if (Directory.Exists(checkForNodeModulesDirPath) == false || parser.Contains(_paramForceNodeInstall) || parser.Contains(_paramPackageJson))
138-
139-
Console.WriteLine("Start npm install...");
140-
ProcessHelper.CmdExecute("npm install --production", tempPath);
135+
ProcessHelper.CheckNodeModules(tempPath, parser.Contains(_paramForceNodeInstall) || parser.Contains(_paramPackageJson));
141136

142137
Console.WriteLine("ElectronHostHook handling started...");
143-
144-
string electronhosthookDir = Path.Combine(Directory.GetCurrentDirectory(), "ElectronHostHook");
145-
146-
if (Directory.Exists(electronhosthookDir))
147-
{
148-
string hosthookDir = Path.Combine(tempPath, "ElectronHostHook");
149-
DirectoryCopy.Do(electronhosthookDir, hosthookDir, true, new List<string>() { "node_modules" });
150-
151-
Console.WriteLine("Start npm install for hosthooks...");
152-
ProcessHelper.CmdExecute("npm install", hosthookDir);
153-
154-
// ToDo: Not sure if this runs under linux/macos
155-
ProcessHelper.CmdExecute(@"npx tsc -p . --sourceMap false", hosthookDir);
156-
}
138+
ProcessHelper.BundleHostHook(tempPath);
157139

158140
Console.WriteLine("Build Electron Desktop Application...");
159141

160142
// Specifying an absolute path supercedes a relative path
161-
string buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop");
143+
var buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop");
144+
162145
if (parser.Arguments.ContainsKey(_paramAbsoluteOutput))
163146
{
164147
buildPath = parser.Arguments[_paramAbsoluteOutput][0];
@@ -170,13 +153,15 @@ public Task<bool> ExecuteAsync()
170153

171154
Console.WriteLine("Executing electron magic in this directory: " + buildPath);
172155

173-
string electronArch = "x64";
156+
var electronArch = "x64";
157+
174158
if (parser.Arguments.ContainsKey(_paramElectronArch))
175159
{
176160
electronArch = parser.Arguments[_paramElectronArch][0];
177161
}
178162

179-
string electronParams = "";
163+
var electronParams = string.Empty;
164+
180165
if (parser.Arguments.ContainsKey(_paramElectronParams))
181166
{
182167
electronParams = parser.Arguments[_paramElectronParams][0];
@@ -185,7 +170,7 @@ public Task<bool> ExecuteAsync()
185170
// ToDo: Make the same thing easer with native c# - we can save a tmp file in production code :)
186171
Console.WriteLine("Create electron-builder configuration file...");
187172

188-
string manifestFileName = "electron.manifest.json";
173+
var manifestFileName = "electron.manifest.json";
189174

190175
if (parser.Arguments.ContainsKey(_manifest))
191176
{
@@ -194,14 +179,13 @@ public Task<bool> ExecuteAsync()
194179

195180
ProcessHelper.CmdExecute(
196181
string.IsNullOrWhiteSpace(version)
197-
? $"node build-helper.js {manifestFileName}"
198-
: $"node build-helper.js {manifestFileName} {version}", tempPath);
182+
? $"node dist/build-helper.js {manifestFileName}"
183+
: $"node dist/build-helper.js {manifestFileName} {version}", tempPath);
199184

200-
Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}...");
185+
Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform} ...");
201186
ProcessHelper.CmdExecute($"npx electron-builder --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=23.2.0 {electronParams}", tempPath);
202187

203188
Console.WriteLine("... done");
204-
205189
return true;
206190
});
207191
}
@@ -216,21 +200,28 @@ private Dictionary<string, string> GetDotNetPublishFlags(SimpleCommandLineParser
216200

217201
if (parser.Arguments.ContainsKey(_paramVersion))
218202
{
219-
if(parser.Arguments.Keys.All(key => !key.StartsWith("p:Version=") && !key.StartsWith("property:Version=")))
203+
if (parser.Arguments.Keys.All(key => !key.StartsWith("p:Version=") && !key.StartsWith("property:Version=")))
204+
{
220205
dotNetPublishFlags.Add("/p:Version", parser.Arguments[_paramVersion][0]);
221-
if(parser.Arguments.Keys.All(key => !key.StartsWith("p:ProductVersion=") && !key.StartsWith("property:ProductVersion=")))
206+
}
207+
208+
if (parser.Arguments.Keys.All(key => !key.StartsWith("p:ProductVersion=") && !key.StartsWith("property:ProductVersion=")))
209+
{
222210
dotNetPublishFlags.Add("/p:ProductVersion", parser.Arguments[_paramVersion][0]);
211+
}
223212
}
224213

225214
foreach (var parm in parser.Arguments.Keys.Where(key => key.StartsWith("p:") || key.StartsWith("property:")))
226215
{
227216
var split = parm.IndexOf('=');
217+
228218
if (split < 0)
229219
{
230220
continue;
231221
}
232222

233223
var key = $"/{parm.Substring(0, split)}";
224+
234225
// normalize the key
235226
if (key.StartsWith("/property:"))
236227
{

src/ElectronNET.CLI/Commands/CommandOption.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ public string ConfigFileKey
4343
get
4444
{
4545
var key = this.Switch;
46+
4647
if (key.StartsWith("--"))
48+
{
4749
key = key.Substring(2);
50+
}
4851

4952
return key;
5053
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/ElectronNET/Electron.NET/commit/f6d17406cd8d19a2af8095421a199edc6ed1a181

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy