public static void Run(string filePath, string buildSolutionDirectory, IFileSystem fileSystem) { try { GlobalSingleton instance = GlobalSingleton.GetInstance(); FileParsingHelper.RunInitialTemplateParsingGuards(filePath); var template = FileParsingHelper.GetTemplateFromFile <MicroTemplate>(filePath); WriteHelpText($"Your template file was parsed successfully."); foreach (var micro in template.Microservices) { FileParsingHelper.RunPrimaryKeyGuard(micro.Entities); } FileParsingHelper.RunSolutionNameAssignedGuard(template.SolutionName); // solution level stuff var solutionDirectory = $"{buildSolutionDirectory}{Path.DirectorySeparatorChar}{template.SolutionName}"; var srcDirectory = Path.Combine(solutionDirectory, "src"); fileSystem.Directory.CreateDirectory(srcDirectory); SolutionBuilder.BuildSolution(srcDirectory, template.SolutionName, fileSystem); // add all files based on the given template config RunMicroTemplateBuilders(srcDirectory, template.Microservices, template.Gateways, fileSystem); ReadmeBuilder.CreateReadme(solutionDirectory, template.SolutionName, fileSystem); if (template.AddGit) { GitSetup(solutionDirectory); } WriteFileCreatedUpdatedResponse(); WriteHelpHeader($"{Environment.NewLine}Your API is ready! Build something amazing."); StarGithubRequest(); } catch (Exception e) { if (e is FileAlreadyExistsException || e is DirectoryAlreadyExistsException || e is InvalidSolutionNameException || e is FileNotFoundException || e is InvalidDbProviderException || e is InvalidFileTypeException || e is EntityNotFoundException) { WriteError($"{e.Message}"); } else { WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}"); } } }
public static void Run(string filePath, string solutionDirectory, IFileSystem fileSystem, Verbosity verbosity) { try { FileParsingHelper.RunInitialTemplateParsingGuards(filePath); var template = FileParsingHelper.GetTemplateFromFile <AddEntityTemplate>(filePath); var srcDirectory = Path.Combine(solutionDirectory, "src"); var testDirectory = Path.Combine(solutionDirectory, "tests"); Utilities.IsBoundedContextDirectoryGuard(srcDirectory, testDirectory); var projectBaseName = Directory.GetParent(srcDirectory).Name; template = GetDbContext(srcDirectory, template, projectBaseName); template.SolutionName = projectBaseName; WriteHelpText($"Your template file was parsed successfully."); FileParsingHelper.RunPrimaryKeyGuard(template.Entities); // add all files based on the given template config RunEntityBuilders(srcDirectory, testDirectory, template, fileSystem); WriteHelpHeader($"{Environment.NewLine}Your entities have been successfully added. Keep up the good work!"); } catch (Exception e) { if (e is IsNotBoundedContextDirectory) { WriteError($"{e.Message}"); } else { AnsiConsole.WriteException(e, new ExceptionSettings { Format = ExceptionFormats.ShortenEverything | ExceptionFormats.ShowLinks, Style = new ExceptionStyle { Exception = new Style().Foreground(Color.Grey), Message = new Style().Foreground(Color.White), NonEmphasized = new Style().Foreground(Color.Cornsilk1), Parenthesis = new Style().Foreground(Color.Cornsilk1), Method = new Style().Foreground(Color.Red), ParameterName = new Style().Foreground(Color.Cornsilk1), ParameterType = new Style().Foreground(Color.Red), Path = new Style().Foreground(Color.Red), LineNumber = new Style().Foreground(Color.Cornsilk1), } }); } } }
public static void Run(string filePath, string buildSolutionDirectory, IFileSystem fileSystem) { try { GlobalSingleton instance = GlobalSingleton.GetInstance(); FileParsingHelper.RunInitialTemplateParsingGuards(filePath); var template = FileParsingHelper.GetApiTemplateFromFile(filePath); WriteHelpText($"Your template file was parsed successfully."); FileParsingHelper.RunPrimaryKeyGuard(template); FileParsingHelper.RunSolutionNameAssignedGuard(template); //var rootProjectDirectory = Directory.GetCurrentDirectory().Contains("Debug") ? @"C:\Users\Paul\Documents\testoutput" : Directory.GetCurrentDirectory(); //var buildSolutionDirectory = @"C:\Users\Paul\Documents\testoutput"; // scaffold projects // should i add an accelerate.config.yaml file to the root? CreateNewFoundation(template, buildSolutionDirectory); // todo scaffold this manually instead of using dotnet new foundation var solutionDirectory = $"{buildSolutionDirectory}{Path.DirectorySeparatorChar}{template.SolutionName}"; // remove placeholder valuetoreplace files and directories ApiTemplateCleaner.CleanTemplateFilesAndDirectories(solutionDirectory, template); // 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}"); } } }
public static void Run(string filePath, string buildSolutionDirectory, IFileSystem fileSystem) { try { GlobalSingleton instance = GlobalSingleton.GetInstance(); FileParsingHelper.RunInitialTemplateParsingGuards(filePath); var template = FileParsingHelper.GetApiTemplateFromFile(filePath); WriteHelpText($"Your template file was parsed successfully."); FileParsingHelper.RunPrimaryKeyGuard(template); FileParsingHelper.RunSolutionNameAssignedGuard(template); // scaffold projects // add an accelerate.config.yaml file to the root? var solutionDirectory = $"{buildSolutionDirectory}{Path.DirectorySeparatorChar}{template.SolutionName}"; // adding this for my test auth scaffolding so i don't have to do stuff that might not last manaully. **not officially supported** if (template.AuthSetup.AuthMethod == "JWT") { CreateNewFoundation(template, buildSolutionDirectory); // todo scaffold this manually instead of using dotnet new foundation } SolutionBuilder.BuildSolution(solutionDirectory, template, 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}"); } } }
public void RunPrimaryKeyGuard_throws_MissingPrimaryKeyException_with_no_pk_flag() { var template = new ApiTemplate() { Entities = new List <Entity>() { new Entity() { } } }; Action act = () => FileParsingHelper.RunPrimaryKeyGuard(template.Entities); act.Should().Throw <MissingPrimaryKeyException>(); }
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}"); } } }
public static void Run(string filePath, string solutionDirectory, IFileSystem fileSystem) { try { GlobalSingleton instance = GlobalSingleton.GetInstance(); FileParsingHelper.RunInitialTemplateParsingGuards(filePath); var template = FileParsingHelper.GetApiTemplateFromFile(filePath); //var solutionDirectory = Directory.GetCurrentDirectory(); //var solutionDirectory = @"C:\Users\Paul\Documents\testoutput\MyApi.Mine"; template = SolutionGuard(solutionDirectory, template); template = GetDbContext(solutionDirectory, template); WriteHelpText($"Your template file was parsed successfully."); FileParsingHelper.RunPrimaryKeyGuard(template); // add all files based on the given template config RunEntityBuilders(solutionDirectory, template, fileSystem); WriteFileCreatedUpdatedResponse(); WriteHelpHeader($"{Environment.NewLine}Your entities have been successfully added. Keep up the good work!"); } catch (Exception e) { if (e is FileAlreadyExistsException || e is DirectoryAlreadyExistsException || e is InvalidSolutionNameException || e is FileNotFoundException || e is InvalidDbProviderException || e is InvalidFileTypeException || e is SolutionNotFoundException) { WriteError($"{e.Message}"); } else { WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}"); } } }
public static void Run(string filePath, string solutionDirectory, IFileSystem fileSystem, Verbosity verbosity) { try { FileParsingHelper.RunInitialTemplateParsingGuards(filePath); var template = FileParsingHelper.GetTemplateFromFile <AddEntityTemplate>(filePath); var srcDirectory = Path.Combine(solutionDirectory, "src"); var testDirectory = Path.Combine(solutionDirectory, "tests"); template.SolutionName = Utilities.SolutionGuard(solutionDirectory); // this needs to happen before the projectbasename assignment ProperDirectoryGuard(srcDirectory, testDirectory); template = GetDbContext(srcDirectory, template, template.SolutionName); WriteHelpText($"Your template file was parsed successfully."); FileParsingHelper.RunPrimaryKeyGuard(template.Entities); // add all files based on the given template config RunEntityBuilders(srcDirectory, testDirectory, template, fileSystem, verbosity); WriteHelpHeader($"{Environment.NewLine}Your entities have been successfully added. Keep up the good work!"); } catch (Exception e) { if (e is FileAlreadyExistsException || e is DirectoryAlreadyExistsException || e is InvalidSolutionNameException || e is FileNotFoundException || e is InvalidDbProviderException || e is InvalidFileTypeException || e is SolutionNotFoundException || e is InvalidBaseDirectory) { WriteError($"{e.Message}"); } else { WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}"); } } }