summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/technical/mod-package.md4
-rw-r--r--src/SMAPI.ModBuildConfig/DeployModTask.cs56
2 files changed, 48 insertions, 12 deletions
diff --git a/docs/technical/mod-package.md b/docs/technical/mod-package.md
index 26ef019f..b46bca2c 100644
--- a/docs/technical/mod-package.md
+++ b/docs/technical/mod-package.md
@@ -356,6 +356,10 @@ That will create a `Pathoschild.Stardew.ModBuildConfig-<version>.nupkg` file in
which can be uploaded to NuGet or referenced directly.
## Release notes
+### Upcoming release
+
+* Added more detailed logging.
+
### 3.2
Released 07 September 2020.
diff --git a/src/SMAPI.ModBuildConfig/DeployModTask.cs b/src/SMAPI.ModBuildConfig/DeployModTask.cs
index c47c8ec4..9ee6be12 100644
--- a/src/SMAPI.ModBuildConfig/DeployModTask.cs
+++ b/src/SMAPI.ModBuildConfig/DeployModTask.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
+using System.Reflection;
using System.Text.RegularExpressions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
@@ -55,6 +56,14 @@ namespace StardewModdingAPI.ModBuildConfig
/// <returns>true if the task successfully executed; otherwise, false.</returns>
public override bool Execute()
{
+ // log build settings
+ {
+ var properties = this
+ .GetPropertiesToLog()
+ .Select(p => $"{p.Key}: {p.Value}");
+ this.Log.LogMessage(MessageImportance.High, $"[mod build package] Handling build with options {string.Join(", ", properties)}");
+ }
+
if (!this.EnableModDeploy && !this.EnableModZip)
return true; // nothing to do
@@ -70,15 +79,18 @@ namespace StardewModdingAPI.ModBuildConfig
if (this.EnableModDeploy)
{
string outputPath = Path.Combine(this.GameModsDir, this.EscapeInvalidFilenameCharacters(this.ModFolderName));
- this.Log.LogMessage(MessageImportance.High, $"The mod build package is copying the mod files to {outputPath}...");
+ this.Log.LogMessage(MessageImportance.High, $"[mod build package] Copying the mod files to {outputPath}...");
this.CreateModFolder(package.GetFiles(), outputPath);
}
// create release zip
if (this.EnableModZip)
{
- this.Log.LogMessage(MessageImportance.High, $"The mod build package is generating a release zip at {this.ModZipPath} for {this.ModFolderName}...");
- this.CreateReleaseZip(package.GetFiles(), this.ModFolderName, package.GetManifestVersion(), this.ModZipPath);
+ string zipName = this.EscapeInvalidFilenameCharacters($"{this.ModFolderName} {package.GetManifestVersion()}.zip");
+ string zipPath = Path.Combine(this.ModZipPath, zipName);
+
+ this.Log.LogMessage(MessageImportance.High, $"[mod build package] Generating the release zip at {zipPath}...");
+ this.CreateReleaseZip(package.GetFiles(), this.ModFolderName, zipPath);
}
return true;
@@ -90,7 +102,7 @@ namespace StardewModdingAPI.ModBuildConfig
}
catch (Exception ex)
{
- this.Log.LogError($"The mod build package failed trying to deploy the mod.\n{ex}");
+ this.Log.LogError($"[mod build package] Failed trying to deploy the mod.\n{ex}");
return false;
}
}
@@ -99,6 +111,29 @@ namespace StardewModdingAPI.ModBuildConfig
/*********
** Private methods
*********/
+ /// <summary>Get the properties to write to the log.</summary>
+ private IEnumerable<KeyValuePair<string, string>> GetPropertiesToLog()
+ {
+ var properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
+ foreach (PropertyInfo property in properties.OrderBy(p => p.Name))
+ {
+ if (property.Name == nameof(this.IgnoreModFilePatterns) && string.IsNullOrWhiteSpace(this.IgnoreModFilePatterns))
+ continue;
+
+ string name = property.Name;
+
+ string value = property.GetValue(this)?.ToString();
+ if (value == null)
+ value = "null";
+ else if (property.PropertyType == typeof(bool))
+ value = value.ToLower();
+ else
+ value = $"'{value}'";
+
+ yield return new KeyValuePair<string, string>(name, value);
+ }
+ }
+
/// <summary>Get the custom ignore patterns provided by the user.</summary>
private IEnumerable<Regex> GetCustomIgnorePatterns()
{
@@ -114,7 +149,7 @@ namespace StardewModdingAPI.ModBuildConfig
}
catch (Exception ex)
{
- this.Log.LogWarning($"Ignored invalid <{nameof(this.IgnoreModFilePatterns)}> pattern {raw}:\n{ex}");
+ this.Log.LogWarning($"[mod build package] Ignored invalid <{nameof(this.IgnoreModFilePatterns)}> pattern {raw}:\n{ex}");
continue;
}
@@ -142,17 +177,14 @@ namespace StardewModdingAPI.ModBuildConfig
/// <summary>Create a release zip in the recommended format for uploading to mod sites.</summary>
/// <param name="files">The files to include.</param>
/// <param name="modName">The name of the mod.</param>
- /// <param name="modVersion">The mod version string.</param>
- /// <param name="outputFolderPath">The absolute or relative path to the folder which should contain the generated zip file.</param>
- private void CreateReleaseZip(IDictionary<string, FileInfo> files, string modName, string modVersion, string outputFolderPath)
+ /// <param name="zipPath">The absolute path to the zip file to create.</param>
+ private void CreateReleaseZip(IDictionary<string, FileInfo> files, string modName, string zipPath)
{
- // get names
- string zipName = this.EscapeInvalidFilenameCharacters($"{modName} {modVersion}.zip");
+ // get folder name within zip
string folderName = this.EscapeInvalidFilenameCharacters(modName);
- string zipPath = Path.Combine(outputFolderPath, zipName);
// create zip file
- Directory.CreateDirectory(outputFolderPath);
+ Directory.CreateDirectory(Path.GetDirectoryName(zipPath)!);
using Stream zipStream = new FileStream(zipPath, FileMode.Create, FileAccess.Write);
using ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create);