Skip to content

Commit

Permalink
Merge branch 'agc93-pack-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
Philo committed Sep 26, 2016
2 parents 7dce7c2 + 5a0d937 commit 3c34afd
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Cake.Npm.Tests/Cake.Npm.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="NpmPackTests.cs" />
<Compile Include="NpmRunnerFixture.cs" />
<Compile Include="NpmRunnerTests.cs" />
<Compile Include="NpmRunScriptTests.cs" />
Expand Down
29 changes: 29 additions & 0 deletions src/Cake.Npm.Tests/NpmPackTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Shouldly;
using Xunit;

namespace Cake.Npm.Tests
{
public class NpmPackTests
{
private readonly NpmPackFixture _fixture;
public NpmPackTests()
{
_fixture = new NpmPackFixture();
}

[Fact]
public void Not_Setting_Target_Should_Use_Empty()
{
var result = _fixture.Run();
result.Args.ShouldBe("pack");
}

[Fact]
public void Including_Target_Should_Set_Correct_Argument()
{
_fixture.Target = "package.tgz";
var result = _fixture.Run();
result.Args.ShouldBe("pack package.tgz");
}
}
}
14 changes: 14 additions & 0 deletions src/Cake.Npm.Tests/NpmRunnerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,18 @@ protected override void RunTool()
tool.RunScript(ScriptName, RunScriptSettings);
}
}

public class NpmPackFixture : ToolFixture<NpmPackSettings>
{
internal string Target { get; set; }
public NpmPackFixture() : base("npm")
{
}

protected override void RunTool()
{
var tool = new NpmRunner(FileSystem, Environment, ProcessRunner, Tools);
tool.Pack(Target);
}
}
}
1 change: 1 addition & 0 deletions src/Cake.Npm/Cake.Npm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<ItemGroup>
<Compile Include="INpmRunnerCommands.cs" />
<Compile Include="NpmLogLevel.cs" />
<Compile Include="NpmPackSettings.cs" />
<Compile Include="NpmRunScriptSettings.cs" />
<Compile Include="..\VersionAssemblyInfo.cs">
<Link>Properties\VersionAssemblyInfo.cs</Link>
Expand Down
44 changes: 44 additions & 0 deletions src/Cake.Npm/NpmPackSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Cake.Core;
using Cake.Core.IO;

namespace Cake.Npm
{
/// <summary>
/// npm pack options
/// </summary>
public class NpmPackSettings : NpmRunnerSettings
{
/// <summary>
/// 'npm pack' settings with target
/// </summary>
public NpmPackSettings(string target) : base("pack")
{
Target = target;
}

/// <summary>
/// 'npm pack' settings
/// </summary>
public NpmPackSettings() : this(null)
{
}

/// <summary>
/// Installation target
/// </summary>
public string Target { get; set; }

/// <summary>
/// evaluate options
/// </summary>
/// <param name="args"></param>
protected override void EvaluateCore(ProcessArgumentBuilder args)
{
base.EvaluateCore(args);
if (!string.IsNullOrWhiteSpace(Target))
{
args.Append(Target);
}
}
}
}
19 changes: 19 additions & 0 deletions src/Cake.Npm/NpmRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,25 @@ private static ProcessArgumentBuilder GetNpmRunArguments(NpmRunScriptSettings se
return args;
}

/// <summary>
/// execute 'npm pack' with an optional installable target
/// </summary>
/// <param name="target">package folder, tarball, or name. Defaults to the current directory</param>
public INpmRunnerCommands Pack(string target = null)
{
var settings = new NpmPackSettings(target);
var args = GetNpmPackArguments(settings);
Run(settings, args);
return this;
}

private ProcessArgumentBuilder GetNpmPackArguments(NpmPackSettings settings)
{
var args = new ProcessArgumentBuilder();
settings?.Evaluate(args);
return args;
}

/// <summary>
/// Gets the name of the tool
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/Cake.Npm/NpmRunnerAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ public static class NpmRunnerAliases
/// });
/// ]]>
/// </code>
/// <para>Run 'npm pack'</para>
/// <para>Cake task:</para>
/// <code>
/// <![CDATA[
/// Task("Npm-RunScript")
/// .Does(() =>
/// {
/// Npm.Pack();
/// });
/// ]]>
/// </code>
/// </example>
[CakePropertyAlias]
public static NpmRunner Npm(this ICakeContext context)
Expand Down
5 changes: 4 additions & 1 deletion usage.cake
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ Task("Default")
// npm run hello
Npm.RunScript("hello");
//npm run arguments -- -debug "arg-value.file"
// npm run arguments -- -debug "arg-value.file"
Npm.RunScript("arguments", settings => settings.WithArgument("-debug").WithArgument("arg-value.file"));
// npm pack
Npm.Pack();
//npm install gulp. Executedwith ./usage set as the working directory
Npm
.WithLogLevel(NpmLogLevel.Silent)
Expand Down

0 comments on commit 3c34afd

Please sign in to comment.