-
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 8f141ee
Showing
3 changed files
with
105 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 NpmViewTools(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,26 @@ | ||
using Cake.Core; | ||
using Cake.Core.IO; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Cake.Npm.View | ||
{ | ||
class NpmViewSettings : NpmSettings | ||
{ | ||
public NpmViewSettings() : base("view") | ||
{ | ||
RedirectStandardOutput = true; | ||
} | ||
|
||
public string PackageName { get; set; } | ||
|
||
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,43 @@ | ||
using Cake.Core; | ||
using Cake.Core.Diagnostics; | ||
using Cake.Core.IO; | ||
using Cake.Core.Tooling; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Cake.Npm.View | ||
{ | ||
class NpmViewTools : NpmTool<NpmSettings> | ||
{ | ||
public NpmViewTools( | ||
IFileSystem fileSystem, | ||
ICakeEnvironment environment, | ||
IProcessRunner processRunner, | ||
IToolLocator tools, | ||
ICakeLog log) | ||
: base(fileSystem, environment, processRunner, tools, log) | ||
{ | ||
} | ||
|
||
public string View(NpmViewSettings settings) | ||
{ | ||
IEnumerable<string> output = new List<string>(); | ||
try | ||
{ | ||
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 ""; | ||
} | ||
|
||
} | ||
} | ||
} |