forked from cake-contrib/Cake.Npm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cake-contribGH-121) Add support for reading npm configuration
- Loading branch information
1 parent
af4da1b
commit 66ebbf0
Showing
3 changed files
with
103 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,24 @@ | ||
using Cake.Core; | ||
using Cake.Core.IO; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Cake.Npm.Get | ||
{ | ||
class NpmGetSettings : NpmSettings | ||
{ | ||
public NpmGetSettings() : base("get") | ||
{ | ||
RedirectStandardOutput = true; | ||
} | ||
public string Key { get; set; } | ||
|
||
protected override void EvaluateCore(ProcessArgumentBuilder args) | ||
{ | ||
base.EvaluateCore(args); | ||
args.Append(Key); | ||
} | ||
} | ||
} |
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,39 @@ | ||
using Cake.Core; | ||
using Cake.Core.Diagnostics; | ||
using Cake.Core.IO; | ||
using Cake.Core.Tooling; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Cake.Npm.Get | ||
{ | ||
class NpmGetTools : NpmTool<NpmSettings> | ||
{ | ||
public NpmGetTools( | ||
IFileSystem fileSystem, | ||
ICakeEnvironment environment, | ||
IProcessRunner processRunner, | ||
IToolLocator tools, | ||
ICakeLog log) | ||
: base(fileSystem, environment, processRunner, tools, log) | ||
{ | ||
} | ||
|
||
|
||
public string Get(NpmGetSettings settings) | ||
{ | ||
if (string.IsNullOrWhiteSpace(settings.Key)) | ||
{ | ||
throw new ArgumentException(); | ||
} | ||
IEnumerable<string> output = new List<string>(); | ||
RunCore(settings, new ProcessSettings(), process => | ||
{ | ||
output = process.GetStandardOutput(); | ||
}); | ||
return output.SingleOrDefault(); | ||
} | ||
} | ||
} |
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,40 @@ | ||
using Cake.Core; | ||
using Cake.Core.Annotations; | ||
using Cake.Npm.Get; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Cake.Npm | ||
{ | ||
/// <summary> | ||
/// Npm get aliases | ||
/// </summary> | ||
[CakeAliasCategory("Npm")] | ||
[CakeNamespaceImport("Cake.Npm")] | ||
public static class NpmGetAliases | ||
{ | ||
/// <summary> | ||
/// Gets the npm config on the given key | ||
/// </summary> | ||
/// <param name="context">The cake context.</param> | ||
/// <param name="key">The config key.</param> | ||
/// <param name="workingDirectory">The working directory</param> | ||
/// <returns>The value on the given key.</returns> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Get")] | ||
public static string NpmGet(this ICakeContext context, string key, string workingDirectory = null) | ||
{ | ||
if (key == null) | ||
{ | ||
throw new ArgumentNullException("key can't be null"); | ||
} | ||
NpmGetSettings settings = new NpmGetSettings() | ||
{ | ||
Key = key, | ||
WorkingDirectory = workingDirectory | ||
}; | ||
return new NpmGetTools(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log).Get(settings); | ||
} | ||
} | ||
} |