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);
     }
 }
Exemple #2
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);
     }
 }
Exemple #3
0
 protected void OpenRelatedWebPage(ProjectBuildArgs projectArgs,
                                   string template,
                                   bool isTiered,
                                   CommandLineArgs commandLineArgs)
 {
     if (AppTemplateBase.IsAppTemplate(template))
     {
         var isCommercial = template == AppProTemplate.TemplateName;
         OpenThanksPage(projectArgs.UiFramework, projectArgs.DatabaseProvider, isTiered || commandLineArgs.Options.ContainsKey("separate-identity-server"), isCommercial);
     }
     else if (MicroserviceTemplateBase.IsMicroserviceTemplate(template))
     {
         OpenMicroserviceDocumentPage();
     }
 }
Exemple #4
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);
            }

            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 uiFramework = GetUiFramework(commandLineArgs);

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

            var connectionString = GetConnectionString(commandLineArgs);

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

            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);

            if (!createSolutionFolder)
            {
                Logger.LogInformation("Create Solution Folder: no");
            }

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

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

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

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

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

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

            var result = await TemplateProjectBuilder.BuildAsync(
                new ProjectBuildArgs(
                    SolutionName.Parse(projectName),
                    template,
                    version,
                    databaseProvider,
                    uiFramework,
                    mobileApp,
                    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 ?? (await TemplateInfoProvider.GetDefaultAsync()).Name))
            {
                var isCommercial = template == AppProTemplate.TemplateName;
                OpenThanksPage(uiFramework, databaseProvider, isTiered || commandLineArgs.Options.ContainsKey("separate-identity-server"), isCommercial);
            }
        }
        public override void Execute(ProjectBuildContext context)
        {
            var launchSettings = context.Files.Where(x =>
                                                     !x.IsDirectory && x.Name.EndsWith("launchSettings.json", StringComparison.InvariantCultureIgnoreCase))
                                 .ToList();

            var appSettings = context.Files.Where(x =>
                                                  !x.IsDirectory && x.Name.EndsWith("appSettings.json", StringComparison.InvariantCultureIgnoreCase))
                              .ToList();

            var angularEnvironments = context.Files.Where(x =>
                                                          !x.IsDirectory &&
                                                          (x.Name.EndsWith("environments/environment.ts", StringComparison.InvariantCultureIgnoreCase) ||
                                                           x.Name.EndsWith("environments/environment.hmr.ts", StringComparison.InvariantCultureIgnoreCase) ||
                                                           x.Name.EndsWith("environments/environment.prod.ts", StringComparison.InvariantCultureIgnoreCase))
                                                          )
                                      .ToList();

            var reactNativeEnvironments = context.Files.Where(x =>
                                                              !x.IsDirectory &&
                                                              x.Name.EndsWith($"{MobileApp.ReactNative.GetFolderName()}/Environment.js", StringComparison.InvariantCultureIgnoreCase)
                                                              )
                                          .ToList();

            if (AppTemplateBase.IsAppTemplate(context.Template.Name))
            {
                // no tiered
                if (launchSettings.Count == 1 &&
                    launchSettings.First().Name
                    .Equals("/aspnet-core/src/MyCompanyName.MyProjectName.Web/Properties/launchSettings.json", StringComparison.InvariantCultureIgnoreCase))
                {
                    var dbMigrator = appSettings.FirstOrDefault(x =>
                                                                x.Name.Equals("/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/appsettings.json", StringComparison.InvariantCultureIgnoreCase));
                    dbMigrator?.SetContent(dbMigrator.Content.Replace("https://localhost:44302", "https://localhost:44303"));

                    var web = appSettings.FirstOrDefault(x =>
                                                         x.Name.Equals("/aspnet-core/src/MyCompanyName.MyProjectName.Web/appsettings.json", StringComparison.InvariantCultureIgnoreCase));
                    web?.SetContent(web.Content.Replace("https://localhost:44301", "https://localhost:44303"));

                    var consoleTestApp = appSettings.FirstOrDefault(x =>
                                                                    x.Name.Equals("/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/appsettings.json", StringComparison.InvariantCultureIgnoreCase));
                    consoleTestApp?.SetContent(consoleTestApp.Content.Replace("https://localhost:44300", "https://localhost:44303"));
                    consoleTestApp?.SetContent(consoleTestApp.Content.Replace("https://localhost:44301", "https://localhost:44303"));
                }
            }

            var excludePorts = new List <string>();

            excludePorts.AddRange(_buildInSslUrls.Select(GetUrlPort).ToList());

            foreach (var buildInUrl in _buildInSslUrls)
            {
                var newPort = GetRandomPort(excludePorts);
                excludePorts.Add(newPort);

                var buildInUrlWithoutPort = GetUrlWithoutPort(buildInUrl);
                var buildInUrlPort        = GetUrlPort(buildInUrl);

                foreach (var launchSetting in launchSettings)
                {
                    launchSetting.NormalizeLineEndings();

                    var launchSettingLines = launchSetting.GetLines();
                    for (var i = 0; i < launchSettingLines.Length; i++)
                    {
                        if (launchSettingLines[i].Contains($"{buildInUrl}"))
                        {
                            launchSettingLines[i] = launchSettingLines[i].Replace($"{buildInUrl}", $"{buildInUrlWithoutPort}:{newPort}");
                        }

                        if (launchSettingLines[i].Contains($"\"sslPort\": {buildInUrlPort}"))
                        {
                            launchSettingLines[i] = launchSettingLines[i]
                                                    .Replace($"\"sslPort\": {buildInUrlPort}", $"\"sslPort\": {newPort}");
                        }
                    }
                    launchSetting.SetLines(launchSettingLines);

                    foreach (var appSetting in appSettings)
                    {
                        appSetting.NormalizeLineEndings();

                        var appSettingLines = appSetting.GetLines();
                        for (var i = 0; i < appSettingLines.Length; i++)
                        {
                            if (appSettingLines[i].Contains(buildInUrl))
                            {
                                appSettingLines[i] = appSettingLines[i].Replace(buildInUrl, $"{buildInUrlWithoutPort}:{newPort}");
                            }
                        }
                        appSetting.SetLines(appSettingLines);
                    }

                    foreach (var environment in angularEnvironments)
                    {
                        environment.NormalizeLineEndings();

                        var environmentLines = environment.GetLines();
                        for (var i = 0; i < environmentLines.Length; i++)
                        {
                            if (environmentLines[i].Contains(buildInUrl))
                            {
                                environmentLines[i] = environmentLines[i].Replace(buildInUrl, $"{buildInUrlWithoutPort}:{newPort}");
                            }
                        }
                        environment.SetLines(environmentLines);
                    }

                    foreach (var environment in reactNativeEnvironments)
                    {
                        environment.NormalizeLineEndings();

                        var buildInUrlHttp            = buildInUrl.Replace("https://", "http://");
                        var buildInUrlWithoutPortHttp = buildInUrlWithoutPort.Replace("https://", "http://");

                        var environmentLines = environment.GetLines();
                        for (var i = 0; i < environmentLines.Length; i++)
                        {
                            if (environmentLines[i].Contains(buildInUrlHttp))
                            {
                                environmentLines[i] = environmentLines[i].Replace(buildInUrlHttp, $"{buildInUrlWithoutPortHttp}:{newPort}");
                            }
                        }
                        environment.SetLines(environmentLines);
                    }
                }
            }
        }
Exemple #6
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()
                          );
            }

            if (!ProjectNameValidator.IsValid(projectName))
            {
                throw new CliUsageException("The project name is invalid! Please specify a different name.");
            }

            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");
            }

            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();
            }
        }