@@ -49,29 +49,42 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
49
49
var rootFolder = ! string . IsNullOrWhiteSpace ( source )
50
50
? ReadFileSystem . DirectoryInfo . New ( source )
51
51
: ReadFileSystem . DirectoryInfo . New ( Path . Combine ( Paths . Root . FullName ) ) ;
52
- SourcePath = FindDocsFolderFromRoot ( rootFolder ) ;
52
+
53
+ ( SourcePath , ConfigurationPath ) = FindDocsFolderFromRoot ( rootFolder ) ;
53
54
54
55
OutputPath = ! string . IsNullOrWhiteSpace ( output )
55
56
? WriteFileSystem . DirectoryInfo . New ( output )
56
57
: WriteFileSystem . DirectoryInfo . New ( Path . Combine ( Paths . Root . FullName , ".artifacts/docs/html" ) ) ;
57
58
58
- ConfigurationPath =
59
- ReadFileSystem . FileInfo . New ( Path . Combine ( SourcePath . FullName , "docset.yml" ) ) ;
60
-
61
59
if ( ConfigurationPath . FullName != SourcePath . FullName )
62
60
SourcePath = ConfigurationPath . Directory ! ;
63
61
64
62
Git = GitCheckoutInformation . Create ( ReadFileSystem ) ;
65
63
}
66
64
67
- private IDirectoryInfo FindDocsFolderFromRoot ( IDirectoryInfo rootPath )
65
+ private ( IDirectoryInfo , IFileInfo ) FindDocsFolderFromRoot ( IDirectoryInfo rootPath )
68
66
{
69
- if ( rootPath . Exists &&
70
- ReadFileSystem . File . Exists ( Path . Combine ( rootPath . FullName , "docset.yml" ) ) )
71
- return rootPath ;
72
-
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 } '") ;
67
+ string [ ] files = [ "docset.yml" , "_docset.yml" ] ;
68
+ string [ ] knownFolders = [ rootPath . FullName , Path . Combine ( rootPath . FullName , "docs" ) ] ;
69
+ var mostLikelyTargets =
70
+ from file in files
71
+ from folder in knownFolders
72
+ select Path . Combine ( folder , file ) ;
73
+
74
+ var knownConfigPath = mostLikelyTargets . FirstOrDefault ( ReadFileSystem . File . Exists ) ;
75
+ var configurationPath = knownConfigPath is null ? null : ReadFileSystem . FileInfo . New ( knownConfigPath ) ;
76
+ if ( configurationPath is not null )
77
+ return ( configurationPath . Directory ! , configurationPath ) ;
78
+
79
+ configurationPath = rootPath
80
+ . EnumerateFiles ( "*docset.yml" , SearchOption . AllDirectories )
81
+ . FirstOrDefault ( )
82
+ ?? throw new Exception ( $ "Can not locate docset.yml file in '{ rootPath } '") ;
83
+
84
+ var docsFolder = configurationPath . Directory
85
+ ?? throw new Exception ( $ "Can not locate docset.yml file in '{ rootPath } '") ;
86
+
87
+ return ( docsFolder , configurationPath ) ;
75
88
}
76
89
77
90
}
0 commit comments