|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using Slugify; |
| 6 | +using Soenneker.Utils.AutoBogus; |
| 7 | + |
| 8 | +namespace Documentation.Generator.Domain; |
| 9 | + |
| 10 | +public static class Generators |
| 11 | +{ |
| 12 | + public static AutoFaker<FolderName> FolderName { get; } = new(); |
| 13 | + public static AutoFaker<Section> Section { get; } = new(); |
| 14 | + public static AutoFaker<MarkdownFile> File { get; } = new(); |
| 15 | + public static SlugHelper Slug { get; } = new(); |
| 16 | + |
| 17 | + static Generators() |
| 18 | + { |
| 19 | + FolderName |
| 20 | + .RuleFor(p => p.Folder, f => f.Lorem.Slug(1)); |
| 21 | + |
| 22 | + Section |
| 23 | + .RuleFor(p => p.Paragraphs, f => f.Lorem.Paragraphs(f.Random.Number(1, 10))) |
| 24 | + .RuleFor(p => p.Level, f => f.Random.Number(2, 4)); |
| 25 | + |
| 26 | + File |
| 27 | + .Ignore(p => p.Links) |
| 28 | + .Ignore(p => p.Directory) |
| 29 | + .RuleFor(p => p.FileName, f => f.System.FileName("md")) |
| 30 | + .RuleFor(p => p.IncludeInUpdate, f => f.Random.Float() <= Determinism.Random.FileProbability) |
| 31 | + .RuleFor(p => p.Sections, f => Section.Generate(Determinism.Random.Contents.Number(1, 12)).ToArray()); |
| 32 | + } |
| 33 | + |
| 34 | + public static IEnumerable<string> CreateSubPaths(string parent, int maxDepth, int currentDepth) |
| 35 | + { |
| 36 | + yield return parent; |
| 37 | + if (currentDepth == maxDepth) yield break; |
| 38 | + var subFolders = FolderName.Generate(Determinism.Random.FileSystem.Number(0, 4)); |
| 39 | + foreach (var subFolder in subFolders) |
| 40 | + { |
| 41 | + var path = $"{parent}/{subFolder.Folder}"; |
| 42 | + yield return path; |
| 43 | + var subPaths = CreateSubPaths(path, maxDepth, currentDepth + 1); |
| 44 | + foreach (var p in subPaths) |
| 45 | + yield return p; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + public static string[] FolderNames { get; set; } = []; |
| 50 | +} |
0 commit comments