Ejemplo n.º 1
0
        public static void Run(string filePath, string domainDirectory, IFileSystem fileSystem, Verbosity verbosity)
        {
            try
            {
                FileParsingHelper.RunInitialTemplateParsingGuards(filePath);
                var boundedContexts = FileParsingHelper.GetTemplateFromFile <BoundedContextsTemplate>(filePath);
                WriteHelpText($"Your template file was parsed successfully.");

                foreach (var template in boundedContexts.BoundedContexts)
                {
                    ApiScaffolding.ScaffoldApi(domainDirectory, template, fileSystem, verbosity);
                }

                WriteHelpHeader($"{Environment.NewLine}Your bounded contexts have been successfully added. Keep up the good work!");
                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 SolutiuonNameEntityMatchException)
                {
                    WriteError($"{e.Message}");
                }
                else
                {
                    WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                }
            }
        }
Ejemplo n.º 2
0
        public static void Run(string filePath, string boundedContextDirectory, IFileSystem fileSystem)
        {
            try
            {
                var template = new Bus();
                template.Environments.Add(new ApiEnvironment {
                    EnvironmentName = "Development"
                });
                if (!string.IsNullOrEmpty(filePath))
                {
                    FileParsingHelper.RunInitialTemplateParsingGuards(filePath);
                    template = FileParsingHelper.GetTemplateFromFile <Bus>(filePath);
                }

                var srcDirectory  = Path.Combine(boundedContextDirectory, "src");
                var testDirectory = Path.Combine(boundedContextDirectory, "tests");

                Utilities.IsBoundedContextDirectoryGuard(srcDirectory, testDirectory);
                var projectBaseName = Directory.GetParent(srcDirectory).Name;
                template.ProjectBaseName = projectBaseName;

                // get solution dir
                var solutionDirectory = Directory.GetParent(boundedContextDirectory).FullName;
                Utilities.IsSolutionDirectoryGuard(solutionDirectory);
                AddBus(template, srcDirectory, testDirectory, projectBaseName, solutionDirectory, fileSystem);

                WriteHelpHeader($"{Environment.NewLine}Your event bus has been successfully added. Keep up the good work!");
            }
            catch (Exception e)
            {
                if (e is InvalidMessageBrokerException ||
                    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),
                        }
                    });
                }
            }
        }
Ejemplo n.º 3
0
        public static void Run(string filePath, string domainDirectory, IFileSystem fileSystem, Verbosity verbosity)
        {
            try
            {
                FileParsingHelper.RunInitialTemplateParsingGuards(filePath);
                Utilities.SolutionGuard(domainDirectory);

                var boundedContexts = FileParsingHelper.GetTemplateFromFile <BoundedContextsTemplate>(filePath);
                WriteHelpText($"Your template file was parsed successfully.");

                foreach (var template in boundedContexts.BoundedContexts)
                {
                    ApiScaffolding.ScaffoldApi(domainDirectory, template, fileSystem);
                }

                // migrations
                Utilities.RunDbMigrations(boundedContexts.BoundedContexts, domainDirectory);

                WriteHelpHeader($"{Environment.NewLine}Your bounded contexts have been successfully added. Keep up the good work!");
                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 DataValidationErrorException ||
                    e is SolutiuonNameEntityMatchException)
                {
                    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),
                        }
                    });
                }
            }
        }
Ejemplo n.º 4
0
        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}");
                }
            }
        }
Ejemplo n.º 5
0
        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),
                        }
                    });
                }
            }
        }
Ejemplo n.º 6
0
        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}");
                }
            }
        }
Ejemplo n.º 7
0
        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}");
                }
            }
        }
Ejemplo n.º 8
0
        public static void Run(string filePath, string buildSolutionDirectory, IFileSystem fileSystem, Verbosity verbosity)
        {
            try
            {
                FileParsingHelper.RunInitialTemplateParsingGuards(filePath);
                var domainProject = FileParsingHelper.GetTemplateFromFile <DomainProject>(filePath);
                WriteLogMessage($"Your template file was parsed successfully");

                var domainDirectory = $"{buildSolutionDirectory}{Path.DirectorySeparatorChar}{domainProject.DomainName}";
                CreateNewDomainProject(domainDirectory, fileSystem, domainProject);

                AnsiConsole.MarkupLine($"{Environment.NewLine}[bold yellow1]Your domain project 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 DataValidationErrorException ||
                    e is SolutiuonNameEntityMatchException)
                {
                    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),
                        }
                    });
                }
            }
        }
Ejemplo n.º 9
0
        public static void Run(string filePath, string buildSolutionDirectory, IFileSystem fileSystem, Verbosity verbosity)
        {
            try
            {
                FileParsingHelper.RunInitialTemplateParsingGuards(filePath);
                var domainProject = FileParsingHelper.GetTemplateFromFile <DomainProject>(filePath);
                WriteHelpText($"Your template file was parsed successfully.");

                var domainDirectory = $"{buildSolutionDirectory}{Path.DirectorySeparatorChar}{domainProject.DomainName}";
                fileSystem.Directory.CreateDirectory(domainDirectory);

                foreach (var template in domainProject.BoundedContexts)
                {
                    ApiScaffolding.ScaffoldApi(domainDirectory, template, fileSystem, verbosity);
                }

                //final
                ReadmeBuilder.CreateReadme(domainDirectory, domainProject.DomainName, fileSystem);

                if (domainProject.AddGit)
                {
                    Utilities.GitSetup(domainDirectory);
                }

                WriteHelpHeader($"{Environment.NewLine}Your domain project 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 SolutiuonNameEntityMatchException)
                {
                    WriteError($"{e.Message}");
                }
                else
                {
                    WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                }
            }
        }
Ejemplo n.º 10
0
        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}");
                }
            }
        }
Ejemplo n.º 11
0
        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}");
                }
            }
        }
Ejemplo n.º 12
0
        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}");
                }
            }
        }
Ejemplo n.º 13
0
        public static void Run(string filePath, string solutionDirectory, IFileSystem fileSystem)
        {
            try
            {
                FileParsingHelper.RunInitialTemplateParsingGuards(filePath);
                var template = FileParsingHelper.GetTemplateFromFile <AuthServerTemplate>(filePath);

                // get solution dir
                Utilities.IsSolutionDirectoryGuard(solutionDirectory);
                AddAuthServer(solutionDirectory, fileSystem, template);

                WriteHelpHeader($"{Environment.NewLine}Your messages have been successfully added. Keep up the good work!");
            }
            catch (Exception e)
            {
                if (e is SolutionNotFoundException ||
                    e is DataValidationErrorException)
                {
                    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),
                        }
                    });
                }
            }
        }