Fix: Switc-to-preview/stable command unable to switch npm packages

resolves https://github.com/abpframework/abp/issues/3154
pull/3156/head
Yunus Emre Kalkan 6 years ago
parent eddbe79585
commit f9050f93b9

@ -141,7 +141,7 @@ abp switch-to-preview [options]
````
#### Options
`--solution-path` or `-sp`: Specifies the solution (.sln) file path. If not specified, CLI tries to find a .sln file in the current directory.
`--solution-directory` or `-sd`: Specifies the directory. The solution should be in that directory or in any of its sub directories. If not specified, default is the current directory.
### switch-to-stable
@ -154,7 +154,7 @@ abp switch-to-stable [options]
````
#### Options
`--solution-path` or `-sp`: Specifies the solution (.sln) file path. If not specified, CLI tries to find a .sln file in the current directory.
`--solution-directory` or `-sd`: Specifies the directory. The solution should be in that directory or in any of its sub directories. If not specified, default is the current directory.
### login

@ -29,7 +29,7 @@ namespace Volo.Abp.Cli.Commands
sb.AppendLine(" abp switch-to-preview [options]");
sb.AppendLine("");
sb.AppendLine("Options:");
sb.AppendLine("-sp|--solution-path");
sb.AppendLine("-sd|--solution-directory");
sb.AppendLine("");
sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI");

@ -29,7 +29,7 @@ namespace Volo.Abp.Cli.Commands
sb.AppendLine(" abp switch-to-stable [options]");
sb.AppendLine("");
sb.AppendLine("Options:");
sb.AppendLine("-sp|--solution-path");
sb.AppendLine("-sd|--solution-directory");
sb.AppendLine("");
sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI");

@ -31,55 +31,74 @@ namespace Volo.Abp.Cli.ProjectModification
{
_packageSourceAdder.Add("ABP Nightly", "https://www.myget.org/F/abp-nightly/api/v3/index.json");
var solutionPath = GetSolutionPath(commandLineArgs);
var solutionFolder = GetSolutionFolder(commandLineArgs);
await _nugetPackagesVersionUpdater.UpdateSolutionAsync(
GetSolutionPath(commandLineArgs),
solutionPath,
true);
await _npmPackagesUpdater.Update(
Path.GetFileName(GetSolutionPath(commandLineArgs)),
solutionFolder,
true);
}
public async Task SwitchToStable(CommandLineArgs commandLineArgs)
{
var solutionPath = GetSolutionPath(commandLineArgs);
var solutionFolder = GetSolutionFolder(commandLineArgs);
await _nugetPackagesVersionUpdater.UpdateSolutionAsync(
GetSolutionPath(commandLineArgs),
solutionPath,
false,
true);
await _npmPackagesUpdater.Update(
Path.GetFileName(GetSolutionPath(commandLineArgs)),
false,
solutionFolder,
false,
true);
}
private string GetSolutionPath(CommandLineArgs commandLineArgs)
{
var solutionPath = commandLineArgs.Options.GetOrNull(Options.SolutionPath.Short, Options.SolutionPath.Long);
var directory = commandLineArgs.Options.GetOrNull(Options.SolutionDirectory.Short, Options.SolutionDirectory.Long)
?? Directory.GetCurrentDirectory();
var solutionPath = Directory.GetFiles(directory, "*.sln").FirstOrDefault();
if (solutionPath == null)
{
try
{
solutionPath = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln").Single();
}
catch (Exception)
var subDirectories = Directory.GetDirectories(directory);
foreach (var subDirectory in subDirectories)
{
Logger.LogError("There is no solution or more that one solution in current directory.");
throw;
var slnInSubDirectory = Directory.GetFiles(subDirectory, "*.sln").FirstOrDefault();
if (slnInSubDirectory != null)
{
return Path.Combine(subDirectory, slnInSubDirectory);
}
}
Logger.LogError("There is no solution or more that one solution in current directory.");
return null;
}
return solutionPath;
}
private string GetSolutionFolder(CommandLineArgs commandLineArgs)
{
return commandLineArgs.Options.GetOrNull(Options.SolutionDirectory.Short, Options.SolutionDirectory.Long)
?? Directory.GetCurrentDirectory();
}
public static class Options
{
public static class SolutionPath
public static class SolutionDirectory
{
public const string Short = "sp";
public const string Long = "solution-path";
public const string Short = "sd";
public const string Long = "solution-directory";
}
}
}

Loading…
Cancel
Save