Skip to content

Commit e7366e2

Browse files
authored
chore: Refactor docfx command related code (#9140)
1 parent d518b06 commit e7366e2

File tree

12 files changed

+56
-6
lines changed

12 files changed

+56
-6
lines changed

src/Docfx.App/Helpers/Constants.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ namespace Docfx;
55

66
internal static class Constants
77
{
8-
public const string ConfigFileName = "docfx.json";
98
public const string DefaultTemplateName = "default";
109
}

src/Docfx.App/RunBuild.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Docfx.Build.Engine;
5-
using Docfx.Common;
65
using Docfx.Common.Git;
76
using Docfx.Exceptions;
87
using Docfx.Plugins;
@@ -11,8 +10,14 @@ namespace Docfx;
1110

1211
#pragma warning disable CS0618 // Type or member is obsolete
1312

13+
/// <summary>
14+
/// Helper class to build document.
15+
/// </summary>
1416
internal static class RunBuild
1517
{
18+
/// <summary>
19+
/// Build document with specified settings.
20+
/// </summary>
1621
public static string Exec(BuildJsonConfig config, BuildOptions options, string configDirectory, string outputDirectory = null)
1722
{
1823
if (config.Templates == null || config.Templates.Count == 0)

src/Docfx.App/RunMerge.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88

99
namespace Docfx;
1010

11+
/// <summary>
12+
/// Helper class to merge document.
13+
/// </summary>
1114
internal static class RunMerge
1215
{
16+
/// <summary>
17+
/// Merge document with specified settings.
18+
/// </summary>
1319
public static void Exec(MergeJsonConfig config, string configDirectory)
1420
{
1521
foreach (var round in config)

src/Docfx.App/RunMetadata.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Docfx.Dotnet;
5+
6+
namespace Docfx;
7+
8+
/// <summary>
9+
/// Helper class to generate metadata.
10+
/// </summary>
11+
internal static class RunMetadata
12+
{
13+
/// <summary>
14+
/// Generate metadata with specified settings.
15+
/// </summary>
16+
public static void Exec(MetadataJsonConfig config, DotnetApiOptions options, string configDirectory, string outputDirectory = null)
17+
{
18+
DotnetApiCatalog.Exec(config, options, configDirectory, outputDirectory).GetAwaiter().GetResult();
19+
}
20+
}

src/Docfx.App/RunPdf.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ namespace Docfx;
1010

1111
#pragma warning disable CS0618 // Type or member is obsolete
1212

13+
/// <summary>
14+
/// Helper class to generate pdf document.
15+
/// </summary>
1316
internal static class RunPdf
1417
{
18+
/// <summary>
19+
/// Generate pdf document with specified settings.
20+
/// </summary>
1521
public static void Exec(PdfJsonConfig config, BuildOptions buildOptions, string configDirectory, string outputDirectory = null)
1622
{
1723
EnvironmentContext.SetBaseDirectory(Path.GetFullPath(string.IsNullOrEmpty(configDirectory) ? Directory.GetCurrentDirectory() : configDirectory));

src/Docfx.App/RunServe.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313

1414
namespace Docfx;
1515

16+
/// <summary>
17+
/// Helper class to serve document.
18+
/// </summary>
1619
internal static class RunServe
1720
{
21+
/// <summary>
22+
/// Start document host server with specified settings.
23+
/// </summary>
1824
public static void Exec(string folder, string host, int? port, bool openBrowser, string openFile)
1925
{
2026
if (string.IsNullOrEmpty(folder))

src/Docfx.DataContracts.Common/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Docfx.DataContracts.Common;
99

1010
public static class Constants
1111
{
12+
public const string ConfigFileName = "docfx.json";
1213
public const string YamlExtension = ".yml";
1314
public const string ContentPlaceholder = "*content";
1415
public const string PrefixSeparator = ".";

src/Docfx.Dotnet/Docfx.Dotnet.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" />
3535
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" />
3636
</ItemGroup>
37-
37+
3838
<ItemGroup>
3939
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.Workspaces" />
4040
</ItemGroup>

src/Docfx.Dotnet/MetadataJsonConfig.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace Docfx;
77

8+
/// <summary>
9+
/// Specifies the layout of members.
10+
/// </summary>
811
public enum MemberLayout
912
{
1013
/// <summary>
@@ -18,6 +21,9 @@ public enum MemberLayout
1821
SeparatePages,
1922
}
2023

24+
/// <summary>
25+
/// Specifies the layout of namepsaces.
26+
/// </summary>
2127
internal enum NamespaceLayout
2228
{
2329
/// <summary>

src/docfx/Models/CommandHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal class CommandHelper
1010
public static (T, string baseDirectory) GetConfig<T>(string configFile)
1111
{
1212
if (string.IsNullOrEmpty(configFile))
13-
configFile = "docfx.json";
13+
configFile = DataContracts.Common.Constants.ConfigFileName;
1414

1515
configFile = Path.GetFullPath(configFile);
1616

src/docfx/Models/InitCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Docfx;
1010

1111
internal class InitCommand : Command<InitCommandOptions>
1212
{
13-
private const string ConfigName = Constants.ConfigFileName;
13+
private const string ConfigName = DataContracts.Common.Constants.ConfigFileName;
1414
private const string DefaultOutputFolder = "docfx_project";
1515
private const string DefaultMetadataOutputFolder = "api";
1616

src/docfx/Models/MetadataCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics.CodeAnalysis;
5+
using Docfx.DataContracts.Common;
56
using Docfx.Dotnet;
67
using Newtonsoft.Json;
78
using Spectre.Console.Cli;
@@ -23,7 +24,7 @@ private static MetadataJsonConfig ParseOptions(MetadataCommandOptions options, o
2324
{
2425
MetadataConfig config;
2526

26-
if (options.Config != null && !string.Equals(Path.GetFileName(options.Config), "docfx.json", StringComparison.OrdinalIgnoreCase))
27+
if (options.Config != null && !string.Equals(Path.GetFileName(options.Config), DataContracts.Common.Constants.ConfigFileName, StringComparison.OrdinalIgnoreCase))
2728
{
2829
config = new()
2930
{

0 commit comments

Comments
 (0)