using System.Net; using System.Text.Json; using XFESystem.Documents; if (args.Length != 1) throw new ArgumentException("Specify a fresh output directory for host-only browser fixtures."); var output = Path.GetFullPath(args[0]); if (Directory.Exists(output)) throw new IOException("The browser fixture directory must be new."); Directory.CreateDirectory(output); var builder = new DocumentPreviewBuilder(new()); var markdown = builder.Markdown(""" # XFESystem 文档 | Language | Status | |---|---| | C# | Ready | ```js const greeting = "Hello XFE"; console.log(greeting); ``` Inline math: $a^2+b^2=c^2$. ```mermaid flowchart LR A[Markdown] --> B[Preview] ``` """, "XFESystem Markdown"); await File.WriteAllTextAsync(Path.Combine(output, "Markdown.html"), markdown.Html); var code = builder.Code("public sealed class Sample { public string Name => \"XFE\"; }", "Sample.cs"); await File.WriteAllTextAsync(Path.Combine(output, "Code.html"), code.Html); var plan = DocumentPreviewBuilder.JavaScript(""" console.log("Result", 6 * 7); document.body.dataset.Executed = "yes"; fetch("https://outside.invalid/Blocked").catch(() => console.log("Network blocked")); console.log("Host bridge", typeof window.chrome?.webview); """); var jsHost = $"Isolated JS host test"; await File.WriteAllTextAsync(Path.Combine(output, "JavaScript.html"), jsHost); await File.WriteAllTextAsync(Path.Combine(output, "ExecutionRequirements.json"), JsonSerializer.Serialize(plan, new JsonSerializerOptions { WriteIndented = true })); using var manifest = JsonDocument.Parse(WebsiteAssets.ReadText("SourceManifest.json")); Directory.CreateDirectory(Path.Combine(output, "Assets")); await File.WriteAllTextAsync(Path.Combine(output, "Assets", "SourceManifest.json"), WebsiteAssets.ReadText("SourceManifest.json")); foreach (var entry in manifest.RootElement.GetProperty("Entries").EnumerateArray()) { var name = entry.GetProperty("SnapshotPath").GetString()!; if (name.StartsWith("../", StringComparison.Ordinal)) continue; var path = Path.Combine(output, "Assets", name.Replace('/', Path.DirectorySeparatorChar)); Directory.CreateDirectory(Path.GetDirectoryName(path)!); using var resource = WebsiteAssets.Open(name); await using var file = File.Create(path); await resource.CopyToAsync(file); } Console.WriteLine(output);