Esempio n. 1
0
 protected virtual void RunGraphBuildForMicroserviceServiceTemplate(ProjectBuildArgs projectArgs)
 {
     if (MicroserviceServiceTemplateBase.IsMicroserviceServiceTemplate(projectArgs.TemplateName))
     {
         CmdHelper.RunCmd("dotnet build /graphbuild", projectArgs.OutputFolder);
     }
 }
Esempio n. 2
0
        public override void Execute(ProjectBuildContext context)
        {
            if (MicroserviceServiceTemplateBase.IsMicroserviceServiceTemplate(context.BuildArgs.TemplateName))
            {
                new SolutionRenamer(
                    context.Files,
                    "MyCompanyName.MyProjectName",
                    "MicroserviceName",
                    context.BuildArgs.SolutionName.CompanyName,
                    context.BuildArgs.SolutionName.ProjectName
                    ).Run();

                new SolutionRenamer(
                    context.Files,
                    null,
                    "MyProjectName",
                    null,
                    SolutionName.Parse(context.BuildArgs.SolutionName.CompanyName).ProjectName
                    ).Run();
            }
            else
            {
                new SolutionRenamer(
                    context.Files,
                    "MyCompanyName",
                    "MyProjectName",
                    context.BuildArgs.SolutionName.CompanyName,
                    context.BuildArgs.SolutionName.ProjectName
                    ).Run();
            }
        }
Esempio n. 3
0
 protected ProjectReferenceReplacer(
     ProjectBuildContext context,
     string projectName)
 {
     _entries = context.Files;
     _isMicroserviceServiceTemplate = MicroserviceServiceTemplateBase.IsMicroserviceServiceTemplate(context.Template?.Name);
     _projectName = projectName;
 }
Esempio n. 4
0
 protected virtual void RunInstallLibsForWebTemplate(ProjectBuildArgs projectArgs)
 {
     if (AppTemplateBase.IsAppTemplate(projectArgs.TemplateName) ||
         ModuleTemplateBase.IsModuleTemplate(projectArgs.TemplateName) ||
         AppNoLayersTemplateBase.IsAppNoLayersTemplate(projectArgs.TemplateName) ||
         MicroserviceServiceTemplateBase.IsMicroserviceTemplate(projectArgs.TemplateName))
     {
         CmdHelper.RunCmd("abp install-libs", projectArgs.OutputFolder);
     }
 }
Esempio n. 5
0
 protected async Task RunInstallLibsForWebTemplateAsync(ProjectBuildArgs projectArgs)
 {
     if (AppTemplateBase.IsAppTemplate(projectArgs.TemplateName) ||
         ModuleTemplateBase.IsModuleTemplate(projectArgs.TemplateName) ||
         AppNoLayersTemplateBase.IsAppNoLayersTemplate(projectArgs.TemplateName) ||
         MicroserviceServiceTemplateBase.IsMicroserviceTemplate(projectArgs.TemplateName))
     {
         Logger.LogInformation("Installing client-side packages...");
         await InstallLibsService.InstallLibsAsync(projectArgs.OutputFolder);
     }
 }
    protected virtual async Task RunGraphBuildForMicroserviceServiceTemplate(ProjectBuildArgs projectArgs)
    {
        if (MicroserviceServiceTemplateBase.IsMicroserviceServiceTemplate(projectArgs.TemplateName))
        {
            await EventBus.PublishAsync(new ProjectCreationProgressEvent {
                Message = "Building the microservice solution"
            }, false);

            CmdHelper.RunCmd("dotnet build /graphbuild", projectArgs.OutputFolder);
        }
    }
Esempio n. 7
0
    protected ProjectBuildArgs GetProjectBuildArgs(CommandLineArgs commandLineArgs, string template, string projectName)
    {
        var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long);

        if (version != null)
        {
            Logger.LogInformation("Version: " + version);
        }

        var preview = commandLineArgs.Options.ContainsKey(Options.Preview.Long);

        if (preview)
        {
            Logger.LogInformation("Preview: yes");
        }

        var pwa = commandLineArgs.Options.ContainsKey(Options.ProgressiveWebApp.Short);

        if (pwa)
        {
            Logger.LogInformation("Progressive Web App: yes");
        }

        var databaseProvider = GetDatabaseProvider(commandLineArgs);

        if (databaseProvider != DatabaseProvider.NotSpecified)
        {
            Logger.LogInformation("Database provider: " + databaseProvider);
        }

        var connectionString = GetConnectionString(commandLineArgs);

        if (connectionString != null)
        {
            Logger.LogInformation("Connection string: " + connectionString);
        }

        var databaseManagementSystem = GetDatabaseManagementSystem(commandLineArgs);

        if (databaseManagementSystem != DatabaseManagementSystem.NotSpecified)
        {
            Logger.LogInformation("DBMS: " + databaseManagementSystem);
        }

        var uiFramework = GetUiFramework(commandLineArgs);

        if (uiFramework != UiFramework.NotSpecified)
        {
            Logger.LogInformation("UI Framework: " + uiFramework);
        }

        var theme = uiFramework == UiFramework.None ? (Theme?)null : GetTheme(commandLineArgs);

        if (theme.HasValue)
        {
            Logger.LogInformation("Theme: " + theme);
        }

        var publicWebSite = uiFramework != UiFramework.None && commandLineArgs.Options.ContainsKey(Options.PublicWebSite.Long);

        if (publicWebSite)
        {
            Logger.LogInformation("Public Web Site: yes");
        }

        var mobileApp = GetMobilePreference(commandLineArgs);

        if (mobileApp != MobileApp.None)
        {
            Logger.LogInformation("Mobile App: " + mobileApp);
        }

        var gitHubAbpLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubAbpLocalRepositoryPath.Long);

        if (gitHubAbpLocalRepositoryPath != null)
        {
            Logger.LogInformation("GitHub Abp Local Repository Path: " + gitHubAbpLocalRepositoryPath);
        }

        var gitHubVoloLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubVoloLocalRepositoryPath.Long);

        if (gitHubVoloLocalRepositoryPath != null)
        {
            Logger.LogInformation("GitHub Volo Local Repository Path: " + gitHubVoloLocalRepositoryPath);
        }

        var templateSource = commandLineArgs.Options.GetOrNull(Options.TemplateSource.Short, Options.TemplateSource.Long);

        if (templateSource != null)
        {
            Logger.LogInformation("Template Source: " + templateSource);
        }

        var createSolutionFolder = GetCreateSolutionFolderPreference(commandLineArgs);

        var outputFolder = commandLineArgs.Options.GetOrNull(Options.OutputFolder.Short, Options.OutputFolder.Long);

        var outputFolderRoot =
            outputFolder != null?Path.GetFullPath(outputFolder) : Directory.GetCurrentDirectory();

        SolutionName solutionName;

        if (MicroserviceServiceTemplateBase.IsMicroserviceServiceTemplate(template))
        {
            var slnPath = commandLineArgs.Options.GetOrNull(Options.MainSolution.Short, Options.MainSolution.Long);

            if (slnPath == null)
            {
                slnPath = Directory.GetFiles(outputFolderRoot, "*.sln").FirstOrDefault();
            }
            else if (slnPath.EndsWith(".sln"))
            {
                Directory.SetCurrentDirectory(Path.GetDirectoryName(slnPath));
                outputFolderRoot = Path.GetDirectoryName(slnPath);
            }
            else if (!Directory.Exists(slnPath))
            {
                slnPath = null;
            }
            else
            {
                Directory.SetCurrentDirectory(slnPath);
                outputFolderRoot = slnPath;
                slnPath          = Directory.GetFiles(outputFolderRoot, "*.sln").FirstOrDefault();
            }

            if (slnPath == null)
            {
                throw new CliUsageException($"This command should be run inside a folder that contains a microservice solution! Or use -{Options.MainSolution.Short} parameter.");
            }

            var microserviceSolutionName = Path.GetFileName(slnPath).RemovePostFix(".sln");

            version ??= SolutionPackageVersionFinder.Find(slnPath);
            solutionName = SolutionName.Parse(microserviceSolutionName, projectName);
            outputFolder = MicroserviceServiceTemplateBase.CalculateTargetFolder(outputFolderRoot, solutionName.ProjectName);
            uiFramework  = uiFramework == UiFramework.NotSpecified ? FindMicroserviceSolutionUiFramework(outputFolderRoot) : uiFramework;
        }
        else
        {
            solutionName = SolutionName.Parse(projectName);

            outputFolder = createSolutionFolder ?
                           Path.Combine(outputFolderRoot, SolutionName.Parse(projectName).FullName) :
                           outputFolderRoot;
        }

        IO.DirectoryHelper.CreateIfNotExists(outputFolder);

        Logger.LogInformation("Output folder: " + outputFolder);

        if (connectionString == null &&
            databaseManagementSystem != DatabaseManagementSystem.NotSpecified &&
            databaseManagementSystem != DatabaseManagementSystem.SQLServer)
        {
            connectionString = ConnectionStringProvider.GetByDbms(databaseManagementSystem, outputFolder);
        }

        commandLineArgs.Options.Add(CliConsts.Command, commandLineArgs.Command);

        return(new ProjectBuildArgs(
                   solutionName,
                   template,
                   version,
                   outputFolder,
                   databaseProvider,
                   databaseManagementSystem,
                   uiFramework,
                   mobileApp,
                   publicWebSite,
                   gitHubAbpLocalRepositoryPath,
                   gitHubVoloLocalRepositoryPath,
                   templateSource,
                   commandLineArgs.Options,
                   connectionString,
                   pwa,
                   theme
                   ));
    }
Esempio n. 8
0
        public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
        {
            var projectName = NamespaceHelper.NormalizeNamespace(commandLineArgs.Target);

            if (projectName == null)
            {
                throw new CliUsageException(
                          "Project name is missing!" +
                          Environment.NewLine + Environment.NewLine +
                          GetUsageInfo()
                          );
            }

            Logger.LogInformation("Creating your project...");
            Logger.LogInformation("Project name: " + projectName);

            var template = commandLineArgs.Options.GetOrNull(Options.Template.Short, Options.Template.Long);

            if (template != null)
            {
                Logger.LogInformation("Template: " + template);
            }
            else
            {
                template = (await TemplateInfoProvider.GetDefaultAsync()).Name;
            }

            var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long);

            if (version != null)
            {
                Logger.LogInformation("Version: " + version);
            }

            var isTiered = commandLineArgs.Options.ContainsKey(Options.Tiered.Long);

            if (isTiered)
            {
                Logger.LogInformation("Tiered: yes");
            }

            var preview = commandLineArgs.Options.ContainsKey(Options.Preview.Long);

            if (preview)
            {
                Logger.LogInformation("Preview: yes if any exist for next version.");
            }

            var databaseProvider = GetDatabaseProvider(commandLineArgs);

            if (databaseProvider != DatabaseProvider.NotSpecified)
            {
                Logger.LogInformation("Database provider: " + databaseProvider);
            }

            var connectionString = GetConnectionString(commandLineArgs);

            if (connectionString != null)
            {
                Logger.LogInformation("Connection string: " + connectionString);
            }

            var databaseManagementSystem = GetDatabaseManagementSystem(commandLineArgs);

            if (databaseManagementSystem != DatabaseManagementSystem.NotSpecified)
            {
                Logger.LogInformation("DBMS: " + databaseManagementSystem);
            }

            var uiFramework = GetUiFramework(commandLineArgs);

            if (uiFramework != UiFramework.NotSpecified)
            {
                Logger.LogInformation("UI Framework: " + uiFramework);
            }

            var publicWebSite = uiFramework != UiFramework.None && commandLineArgs.Options.ContainsKey(Options.PublicWebSite.Long);

            if (publicWebSite)
            {
                Logger.LogInformation("Public Web Site: yes");
            }

            var mobileApp = GetMobilePreference(commandLineArgs);

            if (mobileApp != MobileApp.None)
            {
                Logger.LogInformation("Mobile App: " + mobileApp);
            }

            var gitHubAbpLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubAbpLocalRepositoryPath.Long);

            if (gitHubAbpLocalRepositoryPath != null)
            {
                Logger.LogInformation("GitHub Abp Local Repository Path: " + gitHubAbpLocalRepositoryPath);
            }

            var gitHubVoloLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubVoloLocalRepositoryPath.Long);

            if (gitHubVoloLocalRepositoryPath != null)
            {
                Logger.LogInformation("GitHub Volo Local Repository Path: " + gitHubVoloLocalRepositoryPath);
            }

            var templateSource = commandLineArgs.Options.GetOrNull(Options.TemplateSource.Short, Options.TemplateSource.Long);

            if (templateSource != null)
            {
                Logger.LogInformation("Template Source: " + templateSource);
            }

            var createSolutionFolder = GetCreateSolutionFolderPreference(commandLineArgs);

            var outputFolder = commandLineArgs.Options.GetOrNull(Options.OutputFolder.Short, Options.OutputFolder.Long);

            var outputFolderRoot =
                outputFolder != null?Path.GetFullPath(outputFolder) : Directory.GetCurrentDirectory();

            SolutionName solutionName;

            if (MicroserviceServiceTemplateBase.IsMicroserviceServiceTemplate(template))
            {
                var microserviceSolutionName = FindMicroserviceSolutionName(outputFolderRoot);

                if (microserviceSolutionName == null)
                {
                    throw new CliUsageException("This command should be run inside a folder that contains a microservice solution!");
                }

                solutionName = SolutionName.Parse(microserviceSolutionName, projectName);
                outputFolder = MicroserviceServiceTemplateBase.CalculateTargetFolder(outputFolderRoot, projectName);
                uiFramework  = uiFramework == UiFramework.NotSpecified ? FindMicroserviceSolutionUiFramework(outputFolderRoot) : uiFramework;
            }
            else
            {
                solutionName = SolutionName.Parse(projectName);

                outputFolder = createSolutionFolder ?
                               Path.Combine(outputFolderRoot, SolutionName.Parse(projectName).FullName) :
                               outputFolderRoot;
            }

            Volo.Abp.IO.DirectoryHelper.CreateIfNotExists(outputFolder);

            Logger.LogInformation("Output folder: " + outputFolder);

            if (connectionString == null &&
                databaseManagementSystem != DatabaseManagementSystem.NotSpecified &&
                databaseManagementSystem != DatabaseManagementSystem.SQLServer)
            {
                connectionString = ConnectionStringProvider.GetByDbms(databaseManagementSystem, outputFolder);
            }

            commandLineArgs.Options.Add(CliConsts.Command, commandLineArgs.Command);

            var result = await TemplateProjectBuilder.BuildAsync(
                new ProjectBuildArgs(
                    solutionName,
                    template,
                    version,
                    databaseProvider,
                    databaseManagementSystem,
                    uiFramework,
                    mobileApp,
                    publicWebSite,
                    gitHubAbpLocalRepositoryPath,
                    gitHubVoloLocalRepositoryPath,
                    templateSource,
                    commandLineArgs.Options,
                    connectionString
                    )
                );

            using (var templateFileStream = new MemoryStream(result.ZipContent))
            {
                using (var zipInputStream = new ZipInputStream(templateFileStream))
                {
                    var zipEntry = zipInputStream.GetNextEntry();
                    while (zipEntry != null)
                    {
                        if (string.IsNullOrWhiteSpace(zipEntry.Name))
                        {
                            zipEntry = zipInputStream.GetNextEntry();
                            continue;
                        }

                        var fullZipToPath = Path.Combine(outputFolder, zipEntry.Name);
                        var directoryName = Path.GetDirectoryName(fullZipToPath);

                        if (!string.IsNullOrEmpty(directoryName))
                        {
                            Directory.CreateDirectory(directoryName);
                        }

                        var fileName = Path.GetFileName(fullZipToPath);
                        if (fileName.Length == 0)
                        {
                            zipEntry = zipInputStream.GetNextEntry();
                            continue;
                        }

                        var buffer = new byte[4096]; // 4K is optimum
                        using (var streamWriter = File.Create(fullZipToPath))
                        {
                            StreamUtils.Copy(zipInputStream, streamWriter, buffer);
                        }

                        zipEntry = zipInputStream.GetNextEntry();
                    }
                }
            }

            Logger.LogInformation($"'{projectName}' has been successfully created to '{outputFolder}'");


            if (AppTemplateBase.IsAppTemplate(template))
            {
                var isCommercial = template == AppProTemplate.TemplateName;
                OpenThanksPage(uiFramework, databaseProvider, isTiered || commandLineArgs.Options.ContainsKey("separate-identity-server"), isCommercial);
            }
            else if (MicroserviceTemplateBase.IsMicroserviceTemplate(template))
            {
                OpenMicroserviceDocumentPage();
            }
        }