mirror of https://github.com/abpframework/abp.git
committed by
GitHub
11 changed files with 414 additions and 37 deletions
@ -0,0 +1,44 @@ |
|||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Cli.Args; |
||||
|
using Volo.Abp.Cli.ProjectModification; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.Commands |
||||
|
{ |
||||
|
public class SwitchNightlyPreviewCommand : IConsoleCommand, ITransientDependency |
||||
|
{ |
||||
|
private readonly PackageSourceSwitcher _packageSourceSwitcher; |
||||
|
|
||||
|
public SwitchNightlyPreviewCommand(PackageSourceSwitcher packageSourceSwitcher) |
||||
|
{ |
||||
|
_packageSourceSwitcher = packageSourceSwitcher; |
||||
|
} |
||||
|
|
||||
|
public async Task ExecuteAsync(CommandLineArgs commandLineArgs) |
||||
|
{ |
||||
|
await _packageSourceSwitcher.SwitchToPreview(commandLineArgs); |
||||
|
} |
||||
|
|
||||
|
public string GetUsageInfo() |
||||
|
{ |
||||
|
var sb = new StringBuilder(); |
||||
|
|
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine("Usage:"); |
||||
|
sb.AppendLine(" abp switch-to-preview [options]"); |
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine("Options:"); |
||||
|
sb.AppendLine("-sp|--solution-path"); |
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI"); |
||||
|
|
||||
|
return sb.ToString(); |
||||
|
} |
||||
|
|
||||
|
public string GetShortDescription() |
||||
|
{ |
||||
|
return "Switches packages to nightly preview ABP version."; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Cli.Args; |
||||
|
using Volo.Abp.Cli.ProjectModification; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.Commands |
||||
|
{ |
||||
|
public class SwitchStableCommand : IConsoleCommand, ITransientDependency |
||||
|
{ |
||||
|
private readonly PackageSourceSwitcher _packageSourceSwitcher; |
||||
|
|
||||
|
public SwitchStableCommand(PackageSourceSwitcher packageSourceSwitcher) |
||||
|
{ |
||||
|
_packageSourceSwitcher = packageSourceSwitcher; |
||||
|
} |
||||
|
|
||||
|
public async Task ExecuteAsync(CommandLineArgs commandLineArgs) |
||||
|
{ |
||||
|
await _packageSourceSwitcher.SwitchToStable(commandLineArgs); |
||||
|
} |
||||
|
|
||||
|
public string GetUsageInfo() |
||||
|
{ |
||||
|
var sb = new StringBuilder(); |
||||
|
|
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine("Usage:"); |
||||
|
sb.AppendLine(" abp switch-to-stable [options]"); |
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine("Options:"); |
||||
|
sb.AppendLine("-sp|--solution-path"); |
||||
|
sb.AppendLine(""); |
||||
|
sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI"); |
||||
|
|
||||
|
return sb.ToString(); |
||||
|
} |
||||
|
|
||||
|
public string GetShortDescription() |
||||
|
{ |
||||
|
return "Switches packages to stable ABP version from preview version."; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.ProjectModification |
||||
|
{ |
||||
|
public class MyGetApiResponse |
||||
|
{ |
||||
|
public string _date { get; set; } |
||||
|
|
||||
|
public List<MyGetPackage> Packages { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.ProjectModification |
||||
|
{ |
||||
|
public class MyGetPackage |
||||
|
{ |
||||
|
public string PackageType { get; set; } |
||||
|
|
||||
|
public string Id { get; set; } |
||||
|
|
||||
|
public List<string> Versions { get; set; } |
||||
|
|
||||
|
public List<string> Dates { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
using System; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Microsoft.Extensions.Logging.Abstractions; |
||||
|
using Newtonsoft.Json; |
||||
|
using Volo.Abp.Cli.Http; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.ProjectModification |
||||
|
{ |
||||
|
public class MyGetPackageListFinder : ISingletonDependency |
||||
|
{ |
||||
|
private MyGetApiResponse _response; |
||||
|
|
||||
|
public ILogger<MyGetPackageListFinder> Logger { get; set; } |
||||
|
|
||||
|
public MyGetPackageListFinder() |
||||
|
{ |
||||
|
Logger = NullLogger<MyGetPackageListFinder>.Instance; |
||||
|
} |
||||
|
|
||||
|
public async Task<MyGetApiResponse> GetPackages() |
||||
|
{ |
||||
|
if (_response != null) |
||||
|
{ |
||||
|
return _response; |
||||
|
} |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
using (var client = new CliHttpClient(TimeSpan.FromMinutes(10))) |
||||
|
{ |
||||
|
var responseMessage = await client.GetAsync( |
||||
|
$"{CliUrls.WwwAbpIo}api/myget/packages/" |
||||
|
); |
||||
|
|
||||
|
_response = JsonConvert.DeserializeObject<MyGetApiResponse>(Encoding.Default.GetString(await responseMessage.Content.ReadAsByteArrayAsync())); |
||||
|
} |
||||
|
} |
||||
|
catch (Exception) |
||||
|
{ |
||||
|
Logger.LogError("Unable to get latest preview version."); |
||||
|
throw; |
||||
|
} |
||||
|
|
||||
|
return _response; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,76 @@ |
|||||
|
using System; |
||||
|
using System.IO; |
||||
|
using System.Xml; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Microsoft.Extensions.Logging.Abstractions; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.ProjectModification |
||||
|
{ |
||||
|
public class PackageSourceAdder: ITransientDependency |
||||
|
{ |
||||
|
public ILogger<PackageSourceAdder> Logger { get; set; } |
||||
|
|
||||
|
public PackageSourceAdder() |
||||
|
{ |
||||
|
Logger = NullLogger<PackageSourceAdder>.Instance; |
||||
|
} |
||||
|
|
||||
|
public void Add(string sourceKey, string sourceValue) |
||||
|
{ |
||||
|
var nugetConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), |
||||
|
"NuGet", "NuGet.Config"); |
||||
|
|
||||
|
if (!File.Exists(nugetConfigPath)) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
var fileContent = File.ReadAllText(nugetConfigPath); |
||||
|
|
||||
|
if (fileContent.Contains($"\"{sourceValue}\"")) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
Logger.LogInformation($"Adding \"{sourceValue}\" ({sourceKey}) to nuget sources..."); |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
var doc = new XmlDocument() { PreserveWhitespace = true }; |
||||
|
|
||||
|
doc.Load(GenerateStreamFromString(fileContent)); |
||||
|
|
||||
|
var sourceNodes = doc.SelectNodes("/configuration/packageSources"); |
||||
|
|
||||
|
var newNode = doc.CreateElement("add"); |
||||
|
|
||||
|
var includeAttr = doc.CreateAttribute("key"); |
||||
|
includeAttr.Value = sourceKey; |
||||
|
newNode.Attributes.Append(includeAttr); |
||||
|
|
||||
|
var versionAttr = doc.CreateAttribute("value"); |
||||
|
versionAttr.Value = sourceValue; |
||||
|
newNode.Attributes.Append(versionAttr); |
||||
|
|
||||
|
sourceNodes?[0]?.AppendChild(newNode); |
||||
|
|
||||
|
File.WriteAllText(nugetConfigPath, doc.OuterXml); |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
Logger.LogWarning($"Adding \"{sourceValue}\" ({sourceKey}) to nuget sources FAILED."); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static Stream GenerateStreamFromString(string s) |
||||
|
{ |
||||
|
var stream = new MemoryStream(); |
||||
|
var writer = new StreamWriter(stream); |
||||
|
writer.Write(s); |
||||
|
writer.Flush(); |
||||
|
stream.Position = 0; |
||||
|
return stream; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,86 @@ |
|||||
|
using System; |
||||
|
using System.IO; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Microsoft.Extensions.Logging.Abstractions; |
||||
|
using Volo.Abp.Cli.Args; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.ProjectModification |
||||
|
{ |
||||
|
public class PackageSourceSwitcher : ITransientDependency |
||||
|
{ |
||||
|
private readonly PackageSourceAdder _packageSourceAdder; |
||||
|
private readonly NpmPackagesUpdater _npmPackagesUpdater; |
||||
|
private readonly VoloNugetPackagesVersionUpdater _nugetPackagesVersionUpdater; |
||||
|
|
||||
|
public ILogger<PackageSourceSwitcher> Logger { get; set; } |
||||
|
|
||||
|
public PackageSourceSwitcher(PackageSourceAdder packageSourceAdder, |
||||
|
NpmPackagesUpdater npmPackagesUpdater, |
||||
|
VoloNugetPackagesVersionUpdater nugetPackagesVersionUpdater) |
||||
|
{ |
||||
|
_packageSourceAdder = packageSourceAdder; |
||||
|
_npmPackagesUpdater = npmPackagesUpdater; |
||||
|
_nugetPackagesVersionUpdater = nugetPackagesVersionUpdater; |
||||
|
Logger = NullLogger<PackageSourceSwitcher>.Instance; |
||||
|
} |
||||
|
|
||||
|
public async Task SwitchToPreview(CommandLineArgs commandLineArgs) |
||||
|
{ |
||||
|
_packageSourceAdder.Add("ABP Nightly", "https://www.myget.org/F/abp-nightly/api/v3/index.json"); |
||||
|
|
||||
|
await _nugetPackagesVersionUpdater.UpdateSolutionAsync( |
||||
|
GetSolutionPath(commandLineArgs), |
||||
|
true); |
||||
|
|
||||
|
await _npmPackagesUpdater.Update( |
||||
|
Path.GetFileName(GetSolutionPath(commandLineArgs)), |
||||
|
true); |
||||
|
} |
||||
|
|
||||
|
public async Task SwitchToStable(CommandLineArgs commandLineArgs) |
||||
|
{ |
||||
|
await _nugetPackagesVersionUpdater.UpdateSolutionAsync( |
||||
|
GetSolutionPath(commandLineArgs), |
||||
|
false, |
||||
|
true); |
||||
|
|
||||
|
await _npmPackagesUpdater.Update( |
||||
|
Path.GetFileName(GetSolutionPath(commandLineArgs)), |
||||
|
false, |
||||
|
true); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private string GetSolutionPath(CommandLineArgs commandLineArgs) |
||||
|
{ |
||||
|
var solutionPath = commandLineArgs.Options.GetOrNull(Options.SolutionPath.Short, Options.SolutionPath.Long); |
||||
|
|
||||
|
if (solutionPath == null) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
solutionPath = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln").Single(); |
||||
|
} |
||||
|
catch (Exception) |
||||
|
{ |
||||
|
Logger.LogError("There is no solution or more that one solution in current directory."); |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return solutionPath; |
||||
|
} |
||||
|
|
||||
|
public static class Options |
||||
|
{ |
||||
|
public static class SolutionPath |
||||
|
{ |
||||
|
public const string Short = "sp"; |
||||
|
public const string Long = "solution-path"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue