Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
64985df
add ability to run PDF generation via Docset API
dpvreony Apr 6, 2023
a7c00f0
refactor build to use exec helper
dpvreony Apr 6, 2023
a432fe1
rename pdf variable
dpvreony Apr 6, 2023
7a86b85
Merge branch 'dotnet:main' into gen-pdf-via-docascodeapp-lib
dpvreony Apr 6, 2023
e684cce
Merge branch 'dotnet:main' into gen-pdf-via-docascodeapp-lib
dpvreony Apr 17, 2023
236cb98
Merge branch 'dotnet:main' into gen-pdf-via-docascodeapp-lib
dpvreony Apr 19, 2023
e1f7ec8
Merge branch 'dotnet:main' into gen-pdf-via-docascodeapp-lib
dpvreony Jun 28, 2023
59a4197
remove method groups
dpvreony Jul 3, 2023
2938e01
prep for pdf unit tests
dpvreony Jul 3, 2023
aee3920
Update DocsetTest.cs
dpvreony Jul 4, 2023
2683e9d
Update DocsetTest.cs
dpvreony Jul 4, 2023
cba3e14
log issues hidden by templates not resolving
dpvreony Jul 4, 2023
4517977
housekeeping on tests
dpvreony Jul 5, 2023
ede880a
Merge remote-tracking branch 'upstream/main' into gen-pdf-via-docasco…
dpvreony Jul 5, 2023
fdbf4d8
remove snapshot test
dpvreony Jul 5, 2023
036cd7c
restore missing docset fact
dpvreony Jul 6, 2023
d69e67f
update template bundle error message
dpvreony Jul 6, 2023
c48a932
split pdf docset tests
dpvreony Jul 10, 2023
d9aa393
limit pdf tests to windows
dpvreony Jul 11, 2023
f383fc6
Merge remote-tracking branch 'upstream/main' into gen-pdf-via-docasco…
dpvreony Jul 11, 2023
a5cb09b
Merge remote-tracking branch 'upstream/main' into gen-pdf-via-docasco…
dpvreony Jul 17, 2023
cb07551
tweak counts on a couple of tests with new log event
dpvreony Jul 17, 2023
a33973d
fix last few tests around log counts
dpvreony Jul 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions src/Docfx.App/Docset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,44 @@ public static Task Build(string configPath)
/// <param name="options">The build options.</param>
/// <returns>A task to await for build completion.</returns>
public static Task Build(string configPath, BuildOptions options)
{
return Exec<BuildJsonConfig>(
configPath,
options,
"build",
(config, exeOptions, configDirectory, outputDirectory) => RunBuild.Exec(config, exeOptions, configDirectory, outputDirectory));
}

/// <summary>
/// Builds a pdf specified by docfx.json config.
/// </summary>
/// <param name="configPath">The path to docfx.json config file.</param>
/// <returns>A task to await for build completion.</returns>
public static Task Pdf(string configPath)
{
return Pdf(configPath, new());
}

/// <summary>
/// Builds a pdf specified by docfx.json config.
/// </summary>
/// <param name="configPath">The path to docfx.json config file.</param>
/// <param name="options">The build options.</param>
/// <returns>A task to await for build completion.</returns>
public static Task Pdf(string configPath, BuildOptions options)
{
return Exec<PdfJsonConfig>(
configPath,
options,
"pdf",
(config, exeOptions, configDirectory, outputDirectory) => RunPdf.Exec(config, exeOptions, configDirectory, outputDirectory));
}

private static Task Exec<TConfig>(
string configPath,
BuildOptions options,
string elementKey,
Action<TConfig, BuildOptions, string, string> execAction)
{
var consoleLogListener = new ConsoleLogListener();
Logger.RegisterListener(consoleLogListener);
Expand All @@ -37,9 +75,19 @@ public static Task Build(string configPath, BuildOptions options)
{
var configDirectory = Path.GetDirectoryName(Path.GetFullPath(configPath));

var defaultSerializer = JsonUtility.DefaultSerializer.Value;

var config = JObject.Parse(File.ReadAllText(configPath));
if (config.TryGetValue("build", out var value))
RunBuild.Exec(value.ToObject<BuildJsonConfig>(JsonUtility.DefaultSerializer.Value), options, configDirectory);

if (config.TryGetValue(elementKey, out var value))
{
execAction(value.ToObject<TConfig>(defaultSerializer), options, configDirectory, null);
}
else
{
Logger.LogError($"Unable to find '{elementKey}' in '{configPath}'.");
}

return Task.CompletedTask;
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ internal ManifestItem Transform(InternalManifestItem item)
var templateBundle = _templateCollection[item.DocumentType];
if (templateBundle == null)
{
Logger.LogInfo($"No template bundle found for {item.DocumentType}, model will be ignored.");
return manifestItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public TemplateProcessor(ResourceFileReader resourceProvider, DocumentBuildConte
_resourceProvider = resourceProvider;
_maxParallelism = maxParallelism;
_templateCollection = new TemplateCollection(resourceProvider, context, maxParallelism);
if (_templateCollection.Count == 0)
{
Logger.LogWarning("No template bundles were found, no template will be applied to the documents. 1) Check your docfx.json 2) the templates subfolder exists inside your application folder or your docfx.json directory.");
}
Tokens = TemplateProcessorUtility.LoadTokens(resourceProvider) ?? new Dictionary<string, string>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public void ProcessSwaggerWithInvalidLinksOverwriteShouldSucceedWithWarning()
files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.invalid.links.second.md" });
BuildDocument(files);

Assert.Equal(6, listener.Items.Count); // Additional warning for "There is no template processing document type(s): RestApi"
Assert.Equal(7, listener.Items.Count); // Additional warning for "There is no template processing document type(s): RestApi"

var outputRawModelPath = GetRawModelFilePath("contacts.json");
Assert.True(File.Exists(outputRawModelPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void TestValidMetadataReferenceWithIncremental()
BuildDocument(files);
}

Assert.Equal(3, listener.Items.Count);
Assert.Equal(4, listener.Items.Count);
Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): MetadataReferenceTest,Toc")));
listener.Items.Clear();

Expand Down Expand Up @@ -433,7 +433,7 @@ public void TestUidWithPatternedTag()
},
});

Assert.Equal(2, listener.Items.Count);
Assert.Equal(3, listener.Items.Count);
Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): PatternedUid")));
listener.Items.Clear();

Expand Down
2 changes: 1 addition & 1 deletion test/Docfx.Build.SchemaDriven.Tests/SchemaMergerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Overwrite with content
BuildDocument(files);

// One plugin warning for yml and one plugin warning for overwrite file
Assert.Equal(6, listener.Items.Count);
Assert.Equal(7, listener.Items.Count);
Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): testmerger")));
Assert.Equal(1, listener.Items.Count(s => s.Message.StartsWith("\"/stringArrayValue/0\" in overwrite object fails to overwrite \"/stringArrayValue\" for \"uid1\" because it does not match any existing item.")));
Assert.Equal(1, listener.Items.Count(s => s.Message.StartsWith("\"/intArrayValue/0\" in overwrite object fails to overwrite \"/intArrayValue\" for \"uid1\" because it does not match any existing item.")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public void ProcessItemWithEmptyUidShouldFail()
using var listener = new TestListenerScope(nameof(UniversalReferenceDocumentProcessorTest));
BuildDocument(files);
Assert.NotNull(listener.Items);
Assert.Single(listener.Items);
Assert.Contains("Uid must not be null or empty", listener.Items[0].Message);
Assert.Equal(2, listener.Items.Count);
Assert.Contains("Uid must not be null or empty", listener.Items[1].Message);
}

private void BuildDocument(FileCollection files)
Expand Down
25 changes: 25 additions & 0 deletions test/docfx.Tests/Attributes/WindowsOnlyFactAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Runtime.InteropServices;
using Xunit;

namespace docfx.Tests.Attributes
{
/// <summary>
/// XUnit Fact attribute that skips the test if the OS is not Windows.
/// </summary>
/// <remarks>
/// Taken from https://github.com/dotnet/sdk/blob/a30e465a2e2ea4e2550f319a2dc088daaafe5649/src/Tests/Microsoft.NET.TestFramework/Attributes/WindowsOnlyFactAttribute.cs
/// </remarks>
public class WindowsOnlyFactAttribute : FactAttribute
{
public WindowsOnlyFactAttribute()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
this.Skip = "This test requires Windows to run";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
namespace Docfx.Tests;

[Collection("docfx STA")]
public class DocsetTest : TestBase
public class DocsetBuildTest : TestBase
{
private static async Task<Dictionary<string, Func<string>>> Build(Dictionary<string, string> files, [CallerMemberName] string testName = null)
{
var testDirectory = $"{nameof(DocsetTest)}/{testName}";
var testDirectory = $"{nameof(DocsetBuildTest)}/{testName}";
var outputDirectory = $"{testDirectory}/_site";

if (Directory.Exists(testDirectory))
Expand All @@ -35,6 +35,31 @@ private static async Task<Dictionary<string, Func<string>>> Build(Dictionary<str
f => new Func<string>(() => File.ReadAllText(f)));
}

private static async Task<Dictionary<string, Func<string>>> Pdf(Dictionary<string, string> files, [CallerMemberName] string testName = null)
{
var testDirectory = $"{nameof(DocsetBuildTest)}/{testName}";
var outputDirectory = $"{testDirectory}/_pdf";

if (Directory.Exists(testDirectory))
Directory.Delete(testDirectory, recursive: true);

Directory.CreateDirectory(testDirectory);
foreach (var (path, content) in files)
{
var targetPath = Path.Combine(testDirectory, path);
Directory.CreateDirectory(Path.GetDirectoryName(targetPath));

File.WriteAllText(targetPath, content);
}

await Docset.Pdf($"{testDirectory}/docfx.json");

return Directory.GetFiles(outputDirectory, "*", SearchOption.AllDirectories)
.ToDictionary(
f => Path.GetRelativePath(outputDirectory, f),
f => new Func<string>(() => File.ReadAllText(f)));
}

[Fact]
public static async Task CustomLogo_Override_LogoFromTemplate()
{
Expand Down
Loading