Skip to content

Commit

Permalink
Merge pull request #116 from pascalberger/feature/version-settings-al…
Browse files Browse the repository at this point in the history
…iases

(GH-115) Add overloads for NpmVersion which accept a settings object
  • Loading branch information
pascalberger authored Aug 30, 2020
2 parents af4da1b + 9c1d323 commit 35d7d10
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
70 changes: 66 additions & 4 deletions src/Cake.Npm/NpmVersionAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,73 @@ public static string NpmVersion(this ICakeContext context)
}

AddinInformation.LogVersionInformation(context.Log);
var settings = new NpmVersionSettings
return context.NpmVersion(new NpmVersionSettings());
}

/// <summary>
/// Versions all packages for the project in the current working directory
/// using the settings returned by a configurator.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="configurator">The settings configurator.</param>
/// <example>
/// <code>
/// <![CDATA[
/// var versionString = NpmVersion(settings => settings.WithLogLevel(NpmLogLevel.Verbose));
/// ]]>
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Version")]
public static string NpmVersion(this ICakeContext context, Action<NpmVersionSettings> 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);
}

/// <summary>
/// Versions all packages for the project in the current working directory
/// using the specified settings.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="settings">The settings.</param>
/// <example>
/// <code>
/// <![CDATA[
/// var settings = new NpmVersionSettings();
/// settings.WithLogLevel(NpmLogLevel.Verbose);
/// var versionString = NpmVersion(settings);
/// ]]>
/// </code>
/// </example>
[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);
}
}
}
2 changes: 2 additions & 0 deletions src/Cake.Npm/Version/NpmVersionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class NpmVersionSettings : NpmSettings
public NpmVersionSettings()
: base("version")
{
// Since 'NpmVersion' returns a string we should redirect standard output.
RedirectStandardOutput = true;
}
}
}

0 comments on commit 35d7d10

Please sign in to comment.