diff --git a/tools/Legerity.PageObjectGenerator/Features/Generators/Web/VuePageObjectGenerator.cs b/tools/Legerity.PageObjectGenerator/Features/Generators/Web/VuePageObjectGenerator.cs new file mode 100644 index 00000000..f5e1967a --- /dev/null +++ b/tools/Legerity.PageObjectGenerator/Features/Generators/Web/VuePageObjectGenerator.cs @@ -0,0 +1,303 @@ +namespace Legerity.Features.Generators.Web; + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HtmlAgilityPack; +using Infrastructure.IO; +using Legerity.Features.Generators; +using Legerity.Features.Generators.Models; +using Legerity.Infrastructure.Extensions; +using MADE.Collections.Compare; +using MADE.Data.Validation.Extensions; +using Scriban; +using Serilog; + +internal class VuePageObjectGenerator : IPageObjectGenerator +{ + private const string BaseElementType = "WebElement"; + + private static readonly GenericEqualityComparer SimpleStringComparer = new(s => s.ToLower()); + + public static IEnumerable SupportedCoreWebElements => new List + { + "Button", + "CheckBox", + "Select", + "TextInput", + "FileInput", + "Image", + "List", + "Table", + "TableRow", + "Form", + "Option", + "TextArea", + "RadioButton", + "RangeInput", + "NumberInput", + "DateInput" + }; + + public async Task GenerateAsync(string ns, string inputPath, string outputPath) + { + IEnumerable? filePaths = GetVueFilePaths(inputPath)?.ToList(); + + if (filePaths == null || !filePaths.Any()) + { + Log.Warning("No Vue files found in {InputPath}", inputPath); + return; + } + + foreach (string filePath in filePaths) + { + Log.Information($"Processing {filePath}..."); + + try + { + string vueContent = await File.ReadAllTextAsync(filePath); + var htmlDoc = new HtmlDocument(); + htmlDoc.LoadHtml(vueContent); + + var templateNode = htmlDoc.DocumentNode.SelectSingleNode("//template"); + if (templateNode == null) + { + Log.Warning($"Skipping {filePath} as no