Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactor docfx command related code #9140

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion src/Docfx.App/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ namespace Docfx;

internal static class Constants
{
public const string ConfigFileName = "docfx.json";
public const string DefaultTemplateName = "default";
}
7 changes: 6 additions & 1 deletion src/Docfx.App/RunBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Docfx.Build.Engine;
using Docfx.Common;
using Docfx.Common.Git;
using Docfx.Exceptions;
using Docfx.Plugins;
Expand All @@ -11,8 +10,14 @@ namespace Docfx;

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

/// <summary>
/// Helper class to build document.
/// </summary>
internal static class RunBuild
{
/// <summary>
/// Build document with specified settings.
/// </summary>
public static string Exec(BuildJsonConfig config, BuildOptions options, string configDirectory, string outputDirectory = null)
{
if (config.Templates == null || config.Templates.Count == 0)
Expand Down
6 changes: 6 additions & 0 deletions src/Docfx.App/RunMerge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@

namespace Docfx;

/// <summary>
/// Helper class to merge document.
/// </summary>
internal static class RunMerge
{
/// <summary>
/// Merge document with specified settings.
/// </summary>
public static void Exec(MergeJsonConfig config, string configDirectory)
{
foreach (var round in config)
Expand Down
20 changes: 20 additions & 0 deletions src/Docfx.App/RunMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Docfx.Dotnet;

namespace Docfx;

/// <summary>
/// Helper class to generate metadata.
/// </summary>
internal static class RunMetadata
{
/// <summary>
/// Generate metadata with specified settings.
/// </summary>
public static void Exec(MetadataJsonConfig config, DotnetApiOptions options, string configDirectory, string outputDirectory = null)
{
DotnetApiCatalog.Exec(config, options, configDirectory, outputDirectory).GetAwaiter().GetResult();
}
}
6 changes: 6 additions & 0 deletions src/Docfx.App/RunPdf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ namespace Docfx;

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

/// <summary>
/// Helper class to generate pdf document.
/// </summary>
internal static class RunPdf
{
/// <summary>
/// Generate pdf document with specified settings.
/// </summary>
public static void Exec(PdfJsonConfig config, BuildOptions buildOptions, string configDirectory, string outputDirectory = null)
{
EnvironmentContext.SetBaseDirectory(Path.GetFullPath(string.IsNullOrEmpty(configDirectory) ? Directory.GetCurrentDirectory() : configDirectory));
Expand Down
6 changes: 6 additions & 0 deletions src/Docfx.App/RunServe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@

namespace Docfx;

/// <summary>
/// Helper class to serve document.
/// </summary>
internal static class RunServe
{
/// <summary>
/// Start document host server with specified settings.
/// </summary>
public static void Exec(string folder, string host, int? port, bool openBrowser, string openFile)
{
if (string.IsNullOrEmpty(folder))
Expand Down
1 change: 1 addition & 0 deletions src/Docfx.DataContracts.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Docfx.DataContracts.Common;

public static class Constants
{
public const string ConfigFileName = "docfx.json";
public const string YamlExtension = ".yml";
public const string ContentPlaceholder = "*content";
public const string PrefixSeparator = ".";
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Dotnet/Docfx.Dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" />
</ItemGroup>

<ItemGroup>
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.Workspaces" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/Docfx.Dotnet/MetadataJsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Docfx;

/// <summary>
/// Specifies the layout of members.
/// </summary>
public enum MemberLayout
{
/// <summary>
Expand All @@ -18,6 +21,9 @@ public enum MemberLayout
SeparatePages,
}

/// <summary>
/// Specifies the layout of namepsaces.
/// </summary>
internal enum NamespaceLayout
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/docfx/Models/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal class CommandHelper
public static (T, string baseDirectory) GetConfig<T>(string configFile)
{
if (string.IsNullOrEmpty(configFile))
configFile = "docfx.json";
configFile = DataContracts.Common.Constants.ConfigFileName;

configFile = Path.GetFullPath(configFile);

Expand Down
2 changes: 1 addition & 1 deletion src/docfx/Models/InitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Docfx;

internal class InitCommand : Command<InitCommandOptions>
{
private const string ConfigName = Constants.ConfigFileName;
private const string ConfigName = DataContracts.Common.Constants.ConfigFileName;
private const string DefaultOutputFolder = "docfx_project";
private const string DefaultMetadataOutputFolder = "api";

Expand Down
3 changes: 2 additions & 1 deletion src/docfx/Models/MetadataCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using Docfx.DataContracts.Common;
using Docfx.Dotnet;
using Newtonsoft.Json;
using Spectre.Console.Cli;
Expand All @@ -23,7 +24,7 @@ private static MetadataJsonConfig ParseOptions(MetadataCommandOptions options, o
{
MetadataConfig config;

if (options.Config != null && !string.Equals(Path.GetFileName(options.Config), "docfx.json", StringComparison.OrdinalIgnoreCase))
if (options.Config != null && !string.Equals(Path.GetFileName(options.Config), DataContracts.Common.Constants.ConfigFileName, StringComparison.OrdinalIgnoreCase))
{
config = new()
{
Expand Down