Skip to content

Commit

Permalink
first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
reicheltp committed Mar 29, 2016
1 parent 31fab71 commit d987650
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
### New in 0.1.0
### New in 0.1.1
- Initial release
- Generate your documentation with DocFxBuild
14 changes: 14 additions & 0 deletions src/Cake.DocFx/Cake.DocFx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<DocumentationFile>bin\Release\Cake.DocFx.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Cake.Core, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Cake.Core.0.10.0\lib\net45\Cake.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -42,9 +46,19 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Build\DocFxBuildRunner.cs" />
<Compile Include="Build\DocFxBuildSettings.cs" />
<Compile Include="DocFxAliases.cs" />
<Compile Include="DocFxTool.cs" />
<Compile Include="Helper\Contract.cs" />
<Compile Include="Metadata\DocFxMetadataRunner.cs" />
<Compile Include="Metadata\DocFxMetadataSettings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.Static.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
82 changes: 82 additions & 0 deletions src/Cake.DocFx/DocFxAliases.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System.Collections.Generic;
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.IO;
using Cake.DocFx.Build;
using Cake.DocFx.Helper;
using Cake.DocFx.Metadata;

namespace Cake.DocFx
{
/// <summary>
/// Contains functionality related to <see href="http://dotnet.github.io/docfx/index.html">DocFx</see>
/// </summary>
[CakeAliasCategory("DocFx")]
public static class DocFxAliases
{
[CakeAliasCategory("Documentation")]
[CakeMethodAlias]
public static void DocFxBuild(this ICakeContext context) => context.DocFxBuild(null, null);

[CakeAliasCategory("Documentation")]
[CakeMethodAlias]
public static void DocFxBuild(this ICakeContext context, FilePath configFile)
=> context.DocFxBuild(configFile, null);

[CakeAliasCategory("Documentation")]
[CakeMethodAlias]
public static void DocFxBuild(this ICakeContext context, DocFxBuildSettings settings)
=> context.DocFxBuild(null, settings);

[CakeAliasCategory("Documentation")]
[CakeMethodAlias]
public static void DocFxBuild(this ICakeContext context, FilePath configFile, DocFxBuildSettings settings)
{
Contract.NotNull(context, nameof(context));

settings = settings ?? new DocFxBuildSettings();

var runner = new DocFxBuildRunner(context.FileSystem, context.Environment, context.ProcessRunner,
context.Globber);
runner.Run(configFile, settings);
}

[CakeAliasCategory("Documentation")]
[CakeMethodAlias]
public static void DocFxMetadata(this ICakeContext context)
=> context.DocFxMetadata((DocFxMetadataSettings) null);

[CakeAliasCategory("Documentation")]
[CakeMethodAlias]
public static void DocFxMetadata(this ICakeContext context, FilePath configFile)
{
context.DocFxMetadata(new DocFxMetadataSettings
{
Projects = new[] {configFile}
});
}

[CakeAliasCategory("Documentation")]
[CakeMethodAlias]
public static void DocFxMetadata(this ICakeContext context, IEnumerable<FilePath> files)
{
context.DocFxMetadata(new DocFxMetadataSettings
{
Projects = files
});
}

[CakeAliasCategory("Documentation")]
[CakeMethodAlias]
public static void DocFxMetadata(this ICakeContext context, DocFxMetadataSettings settings)
{
Contract.NotNull(context, nameof(context));

settings = settings ?? new DocFxMetadataSettings();

var runner = new DocFxMetadataRunner(context.FileSystem, context.Environment, context.ProcessRunner,
context.Globber);
runner.Run(settings);
}
}
}
35 changes: 35 additions & 0 deletions src/Cake.DocFx/DocFxTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using Cake.Core;
using Cake.Core.IO;
using Cake.Core.Tooling;

namespace Cake.DocFx
{
/// <summary>
/// Base class for docfx tools
/// </summary>
/// <typeparam name="TSettings"></typeparam>
public abstract class DocFxTool<TSettings> : Tool<TSettings> where TSettings : ToolSettings
{
protected DocFxTool(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IGlobber globber)
: base(fileSystem, environment, processRunner, globber)
{
}

/// <summary>
/// Gets the name of the tool.
/// </summary>
/// <returns>
/// The name of the tool.
/// </returns>
protected override string GetToolName() => "DocFx";

/// <summary>
/// Gets the possible names of the tool executable.
/// </summary>
/// <returns>
/// The tool executable name.
/// </returns>
protected override IEnumerable<string> GetToolExecutableNames() => new[] {"docfx", "docfx.exe"};
}
}
18 changes: 18 additions & 0 deletions src/Cake.DocFx/Helper/Contract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Cake.DocFx.Helper
{
internal static class Contract
{
/// <summary>
/// Checks if param is not null and otherwise throws exception.
/// </summary>
/// <param name="parameter"></param>
/// <param name="paramName"></param>
internal static void NotNull(object parameter, string paramName)
{
if(parameter == null)
throw new ArgumentNullException(paramName);
}
}
}
40 changes: 40 additions & 0 deletions src/Cake.DocFx/Metadata/DocFxMetadataRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Linq;
using Cake.Core;
using Cake.Core.IO;

namespace Cake.DocFx.Metadata
{
public sealed class DocFxMetadataRunner : DocFxTool<DocFxMetadataSettings>
{
public DocFxMetadataRunner(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IGlobber globber)
: base(fileSystem, environment, processRunner, globber)
{
}

/// <summary>
/// Runs docfx for current folder with the given configuration.
/// </summary>
/// <param name="settings"></param>
public void Run(DocFxMetadataSettings settings)
{
Run(settings, GetArguments(settings));
}

private ProcessArgumentBuilder GetArguments(DocFxMetadataSettings settings)
{
var builder = new ProcessArgumentBuilder();

// command
builder.Append("metadata");

// parameters
if (settings.Projects != null && settings.Projects.Any())
builder.Append(string.Join(",", settings.Projects.Select(val => val.FullPath)));

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

return builder;
}
}
}
30 changes: 30 additions & 0 deletions src/Cake.DocFx/Metadata/DocFxMetadataSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using Cake.Core.IO;
using Cake.Core.Tooling;

namespace Cake.DocFx.Metadata
{
/// <summary>
/// Settings used for docfx metadata
/// </summary>
public class DocFxMetadataSettings : ToolSettings
{
/// <summary>
/// Specifies the projects to have metadata extracted. There are several approaches to extract language metadata.
/// 1. From a supported project file or project file list
/// Supported project file extensions include .csproj, .vbproj, .sln.
/// 2. From a supported source code file or source code file list
/// Supported source code file extensions include .cs and .vb. Files can be combined using , as seperator and search
/// pattern.
/// 3. From docfx.json file. If the argument is not specified, docfx.exe will try reading docfx.json under current
/// directory.
/// </summary>
public IEnumerable<FilePath> Projects { get; set; }

/// <summary>
/// Optional argument.
/// The default output folder is _site/ folder
/// </summary>
public DirectoryPath OutputPath { get; set; }
}
}
6 changes: 3 additions & 3 deletions src/Cake.DocFx/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using System.Reflection;

[assembly: AssemblyProduct("Cake.DocFx")]
[assembly: AssemblyVersion("0.1.0")]
[assembly: AssemblyFileVersion("0.1.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyVersion("0.1.1")]
[assembly: AssemblyFileVersion("0.1.1")]
[assembly: AssemblyInformationalVersion("0.1.1")]
[assembly: AssemblyCopyright("Copyright 2016 (c) Paul Reichelt and contributors")]

4 changes: 4 additions & 0 deletions src/Cake.DocFx/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake.Core" version="0.10.0" targetFramework="net452" />
</packages>
7 changes: 7 additions & 0 deletions tests/Cake.DocFx.Tests/Cake.DocFx.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Cake.Core, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Cake.Core.0.10.0\lib\net45\Cake.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -42,6 +46,9 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 4 additions & 0 deletions tests/Cake.DocFx.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake.Core" version="0.10.0" targetFramework="net452" />
</packages>

0 comments on commit d987650

Please sign in to comment.