mirror of
https://github.com/Ellpeck/GameBundle.git
synced 2024-11-25 09:58:35 +01:00
made all options optional
This commit is contained in:
parent
b3ce0e118a
commit
b6096caf46
2 changed files with 37 additions and 15 deletions
|
@ -4,9 +4,9 @@ using CommandLine;
|
||||||
namespace GameBundle {
|
namespace GameBundle {
|
||||||
public class Options {
|
public class Options {
|
||||||
|
|
||||||
[Option('s', "source", Required = true, HelpText = "The location of the .csproj file that should be built and bundled")]
|
[Option('s', "source", HelpText = "The location of the .csproj file that should be built and bundled. By default, the current directory is scanned for one")]
|
||||||
public string SourceFile { get; set; }
|
public string SourceFile { get; set; }
|
||||||
[Option('o', "output", Required = true, HelpText = "The location of the directory that the bundles should be stored in")]
|
[Option('o', "output", Default = "bin/Bundled", HelpText = "The location of the directory that the bundles should be stored in")]
|
||||||
public string OutputDirectory { get; set; }
|
public string OutputDirectory { get; set; }
|
||||||
[Option('v', "verbose", Default = false)]
|
[Option('v', "verbose", Default = false)]
|
||||||
public bool Verbose { get; set; }
|
public bool Verbose { get; set; }
|
||||||
|
@ -22,7 +22,7 @@ namespace GameBundle {
|
||||||
public string[] ExcludedFiles { get; set; }
|
public string[] ExcludedFiles { get; set; }
|
||||||
[Option("32bit", Default = false, HelpText = "Publish for 32 bit instead of 64 bit. Note that this is only possible on Windows")]
|
[Option("32bit", Default = false, HelpText = "Publish for 32 bit instead of 64 bit. Note that this is only possible on Windows")]
|
||||||
public bool Publish32Bit { get; set; }
|
public bool Publish32Bit { get; set; }
|
||||||
[Option("trim", Default = true, HelpText = "If the application should be trimmed when being published")]
|
[Option("trim", Default = true, HelpText = "Trim the application when publishing")]
|
||||||
public bool Trim { get; set; }
|
public bool Trim { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,25 +15,31 @@ namespace GameBundle {
|
||||||
if (RunProcess(options, "dotnet", "tool install nulastudio.ncbeauty -g") < 0)
|
if (RunProcess(options, "dotnet", "tool install nulastudio.ncbeauty -g") < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
var proj = new FileInfo(options.SourceFile);
|
var proj = GetProjectFile(options);
|
||||||
if (!proj.Exists) {
|
if (proj == null || !proj.Exists) {
|
||||||
Console.WriteLine("Project file not found at " + proj.FullName);
|
Console.WriteLine("Project file not found");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (options.Verbose)
|
Console.WriteLine("Bundling project " + proj.FullName);
|
||||||
Console.WriteLine("Found project file at " + proj.FullName);
|
|
||||||
|
|
||||||
var bundleDir = new DirectoryInfo(Path.Combine(options.OutputDirectory, "Bundled"));
|
var bundleDir = new DirectoryInfo(options.OutputDirectory);
|
||||||
if (!bundleDir.Exists)
|
if (!bundleDir.Exists)
|
||||||
bundleDir.Create();
|
bundleDir.Create();
|
||||||
|
|
||||||
if (options.BundleWindows)
|
if (options.BundleWindows) {
|
||||||
|
Console.WriteLine("Bundling for windows");
|
||||||
Publish(options, proj, $"{bundleDir}/win", options.Publish32Bit ? "win-x86" : "win-x64");
|
Publish(options, proj, $"{bundleDir}/win", options.Publish32Bit ? "win-x86" : "win-x64");
|
||||||
if (options.BundleLinux)
|
}
|
||||||
|
if (options.BundleLinux) {
|
||||||
|
Console.WriteLine("Bundling for linux");
|
||||||
Publish(options, proj, $"{bundleDir}/linux", "linux-x64");
|
Publish(options, proj, $"{bundleDir}/linux", "linux-x64");
|
||||||
if (options.BundleMac)
|
}
|
||||||
|
if (options.BundleMac) {
|
||||||
|
Console.WriteLine("Bundling for mac");
|
||||||
Publish(options, proj, $"{bundleDir}/mac", "osx-x64");
|
Publish(options, proj, $"{bundleDir}/mac", "osx-x64");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Done");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,11 +61,27 @@ namespace GameBundle {
|
||||||
|
|
||||||
private static int RunProcess(Options options, string program, string args) {
|
private static int RunProcess(Options options, string program, string args) {
|
||||||
if (options.Verbose)
|
if (options.Verbose)
|
||||||
Console.WriteLine($"$ {program} {args}");
|
Console.WriteLine($"> {program} {args}");
|
||||||
var process = Process.Start(program, args);
|
var info = new ProcessStartInfo(program, args);
|
||||||
|
if (!options.Verbose)
|
||||||
|
info.CreateNoWindow = true;
|
||||||
|
var process = Process.Start(info);
|
||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
|
if (options.Verbose)
|
||||||
|
Console.WriteLine($"{program} finished with exit code {process.ExitCode}");
|
||||||
return process.ExitCode;
|
return process.ExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static FileInfo GetProjectFile(Options options) {
|
||||||
|
if (!string.IsNullOrEmpty(options.SourceFile))
|
||||||
|
return new FileInfo(options.SourceFile);
|
||||||
|
var dir = new DirectoryInfo(Environment.CurrentDirectory);
|
||||||
|
foreach (var file in dir.EnumerateFiles()) {
|
||||||
|
if (Path.GetExtension(file.FullName).Contains("proj"))
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue