private async Task DownloadSourceCodesToSolutionFolder(ModuleWithMastersInfo module, string modulesFolderInSolution, string version = null, bool newTemplate = false, bool newProTemplate = false) { var targetModuleFolder = Path.Combine(modulesFolderInSolution, module.Name); if (newTemplate || newProTemplate) { await CreateNewModuleAsync(module, modulesFolderInSolution, version, newProTemplate); } else { await SourceCodeDownloadService.DownloadAsync( module.Name, targetModuleFolder, version, null, null, null ); } await DeleteAppAndDemoFolderAsync(targetModuleFolder); if (module.MasterModuleInfos == null) { return; } foreach (var masterModule in module.MasterModuleInfos) { await DownloadSourceCodesToSolutionFolder(masterModule, modulesFolderInSolution, version); } }
private async Task RemoveProjectByTarget(ModuleWithMastersInfo module, string moduleSolutionFile, NuGetPackageTarget target, bool isTieredProject) { var packages = module.NugetPackages.Where(n => (isTieredProject && n.TieredTarget != NuGetPackageTarget.Undefined ? n.TieredTarget : n.Target) == target ).ToList(); foreach (var package in packages) { if (target == NuGetPackageTarget.Web && package.Name.StartsWith("Volo.Abp.Account")) { continue; } await SolutionFileModifier.RemoveProjectFromSolutionFileAsync(moduleSolutionFile, package.Name); var projectPath = Path.Combine(Path.GetDirectoryName(moduleSolutionFile), "src", package.Name); if (Directory.Exists(projectPath)) { Directory.Delete(projectPath, true); } } }
private void ChangeDomainTestReferenceToMongoDB(ModuleWithMastersInfo module, string moduleSolutionFile) { var testPath = Path.Combine(Path.GetDirectoryName(moduleSolutionFile), "test"); if (!Directory.Exists(testPath)) { return; } var projectFolderPath = Directory.GetDirectories(testPath).FirstOrDefault(d => d.EndsWith("Domain.Tests")); if (projectFolderPath == null) { return; } var csprojFile = Directory.GetFiles(projectFolderPath, "*.csproj", SearchOption.AllDirectories).FirstOrDefault(); var moduleFile = Directory.GetFiles(projectFolderPath, "*DomainTestModule.cs", SearchOption.AllDirectories).FirstOrDefault(); if (csprojFile == null || moduleFile == null) { return; } File.WriteAllText(csprojFile, File.ReadAllText(csprojFile).Replace("EntityFrameworkCore", "MongoDB")); File.WriteAllText(moduleFile, File.ReadAllText(moduleFile) .Replace(".EntityFrameworkCore;", ".MongoDB;") .Replace("EntityFrameworkCoreTestModule", "MongoDbTestModule")); }
private async Task RemoveUnnecessaryProjectsAsync(string solutionDirectory, ModuleWithMastersInfo module, string[] projectFiles) { var moduleDirectory = Path.Combine(solutionDirectory, "modules", module.Name); var moduleSolutionFile = Directory.GetFiles(moduleDirectory, "*.sln", SearchOption.TopDirectoryOnly).First(); var isProjectTiered = await IsProjectTiered(projectFiles); if (!projectFiles.Any(p => p.EndsWith(".Blazor.csproj"))) { await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.Blazor, isProjectTiered); } if (!projectFiles.Any(p => p.EndsWith(".Web.csproj"))) { await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.Web, isProjectTiered); } if (!projectFiles.Any(p => p.EndsWith(".MongoDB.csproj"))) { await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.MongoDB, isProjectTiered); await RemoveProjectByPostFix(module, moduleSolutionFile, "test", ".MongoDB.Tests"); } if (!projectFiles.Any(p => p.EndsWith(".EntityFrameworkCore.csproj"))) { await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.EntityFrameworkCore, isProjectTiered); await RemoveProjectByPostFix(module, moduleSolutionFile, "test", ".EntityFrameworkCore.Tests"); } }
private async Task RemoveUnnecessaryProjectsAsync(string solutionDirectory, ModuleWithMastersInfo module, string[] projectFiles) { var moduleDirectory = Path.Combine(solutionDirectory, "modules", module.Name); var moduleSolutionFile = Directory.GetFiles(moduleDirectory, "*.sln", SearchOption.TopDirectoryOnly).First(); var isProjectTiered = await IsProjectTiered(projectFiles); var webPackagesWillBeAddedToBlazorServerProject = false; var blazorProject = projectFiles.FirstOrDefault(p => p.EndsWith(".Blazor.csproj")); if (blazorProject == null) { await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.Blazor, isProjectTiered); await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.BlazorServer, isProjectTiered); await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.BlazorWebAssembly, isProjectTiered); await RemoveProjectByPostFix(module, moduleSolutionFile, "src", ".Blazor"); } else { var isBlazorServer = BlazorProjectTypeChecker.IsBlazorServerProject(blazorProject); if (isBlazorServer) { await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.BlazorWebAssembly, isProjectTiered); webPackagesWillBeAddedToBlazorServerProject = module.NugetPackages.All(np => np.Target != NuGetPackageTarget.BlazorServer && np.TieredTarget != NuGetPackageTarget.BlazorServer); } else { await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.BlazorServer, isProjectTiered); } } if (!projectFiles.Any(p => p.EndsWith(".Web.csproj")) && !webPackagesWillBeAddedToBlazorServerProject) { await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.Web, isProjectTiered); } if (!projectFiles.Any(p => p.EndsWith(".MongoDB.csproj"))) { await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.MongoDB, isProjectTiered); await RemoveProjectByPostFix(module, moduleSolutionFile, "test", ".MongoDB.Tests"); } if (!projectFiles.Any(p => p.EndsWith(".EntityFrameworkCore.csproj"))) { await RemoveProjectByTarget(module, moduleSolutionFile, NuGetPackageTarget.EntityFrameworkCore, isProjectTiered); await RemoveProjectByPostFix(module, moduleSolutionFile, "test", ".EntityFrameworkCore.Tests"); await RemoveProjectByPostFix(module, moduleSolutionFile, "test", ".Application.Tests"); ChangeDomainTestReferenceToMongoDB(module, moduleSolutionFile); } }
private async Task HandleAngularProject(ModuleWithMastersInfo module, string solutionFilePath) { var angularPath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(solutionFilePath)), "angular"); if (!Directory.Exists(angularPath)) { return; } await AngularModuleSourceCodeAdder.AddAsync(solutionFilePath, angularPath); }
public async Task Convert(ModuleWithMastersInfo module, string solutionFile, string modulePrefix = "Volo.") { var nugetPackageList = GetNugetPackages(module); var modulesFolder = Path.Combine(Path.GetDirectoryName(solutionFile), "modules"); var srcFolder = Path.Combine(Path.GetDirectoryName(solutionFile), "src"); var testFolder = Path.Combine(Path.GetDirectoryName(solutionFile), "test"); ConvertToLocalReference(modulesFolder, nugetPackageList, "..\\..\\..\\", "src", modulePrefix); ConvertToLocalReference(srcFolder, nugetPackageList, "..\\..\\modules\\", "src", modulePrefix); ConvertToLocalReference(testFolder, nugetPackageList, "..\\..\\modules\\", "test", modulePrefix); }
private async Task CreateNewModuleAsync(ModuleWithMastersInfo module, string modulesFolderInSolution, string version, bool newProTemplate = false) { var args = new CommandLineArgs("new", module.Name); args.Options.Add("t", newProTemplate ? ModuleProTemplate.TemplateName : ModuleTemplate.TemplateName); args.Options.Add("v", version); args.Options.Add("o", Path.Combine(modulesFolderInSolution, module.Name)); await NewCommand.ExecuteAsync(args); }
private async Task RemoveProjectByPostFix(ModuleWithMastersInfo module, string moduleSolutionFile, string targetFolder, string postFix) { var srcPath = Path.Combine(Path.GetDirectoryName(moduleSolutionFile), targetFolder); var projectFolderPath = Directory.GetDirectories(srcPath).FirstOrDefault(d => d.EndsWith(postFix)); await SolutionFileModifier.RemoveProjectFromSolutionFileAsync(moduleSolutionFile, Path.GetDirectoryName(projectFolderPath)); if (Directory.Exists(projectFolderPath)) { Directory.Delete(projectFolderPath, true); } }
private static bool SouldWebPackagesBeAddedToBlazorServerProject(ModuleWithMastersInfo module, string[] projectFiles) { var blazorProject = projectFiles.FirstOrDefault(p => p.EndsWith(".Blazor.csproj")); if (blazorProject == null) { return(false); } var isBlazorServerProject = BlazorProjectTypeChecker.IsBlazorServerProject(blazorProject); return(isBlazorServerProject && module.NugetPackages.All(np => np.Target != NuGetPackageTarget.BlazorServer && np.TieredTarget != NuGetPackageTarget.BlazorServer)); }
private async Task ChangeDomainTestReferenceToMongoDB(ModuleWithMastersInfo module, string moduleSolutionFile) { var srcPath = Path.Combine(Path.GetDirectoryName(moduleSolutionFile), "test"); var projectFolderPath = Directory.GetDirectories(srcPath).FirstOrDefault(d => d.EndsWith("Domain.Tests")); var csprojFile = Directory.GetFiles(projectFolderPath).First(p => p.EndsWith(".csproj")); var moduleFile = Directory.GetFiles(projectFolderPath).First(p => p.EndsWith("DomainTestModule.cs")); File.WriteAllText(csprojFile, File.ReadAllText(csprojFile).Replace("EntityFrameworkCore", "MongoDB")); File.WriteAllText(moduleFile, File.ReadAllText(moduleFile) .Replace(".EntityFrameworkCore;", ".MongoDB;") .Replace("EntityFrameworkCoreTestModule", "MongoDbTestModule")); }
private async Task AddNugetAndNpmReferences(ModuleWithMastersInfo module, string[] projectFiles, bool useDotnetCliToInstall) { var webPackagesWillBeAddedToBlazorServerProject = SouldWebPackagesBeAddedToBlazorServerProject(module, projectFiles); foreach (var nugetPackage in module.NugetPackages) { var nugetTarget = await IsProjectTiered(projectFiles) && nugetPackage.TieredTarget != NuGetPackageTarget.Undefined ? nugetPackage.TieredTarget : nugetPackage.Target; if (webPackagesWillBeAddedToBlazorServerProject && nugetTarget == NuGetPackageTarget.Web) { nugetTarget = NuGetPackageTarget.BlazorServer; } var targetProjectFile = ProjectFinder.FindNuGetTargetProjectFile(projectFiles, nugetTarget); if (targetProjectFile == null) { Logger.LogDebug($"Target project is not available for this NuGet package '{nugetPackage.Name}'"); continue; } await ProjectNugetPackageAdder.AddAsync(null, targetProjectFile, nugetPackage, null, useDotnetCliToInstall); } var mvcNpmPackages = module.NpmPackages?.Where(p => p.ApplicationType.HasFlag(NpmApplicationType.Mvc)) .ToList(); if (!mvcNpmPackages.IsNullOrEmpty()) { var targetProjects = ProjectFinder.FindNpmTargetProjectFile(projectFiles); if (targetProjects.Any()) { NpmGlobalPackagesChecker.Check(); foreach (var targetProject in targetProjects) { foreach (var npmPackage in mvcNpmPackages) { await ProjectNpmPackageAdder.AddMvcPackageAsync(Path.GetDirectoryName(targetProject), npmPackage); } } } else { Logger.LogDebug("Target project is not available for NPM packages."); } } }
private async Task RunBundleForBlazorAsync(string[] projectFiles, ModuleWithMastersInfo module) { var blazorProject = projectFiles.FirstOrDefault(f => f.EndsWith(".Blazor.csproj")); if (blazorProject == null || !module.NugetPackages.Any(np => np.Target == NuGetPackageTarget.Blazor)) { return; } var args = new CommandLineArgs("bundle"); args.Options.Add(BundleCommand.Options.WorkingDirectory.Short, Path.GetDirectoryName(blazorProject)); args.Options.Add(BundleCommand.Options.ForceBuild.Short, string.Empty); await BundleCommand.ExecuteAsync(args); }
private async Task AddAngularPackages(string solutionFilePath, ModuleWithMastersInfo module) { var angularPath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(solutionFilePath)), "angular"); if (!Directory.Exists(angularPath)) { return; } var angularPackages = module.NpmPackages?.Where(p => p.ApplicationType.HasFlag(NpmApplicationType.Angular)).ToList(); if (!angularPackages.IsNullOrEmpty()) { foreach (var npmPackage in angularPackages) { await ProjectNpmPackageAdder.AddAsync(angularPath, npmPackage, true); } } }
private async Task DownloadSourceCodesToSolutionFolder(ModuleWithMastersInfo module, string modulesFolderInSolution, string version = null) { await SourceCodeDownloadService.DownloadAsync( module.Name, Path.Combine(modulesFolderInSolution, module.Name), version, null, null ); if (module.MasterModuleInfos == null) { return; } foreach (var masterModule in module.MasterModuleInfos) { await DownloadSourceCodesToSolutionFolder(masterModule, modulesFolderInSolution, version); } }
public List <NugetPackageInfoWithModuleName> GetNugetPackages(ModuleWithMastersInfo module) { var list = new List <NugetPackageInfoWithModuleName>(); list.AddRange(module.NugetPackages.Select(n => new NugetPackageInfoWithModuleName { ModuleName = module.Name, NugetPackage = n })); if (module.MasterModuleInfos != null) { foreach (var masterModule in module.MasterModuleInfos) { list.AddRange(GetNugetPackages(masterModule)); } } return(list); }
private async Task AddNugetAndNpmReferences(ModuleWithMastersInfo module, string[] projectFiles) { foreach (var nugetPackage in module.NugetPackages) { var nugetTarget = await IsProjectTiered(projectFiles) && nugetPackage.TieredTarget != NuGetPackageTarget.Undefined ? nugetPackage.TieredTarget : nugetPackage.Target; var targetProjectFile = ProjectFinder.FindNuGetTargetProjectFile(projectFiles, nugetTarget); if (targetProjectFile == null) { Logger.LogDebug($"Target project is not available for this NuGet package '{nugetPackage.Name}'"); continue; } await ProjectNugetPackageAdder.AddAsync(targetProjectFile, nugetPackage); } if (!module.NpmPackages.IsNullOrEmpty()) { var targetProjects = ProjectFinder.FindNpmTargetProjectFile(projectFiles); if (targetProjects.Any()) { NpmGlobalPackagesChecker.Check(); foreach (var targetProject in targetProjects) { foreach (var npmPackage in module.NpmPackages.Where(p => p.ApplicationType.HasFlag(NpmApplicationType.Mvc))) { await ProjectNpmPackageAdder.AddAsync(Path.GetDirectoryName(targetProject), npmPackage); } } } else { Logger.LogDebug("Target project is not available for NPM packages."); } } }
private async Task RemoveProjectByPostFix(ModuleWithMastersInfo module, string moduleSolutionFile, string targetFolder, string postFix) { var srcPath = Path.Combine(Path.GetDirectoryName(moduleSolutionFile), targetFolder); if (!Directory.Exists(srcPath)) { return; } var projectFolderPaths = Directory.GetDirectories(srcPath).Where(d => d.EndsWith(postFix)).ToList(); foreach (var projectFolderPath in projectFolderPaths) { await SolutionFileModifier.RemoveProjectFromSolutionFileAsync(moduleSolutionFile, new DirectoryInfo(projectFolderPath).Name); if (Directory.Exists(projectFolderPath)) { Directory.Delete(projectFolderPath, true); } } }
private async Task <List <string> > FindProjectsToRemoveByTarget(ModuleWithMastersInfo module, NuGetPackageTarget target, bool isTieredProject) { var projectsToRemove = new List <string>(); var packages = module.NugetPackages.Where(n => (isTieredProject && n.TieredTarget != NuGetPackageTarget.Undefined ? n.TieredTarget : n.Target) == target ).ToList(); foreach (var package in packages) { if (target == NuGetPackageTarget.Web && package.Name.StartsWith("Volo.Abp.Account")) { continue; } projectsToRemove.Add(package.Name); } return(projectsToRemove); }
private async Task AddModule(ModuleWithMastersInfo module, string solutionFile) { var srcModuleFolderId = await AddNewFolderAndGetIdOrGetExistingId(solutionFile, module.Name, await AddNewFolderAndGetIdOrGetExistingId(solutionFile, "modules")); var testModuleFolderId = await AddNewFolderAndGetIdOrGetExistingId(solutionFile, module.Name + ".Tests", await AddNewFolderAndGetIdOrGetExistingId(solutionFile, "test")); var file = File.ReadAllText(solutionFile); var lines = file.Split(Environment.NewLine).ToList(); var projectsUnderModule = Directory.GetFiles( Path.Combine(Path.GetDirectoryName(solutionFile), "modules", module.Name), "*.csproj", SearchOption.AllDirectories); var projectsUnderTest = Directory.GetFiles( Path.Combine(Path.GetDirectoryName(solutionFile), "modules", module.Name, "test"), "*.csproj", SearchOption.AllDirectories); foreach (var projectPath in projectsUnderModule) { var parentFolderId = projectsUnderTest.Contains(projectPath) ? testModuleFolderId : srcModuleFolderId; var projectId = Path.GetFileName(projectPath).Replace(".csproj", ""); var projectParentFolderInModule = projectsUnderTest.Contains(projectPath) ? "test" : "src"; if (lines.Any(l => l.Contains($"\"{projectId}\""))) { continue; } var projectGuid = Guid.NewGuid().ToString(); var newProjectLine = "Project(\"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}\") = \"" + projectId + "\"," + " \"modules\\" + module.Name + "\\" + projectParentFolderInModule + "\\" + projectId + "\\" + projectId + ".csproj\", \"{" + projectGuid + "}\"" + Environment.NewLine + "EndProject"; lines.InsertAfter(l => l.Trim().Equals("EndProject"), newProjectLine); var newPostSolutionLine = " {"+ projectGuid + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU" + Environment.NewLine + " {"+ projectGuid + "}.Debug|Any CPU.Build.0 = Debug|Any CPU" + Environment.NewLine + " {"+ projectGuid + "}.Release|Any CPU.ActiveCfg = Release|Any CPU" + Environment.NewLine + " {"+ projectGuid + "}.Release|Any CPU.Build.0 = Release|Any CPU"; lines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("ProjectConfigurationPlatforms"), newPostSolutionLine); var newPreSolutionLine = " {"+ projectGuid + "} = {" + parentFolderId + "}"; lines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("NestedProjects"), newPreSolutionLine); } File.WriteAllText(solutionFile, string.Join(Environment.NewLine, lines)); if (module.MasterModuleInfos != null) { foreach (var masterModule in module.MasterModuleInfos) { await AddModule(masterModule, solutionFile); } } }
private async Task <ModuleWithMastersInfo> GetEmptyModuleProjectInfoAsync(string moduleName, bool newProTemplate = false) { var module = new ModuleWithMastersInfo(); module.Name = moduleName; module.DisplayName = moduleName; module.EfCoreConfigureMethodName = $"{module.Name}.EntityFrameworkCore:Configure{module.Name}"; module.MasterModuleInfos = new List <ModuleWithMastersInfo>(); module.NugetPackages = new List <NugetPackageInfo> { new NugetPackageInfo { Name = $"{module.Name}.Application", ModuleClass = $"{module.Name}.{module.Name}ApplicationModule", Target = NuGetPackageTarget.Application }, new NugetPackageInfo { Name = $"{module.Name}.Application.Contracts", ModuleClass = $"{module.Name}.{module.Name}ApplicationContractsModule", Target = NuGetPackageTarget.ApplicationContracts }, new NugetPackageInfo { Name = $"{module.Name}.Blazor", ModuleClass = $"{module.Name}.Blazor.{module.Name}BlazorModule", Target = NuGetPackageTarget.Blazor }, new NugetPackageInfo { Name = $"{module.Name}.Domain", ModuleClass = $"{module.Name}.{module.Name}DomainModule", Target = NuGetPackageTarget.Domain }, new NugetPackageInfo { Name = $"{module.Name}.Domain.Shared", ModuleClass = $"{module.Name}.{module.Name}DomainSharedModule", Target = NuGetPackageTarget.DomainShared }, new NugetPackageInfo { Name = $"{module.Name}.EntityFrameworkCore", ModuleClass = $"{module.Name}.EntityFrameworkCore.{module.Name}EntityFrameworkCoreModule", Target = NuGetPackageTarget.EntityFrameworkCore }, new NugetPackageInfo { Name = $"{module.Name}.HttpApi", ModuleClass = $"{module.Name}.{module.Name}HttpApiModule", Target = NuGetPackageTarget.HttpApi }, new NugetPackageInfo { Name = $"{module.Name}.HttpApi.Client", ModuleClass = $"{module.Name}.{module.Name}HttpApiClientModule", Target = NuGetPackageTarget.HttpApiClient }, new NugetPackageInfo { Name = $"{module.Name}.MongoDB", ModuleClass = $"{module.Name}.MongoDB.{module.Name}MongoDbModule", Target = NuGetPackageTarget.MongoDB }, new NugetPackageInfo { Name = $"{module.Name}.Web", ModuleClass = $"{module.Name}.Web.{module.Name}WebModule", Target = NuGetPackageTarget.Web }, }; module.NpmPackages = new List <NpmPackageInfo>(); return(module); }
public async Task AddModuleToSolutionFileAsync(ModuleWithMastersInfo module, string solutionFile) { await AddModule(module, solutionFile); }
private ModuleWithMastersInfo RemoveIncompatiblePackages(ModuleWithMastersInfo module, string version) { module.NugetPackages.RemoveAll(np => IsPackageInCompatible(np.MinVersion, np.MaxVersion, version)); module.NpmPackages.RemoveAll(np => IsPackageInCompatible(np.MinVersion, np.MaxVersion, version)); return(module); }