Skip to content

Commit

Permalink
fix: outputFolder path when both output and dest are specified
Browse files Browse the repository at this point in the history
  • Loading branch information
filzrev committed Jun 2, 2024
1 parent 7df2c32 commit 0051a98
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/Docfx.App/Config/BuildJsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal class BuildJsonConfig
/// Defines the output folder of the generated build files.
/// Command line --output argument prepends this value.
/// </summary>
[Obsolete("Use `Output` property instead. This property will be removed in a future release.")]
[JsonProperty("dest")]
[JsonPropertyName("dest")]
public string Dest { get; set; }
Expand Down
9 changes: 6 additions & 3 deletions src/Docfx.App/PdfBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ class Outline

public static Task Run(BuildJsonConfig config, string configDirectory, string? outputDirectory = null)
{
var outputFolder = Path.GetFullPath(Path.Combine(
string.IsNullOrEmpty(outputDirectory) ? Path.Combine(configDirectory, config.Output ?? "") : outputDirectory,
config.Dest ?? ""));
#pragma warning disable CS0618
var outputFolder = Path.GetFullPath(
string.IsNullOrEmpty(outputDirectory)
? Path.Combine(configDirectory, config.Output ?? config.Dest ?? "")
: outputDirectory);
#pragma warning restore CS0618

Logger.LogInfo($"Searching for manifest in {outputFolder}");
return CreatePdf(outputFolder);
Expand Down
11 changes: 7 additions & 4 deletions src/Docfx.App/RunBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ public static string Exec(BuildJsonConfig config, BuildOptions options, string c
config.Template = new ListWithStringFallback { "default" };
}

#pragma warning disable CS0618
var baseDirectory = Path.GetFullPath(string.IsNullOrEmpty(configDirectory) ? Directory.GetCurrentDirectory() : configDirectory);
var outputFolder = Path.GetFullPath(Path.Combine(
string.IsNullOrEmpty(outputDirectory) ? Path.Combine(baseDirectory, config.Output ?? "") : outputDirectory,
config.Dest ?? ""));
var outputFolder = Path.GetFullPath(
string.IsNullOrEmpty(outputDirectory)
? Path.Combine(baseDirectory, config.Output ?? config.Dest ?? "")
: outputDirectory);
#pragma warning restore CS0618

EnvironmentContext.SetGitFeaturesDisabled(config.DisableGitFeatures);
EnvironmentContext.SetBaseDirectory(baseDirectory);

try
{
var templateManager = new TemplateManager(config.Template, config.Theme, configDirectory);
var templateManager = new TemplateManager(config.Template, config.Theme, baseDirectory);

DocumentBuilderWrapper.BuildDocument(config, options, templateManager, baseDirectory, outputFolder, null);

Expand Down
9 changes: 6 additions & 3 deletions src/Docfx.Dotnet/DotnetApiCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig config
var projects = configModel.Src;
var references = configModel.References;

var outputFolder = Path.GetFullPath(Path.Combine(
string.IsNullOrEmpty(outputDirectory) ? Path.Combine(configDirectory, configModel.Output ?? "") : outputDirectory,
configModel.Dest ?? ""));
#pragma warning disable CS0618
var outputFolder = Path.GetFullPath(
string.IsNullOrEmpty(outputDirectory)
? Path.Combine(configDirectory, configModel.Output ?? configModel.Dest ?? "")
: outputDirectory);
#pragma warning restore CS0618

var expandedFiles = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, projects);
var expandedReferences = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, references);
Expand Down
1 change: 1 addition & 0 deletions src/Docfx.Dotnet/MetadataJsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ internal class MetadataJsonItemConfig
/// Defines the output folder of the generated metadata files.
/// Command line --output argument prepends this value.
/// </summary>
[Obsolete("Use `Output` property instead. This property will be removed in a future release.")]
[JsonProperty("dest")]
[JsonPropertyName("dest")]
public string Dest { get; set; }
Expand Down
5 changes: 0 additions & 5 deletions src/docfx/Models/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public override int Execute(CommandContext context, BuildCommandOptions settings

internal static void MergeOptionsToConfig(BuildCommandOptions options, BuildJsonConfig config, string configDirectory)
{
// base directory for content from command line is current directory
// e.g. C:\folder1>docfx build folder2\docfx.json --content "*.cs"
// for `--content "*.cs*`, base directory should be `C:\folder1`
string optionsBaseDirectory = Directory.GetCurrentDirectory();

// Override config file with options from command line
if (options.Templates != null && options.Templates.Any())
{
Expand Down
5 changes: 0 additions & 5 deletions src/docfx/Models/MergeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ private static MergeJsonConfig ParseOptions(MergeCommandOptions options, out str

private static void MergeOptionsToConfig(MergeCommandOptions options, ref MergeJsonItemConfig config)
{
// base directory for content from command line is current directory
// e.g. C:\folder1>docfx build folder2\docfx.json --content "*.cs"
// for `--content "*.cs*`, base directory should be `C:\folder1`
string optionsBaseDirectory = Directory.GetCurrentDirectory();

if (!string.IsNullOrEmpty(options.OutputFolder)) config.Destination = Path.GetFullPath(Path.Combine(options.OutputFolder, config.Destination ?? string.Empty));
}
}
18 changes: 9 additions & 9 deletions test/docfx.Tests/MetadataCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task TestMetadataCommandFromCSProject()
File.Copy("Assets/test.cs.sample.1", sourceFile);

await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(), Directory.GetCurrentDirectory());

CheckResult();
Expand All @@ -48,7 +48,7 @@ public async Task TestMetadataCommandFromDll()
File.Copy("Assets/test.dll.sample.1", dllFile);

await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(dllFile)) { Expanded = true } }),
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(dllFile)) { Expanded = true } }),
new(), Directory.GetCurrentDirectory());

CheckResult();
Expand All @@ -67,7 +67,7 @@ public async Task TestMetadataCommandFromMultipleFrameworksCSProject()
await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig
{
Dest = _outputFolder,
Output = _outputFolder,
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
Properties = new() { ["TargetFramework"] = "net6.0" },
}),
Expand All @@ -90,7 +90,7 @@ public async Task TestMetadataCommandFromVBProject()
File.Copy("Assets/test.vb.sample.1", sourceFile);

await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(), Directory.GetCurrentDirectory());

Assert.True(File.Exists(Path.Combine(_outputFolder, ".manifest")));
Expand Down Expand Up @@ -154,7 +154,7 @@ public async Task TestMetadataCommandFromCSProjectWithFilterInOption()
await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig
{
Dest = _outputFolder,
Output = _outputFolder,
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
Filter = filterFile,
}),
Expand Down Expand Up @@ -202,7 +202,7 @@ public async Task TestMetadataCommandFromCSProjectWithDuplicateProjectReference(
File.Copy("Assets/test.cs.sample.1", sourceFile);

await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(), Directory.GetCurrentDirectory());

CheckResult();
Expand All @@ -220,7 +220,7 @@ public async Task TestMetadataCommandFromCSProjectWithMultipleNamespaces()
await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig
{
Dest = _outputFolder,
Output = _outputFolder,
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
NamespaceLayout = NamespaceLayout.Nested,
}),
Expand Down Expand Up @@ -259,7 +259,7 @@ public async Task TestMetadataCommandFromCSProjectWithMultipleNamespacesWithFlat
await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig
{
Dest = _outputFolder,
Output = _outputFolder,
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
NamespaceLayout = NamespaceLayout.Flattened,
}),
Expand Down Expand Up @@ -298,7 +298,7 @@ public async Task TestMetadataCommandFromCSProjectWithMultipleNamespacesWithGaps
await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig
{
Dest = _outputFolder,
Output = _outputFolder,
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
NamespaceLayout = NamespaceLayout.Nested,
}),
Expand Down

0 comments on commit 0051a98

Please sign in to comment.