6
6
using System . Reflection ;
7
7
using System . Text . Json ;
8
8
using Elastic . Documentation . Legacy ;
9
+ using Elastic . Documentation . Links ;
9
10
using Elastic . Documentation . Serialization ;
10
11
using Elastic . Documentation . State ;
11
12
using Elastic . Markdown . Exporters ;
@@ -27,6 +28,11 @@ public interface IDocumentationFileOutputProvider
27
28
IFileInfo ? OutputFile ( DocumentationSet documentationSet , IFileInfo defaultOutputFile , string relativePath ) ;
28
29
}
29
30
31
+ public record GenerationResult
32
+ {
33
+ public IReadOnlyDictionary < string , LinkRedirect > Redirects { get ; set ; } = new Dictionary < string , LinkRedirect > ( ) ;
34
+ }
35
+
30
36
public class DocumentationGenerator
31
37
{
32
38
private readonly IDocumentationFileOutputProvider ? _documentationFileOutputProvider ;
@@ -87,14 +93,23 @@ public async Task ResolveDirectoryTree(Cancel ctx)
87
93
_logger . LogInformation ( "Resolved tree" ) ;
88
94
}
89
95
90
- public async Task GenerateAll ( Cancel ctx )
96
+ public async Task < GenerationResult > GenerateAll ( Cancel ctx )
91
97
{
92
- var generationState = GetPreviousGenerationState ( ) ;
93
- if ( ! Context . SkipMetadata && ( Context . Force || generationState == null ) )
98
+ var result = new GenerationResult ( ) ;
99
+
100
+ HashSet < string > offendingFiles = [ ] ;
101
+ var outputSeenChanges = DateTimeOffset . MinValue ;
102
+ if ( Context . SkipDocumentationState )
94
103
DocumentationSet . ClearOutputDirectory ( ) ;
104
+ else
105
+ {
106
+ var generationState = GetPreviousGenerationState ( ) ;
107
+ if ( Context . Force || generationState == null )
108
+ DocumentationSet . ClearOutputDirectory ( ) ;
95
109
96
- if ( CompilationNotNeeded ( generationState , out var offendingFiles , out var outputSeenChanges ) )
97
- return ;
110
+ if ( CompilationNotNeeded ( generationState , out offendingFiles , out outputSeenChanges ) )
111
+ return result ;
112
+ }
98
113
99
114
_logger . LogInformation ( $ "Fetching external links") ;
100
115
_ = await Resolver . FetchLinks ( ctx ) ;
@@ -107,14 +122,20 @@ public async Task GenerateAll(Cancel ctx)
107
122
108
123
await ExtractEmbeddedStaticResources ( ctx ) ;
109
124
110
- if ( Context . SkipMetadata )
111
- return ;
112
-
113
- _logger . LogInformation ( $ "Generating documentation compilation state" ) ;
114
- await GenerateDocumentationState ( ctx ) ;
125
+ if ( ! Context . SkipDocumentationState )
126
+ {
127
+ _logger . LogInformation ( $ "Generating documentation compilation state" ) ;
128
+ await GenerateDocumentationState ( ctx ) ;
129
+ }
115
130
116
131
_logger . LogInformation ( $ "Generating links.json") ;
117
- await GenerateLinkReference ( ctx ) ;
132
+ var linkReference = await GenerateLinkReference ( ctx ) ;
133
+
134
+ // ReSharper disable once WithExpressionModifiesAllMembers
135
+ return result with
136
+ {
137
+ Redirects = linkReference . Redirects ?? [ ]
138
+ } ;
118
139
}
119
140
120
141
private async Task ProcessDocumentationFiles ( HashSet < string > offendingFiles , DateTimeOffset outputSeenChanges , Cancel ctx )
@@ -254,13 +275,13 @@ private bool CompilationNotNeeded(GenerationState? generationState, out HashSet<
254
275
return false ;
255
276
}
256
277
257
- private async Task GenerateLinkReference ( Cancel ctx )
278
+ private async Task < LinkReference > GenerateLinkReference ( Cancel ctx )
258
279
{
259
280
var file = DocumentationSet . LinkReferenceFile ;
260
281
var state = DocumentationSet . CreateLinkReference ( ) ;
261
-
262
282
var bytes = JsonSerializer . SerializeToUtf8Bytes ( state , SourceGenerationContext . Default . LinkReference ) ;
263
283
await DocumentationSet . OutputDirectory . FileSystem . File . WriteAllBytesAsync ( file . FullName , bytes , ctx ) ;
284
+ return state ;
264
285
}
265
286
266
287
private async Task GenerateDocumentationState ( Cancel ctx )
0 commit comments