Example #1
0
        public static void CreateNewDomainProject(string domainDirectory, IFileSystem fileSystem,
                                                  DomainProject domainProject)
        {
            fileSystem.Directory.CreateDirectory(domainDirectory);
            SolutionBuilder.BuildSolution(domainDirectory, domainProject.DomainName, fileSystem);

            // need this before boundaries to give them something to build against
            DockerBuilders.CreateDockerComposeSkeleton(domainDirectory, fileSystem);

            //Parallel.ForEach(domainProject.BoundedContexts, (template) =>
            //    ApiScaffolding.ScaffoldApi(domainDirectory, template, fileSystem, verbosity));
            foreach (var bc in domainProject.BoundedContexts)
            {
                ApiScaffolding.ScaffoldApi(domainDirectory, bc, fileSystem);
            }

            // auth server
            if (domainProject.AuthServer != null)
            {
                AddAuthServerCommand.AddAuthServer(domainDirectory, fileSystem, domainProject.AuthServer);
            }

            // messages
            if (domainProject.Messages.Count > 0)
            {
                AddMessageCommand.AddMessages(domainDirectory, fileSystem, domainProject.Messages);
            }

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

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

            if (domainProject.AddGit)
            {
                Utilities.GitSetup(domainDirectory, domainProject.UseSystemGitUser);
            }
        }
Example #2
0
        public void Run(string[] args)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // this makes emojis come up more reliably. might get built into spectre better in the future, so give a go deleting this at some point
                // they seem to show up fine on osx and actually need this to be off to work there
                Console.OutputEncoding = Encoding.Unicode;
            }

            var myEnv = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (args.Length == 0)
            {
                ListCommand.Run();
                CheckForLatestVersion();
                return;
            }

            if (args[0] == "version" || args[0] == "--version")
            {
                WriteInfo($"v{GetInstalledCraftsmanVersion()}");
                CheckForLatestVersion();
                return;
            }

            if (args[0] == "list" || args[0] == "-h" || args[0] == "--help")
            {
                ListCommand.Run();
                CheckForLatestVersion();
                return;
            }

            if (args.Length >= 2 && (args[0] == "add:bc" || args[0] == "add:boundedcontext"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddBoundedContextCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();
                    var verbosity = GetVerbosityFromArgs <AddBcOptions>(args);

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    AddBoundedContextCommand.Run(filePath, rootDir, fileSystem, verbosity);
                }
            }

            if (args.Length >= 2 && (args[0] == "add:authserver"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddAuthServerCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    AddAuthServerCommand.Run(filePath, rootDir, fileSystem);
                }
            }

            if (args.Length >= 2 && (args[0] == "new:domain"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    NewDomainProjectCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();
                    var verbosity = GetVerbosityFromArgs <NewDomainOptions>(args);

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    NewDomainProjectCommand.Run(filePath, rootDir, fileSystem, verbosity);
                }
            }

            if ((args[0] == "new:example" || args[0] == "example"))
            {
                if (args.Length > 1 && (args[1] == "-h" || args[1] == "--help"))
                {
                    NewExampleCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    NewExampleCommand.Run(rootDir, fileSystem);
                }
            }

            if (args[0] == "register:producer")
            {
                if (args.Length > 1 && (args[1] == "-h" || args[1] == "--help"))
                {
                    RegisterProducerCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    RegisterProducerCommand.Run(rootDir, fileSystem);
                }
            }

            if (args.Length == 2 && (args[0] == "add:entity" || args[0] == "add:entities"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddEntityCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();
                    var verbosity = GetVerbosityFromArgs <AddEntityOptions>(args);

                    var solutionDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the solution directory.");
                        solutionDir = Console.ReadLine();
                    }

                    AddEntityCommand.Run(filePath, solutionDir, fileSystem, verbosity);
                }
            }

            if ((args[0] == "add:bus"))
            {
                var filePath = "";
                if (args.Length >= 2)
                {
                    filePath = args[1];
                }

                if (filePath == "-h" || filePath == "--help")
                {
                    AddBusCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }

                    AddBusCommand.Run(filePath, rootDir, fileSystem);
                }
            }

            if ((args[0] == "add:message"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddMessageCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }

                    AddMessageCommand.Run(filePath, rootDir, fileSystem);
                }
            }

            if ((args[0] == "add:consumer" || args[0] == "add:consumers"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddConsumerCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }

                    AddConsumerCommand.Run(filePath, rootDir, fileSystem);
                }
            }

            if ((args[0] == "add:producer" || args[0] == "add:producers"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddProducerCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }

                    AddProducerCommand.Run(filePath, rootDir, fileSystem);
                }
            }

            if (args[0] == "add:feature" || args[0] == "new:feature")
            {
                if (args.Length > 1)
                {
                    var filePath = args[1];
                    if (filePath is "-h" or "--help")
                    {
                        AddFeatureCommand.Help();
                    }

                    return;
                }

                CheckForLatestVersion();

                var rootDir = fileSystem.Directory.GetCurrentDirectory();
                if (myEnv == "Dev")
                {
                    Console.WriteLine("Enter the root directory.");
                    rootDir = Console.ReadLine();
                }
                AddFeatureCommand.Run(rootDir, fileSystem);
            }
        }