private static void AddStartupEnvironmentsWithServices(string solutionDirectory, ApiTemplate template) { // add a development environment by default for local work if none exists if (template.Environments.Where(e => e.EnvironmentName == "Development").Count() == 0) { template.Environments.Add(new ApiEnvironment { EnvironmentName = "Development", ProfileName = $"{template.SolutionName} (Development)" }); } foreach (var env in template.Environments) { // default startup is already built in cleanup phase if (env.EnvironmentName != "Startup") { StartupBuilder.CreateStartup(solutionDirectory, env.EnvironmentName, template); } AppSettingsBuilder.CreateAppSettings(solutionDirectory, env, template.DbContext.DatabaseName, template); LaunchSettingsModifier.AddProfile(solutionDirectory, env); //services if (!template.SwaggerConfig.IsSameOrEqualTo(new SwaggerConfig())) { SwaggerBuilder.RegisterSwaggerInStartup(solutionDirectory, env); } } }
// will probably want to refactor this in the future when there is > 1 startup based on env public static void CleanStartup(string solutionDirectory, ApiTemplate template) { var classPath = ClassPathHelper.StartupClassPath(solutionDirectory, "Startup.cs"); if (!Directory.Exists(classPath.ClassDirectory)) { throw new DirectoryNotFoundException($"The `{classPath.ClassDirectory}` directory could not be found."); } if (!File.Exists(classPath.FullClassPath)) { throw new FileNotFoundException($"The `{classPath.FullClassPath}` file could not be found."); } File.Delete(classPath.FullClassPath); StartupBuilder.CreateStartup(solutionDirectory, "Startup", template); }