@@ -49,29 +49,41 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
4949 var rootFolder = ! string . IsNullOrWhiteSpace ( source )
5050 ? ReadFileSystem . DirectoryInfo . New ( source )
5151 : ReadFileSystem . DirectoryInfo . New ( Path . Combine ( Paths . Root . FullName ) ) ;
52- SourcePath = FindDocsFolderFromRoot ( rootFolder ) ;
52+
53+ ( SourcePath , ConfigurationPath ) = FindDocsFolderFromRoot ( rootFolder ) ;
5354
5455 OutputPath = ! string . IsNullOrWhiteSpace ( output )
5556 ? WriteFileSystem . DirectoryInfo . New ( output )
5657 : WriteFileSystem . DirectoryInfo . New ( Path . Combine ( Paths . Root . FullName , ".artifacts/docs/html" ) ) ;
5758
58- ConfigurationPath =
59- ReadFileSystem . FileInfo . New ( Path . Combine ( SourcePath . FullName , "docset.yml" ) ) ;
60-
6159 if ( ConfigurationPath . FullName != SourcePath . FullName )
6260 SourcePath = ConfigurationPath . Directory ! ;
6361
6462 Git = GitCheckoutInformation . Create ( ReadFileSystem ) ;
6563 }
6664
67- private IDirectoryInfo FindDocsFolderFromRoot ( IDirectoryInfo rootPath )
65+ private ( IDirectoryInfo , IFileInfo ) FindDocsFolderFromRoot ( IDirectoryInfo rootPath )
6866 {
67+ var configurationPath = ReadFileSystem . FileInfo . New ( Path . Combine ( rootPath . FullName , "docset.yml" ) ) ;
6968 if ( rootPath . Exists &&
7069 ReadFileSystem . File . Exists ( Path . Combine ( rootPath . FullName , "docset.yml" ) ) )
71- return rootPath ;
70+ return ( rootPath , configurationPath ) ;
71+
72+ configurationPath = ReadFileSystem . FileInfo . New ( Path . Combine ( rootPath . FullName , "_docset.yml" ) ) ;
73+ if ( rootPath . Exists &&
74+ ReadFileSystem . File . Exists ( Path . Combine ( rootPath . FullName , "_docset.yml" ) ) )
75+ return ( rootPath , configurationPath ) ;
76+
77+ configurationPath = rootPath
78+ . EnumerateFiles ( "docset.yml" , SearchOption . AllDirectories )
79+ . OrderByDescending ( f => f . Name switch { "docset.yml" => 2 , "_docset.yml" => 1 , _ => 0 } )
80+ . FirstOrDefault ( )
81+ ?? throw new Exception ( $ "Can not locate docset.yml file in '{ rootPath } '") ;
82+
83+ var docsFolder = configurationPath . Directory
84+ ?? throw new Exception ( $ "Can not locate docset.yml file in '{ rootPath } '") ;
7285
73- var docsFolder = rootPath . EnumerateFiles ( "docset.yml" , SearchOption . AllDirectories ) . FirstOrDefault ( ) ;
74- return docsFolder ? . Directory ?? throw new Exception ( $ "Can not locate docset.yml file in '{ rootPath } '") ;
86+ return ( docsFolder , configurationPath ) ;
7587 }
7688
7789}
0 commit comments