-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-117) Add support for npm dist-tag
- Loading branch information
1 parent
7e71d48
commit 1e102b2
Showing
8 changed files
with
706 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
Package = packageName; | ||
Version = packageVersion; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the package name on which the tag should be applied. | ||
/// </summary> | ||
public string Package { get; } | ||
|
||
/// <summary> | ||
/// Gets the package version on which the tag will be applied. | ||
/// </summary> | ||
public string Version { 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($"{Package}@{Version}"); | ||
|
||
if (!string.IsNullOrWhiteSpace(Tag)) | ||
{ | ||
args.Append(Tag); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 package name for which tags should be returned. | ||
/// </summary> | ||
public string Package { 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(Package); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Package"/> set to <paramref name="packageName"/>.</returns> | ||
public static NpmDistTagAddSettings ForPackage(this NpmDistTagAddSettings settings, string packageName) | ||
{ | ||
if (settings == null) | ||
{ | ||
throw new ArgumentNullException(nameof(settings)); | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(packageName)) | ||
{ | ||
throw new ArgumentNullException(nameof(packageName)); | ||
} | ||
|
||
settings.Package = packageName; | ||
|
||
return settings; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="package">Package on which a tag should be removed.</param> | ||
/// <param name="tag">Tag which should be removed.</param> | ||
public NpmDistTagRemoveSettings(string package, string tag) | ||
{ | ||
if (string.IsNullOrWhiteSpace(package)) | ||
{ | ||
throw new ArgumentNullException(nameof(package)); | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(tag)) | ||
{ | ||
throw new ArgumentNullException(nameof(tag)); | ||
} | ||
|
||
this.Package = package; | ||
this.Tag = tag; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the package name on which the tag should be removed. | ||
/// </summary> | ||
public string Package { 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(Package); | ||
args.Append(Tag); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.