Skip to content

Commit f7cc2a9

Browse files
author
Gabe Stocco
committed
Adds three new command line options for build. Specifying the output path, and allowing specification of a package.json file to use.
1 parent c0ee3b8 commit f7cc2a9

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

ElectronNET.CLI/Commands/BuildCommand.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class BuildCommand : ICommand
1919
"Optional: '/dotnet-configuration' with the desired .NET Core build config e.g. release or debug. Default = Release" + Environment.NewLine +
2020
"Optional: '/electron-arch' to specify the resulting electron processor architecture (e.g. ia86 for x86 builds). Be aware to use the '/target custom' param as well!" + Environment.NewLine +
2121
"Optional: '/electron-params' specify any other valid parameter, which will be routed to the electron-packager." + Environment.NewLine +
22+
"Optional: '/relative-path' to specify output a subdirectory for output." + Environment.NewLine +
23+
"Optional: '/absolute-path to specify and absolute path for output." + Environment.NewLine +
24+
"Optional: '/package-json' to specify a custom package.json file." + Environment.NewLine +
2225
"Full example for a 32bit debug build with electron prune: build /target custom win7-x86;win32 /dotnet-configuration Debug /electron-arch ia32 /electron-params \"--prune=true \"";
2326

2427
public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
@@ -34,6 +37,10 @@ public BuildCommand(string[] args)
3437
private string _paramDotNetConfig = "dotnet-configuration";
3538
private string _paramElectronArch = "electron-arch";
3639
private string _paramElectronParams = "electron-params";
40+
private string _paramOutputDirectory = "relative-path";
41+
private string _paramAbsoluteOutput = "absolute-path";
42+
private string _paramPackageJson = "package-json";
43+
3744

3845
public Task<bool> ExecuteAsync()
3946
{
@@ -61,8 +68,8 @@ public Task<bool> ExecuteAsync()
6168

6269
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}...");
6370

64-
6571
string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform);
72+
6673
if (Directory.Exists(tempPath) == false)
6774
{
6875
Directory.CreateDirectory(tempPath);
@@ -84,6 +91,13 @@ public Task<bool> ExecuteAsync()
8491

8592
DeployEmbeddedElectronFiles.Do(tempPath);
8693

94+
if (parser.Arguments.ContainsKey(_paramPackageJson))
95+
{
96+
Console.WriteLine("Copying custom package.json.");
97+
98+
File.Copy(parser.Arguments[_paramPackageJson][0], Path.Combine(tempPath, "package.json"), true);
99+
}
100+
87101
var checkForNodeModulesDirPath = Path.Combine(tempPath, "node_modules");
88102

89103
if (Directory.Exists(checkForNodeModulesDirPath) == false)
@@ -113,7 +127,17 @@ public Task<bool> ExecuteAsync()
113127
}
114128

115129
Console.WriteLine("Build Electron Desktop Application...");
130+
131+
// Specifying an absolute path supercedes a relative path
116132
string buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop");
133+
if (parser.Arguments.ContainsKey(_paramAbsoluteOutput))
134+
{
135+
buildPath = parser.Arguments[_paramAbsoluteOutput][0];
136+
}
137+
else if (parser.Arguments.ContainsKey(_paramOutputDirectory))
138+
{
139+
buildPath = Path.Combine(Directory.GetCurrentDirectory(),parser.Arguments[_paramOutputDirectory][0]);
140+
}
117141

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

0 commit comments

Comments
 (0)