public static void ScaffoldApi(string buildSolutionDirectory, ApiTemplate template, IFileSystem fileSystem) { var projectName = template.ProjectName; AnsiConsole.Status() .AutoRefresh(true) .Spinner(Spinner.Known.Dots2) .Start($"[yellow]Creating {template.ProjectName} [/]", ctx => { FileParsingHelper.RunPrimaryKeyGuard(template.Entities); FileParsingHelper.RunSolutionNameAssignedGuard(projectName); FileParsingHelper.SolutionNameDoesNotEqualEntityGuard(projectName, template.Entities); // add an accelerate.config.yaml file to the root? var bcDirectory = $"{buildSolutionDirectory}{Path.DirectorySeparatorChar}{projectName}"; var srcDirectory = Path.Combine(bcDirectory, "src"); var testDirectory = Path.Combine(bcDirectory, "tests"); fileSystem.Directory.CreateDirectory(srcDirectory); fileSystem.Directory.CreateDirectory(testDirectory); ctx.Spinner(Spinner.Known.BouncingBar); ctx.Status($"[bold blue]Building {projectName} Projects [/]"); SolutionBuilder.AddProjects(buildSolutionDirectory, srcDirectory, testDirectory, template.DbContext.Provider, template.DbContext.DatabaseName, projectName, template.AddJwtAuthentication, fileSystem); // add all files based on the given template config ctx.Status($"[bold blue]Scaffolding Files for {projectName} [/]"); RunTemplateBuilders(bcDirectory, srcDirectory, testDirectory, template, fileSystem); WriteLogMessage($"File scaffolding for {template.ProjectName} was successful"); }); }
public static void ScaffoldApi(string buildSolutionDirectory, ApiTemplate template, IFileSystem fileSystem, Verbosity verbosity) { if (verbosity == Verbosity.More) { WriteHelpText($"{Environment.NewLine}Creating {template.SolutionName}..."); } FileParsingHelper.RunPrimaryKeyGuard(template.Entities); FileParsingHelper.RunSolutionNameAssignedGuard(template.SolutionName); FileParsingHelper.SolutionNameDoesNotEqualEntityGuard(template.SolutionName, template.Entities); // scaffold projects // add an accelerate.config.yaml file to the root? // solution level stuff // ***********will add a root directory read from template here for the entire overarching whatever (Koi Katan Operations, LimsLite, ProfiseePlatform) var solutionDirectory = $"{buildSolutionDirectory}{Path.DirectorySeparatorChar}{template.SolutionName}"; var srcDirectory = Path.Combine(solutionDirectory, "src"); var testDirectory = Path.Combine(solutionDirectory, "tests"); fileSystem.Directory.CreateDirectory(srcDirectory); fileSystem.Directory.CreateDirectory(testDirectory); SolutionBuilder.BuildSolution(solutionDirectory, template.SolutionName, fileSystem); SolutionBuilder.AddProjects(solutionDirectory, srcDirectory, testDirectory, template.DbContext.Provider, template.DbContext.DatabaseName, template.SolutionName, template.AddJwtAuthentication, fileSystem); if (verbosity == Verbosity.More) { WriteHelpText($"{template.SolutionName} projects were scaffolded successfully."); } // add all files based on the given template config RunTemplateBuilders(solutionDirectory, srcDirectory, testDirectory, template, fileSystem, verbosity); if (verbosity == Verbosity.More) { WriteHelpText($"{template.SolutionName} templates were scaffolded successfully."); } if (verbosity == Verbosity.More) { WriteHelpText($"Starting {template.SolutionName} database migrations."); } RunDbMigration(template, srcDirectory); if (verbosity == Verbosity.More) { WriteHelpText($"{template.SolutionName} migrations are complete."); } if (verbosity == Verbosity.More) { WriteHelpText($"Completed {template.SolutionName}."); } }
public static void Run(string filePath, string buildSolutionDirectory, IFileSystem fileSystem) { try { GlobalSingleton instance = GlobalSingleton.GetInstance(); FileParsingHelper.RunInitialTemplateParsingGuards(filePath); var template = FileParsingHelper.GetTemplateFromFile <ApiTemplate>(filePath); WriteHelpText($"Your template file was parsed successfully."); FileParsingHelper.RunPrimaryKeyGuard(template.Entities); FileParsingHelper.RunSolutionNameAssignedGuard(template.SolutionName); // scaffold projects // add an accelerate.config.yaml file to the root? var solutionDirectory = $"{buildSolutionDirectory}{Path.DirectorySeparatorChar}{template.SolutionName}"; SolutionBuilder.BuildSolution(solutionDirectory, template.SolutionName, fileSystem); SolutionBuilder.AddProjects(solutionDirectory, solutionDirectory, template.DbContext.Provider, template.SolutionName, template.AddJwtAuthentication, fileSystem); // add all files based on the given template config RunTemplateBuilders(solutionDirectory, template, fileSystem); WriteFileCreatedUpdatedResponse(); WriteHelpHeader($"{Environment.NewLine}Your API is ready! Build something amazing."); WriteGettingStarted(template.SolutionName); StarGithubRequest(); } catch (Exception e) { if (e is FileAlreadyExistsException || e is DirectoryAlreadyExistsException || e is InvalidSolutionNameException || e is FileNotFoundException || e is InvalidDbProviderException || e is InvalidFileTypeException) { WriteError($"{e.Message}"); } else { WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}"); } } }