Skip to content

Commit

Permalink
Merge branch 'release/0.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Jul 3, 2018
2 parents 9fabfa5 + 15b0338 commit a5b0f13
Show file tree
Hide file tree
Showing 12 changed files with 412 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nuspec/nuget/Cake.DocFx.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright (c) Cake Contributions 2016 - Present</copyright>
<tags>Cake Script DocFx</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.DocFx/releases/tag/0.7.0</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.DocFx/releases/tag/0.8.0</releaseNotes>
</metadata>
<files>
<file src="netstandard2.0\Cake.DocFx.dll" target="lib\netstandard2.0" />
Expand Down
16 changes: 16 additions & 0 deletions src/Cake.DocFx.Tests/Build/DocFxBuildRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ public void Should_Add_Serve_To_Arguments_If_True()
// Then
Assert.Equal("build --serve", result.Args);
}

[Fact]
public void Should_Add_Force_To_Arguments_If_True()
{
// Given
var fixture = new DocFxBuildRunnerFixture
{
Settings = {Force = true}
};

// When
var result = fixture.Run();

// Then
Assert.Equal("build --force", result.Args);
}
}
}
}
16 changes: 16 additions & 0 deletions src/Cake.DocFx.Tests/Metadata/DocFxMetadataRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ public void Should_Not_Add_LogLevel_To_Arguments_If_Default()
// Then
Assert.Equal("metadata", result.Args);
}

[Fact]
public void Should_Add_Force_To_Arguments_If_True()
{
// Given
var fixture = new DocFxMetadataRunnerFixture
{
Settings = {Force = true}
};

// When
var result = fixture.Run();

// Then
Assert.Equal("metadata --force", result.Args);
}
}
}
}
20 changes: 20 additions & 0 deletions src/Cake.DocFx.Tests/Pdf/DocFxPdfRunnerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Cake.Core.IO;
using Cake.DocFx.Pdf;

namespace Cake.DocFx.Tests.Pdf
{
internal sealed class DocFxPdfRunnerFixture : DocFxFixture<DocFxPdfSettings>
{
public DocFxPdfRunnerFixture()
{
}

public FilePath ConfigFilePath { get; set; }

protected override void RunTool()
{
var tool = new DocFxPdfRunner(FileSystem, Environment, ProcessRunner, Tools);
tool.Run(ConfigFilePath, Settings);
}
}
}
123 changes: 123 additions & 0 deletions src/Cake.DocFx.Tests/Pdf/DocFxPdfRunnerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using Xunit;

namespace Cake.DocFx.Tests.Pdf
{
public class DocFxPdfRunnerTests
{
public sealed class TheRunMethod
{
[Fact]
public void Should_Throw_If_Settings_Are_Null()
{
// Given
var fixture = new DocFxPdfRunnerFixture
{
Settings = null
};

// When
var result = Record.Exception(() => fixture.Run());

// Then
result.IsArgumentNullException("settings");
}


[Fact]
public void Should_Be_Pdf_Command()
{
// Given
var fixture = new DocFxPdfRunnerFixture
{
Settings = {}
};

// When
var result = fixture.Run();

// Then
Assert.Equal("pdf", result.Args);
}

[Fact]
public void Should_Add_LogPath_To_Arguments_If_Set()
{
// Given
var fixture = new DocFxPdfRunnerFixture
{
Settings = { LogPath = @"c:\temp\docfx.log" }
};

// When
var result = fixture.Run();

// Then
Assert.Equal("pdf -l \"c:/temp/docfx.log\"", result.Args);
}

[Theory]
[InlineData(DocFxLogLevel.Error, "Error")]
[InlineData(DocFxLogLevel.Warning, "Warning")]
[InlineData(DocFxLogLevel.Info, "Info")]
[InlineData(DocFxLogLevel.Verbose, "Verbose")]
public void Should_Add_LogLevel_To_Arguments_If_Set(DocFxLogLevel logLevel, string expectedLevel)
{
// Given
var fixture = new DocFxPdfRunnerFixture
{
Settings = { LogLevel = logLevel }
};

// When
var result = fixture.Run();

// Then
Assert.Equal("pdf --logLevel \"" + expectedLevel + "\"", result.Args);
}

[Fact]
public void Should_Not_Add_LogLevel_To_Arguments_If_Default()
{
// Given
var fixture = new DocFxPdfRunnerFixture
{
Settings = { LogLevel = DocFxLogLevel.Default }
};

// When
var result = fixture.Run();

// Then
Assert.Equal("pdf", result.Args);
}

[Fact]
public void Should_Add_GlobalMetadata_To_Arguments_If_Not_Empty()
{
// Given
var fixture = new DocFxPdfRunnerFixture();
fixture.Settings.GlobalMetadata.Add("foo", "bar");

// When
var result = fixture.Run();

// Then
Assert.Equal("pdf --globalMetadata \"{\\\"foo\\\": \\\"bar\\\"}\"", result.Args);
}

[Fact]
public void Should_Add_Name_To_Arguments_If_Not_Empty()
{
// Given
var fixture = new DocFxPdfRunnerFixture();
fixture.Settings.Name = "foo";

// When
var result = fixture.Run();

// Then
Assert.Equal("pdf --name \"foo\"", result.Args);
}
}
}
}
9 changes: 7 additions & 2 deletions src/Cake.DocFx/Build/DocFxBuildRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ private ProcessArgumentBuilder GetArguments(FilePath configFile, DocFxBuildSetti
builder.Append("build");

// parameters
#region DupFinder Exclusion
if (configFile != null)
builder.Append("\"{0}\"", configFile.FullPath);

#region DupFinder Exclusion
if (settings.OutputPath != null)
builder.Append("-o \"{0}\"", settings.OutputPath.FullPath);

Expand All @@ -55,7 +55,6 @@ private ProcessArgumentBuilder GetArguments(FilePath configFile, DocFxBuildSetti

if (settings.LogLevel != DocFxLogLevel.Default)
builder.Append("--logLevel \"{0}\"", settings.LogLevel);
#endregion

if (settings.TemplateFolder != null)
builder.Append("-t \"{0}\"", settings.TemplateFolder.FullPath);
Expand All @@ -69,6 +68,12 @@ private ProcessArgumentBuilder GetArguments(FilePath configFile, DocFxBuildSetti
{
builder.Append("--serve");
}
#endregion

if (settings.Force)
{
builder.Append("--force");
}

return builder;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Cake.DocFx/Build/DocFxBuildSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,10 @@ public class DocFxBuildSettings : ToolSettings
/// in a built in web server.
/// </summary>
public bool Serve { get; set; }

/// <summary>
/// Gets or sets a value indicating whether all the documentation is re-build.
/// </summary>
public bool Force { get; set; }
}
}
96 changes: 96 additions & 0 deletions src/Cake.DocFx/DocFxPdfAliases.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.IO;
using Cake.DocFx.Helper;
using Cake.DocFx.Pdf;

namespace Cake.DocFx
{
/// <summary>
/// Contains functionality related to creating PDF files using <see href="http://dotnet.github.io/docfx">DocFx</see>.
/// </summary>
[CakeAliasCategory("DocFx")]
[CakeNamespaceImport("Cake.DocFx.Pdf")]
public static class DocFxPdfAliases
{
/// <summary>
/// Generates a PDF document for the <c>docfx.json</c> file in the current working directory.
/// </summary>
/// <param name="context">The Cake context.</param>
/// <example>
/// <code>
/// DocFxPdf();
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Pdf")]
public static void DocFxPdf(this ICakeContext context)
=> context.DocFxPdf(null, null);

/// <summary>
/// Generates a PDF document for a specific <c>docfx.json</c> file.
/// </summary>
/// <param name="context">The Cake context.</param>
/// <param name="configFile">The optional path to a DocFx config file.
/// If no value is passed the docfx.json file in the current working directory will be used.</param>
/// <example>
/// <code>
/// DocFxPdf("./docs/docfx.json");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Pdf")]
public static void DocFxPdf(this ICakeContext context, FilePath configFile)
=> context.DocFxPdf(configFile, null);

/// <summary>
/// Generates a PDF document for the <c>docfx.json</c> file in the current working directory
/// using the specified settings.
/// </summary>
/// <param name="context">The Cake context.</param>
/// <param name="settings">The optional DocFx settings.
/// If no settings are passed default settings are used.</param>
/// <example>
/// <code>
/// DocFxPdf(new DocFxPdfSettings()
/// {
/// OutputPath = "./artifacts/docs",
/// TemplateFolder = "default"
/// });
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Pdf")]
public static void DocFxPdf(this ICakeContext context, DocFxPdfSettings settings)
=> context.DocFxPdf(null, settings);

/// <summary>
/// Generates a PDF document for a specific <c>docfx.json</c> file using the specified settings.
/// </summary>
/// <param name="context">The Cake context.</param>
/// <param name="configFile">The optional path to a DocFx config file.
/// If no value is passed the docfx.json file in the current working directory will be used.</param>
/// <param name="settings">The optional DocFx settings.
/// If no settings are passed default settings are used.</param>
/// <example>
/// <code>
/// DocFxPdf("./docs/docfx.json", new DocFxPdfSettings()
/// {
/// OutputPath = "./artifacts/docs",
/// TemplateFolder = "default"
/// });
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Pdf")]
public static void DocFxPdf(this ICakeContext context, FilePath configFile, DocFxPdfSettings settings)
{
Contract.NotNull(context, nameof(context));

settings = settings ?? new DocFxPdfSettings();

var runner = new DocFxPdfRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
runner.Run(configFile, settings);
}
}
}
5 changes: 5 additions & 0 deletions src/Cake.DocFx/Metadata/DocFxMetadataRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ private ProcessArgumentBuilder GetArguments(DocFxMetadataSettings settings)
builder.Append("--logLevel \"{0}\"", settings.LogLevel);
#endregion

if (settings.Force)
{
builder.Append("--force");
}

return builder;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Cake.DocFx/Metadata/DocFxMetadataSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@ public class DocFxMetadataSettings : ToolSettings
/// Gets or sets to which log level will be logged.
/// </summary>
public DocFxLogLevel LogLevel { get; set; }

/// <summary>
/// Gets or sets a value indicating whether all the documentation is re-build.
/// </summary>
public bool Force { get; set; }
}
}
Loading

0 comments on commit a5b0f13

Please sign in to comment.