From d878181fee1a8f307505060c926d1d982c224888 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Fri, 9 Feb 2024 01:30:01 +0100 Subject: [PATCH] (build) use the Cake.Wyam addin as package --- build/Directory.Packages.props | 1 + .../common/Addins/Cake.Wyam/NuGetSettings.cs | 38 --- build/common/Addins/Cake.Wyam/WyamAliases.cs | 64 ---- build/common/Addins/Cake.Wyam/WyamRunner.cs | 322 ------------------ build/common/Addins/Cake.Wyam/WyamSettings.cs | 174 ---------- build/docs/BuildContext.cs | 2 +- build/docs/BuildLifetime.cs | 2 +- build/docs/Tasks/BuildDocs.cs | 2 +- build/docs/Tasks/PreviewDocs.cs | 2 +- build/docs/Tasks/PublishDocs.cs | 2 +- build/docs/docs.csproj | 1 + 11 files changed, 7 insertions(+), 603 deletions(-) delete mode 100644 build/common/Addins/Cake.Wyam/NuGetSettings.cs delete mode 100644 build/common/Addins/Cake.Wyam/WyamAliases.cs delete mode 100644 build/common/Addins/Cake.Wyam/WyamRunner.cs delete mode 100644 build/common/Addins/Cake.Wyam/WyamSettings.cs diff --git a/build/Directory.Packages.props b/build/Directory.Packages.props index 79dfe40b95..be049a211f 100644 --- a/build/Directory.Packages.props +++ b/build/Directory.Packages.props @@ -13,6 +13,7 @@ + \ No newline at end of file diff --git a/build/common/Addins/Cake.Wyam/NuGetSettings.cs b/build/common/Addins/Cake.Wyam/NuGetSettings.cs deleted file mode 100644 index 144db865a8..0000000000 --- a/build/common/Addins/Cake.Wyam/NuGetSettings.cs +++ /dev/null @@ -1,38 +0,0 @@ -#nullable disable -namespace Common.Addins.Cake.Wyam; - -/// -/// Settings for specifying NuGet packages. -/// -public class NuGetSettings -{ - /// - /// Specifies that prerelease packages are allowed. - /// - public bool Prerelease { get; set; } - - /// - /// Specifies that unlisted packages are allowed. - /// - public bool Unlisted { get; set; } - - /// - /// Indicates that only the specified package source(s) should be used to find the package. - /// - public bool Exclusive { get; set; } - - /// - /// Specifies the version of the package to use. - /// - public string Version { get; set; } - - /// - /// Specifies the package source(s) to get the package from. - /// - public IEnumerable Source { get; set; } - - /// - /// The package to install. - /// - public string Package { get; set; } -} diff --git a/build/common/Addins/Cake.Wyam/WyamAliases.cs b/build/common/Addins/Cake.Wyam/WyamAliases.cs deleted file mode 100644 index afc4b3489b..0000000000 --- a/build/common/Addins/Cake.Wyam/WyamAliases.cs +++ /dev/null @@ -1,64 +0,0 @@ -#nullable disable -namespace Common.Addins.Cake.Wyam; - -/// -/// Contains functionality related to Wyam2. -/// -/// In order to use the commands for this alias, include the following in your build.cake file to download and install from NuGet.org, or specify the ToolPath within the WyamSettings class: -/// -/// #addin "nuget:?package=Cake.Wyam2" -/// #tool "nuget:?package=Wyam2" -/// -/// -/// -/// -/// Make sure to remove existing references to old Cake.Wyam addin (https://www.nuget.org/packages/Wyam/). -/// -[CakeAliasCategory("Wyam2")] -public static class WyamAliases -{ - /// - /// Runs Wyam2 using the specified settings. - /// - /// The context. - /// - /// - /// Wyam(); - /// - /// - [CakeMethodAlias] - public static void Wyam(this ICakeContext context) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - Wyam(context, new WyamSettings()); - } - - /// - /// Runs Wyam2 using the specified settings. - /// - /// The context. - /// The settings. - /// - /// - /// Wyam(new WyamSettings() - /// { - /// OutputPath = Directory("C:/Output") - /// }); - /// - /// - [CakeMethodAlias] - public static void Wyam(this ICakeContext context, WyamSettings settings) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - WyamRunner runner = new WyamRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run(settings); - } -} diff --git a/build/common/Addins/Cake.Wyam/WyamRunner.cs b/build/common/Addins/Cake.Wyam/WyamRunner.cs deleted file mode 100644 index e5d0792204..0000000000 --- a/build/common/Addins/Cake.Wyam/WyamRunner.cs +++ /dev/null @@ -1,322 +0,0 @@ -#nullable disable -using System.Collections; - -namespace Common.Addins.Cake.Wyam; - -/// -/// The Wyam2 Runner used to execute the Wyam2 Executable -/// -public sealed class WyamRunner : Tool -{ - private readonly ICakeEnvironment _environment; - - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - public WyamRunner(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IToolLocator locator) - : base(fileSystem, environment, new PrependDotNetProcessRunner(processRunner), locator) => _environment = environment; - - private class PrependDotNetProcessRunner : IProcessRunner - { - private readonly IProcessRunner _processRunner; - - public PrependDotNetProcessRunner(IProcessRunner processRunner) => _processRunner = processRunner; - - public IProcess Start(FilePath filePath, ProcessSettings settings) - { - // Prepends "dotnet" to the tool and escapes wyam2 path: "dotnet" "some_path/wyam.dll" args - settings.Arguments.Prepend(filePath.FullPath.Quote()); - return _processRunner.Start("dotnet", settings); - } - } - - /// - /// Runs the tool from the provided settings. - /// - /// The settings. - public void Run(WyamSettings settings) - { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } - - Run(settings, GetArguments(settings), new ProcessSettings(), null); - } - - /// - /// Gets the name of the tool. - /// - /// The name of the tool. - protected override string GetToolName() => "Wyam2"; - - /// - /// Gets the possible names of the tool executable. - /// - /// The tool executable name. - protected override IEnumerable GetToolExecutableNames() => new[] { "Wyam.dll" }; - - private ProcessArgumentBuilder GetArguments(WyamSettings settings) - { - ProcessArgumentBuilder builder = new ProcessArgumentBuilder(); - - if (settings.Watch) - { - builder.Append("--watch"); - } - - if (settings.Attach) - { - builder.Append("--attach"); - } - - if (settings.Preview) - { - builder.Append("--preview"); - - if (settings.PreviewPort != 0) - { - builder.Append(settings.PreviewPort.ToString()); - } - else - { - // Append the default port to avoid the CLI thinking the root path is the port when this is the last option - builder.Append("5080"); - } - - if (settings.PreviewForceExtensions) - { - builder.Append("--force-ext"); - } - - if (!string.IsNullOrWhiteSpace(settings.PreviewVirtualDirectory?.FullPath)) - { - builder.Append("--virtual-dir"); - builder.AppendQuoted(settings.PreviewVirtualDirectory.FullPath); - } - - if (settings.PreviewRoot != null) - { - builder.Append("--preview-root"); - builder.AppendQuoted(settings.PreviewRoot.FullPath); - } - } - - if (settings.InputPaths != null) - { - foreach (DirectoryPath inputPath in settings.InputPaths) - { - builder.Append("--input"); - builder.AppendQuoted(inputPath.FullPath); - } - } - - if (settings.OutputPath != null) - { - builder.Append("--output"); - builder.AppendQuoted(settings.OutputPath.FullPath); - } - - if (settings.ConfigurationFile != null) - { - builder.Append("--config"); - builder.AppendQuoted(settings.ConfigurationFile.FullPath); - } - - if (settings.UpdatePackages) - { - builder.Append("--update-packages"); - } - - if (settings.UseLocalPackages) - { - builder.Append("--use-local-packages"); - } - - if (settings.UseGlobalSources) - { - builder.Append("--use-global-sources"); - } - - if (settings.IgnoreDefaultSources) - { - builder.Append("--ignore-default-sources"); - } - - if (settings.PackagesPath != null) - { - builder.Append("--packages-path"); - builder.AppendQuoted(settings.PackagesPath.FullPath); - } - - if (settings.OutputScript) - { - builder.Append("--output-script"); - } - - if (settings.VerifyConfig) - { - builder.Append("--verify-config"); - } - - if (settings.IgnoreConfigHash || settings.VerifyConfig) - { - builder.Append("--ignore-config-hash"); - } - - if (settings.NoClean) - { - builder.Append("--noclean"); - } - - if (settings.NoCache) - { - builder.Append("--nocache"); - } - - if (settings.Verbose) - { - builder.Append("--verbose"); - } - - if (settings.Settings != null) - { - SetMetadata(builder, "--setting", settings.Settings); - } - - if (settings.ContentTypes != null) - { - foreach (KeyValuePair contentType in settings.ContentTypes) - { - builder.Append("--content-type"); - builder.Append($"{contentType.Key.Trim()}={contentType.Value.Trim()}"); - } - } - - if (settings.LogFilePath != null) - { - builder.Append("--log"); - builder.AppendQuoted(settings.LogFilePath.MakeAbsolute(_environment).FullPath); - } - - if (settings.NuGetPackages != null) - { - foreach (NuGetSettings childSettings in settings.NuGetPackages) - { - ProcessArgumentBuilder childBuilder = new ProcessArgumentBuilder(); - - if (childSettings.Package != null) - { - childBuilder.Append(childSettings.Package); - } - - if (childSettings.Prerelease) - { - childBuilder.Append("--prerelease"); - } - - if (childSettings.Unlisted) - { - childBuilder.Append("--unlisted"); - } - - if (childSettings.Exclusive) - { - childBuilder.Append("--exclusive"); - } - - if (childSettings.Version != null) - { - childBuilder.Append("--version"); - childBuilder.Append(childSettings.Version); - } - - if (childSettings.Source != null) - { - foreach (string source in childSettings.Source) - { - childBuilder.Append("--source"); - childBuilder.Append(source); - } - } - - builder.Append("--nuget"); - builder.AppendQuoted(childBuilder.Render()); - } - } - - if (settings.NuGetSources != null) - { - foreach (string nugetSource in settings.NuGetSources) - { - builder.Append("--nuget-source"); - builder.Append(nugetSource); - } - } - - if (settings.Assemblies != null) - { - foreach (string assemblies in settings.Assemblies) - { - builder.Append("--assembly"); - builder.Append(assemblies); - } - } - - if (settings.Recipe != null) - { - builder.Append("--recipe"); - builder.AppendQuoted(settings.Recipe); - } - - if (settings.Theme != null) - { - builder.Append("--theme"); - builder.AppendQuoted(settings.Theme); - } - - if (settings.RootPath != null) - { - builder.AppendQuoted(settings.RootPath.MakeAbsolute(_environment).FullPath); - } - else - { - builder.AppendQuoted(_environment.WorkingDirectory.FullPath); - } - - return builder; - } - - private static void SetMetadata(ProcessArgumentBuilder builder, string argument, IDictionary values) - { - foreach (KeyValuePair metadata in values) - { - builder.Append(argument); - if (metadata.Value is IEnumerable enumerable && !(metadata.Value is string)) - { - // The value is an array - StringBuilder valueBuilder = new StringBuilder(); - foreach (object value in enumerable) - { - if (valueBuilder.Length != 0) - { - valueBuilder.Append(','); - } - valueBuilder.Append($"{EscapeMetadata(value.ToString()).Replace(",", "\\,")}"); - } - builder.Append($"\"{EscapeMetadata(metadata.Key)}=[{valueBuilder}]\""); - } - else - { - builder.Append($"\"{EscapeMetadata(metadata.Key)}={EscapeMetadata(metadata.Value.ToString())}\""); - } - } - } - - private static string EscapeMetadata(string s) => - s.Replace("\\", @"\\").Replace("\"", "\\\"").Replace("=", "\\="); -} diff --git a/build/common/Addins/Cake.Wyam/WyamSettings.cs b/build/common/Addins/Cake.Wyam/WyamSettings.cs deleted file mode 100644 index d1e308379b..0000000000 --- a/build/common/Addins/Cake.Wyam/WyamSettings.cs +++ /dev/null @@ -1,174 +0,0 @@ -#nullable disable -namespace Common.Addins.Cake.Wyam; - -/// -/// Contains settings used by . -/// -public sealed class WyamSettings : DotNetSettings -{ - /// - /// Gets or sets a value indicating whether to enable watching of input folder for changes to files. - /// - /// Default is false - public bool Watch { get; set; } - - /// - /// Pauses execution while waiting for a debugger to attach. - /// - /// Default is false - public bool Attach { get; set; } - - /// - /// Gets or sets a value indicating whether to enable previewing of the generated content in built in web server. - /// - /// Default is false - public bool Preview { get; set; } - - /// - /// Gets or sets a value indicating the port number to use for previewing. - /// - /// Default is 5080 - public int PreviewPort { get; set; } - - /// - /// Gets or sets a value indicating whether to enable forcing of using file extensions. - /// - /// Default is false - public bool PreviewForceExtensions { get; set; } - - /// - /// Gets or sets a value indicating the virtual directory to use for the preview server. - /// - public DirectoryPath PreviewVirtualDirectory { get; set; } - - /// - /// The path to the root of the preview server, if not the output folder. - /// - public DirectoryPath PreviewRoot { get; set; } - - /// - /// Gets or sets a value indicating the input paths that should be used while running Wyam. - /// - public IEnumerable InputPaths { get; set; } - - /// - /// Gets or sets a value indicating the output path that should be used while running Wyam. - /// - public DirectoryPath OutputPath { get; set; } - - /// - /// Gets or sets a value indicating the configuration file that should be used while running Wyam. - /// - public FilePath ConfigurationFile { get; set; } - - /// - /// Gets or sets a value indicating whether to enable updating of packages. - /// - /// Default is false - public bool UpdatePackages { get; set; } - - /// - /// Gets or sets a value indicating whether to use a local NuGet packages folder. - /// - /// Default is false - public bool UseLocalPackages { get; set; } - - /// - /// Toggles the use of the global NuGet sources. - /// - /// Default is false - public bool UseGlobalSources { get; set; } - - /// - /// Ignores default NuGet sources like the NuGet Gallery. - /// - /// Default is false - public bool IgnoreDefaultSources { get; set; } - - /// - /// Gets or sets the packages path to use. - /// - public DirectoryPath PackagesPath { get; set; } - - /// - /// Gets or sets a value indicating whether to output the script at end of execution. - /// - /// Default is false - public bool OutputScript { get; set; } - - /// - /// Compile the configuration but do not execute. - /// - /// Default is false - public bool VerifyConfig { get; set; } - - /// - /// Force evaluating the configuration file, even when no changes were detected. - /// - /// Default is false - public bool IgnoreConfigHash { get; set; } - - /// - /// Gets or sets a value indicating whether to prevent cleaning of the output path on each execution if true. - /// - /// Default is false - public bool NoClean { get; set; } - - /// - /// Gets or sets a value indicating whether to turn off the caching mechanism on all modules if true. - /// - /// Default is false - public bool NoCache { get; set; } - - /// - /// Gets or sets a value indicating whether to run in verbose mode. - /// - /// Default is false - public bool Verbose { get; set; } - - /// - /// Gets or sets metadata settings. - /// - public IDictionary Settings { get; set; } - - /// - /// Gets or sets the path to the Wyam log file. - /// - public FilePath LogFilePath { get; set; } - - /// - /// Gets or sets the The folder (or config file) to use as the root. - /// - /// Default is the current working directory - public DirectoryPath RootPath { get; set; } - - /// - /// Adds NuGet packages (downloading and installing them if needed). - /// - public IEnumerable NuGetPackages { get; set; } - - /// - /// Specifies additional package sources to use. - /// - public IEnumerable NuGetSources { get; set; } - - /// - /// Adds references to multiple assemblies by name, file name, or globbing patterns. - /// - public IEnumerable Assemblies { get; set; } - - /// - /// Gets or sets the recipe. - /// - public string Recipe { get; set; } - - /// - /// Gets or sets the theme. - /// - public string Theme { get; set; } - - /// - /// Specifies additional supported content types for the preview server. - /// - public IDictionary ContentTypes { get; set; } -} diff --git a/build/docs/BuildContext.cs b/build/docs/BuildContext.cs index 0756abc77b..ca79d42541 100644 --- a/build/docs/BuildContext.cs +++ b/build/docs/BuildContext.cs @@ -1,4 +1,4 @@ -using Common.Addins.Cake.Wyam; +using Cake.Wyam; using Common.Utilities; using Docs.Utilities; diff --git a/build/docs/BuildLifetime.cs b/build/docs/BuildLifetime.cs index 2da8d112cd..262ef513bc 100644 --- a/build/docs/BuildLifetime.cs +++ b/build/docs/BuildLifetime.cs @@ -1,4 +1,4 @@ -using Common.Addins.Cake.Wyam; +using Cake.Wyam; using Common.Lifetime; using Common.Utilities; using Docs.Utilities; diff --git a/build/docs/Tasks/BuildDocs.cs b/build/docs/Tasks/BuildDocs.cs index 0c1a59fe22..aefb216d2d 100644 --- a/build/docs/Tasks/BuildDocs.cs +++ b/build/docs/Tasks/BuildDocs.cs @@ -1,4 +1,4 @@ -using Common.Addins.Cake.Wyam; +using Cake.Wyam; using Common.Utilities; namespace Docs.Tasks; diff --git a/build/docs/Tasks/PreviewDocs.cs b/build/docs/Tasks/PreviewDocs.cs index 0f40b6e3de..a9734dd97c 100644 --- a/build/docs/Tasks/PreviewDocs.cs +++ b/build/docs/Tasks/PreviewDocs.cs @@ -1,4 +1,4 @@ -using Common.Addins.Cake.Wyam; +using Cake.Wyam; using Common.Utilities; namespace Docs.Tasks; diff --git a/build/docs/Tasks/PublishDocs.cs b/build/docs/Tasks/PublishDocs.cs index 371e1f85d9..23f0e29056 100644 --- a/build/docs/Tasks/PublishDocs.cs +++ b/build/docs/Tasks/PublishDocs.cs @@ -1,5 +1,5 @@ using Cake.Git; -using Common.Addins.Cake.Wyam; +using Cake.Wyam; using Common.Utilities; namespace Docs.Tasks; diff --git a/build/docs/docs.csproj b/build/docs/docs.csproj index eafaffb25f..3f3987e669 100644 --- a/build/docs/docs.csproj +++ b/build/docs/docs.csproj @@ -8,5 +8,6 @@ +