public IActionResult Index() { if (!_webAppSettings.AllowScriptExecution) { return(NotFound()); } var scriptsFullPath = Path.Combine(_hostEnvironment.ContentRootPath, "Scripts"); if (!Directory.Exists(scriptsFullPath)) { return(View(new ScriptsViewModel() { Scripts = new SelectList(new List <string>() { "No scripts found" }) })); } var scriptFiles = Directory.GetFiles(scriptsFullPath, "*.cs"); List <string> scriptFileNames = scriptFiles.Select(sf => Path.GetFileName(sf)).ToList(); List <string> targets = _targetExtractor.ExtractTargets(scriptFiles[0]); return(View(new ScriptsViewModel { Scripts = new SelectList(scriptFileNames), Targets = new SelectList(targets), })); }
public void ExtractTargetsTest() { var scriptLines = new List <string> { "using System;", "using FlubuCore.Context;", "using FlubuCore.Scripting;", string.Empty, "public class MyBuildScript : DefaultBuildScript", "{", " protected override void ConfigureBuildProperties(IBuildPropertiesContext context)", " {", " System.Console.WriteLine(\"2222\");", " }", string.Empty, " protected override void ConfigureTargets(ITaskContext context)", " {", " var test = new Test();", " context.CreateTarget(\"rebuild.server\")", " .SetDescription(\"Rebuilds the solution and publishes nuget packages.\")", ".DependsOn(compile, flubuTests);", "session.CreateTarget(\"Deploy\")", " .SetDescription(\"Deploys flubu web api\")", "context.CreateTarget(\"rebuild.linux\")", " }", " }", "public class Test", "{", "}" }; var result = _targetExtractor.ExtractTargets(scriptLines); Assert.Equal(3, result.Count); Assert.Equal("rebuild.server", result[0]); Assert.Equal("Deploy", result[1]); Assert.Equal("rebuild.linux", result[2]); }