Beispiel #1
0
 public SolutionModuleAdder(
     IJsonSerializer jsonSerializer,
     ProjectNugetPackageAdder projectNugetPackageAdder,
     DbContextFileBuilderConfigureAdder dbContextFileBuilderConfigureAdder,
     EfCoreMigrationAdder efCoreMigrationAdder,
     DerivedClassFinder derivedClassFinder,
     ProjectNpmPackageAdder projectNpmPackageAdder,
     NpmGlobalPackagesChecker npmGlobalPackagesChecker,
     IRemoteServiceExceptionHandler remoteServiceExceptionHandler,
     SourceCodeDownloadService sourceCodeDownloadService,
     SolutionFileModifier solutionFileModifier,
     NugetPackageToLocalReferenceConverter nugetPackageToLocalReferenceConverter,
     AngularModuleSourceCodeAdder angularModuleSourceCodeAdder)
 {
     JsonSerializer                        = jsonSerializer;
     ProjectNugetPackageAdder              = projectNugetPackageAdder;
     DbContextFileBuilderConfigureAdder    = dbContextFileBuilderConfigureAdder;
     EfCoreMigrationAdder                  = efCoreMigrationAdder;
     DerivedClassFinder                    = derivedClassFinder;
     ProjectNpmPackageAdder                = projectNpmPackageAdder;
     NpmGlobalPackagesChecker              = npmGlobalPackagesChecker;
     RemoteServiceExceptionHandler         = remoteServiceExceptionHandler;
     SourceCodeDownloadService             = sourceCodeDownloadService;
     SolutionFileModifier                  = solutionFileModifier;
     NugetPackageToLocalReferenceConverter = nugetPackageToLocalReferenceConverter;
     AngularModuleSourceCodeAdder          = angularModuleSourceCodeAdder;
     Logger = NullLogger <SolutionModuleAdder> .Instance;
 }
Beispiel #2
0
        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);
                }
            }
        }
        public virtual async Task AddAsync(
            [NotNull] string solutionFile,
            [NotNull] string moduleName,
            string startupProject,
            string version,
            bool skipDbMigrations = false,
            bool withSourceCode   = false)
        {
            Check.NotNull(solutionFile, nameof(solutionFile));
            Check.NotNull(moduleName, nameof(moduleName));

            var module = await FindModuleInfoAsync(moduleName);

            Logger.LogInformation($"Installing module '{module.Name}' to the solution '{Path.GetFileNameWithoutExtension(solutionFile)}'");

            var projectFiles = ProjectFinder.GetProjectFiles(solutionFile);

            await AddNugetAndNpmReferences(module, projectFiles);

            if (withSourceCode)
            {
                var modulesFolderInSolution = Path.Combine(Path.GetDirectoryName(solutionFile), "modules");
                await DownloadSourceCodesToSolutionFolder(module, modulesFolderInSolution, version);

                await SolutionFileModifier.AddModuleToSolutionFileAsync(module, solutionFile);

                await NugetPackageToLocalReferenceConverter.Convert(module, solutionFile);

                await HandleAngularProject(modulesFolderInSolution, solutionFile);
            }

            ModifyDbContext(projectFiles, module, startupProject, skipDbMigrations);
        }
        public async Task AddAsync(
            string projectFile,
            NugetPackageInfo package,
            string version                   = null,
            bool useDotnetCliToInstall       = true,
            bool withSourceCode              = false,
            bool addSourceCodeToSolutionFile = false)
        {
            if (version == null)
            {
                version = GetAbpVersionOrNull(projectFile);
            }

            await AddAsPackageReference(projectFile, package, version, useDotnetCliToInstall);

            if (withSourceCode)
            {
                await AddSourceCode(projectFile, package, version);
                await ConvertPackageReferenceToProjectReference(projectFile, package);

                if (addSourceCodeToSolutionFile)
                {
                    await SolutionFileModifier.AddPackageToSolutionFileAsync(package, FindSolutionFile(projectFile));
                }
            }
        }
Beispiel #5
0
        public virtual async Task AddAsync(
            [NotNull] string solutionFile,
            [NotNull] string moduleName,
            string version,
            bool skipDbMigrations            = false,
            bool withSourceCode              = false,
            bool addSourceCodeToSolutionFile = false,
            bool newTemplate    = false,
            bool newProTemplate = false)
        {
            Check.NotNull(solutionFile, nameof(solutionFile));
            Check.NotNull(moduleName, nameof(moduleName));

            var module = await GetModuleInfoAsync(moduleName, newTemplate, newProTemplate);

            module = RemoveIncompatiblePackages(module, version);

            Logger.LogInformation(
                $"Installing module '{module.Name}' to the solution '{Path.GetFileNameWithoutExtension(solutionFile)}'");

            var projectFiles = ProjectFinder.GetProjectFiles(solutionFile);

            await AddNugetAndNpmReferences(module, projectFiles, !(newTemplate || newProTemplate));

            if (withSourceCode || newTemplate || newProTemplate)
            {
                var modulesFolderInSolution = Path.Combine(Path.GetDirectoryName(solutionFile), "modules");
                await DownloadSourceCodesToSolutionFolder(module, modulesFolderInSolution, version, newTemplate, newProTemplate);
                await RemoveUnnecessaryProjectsAsync(Path.GetDirectoryName(solutionFile), module, projectFiles);

                if (addSourceCodeToSolutionFile)
                {
                    await SolutionFileModifier.AddModuleToSolutionFileAsync(module, solutionFile);
                }

                if (newTemplate || newProTemplate)
                {
                    await NugetPackageToLocalReferenceConverter.Convert(module, solutionFile, $"{module.Name}.");
                }
                else
                {
                    await NugetPackageToLocalReferenceConverter.Convert(module, solutionFile);
                }

                await AddAngularSourceCode(modulesFolderInSolution, solutionFile, module.Name, newTemplate || newProTemplate);
            }
            else
            {
                await AddAngularPackages(solutionFile, module);
            }

            await RunBundleForBlazorAsync(projectFiles, module);

            ModifyDbContext(projectFiles, module, skipDbMigrations);
        }
Beispiel #6
0
        private async Task RemoveProjectFromSolutionAsync(string moduleSolutionFile, string projectName)
        {
            await SolutionFileModifier.RemoveProjectFromSolutionFileAsync(moduleSolutionFile, projectName);

            var projectFolderPath = Path.Combine(Path.GetDirectoryName(moduleSolutionFile), "src", projectName);

            if (Directory.Exists(projectFolderPath))
            {
                Directory.Delete(projectFolderPath, true);
            }
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
        public async Task AddAsync(
            string solutionFile,
            string projectFile,
            NugetPackageInfo package,
            string version                   = null,
            bool useDotnetCliToInstall       = true,
            bool withSourceCode              = false,
            bool addSourceCodeToSolutionFile = false)
        {
            if (projectFile == null)
            {
                if (solutionFile == null)
                {
                    throw new CliUsageException("Couldn't find any project/solution.");
                }

                projectFile = GetProjectFile(solutionFile, package);

                if (projectFile == null)
                {
                    throw new CliUsageException("Couldn't find any project/solution.");
                }
            }

            solutionFile ??= FindSolutionFile(projectFile);

            if (version == null)
            {
                version = GetAbpVersionOrNull(projectFile);
            }

            await AddAsPackageReference(projectFile, package, version, useDotnetCliToInstall);

            if (withSourceCode)
            {
                await AddSourceCode(projectFile, solutionFile, package, version);

                var projectFilesInSolution = Directory.GetFiles(Path.GetDirectoryName(solutionFile), "*.csproj", SearchOption.AllDirectories);
                foreach (var projectFileInSolution in projectFilesInSolution)
                {
                    await ConvertPackageReferenceToProjectReference(projectFileInSolution, solutionFile, package);
                }

                if (addSourceCodeToSolutionFile)
                {
                    await SolutionFileModifier.AddPackageToSolutionFileAsync(package, solutionFile);
                }
            }
        }
Beispiel #9
0
        public async Task AddAsync(
            string solutionFile,
            string projectFile,
            NugetPackageInfo package,
            string version                   = null,
            bool useDotnetCliToInstall       = true,
            bool withSourceCode              = false,
            bool addSourceCodeToSolutionFile = false)
        {
            if (projectFile == null)
            {
                if (solutionFile == null)
                {
                    throw new CliUsageException("Couldn't find any project/solution.");
                }

                projectFile = GetProjectFile(solutionFile, package);

                if (projectFile == null)
                {
                    throw new CliUsageException("Couldn't find any project/solution.");
                }
            }

            solutionFile ??= FindSolutionFile(projectFile);

            if (version == null)
            {
                version = GetAbpVersionOrNull(projectFile);
            }

            await AddAsPackageReference(projectFile, package, version, useDotnetCliToInstall);

            if (withSourceCode)
            {
                await AddSourceCode(projectFile, solutionFile, package, version);
                await ConvertPackageReferenceToProjectReference(projectFile, solutionFile, package);

                if (addSourceCodeToSolutionFile)
                {
                    await SolutionFileModifier.AddPackageToSolutionFileAsync(package, solutionFile);
                }
            }
        }
Beispiel #10
0
        private async Task DeleteRedundantHostProjects(string targetModuleFolder, string folderName)
        {
            var moduleSolutionFile = Directory.GetFiles(targetModuleFolder, "*.sln", SearchOption.TopDirectoryOnly).First();

            var folder = Path.Combine(targetModuleFolder, folderName);

            if (Directory.Exists(folder))
            {
                var projects = Directory.GetDirectories(folder);

                foreach (var project in projects)
                {
                    await SolutionFileModifier.RemoveProjectFromSolutionFileAsync(moduleSolutionFile,
                                                                                  new DirectoryInfo(project).Name);
                }

                Directory.Delete(folder, true);
            }
        }
Beispiel #11
0
 public ProjectNugetPackageAdder(
     IJsonSerializer jsonSerializer,
     ProjectNpmPackageAdder npmPackageAdder,
     DerivedClassFinder moduleClassFinder,
     ModuleClassDependcyAdder moduleClassDependcyAdder,
     IRemoteServiceExceptionHandler remoteServiceExceptionHandler,
     BundleCommand bundleCommand,
     CliHttpClientFactory cliHttpClientFactory,
     SourceCodeDownloadService sourceCodeDownloadService,
     SolutionFileModifier solutionFileModifier)
 {
     JsonSerializer                = jsonSerializer;
     NpmPackageAdder               = npmPackageAdder;
     ModuleClassFinder             = moduleClassFinder;
     ModuleClassDependcyAdder      = moduleClassDependcyAdder;
     RemoteServiceExceptionHandler = remoteServiceExceptionHandler;
     BundleCommand             = bundleCommand;
     SourceCodeDownloadService = sourceCodeDownloadService;
     SolutionFileModifier      = solutionFileModifier;
     _cliHttpClientFactory     = cliHttpClientFactory;
     Logger = NullLogger <ProjectNugetPackageAdder> .Instance;
 }
Beispiel #12
0
        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);
                }
            }
        }