Skip to content

Commit 2352935

Browse files
committed
feat: add overridable metadata output json config
1 parent f205a44 commit 2352935

File tree

7 files changed

+24
-36
lines changed

7 files changed

+24
-36
lines changed

docs/reference/docfx-json-reference.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,13 @@ Configuration options that are applied for `docfx metadata` command:
295295

296296
Specifies the source projects using [File Mappings](#file-mappings).
297297

298+
### `output`
299+
300+
Defines the output folder of the generated metadata files relative to `docfx.json` directory. The `docfx metadata --output <outdir>` command line argument overrides this value.
301+
298302
### `dest`
299303

300-
Defines the output folder of the generated metadata files. Relative paths are relative to the docfx.json file being used. To go up a folder use `../`.
304+
Defines the output folder of the generated metadata files relative to `docfx.json` directory. The `docfx metadata --output <outdir>` command line argument prepends this value.
301305

302306
### `shouldSkipMarkup`
303307

samples/seed/docfx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"namespaceLayout": "nested",
2020
"enumSortOrder": "declaringOrder",
21-
"dest": "obj/api"
21+
"output": "obj/api"
2222
}
2323
],
2424
"build": {

src/Docfx.App/Config/BuildJsonConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ internal class BuildJsonConfig
4141

4242
/// <summary>
4343
/// Defines the output folder of the generated build files.
44+
/// Command line --output argument prepends this value.
4445
/// </summary>
4546
[Obsolete("Use output instead.")]
4647
[JsonProperty("dest")]
4748
public string Destination { get; set; }
4849

4950
/// <summary>
5051
/// Defines the output folder of the generated build files.
52+
/// Command line --output argument override this value.
5153
/// </summary>
5254
[JsonProperty("output")]
5355
public string Output { get; set; }

src/Docfx.Dotnet/DotnetApiCatalog.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ internal static async Task Exec(MetadataJsonConfig config, DotnetApiOptions opti
6868
EnvironmentContext.SetGitFeaturesDisabled(item.DisableGitFeatures);
6969

7070
// TODO: Use plugin to generate metadata for files with different extension?
71-
using var worker = new ExtractMetadataWorker(ConvertConfig(item, outputDirectory ?? configDirectory), options);
71+
using var worker = new ExtractMetadataWorker(ConvertConfig(item, configDirectory, outputDirectory), options);
7272
await worker.ExtractMetadataAsync();
7373
}
7474

@@ -103,11 +103,10 @@ private static void EnsureMSBuildLocator()
103103
}
104104
}
105105

106-
private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig configModel, string outputDirectory)
106+
private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig configModel, string configDirectory, string outputDirectory)
107107
{
108108
var projects = configModel.Source;
109109
var references = configModel.References;
110-
var outputFolder = configModel.Destination ?? "_api";
111110

112111
var expandedFiles = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, projects);
113112
var expandedReferences = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, references);
@@ -120,7 +119,7 @@ private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig config
120119
GlobalNamespaceId = configModel?.GlobalNamespaceId,
121120
MSBuildProperties = configModel?.MSBuildProperties,
122121
OutputFormat = configModel?.OutputFormat ?? default,
123-
OutputFolder = Path.GetFullPath(Path.Combine(outputDirectory, outputFolder)),
122+
OutputFolder = Path.GetFullPath(Path.Combine(configDirectory, outputDirectory ?? configModel.Output ?? "_api", configModel.Destination ?? "")),
124123
CodeSourceBasePath = configModel?.CodeSourceBasePath,
125124
DisableDefaultFilter = configModel?.DisableDefaultFilter ?? false,
126125
NoRestore = configModel?.NoRestore ?? false,

src/Docfx.Dotnet/MetadataJsonConfig.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,18 @@ internal class MetadataJsonItemConfig
8383

8484
/// <summary>
8585
/// Defines the output folder of the generated metadata files.
86+
/// Command line --output argument prepends this value.
8687
/// </summary>
8788
[JsonProperty("dest")]
8889
public string Destination { get; set; }
8990

91+
/// <summary>
92+
/// Defines the output folder of the generated metadata files.
93+
/// Command line --output argument override this value.
94+
/// </summary>
95+
[JsonProperty("output")]
96+
public string Output { get; set; }
97+
9098
/// <summary>
9199
/// Defines the output file format.
92100
/// </summary>

src/docfx/Models/MetadataCommand.cs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,14 @@ public override int Execute([NotNull] CommandContext context, [NotNull] Metadata
1414
{
1515
return CommandHelper.Run(options, () =>
1616
{
17-
var config = ParseOptions(options, out var baseDirectory, out var outputFolder);
18-
DotnetApiCatalog.Exec(config, new(), baseDirectory, outputFolder).GetAwaiter().GetResult();
17+
var (config, baseDirectory) = CommandHelper.GetConfig<MetadataConfig>(options.Config);
18+
MergeOptionsToConfig(options, config);
19+
DotnetApiCatalog.Exec(config.Item, new(), baseDirectory, options.OutputFolder).GetAwaiter().GetResult();
1920
});
2021
}
2122

22-
private static MetadataJsonConfig ParseOptions(MetadataCommandOptions options, out string baseDirectory, out string outputFolder)
23+
private static void MergeOptionsToConfig(MetadataCommandOptions options, MetadataConfig config)
2324
{
24-
MetadataConfig config;
25-
26-
if (options.Config != null && !string.Equals(Path.GetFileName(options.Config), DataContracts.Common.Constants.ConfigFileName, StringComparison.OrdinalIgnoreCase))
27-
{
28-
config = new()
29-
{
30-
Item = new()
31-
{
32-
new()
33-
{
34-
Destination = options.OutputFolder,
35-
Source = new FileMapping(new FileMappingItem(new[]{ options.Config })) { Expanded = true },
36-
}
37-
}
38-
};
39-
baseDirectory = Directory.GetCurrentDirectory();
40-
}
41-
else
42-
{
43-
(config, baseDirectory) = CommandHelper.GetConfig<MetadataConfig>(options.Config);
44-
}
45-
4625
var msbuildProperties = ResolveMSBuildProperties(options);
4726
foreach (var item in config.Item)
4827
{
@@ -75,10 +54,6 @@ private static MetadataJsonConfig ParseOptions(MetadataCommandOptions options, o
7554
}
7655
}
7756
}
78-
79-
outputFolder = options.OutputFolder;
80-
81-
return config.Item;
8257
}
8358

8459
private static Dictionary<string, string> ResolveMSBuildProperties(MetadataCommandOptions options)

test/docfx.Snapshot.Tests/SamplesTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public async Task SeedMarkdown()
188188

189189
Program.Main(new[] { "metadata", $"{samplePath}/docfx.json", "--outputFormat", "markdown", "--output", nameof(SeedMarkdown) });
190190

191-
await VerifyDirectory($"{nameof(SeedMarkdown)}/obj/api", IncludeFile, fileScrubber: ScrubFile).AutoVerify(includeBuildServer: false);
191+
await VerifyDirectory($"{nameof(SeedMarkdown)}", IncludeFile, fileScrubber: ScrubFile).AutoVerify(includeBuildServer: false);
192192
}
193193

194194
[SnapshotFact]

0 commit comments

Comments
 (0)