From 7ea5e5e6e47c6ea9e50a77234323d690e6f8180b Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Sun, 26 Aug 2018 22:36:59 +0200 Subject: [PATCH 01/10] (GH-83) Build with Cake 0.30.0 --- tools/packages.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/packages.config b/tools/packages.config index 747e13e..0501888 100644 --- a/tools/packages.config +++ b/tools/packages.config @@ -1,4 +1,4 @@ - + From 8be0d8085ea08058b90acc4569b0e7abb9f05370 Mon Sep 17 00:00:00 2001 From: Kjetil Klaussen Date: Mon, 10 Sep 2018 22:23:29 +0200 Subject: [PATCH 02/10] (GH-87) Added 'Registry' to NpmCiSettings (#86) Added 'Registry' to NpmCiSettings Needed to run 'npm ci' with private npm repos, e.g. "npm ci --registry=https://www.myget.org/feed/..." --- src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs | 16 +++++++++++++++- src/Cake.Npm/Ci/NpmCiSettings.cs | 10 ++++++++++ src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs | 17 +++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs b/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs index 2ee4de0..f715f3c 100644 --- a/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs +++ b/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs @@ -106,6 +106,20 @@ public void Should_Include_Production_Flag() Assert.Equal("ci --production", result.Args); } - } + + [Fact] + public void Should_Include_Registry_Args_If_Set() + { + // Given + var fixture = new NpmCiToolFixture(); + fixture.Settings.FromRegistry("https://www.myget.org/feed"); + + // When + var result = fixture.Run(); + + // Then + Assert.Equal("ci --registry=https://www.myget.org/feed", result.Args); + } + } } } diff --git a/src/Cake.Npm/Ci/NpmCiSettings.cs b/src/Cake.Npm/Ci/NpmCiSettings.cs index 19e1103..22242f4 100644 --- a/src/Cake.Npm/Ci/NpmCiSettings.cs +++ b/src/Cake.Npm/Ci/NpmCiSettings.cs @@ -21,6 +21,11 @@ public NpmCiSettings() /// public bool Production { get; set; } + /// + /// Sets the registry param for npm + /// + public string Registry { get; set; } + /// protected override void EvaluateCore(ProcessArgumentBuilder args) { @@ -30,6 +35,11 @@ protected override void EvaluateCore(ProcessArgumentBuilder args) { args.Append("--production"); } + + if (!string.IsNullOrWhiteSpace(Registry)) + { + args.Append($"--registry={Registry}"); + } } } } diff --git a/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs b/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs index 6e9ae67..f6f8a51 100644 --- a/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs +++ b/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs @@ -26,5 +26,22 @@ public static NpmCiSettings ForProduction(this NpmCiSettings settings) settings.Production = true; return settings; } + + /// + /// Instructs npm to look for packages in the given registry. + /// + /// The settings. + /// The registry to look up packages from + /// The instance with set to . + public static NpmCiSettings FromRegistry(this NpmCiSettings settings, string registry) + { + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + + settings.Registry = registry; + return settings; + } } } From 1e9390890b2c63727ed013bf28f4b03f320f5bd6 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Mon, 10 Sep 2018 22:32:48 +0200 Subject: [PATCH 03/10] (GH--88) Add FromRegistry method to NpmInstallSettings fluent API --- .../NpmInstallerSettingsExtensionsTests.cs | 73 +++++++++++++++++++ .../Install/NpmInstallSettingsExtensions.cs | 22 ++++++ 2 files changed, 95 insertions(+) diff --git a/src/Cake.Npm.Tests/Install/NpmInstallerSettingsExtensionsTests.cs b/src/Cake.Npm.Tests/Install/NpmInstallerSettingsExtensionsTests.cs index 374f1a5..b1b4f22 100644 --- a/src/Cake.Npm.Tests/Install/NpmInstallerSettingsExtensionsTests.cs +++ b/src/Cake.Npm.Tests/Install/NpmInstallerSettingsExtensionsTests.cs @@ -785,5 +785,78 @@ public void Should_Quote_If_Tag_Contains_WhiteSpace() settings.Packages.ShouldContain(scope + "/" + packageName + "@\"" + tag + "\""); } } + + public sealed class TheFromRegistryMethod + { + [Fact] + public void Should_Throw_If_Settings_Are_Null() + { + // Given + NpmInstallSettings settings = null; + string registry = "foo"; + + // When + var result = Record.Exception(() => settings.FromRegistry(registry)); + + // Then + result.IsArgumentNullException("settings"); + } + + [Fact] + public void Should_Throw_If_Registry_Is_Null() + { + // Given + var settings = new NpmInstallSettings(); + string registry = null; + + // When + var result = Record.Exception(() => settings.FromRegistry(registry)); + + // Then + result.IsArgumentNullException("registry"); + } + + [Fact] + public void Should_Throw_If_Registry_Is_Empty() + { + // Given + var settings = new NpmInstallSettings(); + string registry = string.Empty; + + // When + var result = Record.Exception(() => settings.FromRegistry(registry)); + + // Then + result.IsArgumentNullException("registry"); + } + + [Fact] + public void Should_Throw_If_Registry_Is_WhiteSpace() + { + // Given + var settings = new NpmInstallSettings(); + string registry = " "; + + // When + var result = Record.Exception(() => settings.FromRegistry(registry)); + + // Then + result.IsArgumentNullException("registry"); + } + + [Fact] + public void Should_Set_Registry() + { + // Given + var settings = new NpmInstallSettings(); + string registry = "foo"; + + // When + var result = settings.FromRegistry(registry); + + // Then + result.Registry.ShouldBe(registry); + } + } } } diff --git a/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs b/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs index 09ca17b..aa9c439 100644 --- a/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs +++ b/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs @@ -300,5 +300,27 @@ public static NpmInstallSettings AddPackage(this NpmInstallSettings settings, st settings.Packages.Add(resolvedPackageName); return settings; } + + /// + /// Instructs npm to look for packages in the given registry. + /// + /// The settings. + /// The registry to look up packages from + /// The instance with set to . + public static NpmInstallSettings FromRegistry(this NpmInstallSettings settings, string registry) + { + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + + if (string.IsNullOrWhiteSpace(registry)) + { + throw new ArgumentNullException(nameof(registry)); + } + + settings.Registry = registry; + return settings; + } } } From 71fa9298c913c746496267fb65764ab6bed723db Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Mon, 10 Sep 2018 22:36:55 +0200 Subject: [PATCH 04/10] Update XUnit to 2.4.0 --- src/Cake.Npm.Tests/Cake.Npm.Tests.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cake.Npm.Tests/Cake.Npm.Tests.csproj b/src/Cake.Npm.Tests/Cake.Npm.Tests.csproj index 0a8cd5e..963199e 100644 --- a/src/Cake.Npm.Tests/Cake.Npm.Tests.csproj +++ b/src/Cake.Npm.Tests/Cake.Npm.Tests.csproj @@ -12,10 +12,10 @@ - + - - + + From d676d3f603543c96bdef123d7342a43427cce250 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Mon, 10 Sep 2018 23:35:39 +0200 Subject: [PATCH 05/10] Add missing tests --- .../Ci/NpmCiSettingsExtensionsTests.cs | 110 +++++++++ ...s => NpmInstallSettingsExtensionsTests.cs} | 2 +- .../NpmRebuildSettingsExtensionsTests.cs | 211 ++++++++++++++++++ .../NpmUpdateSettingsExtensionsTests.cs | 38 ++++ src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs | 5 + ...ons.cs => NpmRebuildSettingsExtensions.cs} | 2 +- src/Cake.Npm/Set/NpmSetSettings.cs | 112 +++++----- .../Update/NpmUpdateSettingsExtensions.cs | 5 +- 8 files changed, 423 insertions(+), 62 deletions(-) create mode 100644 src/Cake.Npm.Tests/Ci/NpmCiSettingsExtensionsTests.cs rename src/Cake.Npm.Tests/Install/{NpmInstallerSettingsExtensionsTests.cs => NpmInstallSettingsExtensionsTests.cs} (99%) create mode 100644 src/Cake.Npm.Tests/Rebuild/NpmRebuildSettingsExtensionsTests.cs create mode 100644 src/Cake.Npm.Tests/Update/NpmUpdateSettingsExtensionsTests.cs rename src/Cake.Npm/Rebuild/{NpmRebuilSettingsExtensions.cs => NpmRebuildSettingsExtensions.cs} (97%) diff --git a/src/Cake.Npm.Tests/Ci/NpmCiSettingsExtensionsTests.cs b/src/Cake.Npm.Tests/Ci/NpmCiSettingsExtensionsTests.cs new file mode 100644 index 0000000..57cf3d5 --- /dev/null +++ b/src/Cake.Npm.Tests/Ci/NpmCiSettingsExtensionsTests.cs @@ -0,0 +1,110 @@ +namespace Cake.Npm.Tests.Ci +{ + using Cake.Npm.Ci; + using Shouldly; + using Xunit; + + public sealed class NpmUpdateSettingsExtensionsTests + { + public sealed class TheForProductionMethod + { + [Fact] + public void Should_Throw_If_Settings_Are_Null() + { + // Given + NpmCiSettings settings = null; + + // When + var result = Record.Exception(() => settings.ForProduction()); + + // Then + result.IsArgumentNullException("settings"); + } + [Fact] + public void Should_Set_Production() + { + // Given + var settings = new NpmCiSettings(); + + // When + settings.ForProduction(); + + // Then + settings.Production.ShouldBe(true); + } + } + + public sealed class TheFromRegistryMethod + { + [Fact] + public void Should_Throw_If_Settings_Are_Null() + { + // Given + NpmCiSettings settings = null; + string registry = "foo"; + + // When + var result = Record.Exception(() => settings.FromRegistry(registry)); + + // Then + result.IsArgumentNullException("settings"); + } + + [Fact] + public void Should_Throw_If_Registry_Is_Null() + { + // Given + var settings = new NpmCiSettings(); + string registry = null; + + // When + var result = Record.Exception(() => settings.FromRegistry(registry)); + + // Then + result.IsArgumentNullException("registry"); + } + + [Fact] + public void Should_Throw_If_Registry_Is_Empty() + { + // Given + var settings = new NpmCiSettings(); + string registry = string.Empty; + + // When + var result = Record.Exception(() => settings.FromRegistry(registry)); + + // Then + result.IsArgumentNullException("registry"); + } + + [Fact] + public void Should_Throw_If_Registry_Is_WhiteSpace() + { + // Given + var settings = new NpmCiSettings(); + string registry = " "; + + // When + var result = Record.Exception(() => settings.FromRegistry(registry)); + + // Then + result.IsArgumentNullException("registry"); + } + + [Fact] + public void Should_Set_Registry() + { + // Given + var settings = new NpmCiSettings(); + string registry = "foo"; + + // When + var result = settings.FromRegistry(registry); + + // Then + result.Registry.ShouldBe(registry); + } + } + } +} diff --git a/src/Cake.Npm.Tests/Install/NpmInstallerSettingsExtensionsTests.cs b/src/Cake.Npm.Tests/Install/NpmInstallSettingsExtensionsTests.cs similarity index 99% rename from src/Cake.Npm.Tests/Install/NpmInstallerSettingsExtensionsTests.cs rename to src/Cake.Npm.Tests/Install/NpmInstallSettingsExtensionsTests.cs index b1b4f22..7b7ba23 100644 --- a/src/Cake.Npm.Tests/Install/NpmInstallerSettingsExtensionsTests.cs +++ b/src/Cake.Npm.Tests/Install/NpmInstallSettingsExtensionsTests.cs @@ -5,7 +5,7 @@ using Shouldly; using Xunit; - public sealed class NpmInstallSettingsExtensionsTests + public sealed class NpmRebuildSettingsExtensionsTests { public sealed class TheWithForceMethod { diff --git a/src/Cake.Npm.Tests/Rebuild/NpmRebuildSettingsExtensionsTests.cs b/src/Cake.Npm.Tests/Rebuild/NpmRebuildSettingsExtensionsTests.cs new file mode 100644 index 0000000..26eea64 --- /dev/null +++ b/src/Cake.Npm.Tests/Rebuild/NpmRebuildSettingsExtensionsTests.cs @@ -0,0 +1,211 @@ +namespace Cake.Npm.Tests.Rebuild +{ + using Cake.Npm.Rebuild; + using Shouldly; + using Xunit; + + public sealed class NpmRebuildSettingsExtensionsTests + { + public sealed class TheAddPackageMethod + { + [Fact] + public void Should_Throw_If_Settings_Are_Null() + { + // Given + NpmRebuildSettings settings = null; + + // When + var result = Record.Exception(() => settings.AddPackage("foo")); + + // Then + result.IsArgumentNullException("settings"); + } + + [Fact] + public void Should_Throw_If_Package_Is_Null() + { + // Given + var settings = new NpmRebuildSettings(); + + // When + var result = Record.Exception(() => settings.AddPackage((string)null)); + + // Then + result.IsArgumentNullException("packageName"); + } + + [Fact] + public void Should_Throw_If_Package_Is_Empty() + { + // Given + var settings = new NpmRebuildSettings(); + + // When + var result = Record.Exception(() => settings.AddPackage(string.Empty)); + + // Then + result.IsArgumentNullException("packageName"); + } + + [Fact] + public void Should_Throw_If_Package_Is_WhiteSpace() + { + // Given + var settings = new NpmRebuildSettings(); + + // When + var result = Record.Exception(() => settings.AddPackage(" ")); + + // Then + result.IsArgumentNullException("packageName"); + } + + [Fact] + public void Should_Add_Package() + { + // Given + var settings = new NpmRebuildSettings(); + var packageName = "foo"; + + // When + settings.AddPackage(packageName); + + // Then + settings.Packages.Count.ShouldBe(1); + settings.Packages.ShouldContain(packageName); + } + } + + public sealed class TheAddScopedPackageMethod + { + [Fact] + public void Should_Throw_If_Settings_Are_Null() + { + // Given + NpmRebuildSettings settings = null; + + // When + var result = Record.Exception(() => settings.AddScopedPackage("foo", "@bar")); + + // Then + result.IsArgumentNullException("settings"); + } + + [Fact] + public void Should_Throw_If_Package_Is_Null() + { + // Given + var settings = new NpmRebuildSettings(); + + // When + var result = Record.Exception(() => settings.AddScopedPackage(null, "@bar")); + + // Then + result.IsArgumentNullException("packageName"); + } + + [Fact] + public void Should_Throw_If_Package_Is_Empty() + { + // Given + var settings = new NpmRebuildSettings(); + + // When + var result = Record.Exception(() => settings.AddScopedPackage(string.Empty, "@bar")); + + // Then + result.IsArgumentNullException("packageName"); + } + + [Fact] + public void Should_Throw_If_Package_Is_WhiteSpace() + { + // Given + var settings = new NpmRebuildSettings(); + + // When + var result = Record.Exception(() => settings.AddScopedPackage(" ", "@bar")); + + // Then + result.IsArgumentNullException("packageName"); + } + + [Fact] + public void Should_Throw_If_Scope_Does_Not_Start_With_At() + { + // Given + var settings = new NpmRebuildSettings(); + + // When + var result = Record.Exception(() => settings.AddScopedPackage("foo", "bar")); + + // Then + result.IsArgumentException("scope"); + } + + [Fact] + public void Should_Add_Package() + { + // Given + var settings = new NpmRebuildSettings(); + var packageName = "foo"; + var scope = "@bar"; + + // When + settings.AddScopedPackage(packageName, scope); + + // Then + settings.Packages.Count.ShouldBe(1); + settings.Packages.ShouldContain(scope + "/" + packageName); + } + + [Fact] + public void Should_Add_Package_If_Scope_Is_Null() + { + // Given + var settings = new NpmRebuildSettings(); + var packageName = "foo"; + string scope = null; + + // When + settings.AddScopedPackage(packageName, scope); + + // Then + settings.Packages.Count.ShouldBe(1); + settings.Packages.ShouldContain(packageName); + } + + [Fact] + public void Should_Add_Package_If_Scope_Is_Empty() + { + // Given + var settings = new NpmRebuildSettings(); + var packageName = "foo"; + var scope = string.Empty; + + // When + settings.AddScopedPackage(packageName, scope); + + // Then + settings.Packages.Count.ShouldBe(1); + settings.Packages.ShouldContain(packageName); + } + + [Fact] + public void Should_Add_Package_If_Scope_Is_WhiteSpace() + { + // Given + var settings = new NpmRebuildSettings(); + var packageName = "foo"; + var scope = " "; + + // When + settings.AddScopedPackage(packageName, scope); + + // Then + settings.Packages.Count.ShouldBe(1); + settings.Packages.ShouldContain(packageName); + } + } + } +} diff --git a/src/Cake.Npm.Tests/Update/NpmUpdateSettingsExtensionsTests.cs b/src/Cake.Npm.Tests/Update/NpmUpdateSettingsExtensionsTests.cs new file mode 100644 index 0000000..b26922d --- /dev/null +++ b/src/Cake.Npm.Tests/Update/NpmUpdateSettingsExtensionsTests.cs @@ -0,0 +1,38 @@ +namespace Cake.Npm.Tests.Update +{ + using Cake.Npm.Update; + using Shouldly; + using Xunit; + + public sealed class NpmUpdateSettingsExtensionsTests + { + public sealed class TheUpdateGlobalPackagesMethod + { + [Fact] + public void Should_Throw_If_Settings_Are_Null() + { + // Given + NpmUpdateSettings settings = null; + + // When + var result = Record.Exception(() => settings.UpdateGlobalPackages()); + + // Then + result.IsArgumentNullException("settings"); + } + + [Fact] + public void Should_Set_Global() + { + // Given + var settings = new NpmUpdateSettings(); + + // When + settings.UpdateGlobalPackages(); + + // Then + settings.Global.ShouldBe(true); + } + } + } +} diff --git a/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs b/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs index f6f8a51..92b1cd8 100644 --- a/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs +++ b/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs @@ -40,6 +40,11 @@ public static NpmCiSettings FromRegistry(this NpmCiSettings settings, string reg throw new ArgumentNullException(nameof(settings)); } + if (string.IsNullOrWhiteSpace(registry)) + { + throw new ArgumentNullException(nameof(registry)); + } + settings.Registry = registry; return settings; } diff --git a/src/Cake.Npm/Rebuild/NpmRebuilSettingsExtensions.cs b/src/Cake.Npm/Rebuild/NpmRebuildSettingsExtensions.cs similarity index 97% rename from src/Cake.Npm/Rebuild/NpmRebuilSettingsExtensions.cs rename to src/Cake.Npm/Rebuild/NpmRebuildSettingsExtensions.cs index 723a38d..4009a1a 100644 --- a/src/Cake.Npm/Rebuild/NpmRebuilSettingsExtensions.cs +++ b/src/Cake.Npm/Rebuild/NpmRebuildSettingsExtensions.cs @@ -5,7 +5,7 @@ namespace Cake.Npm.Rebuild /// /// Extensions for . /// - public static class NpmRebuilSettingsExtensions + public static class NpmRebuildSettingsExtensions { /// /// Rebuild a package by name diff --git a/src/Cake.Npm/Set/NpmSetSettings.cs b/src/Cake.Npm/Set/NpmSetSettings.cs index 189982e..c2feadd 100644 --- a/src/Cake.Npm/Set/NpmSetSettings.cs +++ b/src/Cake.Npm/Set/NpmSetSettings.cs @@ -1,58 +1,58 @@ -using Cake.Core; -using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; using System; -namespace Cake.Npm.Set -{ - /// - /// Contains settings used by . - /// - public class NpmSetSettings : NpmSettings - { - /// - /// Initializes a new instance of the class. - /// - public NpmSetSettings() - : base("set") - { - } - - /// - /// The config key - /// - public string Key { get; set; } - - /// - /// The config value - /// - public string Value { get; set; } - - /// - /// Determines whether to set the config key value globally - /// - public bool Global { get; set; } - - /// - protected override void EvaluateCore(ProcessArgumentBuilder args) - { - if (string.IsNullOrWhiteSpace(Key)) - { - throw new ArgumentNullException(nameof(Key)); - } - - if (string.IsNullOrWhiteSpace(Value)) - { - throw new ArgumentNullException(nameof(Value)); - } - - args.Append($"\"{Key}\"=\"{Value}\""); - - if (Global) - { - args.Append("-g"); - } - - base.EvaluateCore(args); - } - } -} +namespace Cake.Npm.Set +{ + /// + /// Contains settings used by . + /// + public class NpmSetSettings : NpmSettings + { + /// + /// Initializes a new instance of the class. + /// + public NpmSetSettings() + : base("set") + { + } + + /// + /// The config key + /// + public string Key { get; set; } + + /// + /// The config value + /// + public string Value { get; set; } + + /// + /// Determines whether to set the config key value globally + /// + public bool Global { get; set; } + + /// + protected override void EvaluateCore(ProcessArgumentBuilder args) + { + if (string.IsNullOrWhiteSpace(Key)) + { + throw new ArgumentNullException(nameof(Key)); + } + + if (string.IsNullOrWhiteSpace(Value)) + { + throw new ArgumentNullException(nameof(Value)); + } + + args.Append($"\"{Key}\"=\"{Value}\""); + + if (Global) + { + args.Append("-g"); + } + + base.EvaluateCore(args); + } + } +} diff --git a/src/Cake.Npm/Update/NpmUpdateSettingsExtensions.cs b/src/Cake.Npm/Update/NpmUpdateSettingsExtensions.cs index b633596..a9adcfa 100644 --- a/src/Cake.Npm/Update/NpmUpdateSettingsExtensions.cs +++ b/src/Cake.Npm/Update/NpmUpdateSettingsExtensions.cs @@ -1,9 +1,6 @@ -using Cake.Npm.Update; - -namespace Cake.Npm.Update +namespace Cake.Npm.Update { using System; - using Core; /// /// Extensions for . From 10893b57ad32a415d270ba948aaf3b9af67d4609 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Mon, 10 Sep 2018 23:53:23 +0200 Subject: [PATCH 06/10] (GH-89) Use System.Uri for all registry properties --- .../Ci/NpmCiSettingsExtensionsTests.cs | 35 +++---------------- src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs | 4 +-- .../NpmInstallSettingsExtensionsTests.cs | 34 ++---------------- .../Install/NpmInstallerTests.cs | 8 ++--- src/Cake.Npm/Ci/NpmCiSettings.cs | 10 +++--- src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs | 4 +-- src/Cake.Npm/Install/NpmInstallSettings.cs | 6 ++-- .../Install/NpmInstallSettingsExtensions.cs | 4 +-- src/Cake.Npm/Publish/NpmPublishSettings.cs | 1 + 9 files changed, 27 insertions(+), 79 deletions(-) diff --git a/src/Cake.Npm.Tests/Ci/NpmCiSettingsExtensionsTests.cs b/src/Cake.Npm.Tests/Ci/NpmCiSettingsExtensionsTests.cs index 57cf3d5..8f02779 100644 --- a/src/Cake.Npm.Tests/Ci/NpmCiSettingsExtensionsTests.cs +++ b/src/Cake.Npm.Tests/Ci/NpmCiSettingsExtensionsTests.cs @@ -2,6 +2,7 @@ { using Cake.Npm.Ci; using Shouldly; + using System; using Xunit; public sealed class NpmUpdateSettingsExtensionsTests @@ -41,7 +42,7 @@ public void Should_Throw_If_Settings_Are_Null() { // Given NpmCiSettings settings = null; - string registry = "foo"; + var registry = new Uri("https://myregistry.com"); // When var result = Record.Exception(() => settings.FromRegistry(registry)); @@ -55,35 +56,7 @@ public void Should_Throw_If_Registry_Is_Null() { // Given var settings = new NpmCiSettings(); - string registry = null; - - // When - var result = Record.Exception(() => settings.FromRegistry(registry)); - - // Then - result.IsArgumentNullException("registry"); - } - - [Fact] - public void Should_Throw_If_Registry_Is_Empty() - { - // Given - var settings = new NpmCiSettings(); - string registry = string.Empty; - - // When - var result = Record.Exception(() => settings.FromRegistry(registry)); - - // Then - result.IsArgumentNullException("registry"); - } - - [Fact] - public void Should_Throw_If_Registry_Is_WhiteSpace() - { - // Given - var settings = new NpmCiSettings(); - string registry = " "; + Uri registry = null; // When var result = Record.Exception(() => settings.FromRegistry(registry)); @@ -97,7 +70,7 @@ public void Should_Set_Registry() { // Given var settings = new NpmCiSettings(); - string registry = "foo"; + var registry = new Uri("https://myregistry.com"); // When var result = settings.FromRegistry(registry); diff --git a/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs b/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs index f715f3c..4d5c0c6 100644 --- a/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs +++ b/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs @@ -112,13 +112,13 @@ public void Should_Include_Registry_Args_If_Set() { // Given var fixture = new NpmCiToolFixture(); - fixture.Settings.FromRegistry("https://www.myget.org/feed"); + fixture.Settings.FromRegistry(new Uri("https://myregistry/")); // When var result = fixture.Run(); // Then - Assert.Equal("ci --registry=https://www.myget.org/feed", result.Args); + Assert.Equal("ci --registry https://myregistry/", result.Args); } } } diff --git a/src/Cake.Npm.Tests/Install/NpmInstallSettingsExtensionsTests.cs b/src/Cake.Npm.Tests/Install/NpmInstallSettingsExtensionsTests.cs index 7b7ba23..c83ffc1 100644 --- a/src/Cake.Npm.Tests/Install/NpmInstallSettingsExtensionsTests.cs +++ b/src/Cake.Npm.Tests/Install/NpmInstallSettingsExtensionsTests.cs @@ -793,7 +793,7 @@ public void Should_Throw_If_Settings_Are_Null() { // Given NpmInstallSettings settings = null; - string registry = "foo"; + Uri registry = new Uri("https://myregistry.com"); // When var result = Record.Exception(() => settings.FromRegistry(registry)); @@ -807,35 +807,7 @@ public void Should_Throw_If_Registry_Is_Null() { // Given var settings = new NpmInstallSettings(); - string registry = null; - - // When - var result = Record.Exception(() => settings.FromRegistry(registry)); - - // Then - result.IsArgumentNullException("registry"); - } - - [Fact] - public void Should_Throw_If_Registry_Is_Empty() - { - // Given - var settings = new NpmInstallSettings(); - string registry = string.Empty; - - // When - var result = Record.Exception(() => settings.FromRegistry(registry)); - - // Then - result.IsArgumentNullException("registry"); - } - - [Fact] - public void Should_Throw_If_Registry_Is_WhiteSpace() - { - // Given - var settings = new NpmInstallSettings(); - string registry = " "; + Uri registry = null; // When var result = Record.Exception(() => settings.FromRegistry(registry)); @@ -849,7 +821,7 @@ public void Should_Set_Registry() { // Given var settings = new NpmInstallSettings(); - string registry = "foo"; + Uri registry = new Uri("https://myregistry.com"); // When var result = settings.FromRegistry(registry); diff --git a/src/Cake.Npm.Tests/Install/NpmInstallerTests.cs b/src/Cake.Npm.Tests/Install/NpmInstallerTests.cs index bcf7557..9decfac 100644 --- a/src/Cake.Npm.Tests/Install/NpmInstallerTests.cs +++ b/src/Cake.Npm.Tests/Install/NpmInstallerTests.cs @@ -218,11 +218,11 @@ public void Should_Add_PreferOffline_To_Arguments_If_Not_Null() } [Fact] - public void Should_Add_Registry_To_Arguments_If_Not_Empty() + public void Should_Add_Registry_To_Arguments_If_Set() { // Given var fixture = new NpmInstallerFixture(); - var registry = "http://exampleregistry.com"; + var registry = new Uri("http://exampleregistry.com"); fixture.Settings.Registry = registry; // When @@ -233,11 +233,11 @@ public void Should_Add_Registry_To_Arguments_If_Not_Empty() } [Fact] - public void Should_Not_Add_Registry_To_Arguments_If_Empty() + public void Should_Not_Add_Registry_To_Arguments_If_Not_Set() { // Given var fixture = new NpmInstallerFixture(); - fixture.Settings.Registry = ""; + fixture.Settings.Registry = null; // When var result = fixture.Run(); diff --git a/src/Cake.Npm/Ci/NpmCiSettings.cs b/src/Cake.Npm/Ci/NpmCiSettings.cs index 22242f4..16eecc0 100644 --- a/src/Cake.Npm/Ci/NpmCiSettings.cs +++ b/src/Cake.Npm/Ci/NpmCiSettings.cs @@ -1,5 +1,6 @@ using Cake.Core; using Cake.Core.IO; +using System; namespace Cake.Npm.Ci { @@ -22,9 +23,10 @@ public NpmCiSettings() public bool Production { get; set; } /// - /// Sets the registry param for npm + /// Gets or sets the registry where packages should be restored from. + /// Defaulted to whatever the NPM configuration is. /// - public string Registry { get; set; } + public Uri Registry { get; set; } /// protected override void EvaluateCore(ProcessArgumentBuilder args) @@ -36,9 +38,9 @@ protected override void EvaluateCore(ProcessArgumentBuilder args) args.Append("--production"); } - if (!string.IsNullOrWhiteSpace(Registry)) + if (Registry != null) { - args.Append($"--registry={Registry}"); + args.AppendSwitch("--registry", Registry.ToString()); } } } diff --git a/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs b/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs index 92b1cd8..72147f2 100644 --- a/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs +++ b/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs @@ -33,14 +33,14 @@ public static NpmCiSettings ForProduction(this NpmCiSettings settings) /// The settings. /// The registry to look up packages from /// The instance with set to . - public static NpmCiSettings FromRegistry(this NpmCiSettings settings, string registry) + public static NpmCiSettings FromRegistry(this NpmCiSettings settings, Uri registry) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } - if (string.IsNullOrWhiteSpace(registry)) + if (registry == null) { throw new ArgumentNullException(nameof(registry)); } diff --git a/src/Cake.Npm/Install/NpmInstallSettings.cs b/src/Cake.Npm/Install/NpmInstallSettings.cs index b4d15c5..81860e7 100644 --- a/src/Cake.Npm/Install/NpmInstallSettings.cs +++ b/src/Cake.Npm/Install/NpmInstallSettings.cs @@ -51,7 +51,7 @@ public NpmInstallSettings() /// /// Gets or sets a value indicating which registry we should point to. Defaulted to whatever the NPM configuration is. /// - public string Registry { get; set; } + public Uri Registry { get; set; } /// /// Gets or sets a value indicating whether or not to utilise the prefer offline flag, avoiding going to the internet for packages if possible. @@ -86,9 +86,9 @@ protected override void EvaluateCore(ProcessArgumentBuilder args) args.Append("--no-optional"); } - if (!string.IsNullOrWhiteSpace(Registry)) + if (Registry != null) { - args.Append($"--registry {Registry.ToLower()}"); + args.AppendSwitch("--registry", Registry.ToString()); } if (PreferOffline) diff --git a/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs b/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs index aa9c439..67c87cb 100644 --- a/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs +++ b/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs @@ -307,14 +307,14 @@ public static NpmInstallSettings AddPackage(this NpmInstallSettings settings, st /// The settings. /// The registry to look up packages from /// The instance with set to . - public static NpmInstallSettings FromRegistry(this NpmInstallSettings settings, string registry) + public static NpmInstallSettings FromRegistry(this NpmInstallSettings settings, Uri registry) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } - if (string.IsNullOrWhiteSpace(registry)) + if (registry == null) { throw new ArgumentNullException(nameof(registry)); } diff --git a/src/Cake.Npm/Publish/NpmPublishSettings.cs b/src/Cake.Npm/Publish/NpmPublishSettings.cs index 109e681..8a120bd 100644 --- a/src/Cake.Npm/Publish/NpmPublishSettings.cs +++ b/src/Cake.Npm/Publish/NpmPublishSettings.cs @@ -37,6 +37,7 @@ public NpmPublishSettings() /// /// Gets or sets the registry where the package should be published to. + /// Defaulted to whatever the NPM configuration is. /// public Uri Registry { get; set; } From 5f28f1371b1439ae0e6b52fa5c3494a4487adbd0 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Tue, 11 Sep 2018 20:55:57 +0200 Subject: [PATCH 07/10] (GH-90) Add NpmCi alias which accepts a settings configurator --- src/Cake.Npm/NpmCiAliases.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Cake.Npm/NpmCiAliases.cs b/src/Cake.Npm/NpmCiAliases.cs index 0c1bb5e..afc75ca 100644 --- a/src/Cake.Npm/NpmCiAliases.cs +++ b/src/Cake.Npm/NpmCiAliases.cs @@ -35,6 +35,38 @@ public static void NpmCi(this ICakeContext context) context.NpmCi(new NpmCiSettings()); } + /// + /// Cis packages using the settings returned by a configurator. + /// + /// The context. + /// The settings configurator. + /// + /// Use specific log level ('npm ci') + /// + /// settings.WithLogLevel(NpmLogLevel.Verbose)); + /// ]]> + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Ci")] + public static void NpmCi(this ICakeContext context, Action configurator) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (configurator == null) + { + throw new ArgumentNullException(nameof(configurator)); + } + + var settings = new NpmCiSettings(); + configurator(settings); + context.NpmCi(settings); + } + /// /// Cis packages using the specified settings. /// From 9ca9682a5aff55a64b379a8a9124bd6b022735cf Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Tue, 11 Sep 2018 21:07:40 +0200 Subject: [PATCH 08/10] (GH-91) Add NpmSet alias which accepts a settings configurator --- .../Set/NpmSetSettingsExtensionsTests.cs | 147 ++++++++++++++++++ src/Cake.Npm/NpmSetAliases.cs | 32 ++++ src/Cake.Npm/Set/NpmSetSettingsExtensions.cs | 54 +++++++ 3 files changed, 233 insertions(+) create mode 100644 src/Cake.Npm.Tests/Set/NpmSetSettingsExtensionsTests.cs create mode 100644 src/Cake.Npm/Set/NpmSetSettingsExtensions.cs diff --git a/src/Cake.Npm.Tests/Set/NpmSetSettingsExtensionsTests.cs b/src/Cake.Npm.Tests/Set/NpmSetSettingsExtensionsTests.cs new file mode 100644 index 0000000..25da441 --- /dev/null +++ b/src/Cake.Npm.Tests/Set/NpmSetSettingsExtensionsTests.cs @@ -0,0 +1,147 @@ +namespace Cake.Npm.Tests.Set +{ + using Cake.Npm.Set; + using Shouldly; + using Xunit; + + public sealed class NpmSetSettingsExtensionsTests + { + public sealed class TheForKeyMethod + { + [Fact] + public void Should_Throw_If_Settings_Are_Null() + { + // Given + NpmSetSettings settings = null; + + // When + var result = Record.Exception(() => settings.ForKey("foo")); + + // Then + result.IsArgumentNullException("settings"); + } + + [Fact] + public void Should_Throw_If_Key_Is_Null() + { + // Given + var settings = new NpmSetSettings(); + + // When + var result = Record.Exception(() => settings.ForKey(null)); + + // Then + result.IsArgumentNullException("key"); + } + + [Fact] + public void Should_Throw_If_Key_Is_Empty() + { + // Given + var settings = new NpmSetSettings(); + + // When + var result = Record.Exception(() => settings.ForKey(string.Empty)); + + // Then + result.IsArgumentNullException("key"); + } + + [Fact] + public void Should_Throw_If_Key_Is_WhiteSpace() + { + // Given + var settings = new NpmSetSettings(); + + // When + var result = Record.Exception(() => settings.ForKey(" ")); + + // Then + result.IsArgumentNullException("key"); + } + + [Fact] + public void Should_Set_Key() + { + // Given + var settings = new NpmSetSettings(); + var key = "foo"; + + // When + settings.ForKey(key); + + // Then + settings.Key.ShouldBe(key); + } + } + + public sealed class TheWithValueMethod + { + [Fact] + public void Should_Throw_If_Settings_Are_Null() + { + // Given + NpmSetSettings settings = null; + + // When + var result = Record.Exception(() => settings.WithValue("foo")); + + // Then + result.IsArgumentNullException("settings"); + } + + [Fact] + public void Should_Throw_If_Value_Is_Null() + { + // Given + var settings = new NpmSetSettings(); + + // When + var result = Record.Exception(() => settings.WithValue(null)); + + // Then + result.IsArgumentNullException("value"); + } + + [Fact] + public void Should_Throw_If_Value_Is_Empty() + { + // Given + var settings = new NpmSetSettings(); + + // When + var result = Record.Exception(() => settings.WithValue(string.Empty)); + + // Then + result.IsArgumentNullException("value"); + } + + [Fact] + public void Should_Throw_If_Value_Is_WhiteSpace() + { + // Given + var settings = new NpmSetSettings(); + + // When + var result = Record.Exception(() => settings.WithValue(" ")); + + // Then + result.IsArgumentNullException("value"); + } + + [Fact] + public void Should_Set_Value() + { + // Given + var settings = new NpmSetSettings(); + var value = "foo"; + + // When + settings.WithValue(value); + + // Then + settings.Value.ShouldBe(value); + } + } + } +} diff --git a/src/Cake.Npm/NpmSetAliases.cs b/src/Cake.Npm/NpmSetAliases.cs index 70869f4..fac3968 100644 --- a/src/Cake.Npm/NpmSetAliases.cs +++ b/src/Cake.Npm/NpmSetAliases.cs @@ -43,6 +43,38 @@ public static void NpmSet(this ICakeContext context, string key, string value, b }); } + /// + /// Sets an npm configuration setting returned by a configurator. + /// + /// The context. + /// The settings configurator. + /// + /// Use speSetfic log level ('npm Set') + /// + /// settings.ForKey("progress").WithValue("false")); + /// ]]> + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Set")] + public static void NpmSet(this ICakeContext context, Action configurator) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (configurator == null) + { + throw new ArgumentNullException(nameof(configurator)); + } + + var settings = new NpmSetSettings(); + configurator(settings); + context.NpmSet(settings); + } + /// /// Sets an npm configuration setting. /// diff --git a/src/Cake.Npm/Set/NpmSetSettingsExtensions.cs b/src/Cake.Npm/Set/NpmSetSettingsExtensions.cs new file mode 100644 index 0000000..5d01dbe --- /dev/null +++ b/src/Cake.Npm/Set/NpmSetSettingsExtensions.cs @@ -0,0 +1,54 @@ +namespace Cake.Npm.Set +{ + using System; + + /// + /// Extensions for . + /// + public static class NpmSetSettingsExtensions + { + /// + /// Defines the key which should be set. + /// + /// The settings. + /// Key which should be set. + /// The instance with set to . + public static NpmSetSettings ForKey(this NpmSetSettings settings, string key) + { + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + + if (string.IsNullOrWhiteSpace(key)) + { + throw new ArgumentNullException(nameof(key)); + } + + settings.Key = key; + return settings; + } + + /// + /// Defines the value which should be set. + /// + /// The settings. + /// Value which should be set. + /// The instance with set to . + public static NpmSetSettings WithValue(this NpmSetSettings settings, string value) + { + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentNullException(nameof(value)); + } + + settings.Value = value; + return settings; + } + } +} From 07d9626cca940624c9f2967c86896d48b2592f23 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Tue, 11 Sep 2018 21:13:57 +0200 Subject: [PATCH 09/10] (GH-92) Add NpmUpdate alias which accepts a settings configurator --- src/Cake.Npm/NpmUpdateAliases.cs | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Cake.Npm/NpmUpdateAliases.cs b/src/Cake.Npm/NpmUpdateAliases.cs index 6ef192f..ec33397 100644 --- a/src/Cake.Npm/NpmUpdateAliases.cs +++ b/src/Cake.Npm/NpmUpdateAliases.cs @@ -36,7 +36,38 @@ public static void NpmUpdate(this ICakeContext context) } /// - /// Updates all packages for the project in the current working directory. + /// Updates all packages for the project using the settings returned by a configurator. + /// + /// The context. + /// The settings configurator. + /// + /// + /// settings.UpdateGlobalPackages()); + /// ]]> + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Update")] + public static void NpmUpdate(this ICakeContext context, Action configurator) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (configurator == null) + { + throw new ArgumentNullException(nameof(configurator)); + } + + var settings = new NpmUpdateSettings(); + configurator(settings); + context.NpmUpdate(settings); + } + + /// + /// Updates all packages for the project using the specified settings. /// /// The context. /// The settings. From 28a7b2b979d70be6b452a2b665cc5ab533b08bf6 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Wed, 12 Sep 2018 07:33:24 +0200 Subject: [PATCH 10/10] Uses global package folder --- .appveyor.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index bd21071..2b5f541 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -27,5 +27,4 @@ branches: # Build Cache # #---------------------------------# cache: -- src\packages -> src\**\packages.config - tools -> setup.cake \ No newline at end of file