don't validate manifest if we're not deploying or zipping the mod

That would break cases like unit test projects, which don't have a manifest.json file.
This commit is contained in:
Jesse Plamondon-Willard 2022-11-10 23:27:38 -05:00
parent 346fddda67
commit 6ee0d2f93d
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
1 changed files with 36 additions and 30 deletions

View File

@ -79,38 +79,44 @@ namespace StardewModdingAPI.ModBuildConfig
this.Log.LogMessage(MessageImportance.High, $"[mod build package] Handling build with options {string.Join(", ", properties)}");
}
// check if manifest file exists
FileInfo manifestFile = new(Path.Combine(this.ProjectDir, "manifest.json"));
if (!manifestFile.Exists)
{
this.Log.LogError("[mod build package] The mod does not have a manifest.json file.");
return false;
}
// check if the json is valid
Manifest manifest;
try
{
new JsonHelper().ReadJsonFileIfExists(manifestFile.FullName, out manifest);
}
catch (JsonReaderException ex)
{
// log the inner exception, otherwise the message will be generic
Exception exToShow = ex.InnerException ?? ex;
this.Log.LogError($"[mod build package] Failed to parse manifest.json: {exToShow.Message}");
return false;
}
// validate the manifest's fields
if (!ManifestValidator.TryValidate(manifest, out string error))
{
this.Log.LogError($"[mod build package] The mod manifest is invalid: {error}");
return false;
}
// skip if nothing to do
// (This must be checked before the manifest validation, to allow cases like unit test projects.)
if (!this.EnableModDeploy && !this.EnableModZip)
return true; // nothing to do
return true;
// validate the manifest file
Manifest manifest;
{
// check if manifest file exists
FileInfo manifestFile = new(Path.Combine(this.ProjectDir, "manifest.json"));
if (!manifestFile.Exists)
{
this.Log.LogError("[mod build package] The mod does not have a manifest.json file.");
return false;
}
// check if the json is valid
try
{
new JsonHelper().ReadJsonFileIfExists(manifestFile.FullName, out manifest);
}
catch (JsonReaderException ex)
{
// log the inner exception, otherwise the message will be generic
Exception exToShow = ex.InnerException ?? ex;
this.Log.LogError($"[mod build package] Failed to parse manifest.json: {exToShow.Message}");
return false;
}
// validate the manifest's fields
if (!ManifestValidator.TryValidate(manifest, out string error))
{
this.Log.LogError($"[mod build package] The mod manifest is invalid: {error}");
return false;
}
}
// deploy files
try
{
// parse extra DLLs to bundle