Skip to content

Commit

Permalink
improve docset.yml locating routine
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Dec 17, 2024
1 parent 3311063 commit 00532cc
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Elastic.Markdown/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
ReadFileSystem = readFileSystem;
WriteFileSystem = writeFileSystem;

var docsFolder = FindDocsFolderFromRoot();

SourcePath = !string.IsNullOrWhiteSpace(source) ? ReadFileSystem.DirectoryInfo.New(source) : docsFolder;
var rootFolder = !string.IsNullOrWhiteSpace(source)
? ReadFileSystem.DirectoryInfo.New(source)
: ReadFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, "docs"));
SourcePath = FindDocsFolderFromRoot(rootFolder);

OutputPath = !string.IsNullOrWhiteSpace(output)
? WriteFileSystem.DirectoryInfo.New(output)
Expand All @@ -59,12 +60,14 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
Git = GitConfiguration.Create(ReadFileSystem);
}

private IDirectoryInfo FindDocsFolderFromRoot()
private IDirectoryInfo FindDocsFolderFromRoot(IDirectoryInfo rootPath)
{
var defaultDocsFolder = ReadFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, "docs"));
var root = ReadFileSystem.DirectoryInfo.New(Paths.Root.FullName);
var docsFolder = root.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault();
return docsFolder?.Directory ?? defaultDocsFolder;
if (rootPath.Exists &&
ReadFileSystem.File.Exists(Path.Combine(rootPath.FullName, "docset.yml")))
return rootPath;

var docsFolder = rootPath.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault();
return docsFolder?.Directory ?? throw new Exception($"Can not locate docset.yml file in '{rootPath}'");
}

}

0 comments on commit 00532cc

Please sign in to comment.