Browse Source

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 7 years ago
parent
commit
f9050f93b9
  1. 4
      docs/en/CLI.md
  2. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchNightlyPreviewCommand.cs
  3. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchStableCommand.cs
  4. 53
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceSwitcher.cs

4
docs/en/CLI.md

@ -141,7 +141,7 @@ abp switch-to-preview [options]
```` ````
#### 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 ### switch-to-stable
@ -154,7 +154,7 @@ abp switch-to-stable [options]
```` ````
#### 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 ### login

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchNightlyPreviewCommand.cs

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

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchStableCommand.cs

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

53
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceSwitcher.cs

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

Loading…
Cancel
Save