@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO ;
using System.Linq ;
using System.Threading.Tasks ;
using JetBrains.Annotations ;
using Microsoft.Extensions.Logging ;
using Microsoft.Extensions.Logging.Abstractions ;
using Volo.Abp.Cli.Args ;
@ -32,6 +33,37 @@ public class PackagePreviewSwitcher : ITransientDependency
{
var solutionPaths = GetSolutionPaths ( commandLineArgs ) ;
if ( solutionPaths . Any ( ) )
{
await SwitchSolutionsToPreview ( solutionPaths ) ;
}
else
{
var projectPaths = GetProjectPaths ( commandLineArgs ) ;
await SwitchProjectsToPreview ( projectPaths ) ;
}
}
private async Task SwitchProjectsToPreview ( List < string > projects )
{
foreach ( var project in projects )
{
var folder = Path . GetDirectoryName ( project ) ;
await _ nugetPackagesVersionUpdater . UpdateProjectAsync (
project ,
includeReleaseCandidates : true ) ;
await _ npmPackagesUpdater . Update (
folder ,
false ,
true ) ;
}
}
private async Task SwitchSolutionsToPreview ( List < string > solutionPaths )
{
foreach ( var solutionPath in solutionPaths )
{
var solutionFolder = Path . GetDirectoryName ( solutionPath ) ;
@ -56,69 +88,134 @@ public class PackagePreviewSwitcher : ITransientDependency
}
}
public async Task SwitchToNightlyPreview ( CommandLineArgs commandLineArgs )
public async Task SwitchToStable ( CommandLineArgs commandLineArgs )
{
var solutionPaths = GetSolutionPaths ( commandLineArgs ) ;
if ( solutionPaths . Any ( ) )
{
await SwitchSolutionsToStable ( solutionPaths ) ;
}
else
{
var projectPaths = GetProjectPaths ( commandLineArgs ) ;
await SwitchProjectsToStable ( projectPaths ) ;
}
}
private async Task SwitchProjectsToStable ( List < string > projects )
{
foreach ( var project in projects )
{
var folder = Path . GetDirectoryName ( project ) ;
await _ nugetPackagesVersionUpdater . UpdateProjectAsync (
project ,
false ,
false ,
true ) ;
await _ npmPackagesUpdater . Update (
folder ,
false ,
false ,
true ) ;
}
}
private async Task SwitchSolutionsToStable ( List < string > solutionPaths )
{
foreach ( var solutionPath in solutionPaths )
{
var solutionFolder = Path . GetDirectoryName ( solutionPath ) ;
var solutionAngularFolder = GetSolutionAngularFolder ( solutionFolder ) ;
_ packageSourceManager . Add ( solutionFolder , "ABP Nightly" , "https://www.myget.org/F/abp-nightly/api/v3/index.json" ) ;
_ packageSourceManager . Remove ( solutionFolder , "ABP Nightly" ) ;
if ( solutionPath ! = null )
{
await _ nugetPackagesVersionUpdater . UpdateSolutionAsync (
solutionPath ,
true ) ;
}
await _ nugetPackagesVersionUpdater . UpdateSolutionAsync (
solutionPath ,
false ,
false ,
true ) ;
await _ npmPackagesUpdater . Update (
solutionFolder ,
false ,
false ,
true ) ;
if ( solutionAngularFolder ! = null )
{
await _ npmPackagesUpdater . Update (
solutionAngularFolder ,
false ,
false ,
true ) ;
}
}
}
public async Task SwitchToStable ( CommandLineArgs commandLineArgs )
public async Task SwitchToNightlyPreview ( CommandLineArgs commandLineArgs )
{
var solutionPaths = GetSolutionPaths ( commandLineArgs ) ;
if ( solutionPaths . Any ( ) )
{
await SwitchSolutionsToNightlyPreview ( solutionPaths ) ;
}
else
{
var projectPaths = GetProjectPaths ( commandLineArgs ) ;
await SwitchProjectsToNightlyPreview ( projectPaths ) ;
}
}
private async Task SwitchProjectsToNightlyPreview ( List < string > projects )
{
foreach ( var project in projects )
{
var folder = Path . GetDirectoryName ( project ) ;
_ packageSourceManager . Add ( FindSolutionFolder ( project ) ? ? folder , "ABP Nightly" ,
"https://www.myget.org/F/abp-nightly/api/v3/index.json" ) ;
await _ nugetPackagesVersionUpdater . UpdateSolutionAsync (
project ,
true ) ;
await _ npmPackagesUpdater . Update (
folder ,
true ) ;
}
}
private async Task SwitchSolutionsToNightlyPreview ( List < string > solutionPaths )
{
foreach ( var solutionPath in solutionPaths )
{
var solutionFolder = Path . GetDirectoryName ( solutionPath ) ;
var solutionAngularFolder = GetSolutionAngularFolder ( solutionFolder ) ;
_ packageSourceManager . Remove ( solutionFolder , "ABP Nightly" ) ;
_ packageSourceManager . Add ( solutionFolder , "ABP Nightly" ,
"https://www.myget.org/F/abp-nightly/api/v3/index.json" ) ;
if ( solutionPath ! = null )
{
await _ nugetPackagesVersionUpdater . UpdateSolutionAsync (
solutionPath ,
false ,
false ,
true ) ;
}
await _ npmPackagesUpdater . Update (
solutionFolder ,
false ,
false ,
true ) ;
if ( solutionAngularFolder ! = null )
{
await _ npmPackagesUpdater . Update (
solutionAngularFolder ,
false ,
false ,
true ) ;
}
}
@ -126,22 +223,18 @@ public class PackagePreviewSwitcher : ITransientDependency
private List < string > GetSolutionPaths ( CommandLineArgs commandLineArgs )
{
var directory = commandLineArgs . Options . GetOrNull ( Options . SolutionDirectory . Short , Options . SolutionDirectory . Long )
? ? Directory . GetCurrentDirectory ( ) ;
var solutionPaths = Directory . GetFiles ( directory , "*.sln" , SearchOption . AllDirectories ) ;
if ( ! solutionPaths . Any ( ) )
{
Logger . LogWarning ( "No solution (.sln) found to change version." ) ;
}
return Directory . GetFiles ( GetDirectory ( commandLineArgs ) , "*.sln" , SearchOption . AllDirectories ) . ToList ( ) ;
}
return solutionPaths . ToList ( ) ;
private List < string > GetProjectPaths ( CommandLineArgs commandLineArgs )
{
return Directory . GetFiles ( GetDirectory ( commandLineArgs ) , "*.csproj" , SearchOption . AllDirectories ) . ToList ( ) ;
}
private string GetSolutionFolder ( CommandLineArgs commandLineArgs )
private string GetDirectory ( CommandLineArgs commandLineArgs )
{
return commandLineArgs . Options . GetOrNull ( Options . SolutionDirectory . Short , Options . SolutionDirectory . Long )
? ? commandLineArgs . Options . GetOrNull ( Options . Directory . Short , Options . Directory . Long )
? ? Directory . GetCurrentDirectory ( ) ;
}
@ -160,6 +253,31 @@ public class PackagePreviewSwitcher : ITransientDependency
}
return null ;
}
[CanBeNull]
private string FindSolutionFolder ( string projectFile )
{
var targetFolder = Path . GetDirectoryName ( projectFile ) ;
do
{
if ( Directory . GetParent ( targetFolder ) ! = null )
{
targetFolder = Directory . GetParent ( targetFolder ) . FullName ;
}
else
{
return Path . GetDirectoryName ( projectFile ) ;
}
if ( Directory . GetFiles ( targetFolder , "*.sln" , SearchOption . TopDirectoryOnly ) . Any ( ) )
{
break ;
}
} while ( targetFolder ! = null ) ;
return targetFolder ;
}
public static class Options
@ -169,5 +287,10 @@ public class PackagePreviewSwitcher : ITransientDependency
public const string Short = "sd" ;
public const string Long = "solution-directory" ;
}
public static class Directory
{
public const string Short = "d" ;
public const string Long = "directory" ;
}
}
}