private async Task <TemplateInfo> GetTemplateInfoAsync(ProjectBuildArgs args) { if (args.TemplateName.IsNullOrWhiteSpace()) { return(await TemplateInfoProvider.GetDefaultAsync()); } else { return(TemplateInfoProvider.Get(args.TemplateName)); } }
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(); } }