diff --git a/src/Cake.Npm/Publish/NpmPublishAccess.cs b/src/Cake.Npm/Publish/NpmPublishAccess.cs
new file mode 100644
index 0000000..b756fa3
--- /dev/null
+++ b/src/Cake.Npm/Publish/NpmPublishAccess.cs
@@ -0,0 +1,23 @@
+namespace Cake.Npm.Publish
+{
+ ///
+ /// Possible values for .
+ ///
+ public enum NpmPublishAccess
+ {
+ ///
+ /// Default value for npm publish.
+ ///
+ Default,
+
+ ///
+ /// Public access.
+ ///
+ Public,
+
+ ///
+ /// Restricted access.
+ ///
+ Restricted
+ }
+}
diff --git a/src/Cake.Npm/Publish/NpmPublishSettings.cs b/src/Cake.Npm/Publish/NpmPublishSettings.cs
index 0c3dfa9..109e681 100644
--- a/src/Cake.Npm/Publish/NpmPublishSettings.cs
+++ b/src/Cake.Npm/Publish/NpmPublishSettings.cs
@@ -18,14 +18,25 @@ public NpmPublishSettings()
}
///
- /// Source to publish.
+ /// Gets or sets the source to publish.
/// A folder containing a package.json file or an url or file path to a gzipped tar archive
/// containing a single folder with a package.json file inside.
///
public string Source { get; set; }
///
- /// Registry where the package should be published to.
+ /// Gets or sets the tag with which the package will be published.
+ /// By default the latest tag is used.
+ ///
+ public string Tag { get; set; }
+
+ ///
+ /// Gets or sets whether the package should be published as public or restricted.
+ ///
+ public NpmPublishAccess Access { get; set; }
+
+ ///
+ /// Gets or sets the registry where the package should be published to.
///
public Uri Registry { get; set; }
@@ -42,6 +53,16 @@ protected override void EvaluateCore(ProcessArgumentBuilder args)
args.AppendQuoted(Source);
}
+ if (!string.IsNullOrWhiteSpace(Tag))
+ {
+ args.AppendSwitch("--tag", Tag);
+ }
+
+ if (Access != NpmPublishAccess.Default)
+ {
+ args.AppendSwitch("--access", Access.ToString().ToLowerInvariant());
+ }
+
if (Registry != null)
{
args.AppendSwitch("--registry", Registry.ToString());
diff --git a/src/Cake.Npm/Publish/NpmPublishSettingsExtensions.cs b/src/Cake.Npm/Publish/NpmPublishSettingsExtensions.cs
index 663fb66..2c068e5 100644
--- a/src/Cake.Npm/Publish/NpmPublishSettingsExtensions.cs
+++ b/src/Cake.Npm/Publish/NpmPublishSettingsExtensions.cs
@@ -32,6 +32,47 @@ public static NpmPublishSettings FromSource(this NpmPublishSettings settings, st
return settings;
}
+ ///
+ /// Sets the tag of the package to publish.
+ ///
+ /// The settings.
+ /// Tag with which the package will be published.
+ /// The instance with set to .
+ public static NpmPublishSettings WithTag(this NpmPublishSettings 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;
+ }
+
+ ///
+ /// Sets the access of the published package.
+ ///
+ /// The settings.
+ /// Access of the published package.
+ /// The instance with set to .
+ public static NpmPublishSettings WithAccess(this NpmPublishSettings settings, NpmPublishAccess access)
+ {
+ if (settings == null)
+ {
+ throw new ArgumentNullException(nameof(settings));
+ }
+
+ settings.Access = access;
+
+ return settings;
+ }
+
///
/// Sets the registry where the package will be published to.
///
diff --git a/tests/Cake.Npm.Tests/Publish/NpmPublishSettingsExtensionsTests.cs b/tests/Cake.Npm.Tests/Publish/NpmPublishSettingsExtensionsTests.cs
index 45ffd03..d4d79cd 100644
--- a/tests/Cake.Npm.Tests/Publish/NpmPublishSettingsExtensionsTests.cs
+++ b/tests/Cake.Npm.Tests/Publish/NpmPublishSettingsExtensionsTests.cs
@@ -75,6 +75,73 @@ public void Should_Set_Source()
settings.Source.ShouldBe(source);
}
+ [Fact]
+ public void Should_Throw_If_Tag_Is_Null()
+ {
+ // Given
+ var settings = new NpmPublishSettings();
+
+ // When
+ var result = Record.Exception(() => settings.WithTag(null));
+
+ // Then
+ result.IsArgumentNullException("tag");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Tag_Is_Empty()
+ {
+ // Given
+ var settings = new NpmPublishSettings();
+
+ // When
+ var result = Record.Exception(() => settings.WithTag(string.Empty));
+
+ // Then
+ result.IsArgumentNullException("tag");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Tag_Is_WhiteSpace()
+ {
+ // Given
+ var settings = new NpmPublishSettings();
+
+ // When
+ var result = Record.Exception(() => settings.WithTag(" "));
+
+ // Then
+ result.IsArgumentNullException("tag");
+ }
+
+ [Fact]
+ public void Should_Set_Tag()
+ {
+ // Given
+ var settings = new NpmPublishSettings();
+ var tag = "1.2.3";
+
+ // When
+ settings.WithTag(tag);
+
+ // Then
+ settings.Tag.ShouldBe(tag);
+ }
+
+ [Fact]
+ public void Should_Set_Access()
+ {
+ // Given
+ var settings = new NpmPublishSettings();
+ var access = NpmPublishAccess.Restricted;
+
+ // When
+ settings.WithAccess(access);
+
+ // Then
+ settings.Access.ShouldBe(access);
+ }
+
[Fact]
public void Should_Throw_If_Registry_Is_Null()
{
diff --git a/tests/Cake.Npm.Tests/Publish/NpmPublisherTests.cs b/tests/Cake.Npm.Tests/Publish/NpmPublisherTests.cs
index e52410f..6aef7b3 100644
--- a/tests/Cake.Npm.Tests/Publish/NpmPublisherTests.cs
+++ b/tests/Cake.Npm.Tests/Publish/NpmPublisherTests.cs
@@ -1,6 +1,7 @@
namespace Cake.Npm.Tests.Publish
{
using System;
+ using Cake.Npm.Publish;
using Core.Diagnostics;
using Xunit;
@@ -49,6 +50,34 @@ public void Should_Add_Source_To_Arguments_If_Not_Null()
Assert.Equal("publish \"c:\\mypackage\"", result.Args);
}
+ [Fact]
+ public void Should_Add_Tag_To_Arguments_If_Not_Null()
+ {
+ // Given
+ var fixture = new NpmPublisherFixture();
+ fixture.Settings.Tag = "foo";
+
+ // When
+ var result = fixture.Run();
+
+ // Then
+ Assert.Equal("publish --tag foo", result.Args);
+ }
+
+ [Fact]
+ public void Should_Add_Access_To_Arguments_If_Not_Default()
+ {
+ // Given
+ var fixture = new NpmPublisherFixture();
+ fixture.Settings.Access = NpmPublishAccess.Public;
+
+ // When
+ var result = fixture.Run();
+
+ // Then
+ Assert.Equal("publish --access public", result.Args);
+ }
+
[Fact]
public void Should_Add_Registry_To_Arguments_If_Not_Null()
{