Handling nullability on BuildAssets

This commit is contained in:
Kevin Bost
2024-12-26 23:32:58 -08:00
committed by Caelan
parent 63b04c82dd
commit d8b54ce032

View File

@@ -1,33 +1,36 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Velopack.Util; using Velopack.Util;
#nullable disable
namespace Velopack.Core; namespace Velopack.Core;
public class BuildAssets public class BuildAssets
{ {
[JsonIgnore] [JsonIgnore]
private string _outputDir; private string? _outputDir;
public List<string> RelativeFileNames { get; set; } = new List<string>(); public List<string>? RelativeFileNames { get; set; } = [];
public List<VelopackAsset> GetReleaseEntries() public List<VelopackAsset> GetReleaseEntries()
{ {
return GetFilePaths().Where(x => x.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase)) return GetFilePaths()
.Where(x => x.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase))
.Select(VelopackAsset.FromNupkg) .Select(VelopackAsset.FromNupkg)
.ToList(); .ToList();
} }
public List<string> GetNonReleaseAssetPaths() public List<string> GetNonReleaseAssetPaths()
{ {
return GetFilePaths().Where(x => !x.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase)) return GetFilePaths()
.Where(x => !x.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase))
.ToList(); .ToList();
} }
public List<string> GetFilePaths() public IEnumerable<string> GetFilePaths()
{ {
return RelativeFileNames.Select(f => Path.GetFullPath(Path.Combine(_outputDir, f))).ToList(); if (RelativeFileNames is { } relativeFileNames && _outputDir is { } outputDir) {
return relativeFileNames.Select(f => Path.GetFullPath(Path.Combine(outputDir, f))).ToList();
}
return [];
} }
public static void Write(string outputDir, string channel, IEnumerable<string> files) public static void Write(string outputDir, string channel, IEnumerable<string> files)
@@ -51,7 +54,7 @@ public class BuildAssets
$"If you've just created a Velopack release, verify you're calling this command with the same '--channel' as you did with 'pack'."); $"If you've just created a Velopack release, verify you're calling this command with the same '--channel' as you did with 'pack'.");
} }
var assets = SimpleJson.DeserializeObject<BuildAssets>(File.ReadAllText(path)); var assets = SimpleJson.DeserializeObject<BuildAssets>(File.ReadAllText(path)) ?? new();
assets._outputDir = outputDir; assets._outputDir = outputDir;
return assets; return assets;
} }