|
| 1 | +using System; |
1 | 2 | using System.IO;
|
2 | 3 | using System.Linq;
|
| 4 | +using System.Reflection; |
3 | 5 | using System.Text;
|
| 6 | +using System.Threading.Tasks; |
4 | 7 | using Build;
|
5 | 8 | using Cake.Common;
|
6 | 9 | using Cake.Common.Build;
|
@@ -195,10 +198,46 @@ public void RunDocfx(FilePath docfxJson)
|
195 | 198 |
|
196 | 199 | var currentDirectory = Directory.GetCurrentDirectory();
|
197 | 200 | Directory.SetCurrentDirectory(docfxJson.GetDirectory().FullPath);
|
| 201 | + DocfxGenerateMetadata(docfxJson.FullPath); |
198 | 202 | Microsoft.DocAsCode.Docset.Build(docfxJson.FullPath).Wait();
|
199 | 203 | Directory.SetCurrentDirectory(currentDirectory);
|
200 | 204 | }
|
201 | 205 |
|
| 206 | + private void DocfxGenerateMetadata(string configPath) |
| 207 | + { |
| 208 | + Microsoft.DocAsCode.Common.Logger.RegisterListener(new Microsoft.DocAsCode.Common.ConsoleLogListener()); |
| 209 | + try |
| 210 | + { |
| 211 | + string directoryName = System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(configPath)); |
| 212 | + Newtonsoft.Json.Linq.JToken jtoken; |
| 213 | + if (!Newtonsoft.Json.Linq.JObject.Parse(File.ReadAllText(configPath)).TryGetValue("metadata", out jtoken)) |
| 214 | + return; |
| 215 | + |
| 216 | + var dotnetApiCatalogType = typeof(Microsoft.DocAsCode.Dotnet.DotnetApiOptions).Assembly.GetTypes() |
| 217 | + .First(t => t.Name == "DotnetApiCatalog"); |
| 218 | + var dotnetApiCatalogExecMethod = dotnetApiCatalogType.GetMethod("Exec", BindingFlags.Static | BindingFlags.NonPublic); |
| 219 | + var metadataJsonConfigType = typeof(Microsoft.DocAsCode.Dotnet.DotnetApiOptions).Assembly.GetTypes() |
| 220 | + .First(t => t.Name == "MetadataJsonConfig"); |
| 221 | + |
| 222 | + var config = jtoken.ToObject(metadataJsonConfigType, Microsoft.DocAsCode.Common.JsonUtility.DefaultSerializer.Value); |
| 223 | + |
| 224 | + var execTask = (Task)dotnetApiCatalogExecMethod.Invoke(null, new[] |
| 225 | + { |
| 226 | + config, |
| 227 | + new Microsoft.DocAsCode.Dotnet.DotnetApiOptions(), |
| 228 | + directoryName, |
| 229 | + null |
| 230 | + }); |
| 231 | + execTask.Wait(); |
| 232 | + } |
| 233 | + finally |
| 234 | + { |
| 235 | + Microsoft.DocAsCode.Common.Logger.Flush(); |
| 236 | + Microsoft.DocAsCode.Common.Logger.PrintSummary(); |
| 237 | + Microsoft.DocAsCode.Common.Logger.UnregisterAllListeners(); |
| 238 | + } |
| 239 | + } |
| 240 | + |
202 | 241 | public void GenerateRedirects()
|
203 | 242 | {
|
204 | 243 | var redirectProjectFile = RedirectProjectDirectory.CombineWithFilePath("RedirectGenerator.csproj");
|
|
0 commit comments