Skip to content

Commit

Permalink
docs: Added WikiTests from Meta integration tests to documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Aug 18, 2024
1 parent 837a043 commit bf0608e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Helpers/GenerateDocs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ await File.WriteAllTextAsync(newPath, $@"```csharp
```");
}

var metaTestsFolder = Path.Combine(solutionDirectory, "src", "Meta", "test");
Console.WriteLine($"Generating samples from {metaTestsFolder}...");
foreach (var path in Directory.EnumerateFiles(metaTestsFolder, "WikiTests.*.cs", SearchOption.AllDirectories))
{
var code = await File.ReadAllTextAsync(path);

var newDir = Path.Combine(solutionDirectory, "docs", "samples");
Directory.CreateDirectory(newDir);

var start = code.IndexOf("\n {", StringComparison.Ordinal);
var end = code.IndexOf("\n }", StringComparison.Ordinal);
code = code.Substring(start + 4, end - start + 4);

var lines = code.Split('\n')[1..^2];
code = string.Join('\n', lines.Select(x => x.Length > 8 ? x[8..] : string.Empty));

var newPath = Path.Combine(newDir, $"{Path.GetExtension(Path.GetFileNameWithoutExtension(path)).TrimStart('.')}.md");
await File.WriteAllTextAsync(newPath, $@"```csharp
{code}
```");
}

var mkDocs = await File.ReadAllTextAsync(mkDocsPath);
var newMkDocs = mkDocs.Replace(
"# EXAMPLES #",
Expand Down

0 comments on commit bf0608e

Please sign in to comment.