mirror of https://github.com/abpframework/abp.git
18 changed files with 496 additions and 55 deletions
@ -0,0 +1,18 @@ |
|||
using Volo.Abp.Cli.ProjectBuilding.Building.Steps; |
|||
using Volo.Abp.Cli.ProjectBuilding.Templates; |
|||
|
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building |
|||
{ |
|||
public static class NpmPackageProjectBuildPipelineBuilder |
|||
{ |
|||
public static ProjectBuildPipeline Build(ProjectBuildContext context) |
|||
{ |
|||
var pipeline = new ProjectBuildPipeline(context); |
|||
|
|||
pipeline.Steps.Add(new FileEntryListReadStep()); |
|||
pipeline.Steps.Add(new CreateProjectResultZipStep()); |
|||
|
|||
return pipeline; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Cli.ProjectModification; |
|||
|
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public interface INpmPackageInfoProvider |
|||
{ |
|||
Task<NpmPackageInfo> GetAsync(string name); |
|||
} |
|||
} |
|||
@ -0,0 +1,62 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Json; |
|||
using Volo.Abp.Cli.Http; |
|||
using Volo.Abp.Cli.ProjectModification; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public class NpmPackageInfoProvider : INpmPackageInfoProvider, ITransientDependency |
|||
{ |
|||
public IJsonSerializer JsonSerializer { get; } |
|||
public ICancellationTokenProvider CancellationTokenProvider { get; } |
|||
public IRemoteServiceExceptionHandler RemoteServiceExceptionHandler { get; } |
|||
|
|||
private readonly CliHttpClientFactory _cliHttpClientFactory; |
|||
|
|||
public NpmPackageInfoProvider( |
|||
IJsonSerializer jsonSerializer, |
|||
ICancellationTokenProvider cancellationTokenProvider, |
|||
IRemoteServiceExceptionHandler remoteServiceExceptionHandler, |
|||
CliHttpClientFactory cliHttpClientFactory) |
|||
{ |
|||
JsonSerializer = jsonSerializer; |
|||
CancellationTokenProvider = cancellationTokenProvider; |
|||
RemoteServiceExceptionHandler = remoteServiceExceptionHandler; |
|||
_cliHttpClientFactory = cliHttpClientFactory; |
|||
} |
|||
|
|||
public async Task<NpmPackageInfo> GetAsync(string name) |
|||
{ |
|||
var packageList = await GetPackageListInternalAsync(); |
|||
|
|||
var package = packageList.FirstOrDefault(m => m.Name == name); |
|||
|
|||
if (package == null) |
|||
{ |
|||
throw new Exception("Package is not found or downloadable!"); |
|||
} |
|||
|
|||
return package; |
|||
} |
|||
|
|||
private async Task<List<NpmPackageInfo>> GetPackageListInternalAsync() |
|||
{ |
|||
var client = _cliHttpClientFactory.CreateClient(); |
|||
|
|||
using (var responseMessage = await client.GetAsync( |
|||
$"{CliUrls.WwwAbpIo}api/download/npmPackages/", |
|||
CancellationTokenProvider.Token |
|||
)) |
|||
{ |
|||
await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(responseMessage); |
|||
var result = await responseMessage.Content.ReadAsStringAsync(); |
|||
return JsonSerializer.Deserialize<List<NpmPackageInfo>>(result); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,110 @@ |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Extensions.Logging.Abstractions; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Cli.Commands; |
|||
using Volo.Abp.Cli.Licensing; |
|||
using Volo.Abp.Cli.ProjectBuilding.Analyticses; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building; |
|||
using Volo.Abp.Cli.ProjectModification; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Json; |
|||
|
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public class NpmPackageProjectBuilder : IProjectBuilder, ITransientDependency |
|||
{ |
|||
public ILogger<NpmPackageProjectBuilder> Logger { get; set; } |
|||
protected ISourceCodeStore SourceCodeStore { get; } |
|||
protected INpmPackageInfoProvider NpmPackageInfoProvider { get; } |
|||
protected ICliAnalyticsCollect CliAnalyticsCollect { get; } |
|||
protected AbpCliOptions Options { get; } |
|||
protected IJsonSerializer JsonSerializer { get; } |
|||
protected IApiKeyService ApiKeyService { get; } |
|||
|
|||
public NpmPackageProjectBuilder(ISourceCodeStore sourceCodeStore, |
|||
INpmPackageInfoProvider npmPackageInfoProvider, |
|||
ICliAnalyticsCollect cliAnalyticsCollect, |
|||
IOptions<AbpCliOptions> options, |
|||
IJsonSerializer jsonSerializer, |
|||
IApiKeyService apiKeyService) |
|||
{ |
|||
SourceCodeStore = sourceCodeStore; |
|||
NpmPackageInfoProvider = npmPackageInfoProvider; |
|||
CliAnalyticsCollect = cliAnalyticsCollect; |
|||
Options = options.Value; |
|||
JsonSerializer = jsonSerializer; |
|||
ApiKeyService = apiKeyService; |
|||
|
|||
Logger = NullLogger<NpmPackageProjectBuilder>.Instance; |
|||
} |
|||
|
|||
public async Task<ProjectBuildResult> BuildAsync(ProjectBuildArgs args) |
|||
{ |
|||
var packageInfo = await GetPackageInfoAsync(args); |
|||
|
|||
var templateFile = await SourceCodeStore.GetAsync( |
|||
args.TemplateName, |
|||
SourceCodeTypes.NpmPackage, |
|||
args.Version, |
|||
null, |
|||
args.ExtraProperties.ContainsKey(GetSourceCommand.Options.Preview.Long) |
|||
); |
|||
|
|||
var apiKeyResult = await ApiKeyService.GetApiKeyOrNullAsync(); |
|||
if (apiKeyResult?.ApiKey != null) |
|||
{ |
|||
args.ExtraProperties["api-key"] = apiKeyResult.ApiKey; |
|||
} |
|||
|
|||
if (apiKeyResult?.LicenseCode != null) |
|||
{ |
|||
args.ExtraProperties["license-code"] = apiKeyResult.LicenseCode; |
|||
} |
|||
|
|||
var context = new ProjectBuildContext( |
|||
null, |
|||
null, |
|||
null, |
|||
packageInfo, |
|||
templateFile, |
|||
args |
|||
); |
|||
|
|||
NpmPackageProjectBuildPipelineBuilder.Build(context).Execute(); |
|||
|
|||
// Exclude unwanted or known options.
|
|||
var options = args.ExtraProperties |
|||
.Where(x => !x.Key.Equals(CliConsts.Command, StringComparison.InvariantCultureIgnoreCase)) |
|||
.Where(x => !x.Key.Equals(NewCommand.Options.OutputFolder.Long, StringComparison.InvariantCultureIgnoreCase) && |
|||
!x.Key.Equals(NewCommand.Options.OutputFolder.Short, StringComparison.InvariantCultureIgnoreCase)) |
|||
.Where(x => !x.Key.Equals(NewCommand.Options.Version.Long, StringComparison.InvariantCultureIgnoreCase) && |
|||
!x.Key.Equals(NewCommand.Options.Version.Short, StringComparison.InvariantCultureIgnoreCase)) |
|||
.Where(x => !x.Key.Equals(NewCommand.Options.TemplateSource.Short, StringComparison.InvariantCultureIgnoreCase) && |
|||
!x.Key.Equals(NewCommand.Options.TemplateSource.Long, StringComparison.InvariantCultureIgnoreCase)) |
|||
.Select(x => x.Key).ToList(); |
|||
|
|||
await CliAnalyticsCollect.CollectAsync(new CliAnalyticsCollectInputDto |
|||
{ |
|||
Tool = Options.ToolName, |
|||
Command = args.ExtraProperties.ContainsKey(CliConsts.Command) ? args.ExtraProperties[CliConsts.Command] : "", |
|||
DatabaseProvider = null, |
|||
IsTiered = null, |
|||
UiFramework = null, |
|||
Options = JsonSerializer.Serialize(options), |
|||
ProjectName = null, |
|||
TemplateName = args.TemplateName, |
|||
TemplateVersion = templateFile.Version |
|||
}); |
|||
|
|||
return new ProjectBuildResult(context.Result.ZipContent, args.TemplateName); |
|||
} |
|||
|
|||
private async Task<NpmPackageInfo> GetPackageInfoAsync(ProjectBuildArgs args) |
|||
{ |
|||
return await NpmPackageInfoProvider.GetAsync(args.TemplateName); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue