Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-117) Add support for npm dist-tag #102

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Cake.Npm/DistTag/BaseNpmDistTagSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Cake.Npm.DistTag
{
/// <summary>
/// Contains settings used by <see cref="NpmDistTagTool"/>.
/// </summary>
public abstract class BaseNpmDistTagSettings : NpmSettings
{
/// <summary>
/// Initializes a new instance of the <see cref="BaseNpmDistTagSettings"/> class.
/// </summary>
protected BaseNpmDistTagSettings()
: base("dist-tag")
{
}
}
}
66 changes: 66 additions & 0 deletions src/Cake.Npm/DistTag/NpmDistTagAddSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
namespace Cake.Npm.DistTag
{
using Cake.Core;
using Cake.Core.IO;
using System;
using System.Linq;

/// <summary>
/// Contains settings used by <see cref="NpmDistTagTool"/> to add distribution tags.
/// </summary>
public class NpmDistTagAddSettings : BaseNpmDistTagSettings
{
/// <summary>
/// Initializes a new instance of the <see cref="NpmDistTagAddSettings"/> class.
/// </summary>
/// <param name="packageName">Package to which the tag should be added.</param>
/// <param name="packageVersion">The package version on which the tag will be applied</param>
public NpmDistTagAddSettings(string packageName, string packageVersion)
{
if (string.IsNullOrWhiteSpace(packageName))
{
throw new ArgumentNullException(nameof(packageName));
}

if (string.IsNullOrWhiteSpace(packageVersion))
{
throw new ArgumentNullException(nameof(packageVersion));
}

PackageName = packageName;
PacakgeVersion = packageVersion;
}

/// <summary>
/// Gets the bane of the package on which the tag should be applied.
/// </summary>
public string PackageName { get; }

/// <summary>
/// Gets the vrsion of the package on which the tag will be applied.
/// </summary>
public string PacakgeVersion { get; }

/// <summary>
/// Gets or sets the tag to be added.
/// </summary>
public string Tag { get; set; }

/// <summary>
/// Evaluates the settings and writes them to <paramref name="args" />.
/// </summary>
/// <param name="args">The argument builder into which the settings should be written.</param>
protected override void EvaluateCore(ProcessArgumentBuilder args)
{
base.EvaluateCore(args);

args.Append("add");
args.Append($"{PackageName}@{PacakgeVersion}");

if (!string.IsNullOrWhiteSpace(Tag))
{
args.Append(Tag);
}
}
}
}
33 changes: 33 additions & 0 deletions src/Cake.Npm/DistTag/NpmDistTagAddSettingsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Cake.Npm.DistTag
{
using System;

/// <summary>
/// Extensions for <see cref="NpmDistTagAddSettings"/>.
/// </summary>
public static class NpmDistTagAddSettingsExtensions
{
/// <summary>
/// Sets the tag which should be set on the package.
/// </summary>
/// <param name="settings">The settings.</param>
/// <param name="tag">Tag with which should be set on the package.</param>
/// <returns>The <paramref name="settings"/> instance with <see cref="NpmDistTagAddSettings.Tag"/> set to <paramref name="tag"/>.</returns>
public static NpmDistTagAddSettings WithTag(this NpmDistTagAddSettings settings, string tag)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}

if (string.IsNullOrWhiteSpace(tag))
{
throw new ArgumentNullException(nameof(tag));
}

settings.Tag = tag;

return settings;
}
}
}
36 changes: 36 additions & 0 deletions src/Cake.Npm/DistTag/NpmDistTagListSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Cake.Npm.DistTag
{
using Cake.Core;
using Cake.Core.IO;
using System.Linq;

/// <summary>
/// Contains settings used by <see cref="NpmDistTagTool"/> to list distribution tags.
/// </summary>
public class NpmDistTagListSettings : BaseNpmDistTagSettings
{
/// <summary>
/// Initializes a new instance of the <see cref="NpmDistTagListSettings"/> class.
/// </summary>
public NpmDistTagListSettings()
{
}

/// <summary>
/// Gets or sets the name of the package for which tags should be returned.
/// </summary>
public string PackageName { get; set; }

/// <summary>
/// Evaluates the settings and writes them to <paramref name="args" />.
/// </summary>
/// <param name="args">The argument builder into which the settings should be written.</param>
protected override void EvaluateCore(ProcessArgumentBuilder args)
{
base.EvaluateCore(args);

args.Append("ls");
args.Append(PackageName);
}
}
}
33 changes: 33 additions & 0 deletions src/Cake.Npm/DistTag/NpmDistTagListSettingsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Cake.Npm.DistTag
{
using System;

/// <summary>
/// Extensions for <see cref="NpmDistTagListSettings"/>.
/// </summary>
public static class NpmDistTagListSettingsExtensions
{
/// <summary>
/// Sets the name of the package for which tags should be listed.
/// </summary>
/// <param name="settings">The settings.</param>
/// <param name="packageName">Tag with which should be set on the package.</param>
/// <returns>The <paramref name="settings"/> instance with <see cref="NpmDistTagAddSettings.PackageName"/> set to <paramref name="packageName"/>.</returns>
public static NpmDistTagListSettings ForPackage(this NpmDistTagListSettings settings, string packageName)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}

if (string.IsNullOrWhiteSpace(packageName))
{
throw new ArgumentNullException(nameof(packageName));
}

settings.PackageName = packageName;

return settings;
}
}
}
57 changes: 57 additions & 0 deletions src/Cake.Npm/DistTag/NpmDistTagRemoveSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Cake.Npm.DistTag
{
using System;
using System.Linq;
using Cake.Core;
using Cake.Core.IO;

/// <summary>
/// Contains settings used by <see cref="NpmDistTagTool"/> to remove distribution tags.
/// </summary>
public class NpmDistTagRemoveSettings : BaseNpmDistTagSettings
{
/// <summary>
/// Initializes a new instance of the <see cref="NpmDistTagRemoveSettings"/> class.
/// </summary>
/// <param name="packageName">Package on which a tag should be removed.</param>
/// <param name="tag">Tag which should be removed.</param>
public NpmDistTagRemoveSettings(string packageName, string tag)
{
if (string.IsNullOrWhiteSpace(packageName))
{
throw new ArgumentNullException(nameof(packageName));
}

if (string.IsNullOrWhiteSpace(tag))
{
throw new ArgumentNullException(nameof(tag));
}

this.PackageName = packageName;
this.Tag = tag;
}

/// <summary>
/// Gets the name of the package on which the tag should be removed.
/// </summary>
public string PackageName { get; }

/// <summary>
/// Gets the tag to be removed.
/// </summary>
public string Tag { get; }

/// <summary>
/// Evaluates the settings and writes them to <paramref name="args" />.
/// </summary>
/// <param name="args">The argument builder into which the settings should be written.</param>
protected override void EvaluateCore(ProcessArgumentBuilder args)
{
base.EvaluateCore(args);

args.Append("rm");
args.Append(PackageName);
args.Append(Tag);
}
}
}
46 changes: 46 additions & 0 deletions src/Cake.Npm/DistTag/NpmDistTagTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace Cake.Npm.DistTag
{
using System;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Core.Tooling;

/// <summary>
/// Tool for running npm dist-tags.
/// </summary>
public class NpmDistTagTool : NpmTool<BaseNpmDistTagSettings>
{
/// <summary>
/// Initializes a new instance of the <see cref="NpmDistTagTool"/> class.
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="environment">The environment.</param>
/// <param name="processRunner">The process runner.</param>
/// <param name="tools">The tool locator.</param>
/// <param name="log">Cake log instance.</param>
public NpmDistTagTool(
IFileSystem fileSystem,
ICakeEnvironment environment,
IProcessRunner processRunner,
IToolLocator tools,
ICakeLog log)
: base(fileSystem, environment, processRunner, tools, log)
{
}

/// <summary>
/// Runs <c>npm dist-tags</c> with the specified settings.
/// </summary>
/// <param name="settings">The settings.</param>
public void RunDistTag(BaseNpmDistTagSettings settings)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}

RunCore(settings);
}
}
}
Loading