Browse Source

Support to install the MVC npm package.

pull/23136/head
maliming 1 year ago
parent
commit
058af963f0
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 16
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs
  2. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/INpmPackageInfoProvider.cs
  3. 4
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/NpmPackageInfoProvider.cs
  4. 43
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNpmPackageAdder.cs
  5. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs

16
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs

@ -15,7 +15,7 @@ namespace Volo.Abp.Cli.Commands;
public class AddPackageCommand : IConsoleCommand, ITransientDependency public class AddPackageCommand : IConsoleCommand, ITransientDependency
{ {
public const string Name = "add-package"; public const string Name = "add-package";
public ILogger<AddPackageCommand> Logger { get; set; } public ILogger<AddPackageCommand> Logger { get; set; }
protected ProjectNugetPackageAdder ProjectNugetPackageAdder { get; } protected ProjectNugetPackageAdder ProjectNugetPackageAdder { get; }
@ -40,12 +40,12 @@ public class AddPackageCommand : IConsoleCommand, ITransientDependency
); );
} }
var isAngularPackage = false; var isNpmPackage = false;
var isNugetPackage = true; var isNugetPackage = true;
if (commandLineArgs.Target.StartsWith("@")) if (commandLineArgs.Target.StartsWith("@"))
{ {
isAngularPackage = true; isNpmPackage = true;
isNugetPackage = false; isNugetPackage = false;
} }
@ -66,16 +66,15 @@ public class AddPackageCommand : IConsoleCommand, ITransientDependency
addSourceCodeToSolutionFile addSourceCodeToSolutionFile
); );
} }
else if (isAngularPackage) else if (isNpmPackage)
{ {
await ProjectNpmPackageAdder.AddAngularPackageAsync( await ProjectNpmPackageAdder.AddNpmPackageAsync(
GetAngularDirectory(commandLineArgs), GetAngularDirectory(commandLineArgs),
commandLineArgs.Target, commandLineArgs.Target,
version, version,
withSourceCode withSourceCode
); );
} }
} }
public string GetUsageInfo() public string GetUsageInfo()
@ -84,7 +83,7 @@ public class AddPackageCommand : IConsoleCommand, ITransientDependency
sb.AppendLine(""); sb.AppendLine("");
sb.AppendLine("'add-package' command is used to add an ABP package to a project."); sb.AppendLine("'add-package' command is used to add an ABP package to a project.");
sb.AppendLine("It should be used in a folder containing a .csproj file, .sln file or angular.json."); sb.AppendLine("It should be used in a folder containing a .csproj file, .sln file or packages.json.");
sb.AppendLine(""); sb.AppendLine("");
sb.AppendLine("Usage:"); sb.AppendLine("Usage:");
sb.AppendLine(""); sb.AppendLine("");
@ -94,7 +93,7 @@ public class AddPackageCommand : IConsoleCommand, ITransientDependency
sb.AppendLine(""); sb.AppendLine("");
sb.AppendLine(" -p|--project <project-file> Specifies the project file explicitly. (Only available for NuGet packages)"); sb.AppendLine(" -p|--project <project-file> Specifies the project file explicitly. (Only available for NuGet packages)");
sb.AppendLine(" -s|--solution <solution-file> Specifies the solution file explicitly. (Only available for NuGet packages)"); sb.AppendLine(" -s|--solution <solution-file> Specifies the solution file explicitly. (Only available for NuGet packages)");
sb.AppendLine(" --with-source-code Downloads the source code of the NPM/NuGet package and make other projects depends on it."); sb.AppendLine(" --with-source-code Downloads the source code of the Angular NPM/NuGet package and make other projects depends on it.");
sb.AppendLine(" --add-to-solution-file Adds the downloaded project to the .sln file, when source code is downloaded. (Only available for NuGet packages)"); sb.AppendLine(" --add-to-solution-file Adds the downloaded project to the .sln file, when source code is downloaded. (Only available for NuGet packages)");
sb.AppendLine(" -ad|--angular-directory <angular-project-directory> Specifies the Angular project directory explicitly. (Only available for Angular packages)"); sb.AppendLine(" -ad|--angular-directory <angular-project-directory> Specifies the Angular project directory explicitly. (Only available for Angular packages)");
sb.AppendLine(" -v|--version <version> Specifies the version of the package. Default is your project's ABP version or latest ABP version."); sb.AppendLine(" -v|--version <version> Specifies the version of the package. Default is your project's ABP version or latest ABP version.");
@ -103,6 +102,7 @@ public class AddPackageCommand : IConsoleCommand, ITransientDependency
sb.AppendLine(""); sb.AppendLine("");
sb.AppendLine(" abp add-package Volo.Abp.FluentValidation Adds the NuGet package to the current project."); sb.AppendLine(" abp add-package Volo.Abp.FluentValidation Adds the NuGet package to the current project.");
sb.AppendLine(" abp add-package Volo.Abp.FluentValidation -p Acme.BookStore.Application Adds the NuGet package to the given project."); sb.AppendLine(" abp add-package Volo.Abp.FluentValidation -p Acme.BookStore.Application Adds the NuGet package to the given project.");
sb.AppendLine(" abp add-package @abp/signalr Adds the NPM package to the given corresponding project.");
sb.AppendLine(" abp add-package @abp/ng.theme.basic Adds the NPM package to the given corresponding project."); sb.AppendLine(" abp add-package @abp/ng.theme.basic Adds the NPM package to the given corresponding project.");
sb.AppendLine(""); sb.AppendLine("");
sb.AppendLine("See the documentation for more info: https://abp.io/docs/latest/cli"); sb.AppendLine("See the documentation for more info: https://abp.io/docs/latest/cli");

5
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/INpmPackageInfoProvider.cs

@ -1,4 +1,5 @@
using System.Threading.Tasks; using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Cli.ProjectModification; using Volo.Abp.Cli.ProjectModification;
namespace Volo.Abp.Cli.ProjectBuilding; namespace Volo.Abp.Cli.ProjectBuilding;
@ -6,4 +7,6 @@ namespace Volo.Abp.Cli.ProjectBuilding;
public interface INpmPackageInfoProvider public interface INpmPackageInfoProvider
{ {
Task<NpmPackageInfo> GetAsync(string name); Task<NpmPackageInfo> GetAsync(string name);
Task<List<NpmPackageInfo>> GetPackageListAsync();
} }

4
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/NpmPackageInfoProvider.cs

@ -32,7 +32,7 @@ public class NpmPackageInfoProvider : INpmPackageInfoProvider, ITransientDepende
public async Task<NpmPackageInfo> GetAsync(string name) public async Task<NpmPackageInfo> GetAsync(string name)
{ {
var packageList = await GetPackageListInternalAsync(); var packageList = await GetPackageListAsync();
var package = packageList.FirstOrDefault(m => m.Name == name); var package = packageList.FirstOrDefault(m => m.Name == name);
@ -44,7 +44,7 @@ public class NpmPackageInfoProvider : INpmPackageInfoProvider, ITransientDepende
return package; return package;
} }
private async Task<List<NpmPackageInfo>> GetPackageListInternalAsync() public async Task<List<NpmPackageInfo>> GetPackageListAsync()
{ {
var client = _cliHttpClientFactory.CreateClient(); var client = _cliHttpClientFactory.CreateClient();

43
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNpmPackageAdder.cs

@ -24,16 +24,20 @@ public class ProjectNpmPackageAdder : ITransientDependency
public IRemoteServiceExceptionHandler RemoteServiceExceptionHandler { get; } public IRemoteServiceExceptionHandler RemoteServiceExceptionHandler { get; }
public IInstallLibsService InstallLibsService { get; } public IInstallLibsService InstallLibsService { get; }
public ICmdHelper CmdHelper { get; } public ICmdHelper CmdHelper { get; }
private readonly CliHttpClientFactory _cliHttpClientFactory; public CliHttpClientFactory CliHttpClientFactory { get; }
public INpmPackageInfoProvider NpmPackageInfoProvider { get; }
public ILogger<ProjectNpmPackageAdder> Logger { get; set; } public ILogger<ProjectNpmPackageAdder> Logger { get; set; }
public ProjectNpmPackageAdder(CliHttpClientFactory cliHttpClientFactory, public ProjectNpmPackageAdder(
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
SourceCodeDownloadService sourceCodeDownloadService, SourceCodeDownloadService sourceCodeDownloadService,
AngularSourceCodeAdder angularSourceCodeAdder, AngularSourceCodeAdder angularSourceCodeAdder,
IRemoteServiceExceptionHandler remoteServiceExceptionHandler, IRemoteServiceExceptionHandler remoteServiceExceptionHandler,
IInstallLibsService installLibsService, IInstallLibsService installLibsService,
ICmdHelper cmdHelper) ICmdHelper cmdHelper,
CliHttpClientFactory cliHttpClientFactory,
INpmPackageInfoProvider npmPackageInfoProvider)
{ {
JsonSerializer = jsonSerializer; JsonSerializer = jsonSerializer;
SourceCodeDownloadService = sourceCodeDownloadService; SourceCodeDownloadService = sourceCodeDownloadService;
@ -41,14 +45,16 @@ public class ProjectNpmPackageAdder : ITransientDependency
RemoteServiceExceptionHandler = remoteServiceExceptionHandler; RemoteServiceExceptionHandler = remoteServiceExceptionHandler;
InstallLibsService = installLibsService; InstallLibsService = installLibsService;
CmdHelper = cmdHelper; CmdHelper = cmdHelper;
_cliHttpClientFactory = cliHttpClientFactory; CliHttpClientFactory = cliHttpClientFactory;
NpmPackageInfoProvider = npmPackageInfoProvider;
Logger = NullLogger<ProjectNpmPackageAdder>.Instance; Logger = NullLogger<ProjectNpmPackageAdder>.Instance;
} }
public async Task AddAngularPackageAsync(string directory, string npmPackageName, string version = null, public async Task AddNpmPackageAsync(string directory, string npmPackageName, string version = null,
bool withSourceCode = false) bool withSourceCode = false)
{ {
await AddAngularPackageAsync( await AddNpmPackageAsync(
directory, directory,
await FindNpmPackageInfoAsync(npmPackageName), await FindNpmPackageInfoAsync(npmPackageName),
version, version,
@ -56,7 +62,7 @@ public class ProjectNpmPackageAdder : ITransientDependency
); );
} }
public async Task AddAngularPackageAsync(string directory, NpmPackageInfo npmPackage, string version = null, public async Task AddNpmPackageAsync(string directory, NpmPackageInfo npmPackage, string version = null,
bool withSourceCode = false) bool withSourceCode = false)
{ {
var packageJsonFilePath = Path.Combine(directory, "package.json"); var packageJsonFilePath = Path.Combine(directory, "package.json");
@ -83,16 +89,27 @@ public class ProjectNpmPackageAdder : ITransientDependency
Logger.LogInformation($"'{npmPackage.Name}' is already installed."); Logger.LogInformation($"'{npmPackage.Name}' is already installed.");
} }
if (withSourceCode) if (withSourceCode && await DownloadAngularSourceCode(directory, npmPackage, version))
{ {
await DownloadAngularSourceCode(directory, npmPackage, version);
await AngularSourceCodeAdder.AddAsync(directory, npmPackage); await AngularSourceCodeAdder.AddAsync(directory, npmPackage);
} }
} }
protected virtual async Task DownloadAngularSourceCode(string angularDirectory, NpmPackageInfo package, protected virtual async Task<bool> DownloadAngularSourceCode(string angularDirectory, NpmPackageInfo package,
string version = null) string version = null)
{ {
var downloadablePackages = await NpmPackageInfoProvider.GetPackageListAsync();
if (!downloadablePackages.Exists(p => p.Name == package.Name))
{
Logger.LogError($"'{package.Name}' is not downloadable!");
Logger.LogInformation("The downloadable packages are: ");
foreach (var downloadablePackage in downloadablePackages)
{
Logger.LogInformation($"> {downloadablePackage.Name}");
}
return false;
}
var targetFolder = Path.Combine(angularDirectory, "projects", var targetFolder = Path.Combine(angularDirectory, "projects",
package.Name.RemovePreFix("@").Replace("/", "-")); package.Name.RemovePreFix("@").Replace("/", "-"));
@ -106,6 +123,8 @@ public class ProjectNpmPackageAdder : ITransientDependency
targetFolder, targetFolder,
version version
); );
return true;
} }
public async Task AddMvcPackageAsync(string directory, NpmPackageInfo npmPackage, string version = null, public async Task AddMvcPackageAsync(string directory, NpmPackageInfo npmPackage, string version = null,
@ -210,9 +229,9 @@ public class ProjectNpmPackageAdder : ITransientDependency
private async Task<NpmPackageInfo> FindNpmPackageInfoAsync(string packageName) private async Task<NpmPackageInfo> FindNpmPackageInfoAsync(string packageName)
{ {
var url = $"{CliUrls.WwwAbpIo}api/app/npmPackage/byName/?name=" + packageName; var url = $"{CliUrls.WwwAbpIo}api/app/npmPackage/byName/?name=" + packageName;
var client = _cliHttpClientFactory.CreateClient(); var client = CliHttpClientFactory.CreateClient();
using (var response = await client.GetAsync(url, _cliHttpClientFactory.GetCancellationToken())) using (var response = await client.GetAsync(url, CliHttpClientFactory.GetCancellationToken()))
{ {
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode)
{ {

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs

@ -513,7 +513,7 @@ public class SolutionModuleAdder : ITransientDependency
foreach (var npmPackage in angularPackages) foreach (var npmPackage in angularPackages)
{ {
await ProjectNpmPackageAdder.AddAngularPackageAsync(angularPath, npmPackage); await ProjectNpmPackageAdder.AddNpmPackageAsync(angularPath, npmPackage);
} }
} }
} }

Loading…
Cancel
Save