Exemplo n.º 1
0
        public async Task Convert(ModuleWithMastersInfo module, string solutionFile)
        {
            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");

            await ConvertToLocalReference(modulesFolder, nugetPackageList, "..\\..\\..\\");
            await ConvertToLocalReference(srcFolder, nugetPackageList, "..\\..\\modules\\");
            await ConvertToLocalReference(testFolder, nugetPackageList, "..\\..\\modules\\", "test");
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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.");
                }
            }
        }
Exemplo n.º 4
0
        private async Task DownloadSourceCodesToSolutionFolder(ModuleWithMastersInfo module, string modulesFolderInSolution, string version = null)
        {
            var targetModuleFolder = Path.Combine(modulesFolderInSolution, module.Name);

            await SourceCodeDownloadService.DownloadAsync(
                module.Name,
                targetModuleFolder,
                version,
                null,
                null
                );

            await DeleteAppAndDemoFolderAsync(targetModuleFolder);

            if (module.MasterModuleInfos == null)
            {
                return;
            }

            foreach (var masterModule in module.MasterModuleInfos)
            {
                await DownloadSourceCodesToSolutionFolder(masterModule, modulesFolderInSolution, version);
            }
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
 public async Task AddModuleToSolutionFileAsync(ModuleWithMastersInfo module, string solutionFile)
 {
     await AddModule(module, solutionFile);
 }