static async Task DoTask(Lang lang, string filePath, string outputDir) { if (!File.Exists(filePath)) { throw new Exception("File does not exist"); } if (!Directory.Exists(outputDir)) { Console.WriteLine("Output directory does not exist. It will be created"); } string fileName = Path.GetFileNameWithoutExtension(filePath); CancellationTokenSource source = new(); CancellationToken token = source.Token; string fileText = await File.ReadAllTextAsync(filePath, Encoding.UTF8, token); JLMLDocument script = JLMLDocumentLoader.Load(fileText); IScriptable transpiler = lang switch { Lang.Html => new HtmlTranspiler(), _ => throw new NotImplementedException(), }; string contents = transpiler.ToScript(script); Directory.CreateDirectory(outputDir); await File.WriteAllTextAsync(Path.Join(outputDir, fileName + ".html"), contents, Encoding.UTF8, token); }
public async Task <IActionResult> GetCompiledSampleAsync(string sample) { using HttpClient http = new(); try { var text = await http.GetStringAsync("https://mr9madness.github.io/JLML/samples/" + sample); var document = JLMLDocumentLoader.Load(text); return(Content(_scripter.ToScript(document), "text/html")); } catch (Exception) { return(BadRequest("Sample does not exist")); } }