Skip to content

Commit 6130248

Browse files
committed
Improves CLI command execution and project setup
Refactor the Init and Start commands: - Use MSBuild to get certain project properties. - Use XML tools to read and manipulate XML files. - Use JSON tools to read and manipulate JSON files. - Include and deploy package-lock.json. - Pay close attention to all paths and try to avoid making path assumptions. - Use npm (npx) to launch electron. Refactors `ProcessHelpers` to use `CliWrap` library for more robust command execution (argument escaping primarily). > Note: We currently need to use an older version of the library since the bleeding edge no longer supports .NET 6.
1 parent 846b744 commit 6130248

10 files changed

+865
-318
lines changed

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,19 @@ public static class DeployEmbeddedElectronFiles
66
{
77
public static void Do(string tempPath)
88
{
9+
Directory.CreateDirectory(tempPath);
910
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js");
1011
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
12+
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json");
1113
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "build-helper.js");
1214

1315
string vscodeFolder = Path.Combine(tempPath, ".vscode");
14-
if (Directory.Exists(vscodeFolder) == false)
15-
{
16-
Directory.CreateDirectory(vscodeFolder);
17-
}
16+
Directory.CreateDirectory(vscodeFolder);
1817
EmbeddedFileHelper.DeployEmbeddedFile(vscodeFolder, "launch.json", ".vscode.");
1918
EmbeddedFileHelper.DeployEmbeddedFile(vscodeFolder, "tasks.json", ".vscode.");
2019

2120
string hostApiFolder = Path.Combine(tempPath, "api");
22-
if (Directory.Exists(hostApiFolder) == false)
23-
{
24-
Directory.CreateDirectory(hostApiFolder);
25-
}
26-
21+
Directory.CreateDirectory(hostApiFolder);
2722
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
2823
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
2924
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
@@ -44,10 +39,7 @@ public static void Do(string tempPath)
4439
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "nativeTheme.js", "api.");
4540

4641
string splashscreenFolder = Path.Combine(tempPath, "splashscreen");
47-
if (Directory.Exists(splashscreenFolder) == false)
48-
{
49-
Directory.CreateDirectory(splashscreenFolder);
50-
}
42+
Directory.CreateDirectory(splashscreenFolder);
5143
EmbeddedFileHelper.DeployEmbeddedFile(splashscreenFolder, "index.html", "splashscreen.");
5244
}
5345
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using System.Collections.Generic;
22
using System.IO;
3+
using System.Linq;
34

45
namespace ElectronNET.CLI.Commands.Actions
56
{
67
public static class DirectoryCopy
78
{
8-
public static void Do(string sourceDirName, string destDirName, bool copySubDirs, List<string> ignoredSubDirs)
9+
public static void Do(string sourceDirName, string destDirName, bool copySubDirs, IEnumerable<string> ignoredSubDirs)
910
{
1011
// Get the subdirectories for the specified directory.
1112
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
@@ -26,7 +27,7 @@ public static void Do(string sourceDirName, string destDirName, bool copySubDirs
2627
else
2728
{
2829
DirectoryInfo targetDir = new DirectoryInfo(destDirName);
29-
30+
3031
foreach (FileInfo fileDel in targetDir.EnumerateFiles())
3132
{
3233
fileDel.Delete();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ namespace ElectronNET.CLI.Commands.Actions
55
{
66
public static class GetTargetPlatformInformation
77
{
8-
public struct GetTargetPlatformInformationResult
8+
public struct Result
99
{
1010
public string NetCorePublishRid { get; set; }
1111
public string ElectronPackerPlatform { get; set; }
1212

1313
}
1414

15-
public static GetTargetPlatformInformationResult Do(string desiredPlatform, string specifiedPlatfromFromCustom)
15+
public static Result Do(string desiredPlatform, string specifiedPlatfromFromCustom)
1616
{
1717
string netCorePublishRid = string.Empty;
1818
string electronPackerPlatform = string.Empty;
@@ -60,7 +60,7 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri
6060
break;
6161
}
6262

63-
return new GetTargetPlatformInformationResult()
63+
return new Result()
6464
{
6565
ElectronPackerPlatform = electronPackerPlatform,
6666
NetCorePublishRid = netCorePublishRid

0 commit comments

Comments
 (0)