Skip to content

Commit ba16c4e

Browse files
Merge pull request #228 from gfs/master
Adds new command line parameters to 'electronize build'
2 parents 0fac6ae + 8b5bb63 commit ba16c4e

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

ElectronNET.CLI/Commands/BuildCommand.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public class BuildCommand : ICommand
1717
"Optional: '/dotnet-configuration' with the desired .NET Core build config e.g. release or debug. Default = Release" + Environment.NewLine +
1818
"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 +
1919
"Optional: '/electron-params' specify any other valid parameter, which will be routed to the electron-packager." + Environment.NewLine +
20+
"Optional: '/relative-path' to specify output a subdirectory for output." + Environment.NewLine +
21+
"Optional: '/absolute-path to specify and absolute path for output." + Environment.NewLine +
22+
"Optional: '/package-json' to specify a custom package.json file." + Environment.NewLine +
23+
"Optional: '/install-modules' to force node module install. Implied by '/package-json'" + Environment.NewLine +
2024
"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 \"";
2125

2226
public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
@@ -32,6 +36,10 @@ public BuildCommand(string[] args)
3236
private string _paramDotNetConfig = "dotnet-configuration";
3337
private string _paramElectronArch = "electron-arch";
3438
private string _paramElectronParams = "electron-params";
39+
private string _paramOutputDirectory = "relative-path";
40+
private string _paramAbsoluteOutput = "absolute-path";
41+
private string _paramPackageJson = "package-json";
42+
private string _paramForceNodeInstall = "install-modules";
3543

3644
public Task<bool> ExecuteAsync()
3745
{
@@ -59,8 +67,8 @@ public Task<bool> ExecuteAsync()
5967

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

62-
6370
string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform);
71+
6472
if (Directory.Exists(tempPath) == false)
6573
{
6674
Directory.CreateDirectory(tempPath);
@@ -83,12 +91,24 @@ public Task<bool> ExecuteAsync()
8391
DeployEmbeddedElectronFiles.Do(tempPath);
8492
var nodeModulesDirPath = Path.Combine(tempPath, "node_modules");
8593

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+
101+
var checkForNodeModulesDirPath = Path.Combine(tempPath, "node_modules");
102+
103+
if (Directory.Exists(checkForNodeModulesDirPath) == false || parser.Contains(_paramForceNodeInstall) || parser.Contains(_paramPackageJson))
104+
86105
Console.WriteLine("Start npm install...");
87106
ProcessHelper.CmdExecute("npm install --production", tempPath);
88107

89108
Console.WriteLine("Start npm install electron-packager...");
90109

91110
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
111+
92112
{
93113
// Works proper on Windows...
94114
ProcessHelper.CmdExecute("npm install electron-packager --global", tempPath);
@@ -118,7 +138,17 @@ public Task<bool> ExecuteAsync()
118138
}
119139

120140
Console.WriteLine("Build Electron Desktop Application...");
141+
142+
// Specifying an absolute path supercedes a relative path
121143
string buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop");
144+
if (parser.Arguments.ContainsKey(_paramAbsoluteOutput))
145+
{
146+
buildPath = parser.Arguments[_paramAbsoluteOutput][0];
147+
}
148+
else if (parser.Arguments.ContainsKey(_paramOutputDirectory))
149+
{
150+
buildPath = Path.Combine(Directory.GetCurrentDirectory(),parser.Arguments[_paramOutputDirectory][0]);
151+
}
122152

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

0 commit comments

Comments
 (0)