Skip to content

Commit 00532cc

Browse files
committed
improve docset.yml locating routine
1 parent 3311063 commit 00532cc

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/Elastic.Markdown/BuildContext.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
4242
ReadFileSystem = readFileSystem;
4343
WriteFileSystem = writeFileSystem;
4444

45-
var docsFolder = FindDocsFolderFromRoot();
46-
47-
SourcePath = !string.IsNullOrWhiteSpace(source) ? ReadFileSystem.DirectoryInfo.New(source) : docsFolder;
45+
var rootFolder = !string.IsNullOrWhiteSpace(source)
46+
? ReadFileSystem.DirectoryInfo.New(source)
47+
: ReadFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, "docs"));
48+
SourcePath = FindDocsFolderFromRoot(rootFolder);
4849

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

62-
private IDirectoryInfo FindDocsFolderFromRoot()
63+
private IDirectoryInfo FindDocsFolderFromRoot(IDirectoryInfo rootPath)
6364
{
64-
var defaultDocsFolder = ReadFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, "docs"));
65-
var root = ReadFileSystem.DirectoryInfo.New(Paths.Root.FullName);
66-
var docsFolder = root.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault();
67-
return docsFolder?.Directory ?? defaultDocsFolder;
65+
if (rootPath.Exists &&
66+
ReadFileSystem.File.Exists(Path.Combine(rootPath.FullName, "docset.yml")))
67+
return rootPath;
68+
69+
var docsFolder = rootPath.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault();
70+
return docsFolder?.Directory ?? throw new Exception($"Can not locate docset.yml file in '{rootPath}'");
6871
}
6972

7073
}

0 commit comments

Comments
 (0)