diff --git a/src/Cake.Npm/NpmVersionAliases.cs b/src/Cake.Npm/NpmVersionAliases.cs index fc37253..fbb5c51 100644 --- a/src/Cake.Npm/NpmVersionAliases.cs +++ b/src/Cake.Npm/NpmVersionAliases.cs @@ -33,11 +33,73 @@ public static string NpmVersion(this ICakeContext context) } AddinInformation.LogVersionInformation(context.Log); - var settings = new NpmVersionSettings + return context.NpmVersion(new NpmVersionSettings()); + } + + /// + /// Versions all packages for the project in the current working directory + /// using the settings returned by a configurator. + /// + /// The context. + /// The settings configurator. + /// + /// + /// settings.WithLogLevel(NpmLogLevel.Verbose)); + /// ]]> + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Version")] + public static string NpmVersion(this ICakeContext context, Action configurator) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (configurator == null) + { + throw new ArgumentNullException(nameof(configurator)); + } + + var settings = new NpmVersionSettings(); + configurator(settings); + return context.NpmVersion(settings); + } + + /// + /// Versions all packages for the project in the current working directory + /// using the specified settings. + /// + /// The context. + /// The settings. + /// + /// + /// + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Version")] + public static string NpmVersion(this ICakeContext context, NpmVersionSettings settings) + { + if (context == null) { - RedirectStandardOutput = true - }; - return new NpmVersionTool(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log).Version(settings); + throw new ArgumentNullException(nameof(context)); + } + + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + + AddinInformation.LogVersionInformation(context.Log); + var tool = new NpmVersionTool(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log); + return tool.Version(settings); } } } \ No newline at end of file diff --git a/src/Cake.Npm/Version/NpmVersionSettings.cs b/src/Cake.Npm/Version/NpmVersionSettings.cs index 52159ca..4c07ec0 100644 --- a/src/Cake.Npm/Version/NpmVersionSettings.cs +++ b/src/Cake.Npm/Version/NpmVersionSettings.cs @@ -14,6 +14,8 @@ public class NpmVersionSettings : NpmSettings public NpmVersionSettings() : base("version") { + // Since 'NpmVersion' returns a string we should redirect standard output. + RedirectStandardOutput = true; } } }