From a76dfacf967387ceac439888943a9b8f7df7ebde Mon Sep 17 00:00:00 2001 From: Vitali Semianiaka Date: Wed, 31 Dec 2025 18:04:54 +0300 Subject: [PATCH] real compiler --- Program.cs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++-- s8nc.csproj | 4 ++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/Program.cs b/Program.cs index 8ad7d8f..90771f4 100644 --- a/Program.cs +++ b/Program.cs @@ -1,2 +1,55 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World! {0}", string.Join("; ", args)); +using System.Text.Json; +using s8n_runtime.ViewModels; + +string workflowViewFile = Environment.GetEnvironmentVariable("WORKFLOW_FILE")!; +string projectDirectory = Environment.GetEnvironmentVariable("PROJECT_DIR") ?? $"/sources"; + +var workflow = JsonSerializer.Deserialize(File.OpenRead(workflowViewFile), JsonSerializerOptions.Web)!; + +var edgesFile = Path.Combine("/sources", $"{workflow.Name}.Edges.cs"); +var nodesFile = Path.Combine("/sources", $"{workflow.Name}.Nodes.cs"); + +// Linking +const string templateEdges = """ +// !Warning! Please, don't change this file. Code autogenerated +#pragma warning disable CS8622 // Nullability of reference types in type of parameter doesn't match the target delegate (possibly because of nullability attributes). + +public partial class {0} +{{ + public void Connect() + {{ + // edges connect here >>> + {1} + }} + + public void Disconnect() + {{ + // edges disconnect here >>> + {2} + }} +}} + +"""; +const string templateNodes = """ +// !Warning! Please, don't change this file. Code autogenerated + +public partial class {0} +{{ + // nodes here >>> + + {1} +}} +"""; + +static string GetConnection(WorkflowEdge edge) => + $"{edge.Source}{(string.IsNullOrEmpty(edge.SourceHandle) ? string.Empty : ".")}{edge.SourceHandle ?? string.Empty} {( + edge.IsEvent ? "+" : string.Empty + )}= {edge.Target}{(string.IsNullOrEmpty(edge.TargetHandle) ? string.Empty : ".")}{edge.TargetHandle ?? string.Empty}"; + +string edgesConnections = string.Join("\n", workflow.Edges.Select(e => $"// {e.Id}\n {GetConnection(e)};")); +var edges = string.Format(templateEdges, workflow.Name, edgesConnections, edgesConnections.Replace('+', '-')); +string nodesFields = string.Join("\n ", workflow.Nodes.Select(n => $"// {n.Data?.Label}\n public {n.Class} {n.Id};")); +var nodes = string.Format(templateNodes, workflow.Name, nodesFields); + +await File.WriteAllTextAsync(edgesFile, edges); +await File.WriteAllTextAsync(nodesFile, nodes); diff --git a/s8nc.csproj b/s8nc.csproj index e0e908e..c8be421 100644 --- a/s8nc.csproj +++ b/s8nc.csproj @@ -8,4 +8,8 @@ enable + + + +