-
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.
- Loading branch information
1 parent
af4da1b
commit b256db5
Showing
3 changed files
with
129 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,36 @@ | ||
using Cake.Core; | ||
using Cake.Core.Annotations; | ||
using Cake.Npm.View; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Cake.Npm | ||
{ | ||
/// <summary> | ||
/// Npm view aliases | ||
/// </summary> | ||
[CakeAliasCategory("Npm")] | ||
[CakeNamespaceImport("Cake.Npm")] | ||
public static class NpmViewAliases | ||
{ | ||
/// <summary> | ||
/// Call npm view with --json attribute. | ||
/// </summary> | ||
/// <param name="context"></param> | ||
/// <param name="packageName">Name of the package</param> | ||
/// <param name="workingDirectory"></param> | ||
/// <returns>An empty string if the package was not found on the repository</returns> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("View")] | ||
public static string NpmView(this ICakeContext context, string packageName = null, string workingDirectory = null) | ||
{ | ||
NpmViewSettings settings = new NpmViewSettings() | ||
{ | ||
PackageName = packageName, | ||
WorkingDirectory = workingDirectory | ||
}; | ||
return new NpmViewTool(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log).View(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,35 @@ | ||
namespace Cake.Npm.View | ||
{ | ||
using System.Linq; | ||
using Cake.Core; | ||
using Cake.Core.IO; | ||
|
||
/// <summary> | ||
/// Contains settings used by <see cref="NpmViewTool"/>. | ||
/// </summary> | ||
public class NpmViewSettings : NpmSettings | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="NpmViewSettings"/> class. | ||
/// </summary> | ||
public NpmViewSettings() | ||
: base("view") | ||
{ | ||
RedirectStandardOutput = true; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the package for which the registry entry should be shown. | ||
/// </summary> | ||
public string PackageName { get; set; } | ||
|
||
/// <inheritdoc /> | ||
protected override void EvaluateCore(ProcessArgumentBuilder args) | ||
{ | ||
base.EvaluateCore(args); | ||
|
||
args.Append("--json"); | ||
args.Append(PackageName); | ||
} | ||
} | ||
} |
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,58 @@ | ||
namespace Cake.Npm.View | ||
{ | ||
using Cake.Core; | ||
using Cake.Core.Diagnostics; | ||
using Cake.Core.IO; | ||
using Cake.Core.Tooling; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// Tool for viewing registry info. | ||
/// </summary> | ||
public class NpmViewTool : NpmTool<NpmSettings> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="NpmViewTool"/> 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 NpmViewTool( | ||
IFileSystem fileSystem, | ||
ICakeEnvironment environment, | ||
IProcessRunner processRunner, | ||
IToolLocator tools, | ||
ICakeLog log) | ||
: base(fileSystem, environment, processRunner, tools, log) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Returns information about a package registry entry. | ||
/// </summary> | ||
/// <param name="settings">The settings.</param> | ||
public string View(NpmViewSettings settings) | ||
{ | ||
try | ||
{ | ||
IEnumerable<string> output = new List<string>(); | ||
RunCore( | ||
settings, | ||
new ProcessSettings(), | ||
process => | ||
{ | ||
output = process.GetStandardOutput(); | ||
}); | ||
return string.Join("\n", output); | ||
|
||
} | ||
catch (CakeException) | ||
{ | ||
CakeLog.Information("Error should be a 404 and i ignore it."); | ||
return ""; | ||
} | ||
} | ||
} | ||
} |