From 1abc76a2240543e24e944d077271f3dfda9f4d97 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 11 Sep 2020 17:25:38 -0400 Subject: improve logging in mod build package --- src/SMAPI.ModBuildConfig/DeployModTask.cs | 56 ++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 12 deletions(-) (limited to 'src') 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 /// true if the task successfully executed; otherwise, false. 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 *********/ + /// Get the properties to write to the log. + private IEnumerable> 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(name, value); + } + } + /// Get the custom ignore patterns provided by the user. private IEnumerable 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 /// Create a release zip in the recommended format for uploading to mod sites. /// The files to include. /// The name of the mod. - /// The mod version string. - /// The absolute or relative path to the folder which should contain the generated zip file. - private void CreateReleaseZip(IDictionary files, string modName, string modVersion, string outputFolderPath) + /// The absolute path to the zip file to create. + private void CreateReleaseZip(IDictionary 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); -- cgit From 0b6b9b3766286eb34b05878f5682ec0ffc5a8f86 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 11 Sep 2020 17:36:02 -0400 Subject: fix default mods folder path in build package --- docs/technical/mod-package.md | 1 + src/SMAPI.ModBuildConfig/build/smapi.targets | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/docs/technical/mod-package.md b/docs/technical/mod-package.md index b46bca2c..361b257a 100644 --- a/docs/technical/mod-package.md +++ b/docs/technical/mod-package.md @@ -359,6 +359,7 @@ which can be uploaded to NuGet or referenced directly. ### Upcoming release * Added more detailed logging. +* Fixed _path's format is not supported_ error when using default `Mods` path in 3.2. ### 3.2 Released 07 September 2020. diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index 0a0db190..65544b12 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -18,7 +18,7 @@ $(MSBuildProjectName) $(TargetDir) - $([System.IO.Path]::Combine($(GamePath), 'Mods') + $([System.IO.Path]::Combine($(GamePath), 'Mods')) true true false -- cgit From 39b9f363db18c38b0816f3b6a0e6cb86432cd8dc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 11 Sep 2020 17:38:04 -0400 Subject: prepare for release --- docs/technical/mod-package.md | 3 ++- src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj | 2 +- src/SMAPI.ModBuildConfig/package.nuspec | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/docs/technical/mod-package.md b/docs/technical/mod-package.md index 361b257a..a1457405 100644 --- a/docs/technical/mod-package.md +++ b/docs/technical/mod-package.md @@ -356,7 +356,8 @@ That will create a `Pathoschild.Stardew.ModBuildConfig-.nupkg` file in which can be uploaded to NuGet or referenced directly. ## Release notes -### Upcoming release +### 3.2.1 +Released 11 September 2020. * Added more detailed logging. * Fixed _path's format is not supported_ error when using default `Mods` path in 3.2. diff --git a/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj b/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj index 5e35b7e9..605096d9 100644 --- a/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj +++ b/src/SMAPI.ModBuildConfig/SMAPI.ModBuildConfig.csproj @@ -1,7 +1,7 @@  StardewModdingAPI.ModBuildConfig - 3.2.0 + 3.2.1 net45 x86 false diff --git a/src/SMAPI.ModBuildConfig/package.nuspec b/src/SMAPI.ModBuildConfig/package.nuspec index c0b0799a..05aed8f9 100644 --- a/src/SMAPI.ModBuildConfig/package.nuspec +++ b/src/SMAPI.ModBuildConfig/package.nuspec @@ -2,7 +2,7 @@ Pathoschild.Stardew.ModBuildConfig - 3.2.0 + 3.2.1 Build package for SMAPI mods Pathoschild Pathoschild @@ -14,9 +14,9 @@ https://raw.githubusercontent.com/Pathoschild/SMAPI/develop/src/SMAPI.ModBuildConfig/assets/nuget-icon.png Automates the build configuration for crossplatform Stardew Valley SMAPI mods. For SMAPI 3.0 or later. - 3.2.0: - - Added option to change `Mods` folder path. - - Rewrote documentation to make it easier to read. + 3.2.1: + - Added more detailed logging. + - Fixed "path's format is not supported" error when using default Mods path in 3.2. -- cgit