added the ability to zip content

This commit is contained in:
Ellpeck 2020-09-02 17:23:49 +02:00
parent 0bd0c9febe
commit c084765045
3 changed files with 38 additions and 12 deletions

View file

@ -23,6 +23,8 @@ namespace GameBundle {
public bool MacBundle { get; set; }
[Option("mac-bundle-resources", Default = new[] {"Content", "*.icns"}, HelpText = "When creating an app bundle for mac, things that should go into the Resources folder rather than the MacOS folder")]
public IEnumerable<string> MacBundleResources { get; set; }
[Option('z', "zip", HelpText = "Store the build results in zip files instead of folders")]
public bool Zip { get; set; }
[Option('e', "exclude", HelpText = "Files that should not be moved to the library folder")]
public IEnumerable<string> ExcludedFiles { get; set; }
@ -34,6 +36,8 @@ namespace GameBundle {
public string BuildConfig { get; set; }
[Option("lib-name", Default = "Lib", HelpText = "The name of the library folder that is created")]
public string LibFolder { get; set; }
[Option('n', "name-builds", HelpText = "Name the build output directories by the project's name")]
public bool NameBuilds { get; set; }
}
}

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text.RegularExpressions;
using CommandLine;
@ -25,37 +26,40 @@ namespace GameBundle {
}
Console.WriteLine("Bundling project " + proj.FullName);
var bundleDir = new DirectoryInfo(options.OutputDirectory);
if (!bundleDir.Exists)
bundleDir.Create();
var builtAnything = false;
if (options.BuildWindows) {
Console.WriteLine("Bundling for windows");
var res = Publish(options, proj, $"{bundleDir.FullName}/win", options.Publish32Bit ? "win-x86" : "win-x64");
var res = Publish(options, proj, GetBuildDir(options, proj, "win"), options.Publish32Bit ? "win-x86" : "win-x64");
if (res != 0)
return res;
builtAnything = true;
}
if (options.BuildLinux) {
Console.WriteLine("Bundling for linux");
var res = Publish(options, proj, $"{bundleDir.FullName}/linux", "linux-x64");
var res = Publish(options, proj, GetBuildDir(options, proj, "linux"), "linux-x64");
if (res != 0)
return res;
builtAnything = true;
}
if (options.BuildMac) {
Console.WriteLine("Bundling for mac");
var dir = $"{bundleDir.FullName}/mac";
var res = Publish(options, proj, dir, "osx-x64");
if (res != 0)
return res;
var dir = GetBuildDir(options, proj, "mac");
var res = Publish(options, proj, dir, "osx-x64", () => {
if (options.MacBundle)
CreateMacBundle(options, new DirectoryInfo(dir), proj.FullName);
});
if (res != 0)
return res;
builtAnything = true;
}
if (!builtAnything)
Console.WriteLine("No build took place. Supply -w, -l or -m arguments or see available arguments using --help.");
Console.WriteLine("Done");
return 0;
}
private static int Publish(Options options, FileInfo proj, string path, string rid) {
private static int Publish(Options options, FileInfo proj, string path, string rid, Action additionalAction = null) {
var publishResult = RunProcess(options, "dotnet", $"publish {proj.FullName} -o {path} -r {rid} -c {options.BuildConfig} /p:PublishTrimmed={options.Trim}");
if (publishResult != 0)
return publishResult;
@ -71,6 +75,17 @@ namespace GameBundle {
var beautyFile = new FileInfo(Path.Combine(path, "NetCoreBeauty"));
if (beautyFile.Exists)
beautyFile.Delete();
// Run any additional actions like creating the mac bundle
additionalAction?.Invoke();
// Zip the output if required
if (options.Zip) {
var zipLocation = Path.Combine(Directory.GetParent(path).FullName, Path.GetFileName(path) + ".zip");
File.Delete(zipLocation);
ZipFile.CreateFromDirectory(path, zipLocation, CompressionLevel.Optimal, true);
Directory.Delete(path, true);
}
return 0;
}
@ -125,5 +140,12 @@ namespace GameBundle {
return new Regex('(' + string.Join("|", strings.Select(s => s.Replace(".", "[.]").Replace("*", ".*").Replace("?", "."))) + ')');
}
private static string GetBuildDir(Options options, FileInfo proj, string osName) {
var dir = Path.GetFullPath(options.OutputDirectory);
if (options.NameBuilds)
return $"{dir}/{Path.GetFileNameWithoutExtension(proj.Name)}-{osName}";
return $"{dir}/{osName}";
}
}
}

View file

@ -1 +1 @@
"../GameBundle/bin/Debug/netcoreapp3.1/GameBundle.exe" -wlmb -s Test.csproj -o bin/Bundled -v
"../GameBundle/bin/Debug/netcoreapp3.1/GameBundle.exe" -wlm -bzn -s Test.csproj -o bin/Bundled -v