From 2db39732a5508216f16145828d7b9c5199667904 Mon Sep 17 00:00:00 2001 From: wangjun <510423039@qq.com> Date: Sat, 17 Jun 2023 12:57:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=92=8CCli=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 2 +- .github/workflows/nuget.yml | 2 +- aspnet-core/Directory.Build.Microsoft.targets | 3 +- aspnet-core/Directory.Build.Volo.targets | 1 + aspnet-core/Directory.Build.targets | 2 +- aspnet-core/Lion.AbpPro.sln | 14 ++ .../src/Lion.AbpPro.Cli.Core/GlobalUsings.cs | 22 +++ .../AbpPro/Cli/Github/ILionAbpProManager.cs | 19 +++ .../AbpPro/Cli/Github/LionAbpProManager.cs | 68 +++++++++ .../AbpPro/Cli/Options/LionAbpProOptions.cs | 33 +++++ .../Cli/Options/LionAbpProTemplateOptions.cs | 43 ++++++ .../Cli/SourceCode/ISourceCodeManager.cs | 20 +++ .../Cli/SourceCode/SourceCodeContext.cs | 80 +++++++++++ .../Cli/SourceCode/SourceCodeManager.cs | 135 ++++++++++++++++++ .../AbpPro/Cli/SourceCode/TemplateFile.cs | 26 ++++ .../Core/Cli/LionAbpProCoreCliTestBase.cs | 13 ++ .../Cli/LionAbpProCoreCliTestBaseModule.cs | 24 ++++ .../AbpPro/Core/Cli/LionAbpProManagerTests.cs | 39 +++++ aspnet-core/global.json | 2 +- docs/content/about/6.0-7.0.md | 2 +- 20 files changed, 544 insertions(+), 6 deletions(-) create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/GlobalUsings.cs create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Github/ILionAbpProManager.cs create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Github/LionAbpProManager.cs create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Options/LionAbpProOptions.cs create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Options/LionAbpProTemplateOptions.cs create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/ISourceCodeManager.cs create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeContext.cs create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeManager.cs create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/TemplateFile.cs create mode 100644 aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProCoreCliTestBase.cs create mode 100644 aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProCoreCliTestBaseModule.cs create mode 100644 aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProManagerTests.cs diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 00b1ded1..87c5a391 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Install Dotnet 7.0.102 + - name: Install Dotnet 7.0.304 uses: actions/setup-dotnet@v1 with: dotnet-version: 7.0.x diff --git a/.github/workflows/nuget.yml b/.github/workflows/nuget.yml index a14324a0..926e67eb 100644 --- a/.github/workflows/nuget.yml +++ b/.github/workflows/nuget.yml @@ -12,7 +12,7 @@ jobs: - name: Install Dotnet 7.x uses: actions/setup-dotnet@v1 with: - dotnet-version: 7.0.102 + dotnet-version: 7.0.304 include-prerelease: True - name: Setting Version id: vars diff --git a/aspnet-core/Directory.Build.Microsoft.targets b/aspnet-core/Directory.Build.Microsoft.targets index 1050fd89..ec6e680c 100644 --- a/aspnet-core/Directory.Build.Microsoft.targets +++ b/aspnet-core/Directory.Build.Microsoft.targets @@ -1,7 +1,6 @@  - @@ -14,6 +13,8 @@ + + diff --git a/aspnet-core/Directory.Build.Volo.targets b/aspnet-core/Directory.Build.Volo.targets index de18b670..0ccb7e9f 100644 --- a/aspnet-core/Directory.Build.Volo.targets +++ b/aspnet-core/Directory.Build.Volo.targets @@ -1,6 +1,7 @@  + diff --git a/aspnet-core/Directory.Build.targets b/aspnet-core/Directory.Build.targets index 294a8cf1..d338319c 100644 --- a/aspnet-core/Directory.Build.targets +++ b/aspnet-core/Directory.Build.targets @@ -83,7 +83,7 @@ - + diff --git a/aspnet-core/Lion.AbpPro.sln b/aspnet-core/Lion.AbpPro.sln index caaab4e4..9d07d20c 100644 --- a/aspnet-core/Lion.AbpPro.sln +++ b/aspnet-core/Lion.AbpPro.sln @@ -242,6 +242,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.LanguageManagem EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.CAP.EntityFrameworkCore", "frameworks\src\Lion.AbpPro.CAP.EntityFrameworkCore\Lion.AbpPro.CAP.EntityFrameworkCore.csproj", "{68C902A2-A604-4F3A-879D-37941C00C7A9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.Cli.Core", "frameworks\src\Lion.AbpPro.Cli.Core\Lion.AbpPro.Cli.Core.csproj", "{8D5BD955-FFDC-4895-927F-624C42B64A92}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.Cli", "frameworks\src\Lion.AbpPro.Cli\Lion.AbpPro.Cli.csproj", "{B7A68103-D527-421F-8247-5D169A7F8931}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -588,6 +592,14 @@ Global {68C902A2-A604-4F3A-879D-37941C00C7A9}.Debug|Any CPU.Build.0 = Debug|Any CPU {68C902A2-A604-4F3A-879D-37941C00C7A9}.Release|Any CPU.ActiveCfg = Release|Any CPU {68C902A2-A604-4F3A-879D-37941C00C7A9}.Release|Any CPU.Build.0 = Release|Any CPU + {8D5BD955-FFDC-4895-927F-624C42B64A92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D5BD955-FFDC-4895-927F-624C42B64A92}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D5BD955-FFDC-4895-927F-624C42B64A92}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D5BD955-FFDC-4895-927F-624C42B64A92}.Release|Any CPU.Build.0 = Release|Any CPU + {B7A68103-D527-421F-8247-5D169A7F8931}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B7A68103-D527-421F-8247-5D169A7F8931}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B7A68103-D527-421F-8247-5D169A7F8931}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B7A68103-D527-421F-8247-5D169A7F8931}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -703,6 +715,8 @@ Global {E5994C85-C1C2-44F3-BF10-3277CA6CF2C9} = {3FE23400-A323-46ED-A7F4-30BFF8916D64} {15852D6F-4110-4B98-B89D-5747777E8908} = {3FE23400-A323-46ED-A7F4-30BFF8916D64} {68C902A2-A604-4F3A-879D-37941C00C7A9} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3} + {8D5BD955-FFDC-4895-927F-624C42B64A92} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3} + {B7A68103-D527-421F-8247-5D169A7F8931} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F} diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/GlobalUsings.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/GlobalUsings.cs new file mode 100644 index 00000000..1fc4fe11 --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/GlobalUsings.cs @@ -0,0 +1,22 @@ +// Global using directives + +global using System.Diagnostics.CodeAnalysis; +global using System.Net; +global using System.Text; +global using ICSharpCode.SharpZipLib.Core; +global using ICSharpCode.SharpZipLib.Zip; +global using Lion.AbpPro.Cli.Args; +global using Lion.AbpPro.Cli.Github; +global using Lion.AbpPro.Cli.Options; +global using Lion.AbpPro.Cli.Replace; +global using Lion.AbpPro.Cli.Utils; +global using Lion.AbpPro.Cli.Zip; +global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Extensions.Logging; +global using Microsoft.Extensions.Options; +global using Octokit; +global using Polly; +global using Polly.Retry; +global using Volo.Abp; +global using Volo.Abp.DependencyInjection; +global using Volo.Abp.IO; \ No newline at end of file diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Github/ILionAbpProManager.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Github/ILionAbpProManager.cs new file mode 100644 index 00000000..c6d42558 --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Github/ILionAbpProManager.cs @@ -0,0 +1,19 @@ +namespace Lion.AbpPro.Cli.Github; + +public interface ILionAbpProManager +{ + /// + /// 获取最后一个版本 + /// + Task GetLatestSourceCodeVersionAsync(); + + /// + /// 检查版本是否存在 + /// + Task CheckSourceCodeVersionAsync(string version); + + /// + /// 下载源码 + /// + Task DownloadAsync(string version,string outputPath); +} \ No newline at end of file diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Github/LionAbpProManager.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Github/LionAbpProManager.cs new file mode 100644 index 00000000..2d82157a --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Github/LionAbpProManager.cs @@ -0,0 +1,68 @@ +using Uri = System.Uri; + +namespace Lion.AbpPro.Cli.Github; + +public class LionAbpProManager : ITransientDependency, ILionAbpProManager +{ + private readonly LionAbpProOptions _options; + private readonly IHttpClientFactory _httpClientFactory; + + public LionAbpProManager(IOptions options, IHttpClientFactory httpClientFactory) + { + _httpClientFactory = httpClientFactory; + _options = options.Value; + } + + /// + /// 获取最后一个版本 + /// + public async Task GetLatestSourceCodeVersionAsync() + { + var github = new GitHubClient(new ProductHeaderValue(_options.RepositoryId)) + { + // 匿名访问,api会限流,所以需要设置访问令牌 + Credentials = new Credentials(_options.DecryptToken) + }; + + var release = await github.Repository.Release.GetLatest(_options.Owner, _options.RepositoryId); + return release?.TagName; + } + + /// + /// 检查版本是否存在 + /// + public async Task CheckSourceCodeVersionAsync(string version) + { + try + { + var github = new GitHubClient(new ProductHeaderValue(_options.RepositoryId)) + { + // 匿名访问,api会限流,所以需要设置访问令牌 + Credentials = new Credentials(_options.DecryptToken) + }; + + var release = await github.Repository.Release.Get(_options.Owner, _options.RepositoryId, version); + return release != null; + } + catch + { + return false; + } + } + + /// + /// 下载源码 + /// + public async Task DownloadAsync(string version, string outputPath) + { + var httpClient = _httpClientFactory.CreateClient(); + var uri = new Uri($"https://github.com/{_options.Owner}/{_options.RepositoryId}/archive/refs/tags/{version}.zip"); + var response = await httpClient.GetAsync(uri); + DirectoryHelper.CreateIfNotExists(CliPaths.TemplateCache); + var content = await response.Content.ReadAsByteArrayAsync(); + response.Dispose(); + File.Delete(outputPath); + await File.WriteAllBytesAsync(outputPath, content); + return content; + } +} \ No newline at end of file diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Options/LionAbpProOptions.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Options/LionAbpProOptions.cs new file mode 100644 index 00000000..9c80b8fe --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Options/LionAbpProOptions.cs @@ -0,0 +1,33 @@ +namespace Lion.AbpPro.Cli.Options; + +public class LionAbpProOptions +{ + /// + /// 仓库拥有者 + /// + public string Owner { get; set; } + + /// + /// 仓库Id + /// + public string RepositoryId { get; set; } + + /// + /// Github Token + /// + public string Token { get; set; } + + /// + /// 解密 Github Token + /// + public string DecryptToken => Cryptography.TokenHelper.Decrypt(Token); + + /// + /// 模板信息 + /// + public List Templates { get; set; } + + public string OldCompanyName { get; set; }= "Lion"; + + public string OldProjectName { get; set; } = "AbpPro"; +} \ No newline at end of file diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Options/LionAbpProTemplateOptions.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Options/LionAbpProTemplateOptions.cs new file mode 100644 index 00000000..c87a0b23 --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Options/LionAbpProTemplateOptions.cs @@ -0,0 +1,43 @@ +namespace Lion.AbpPro.Cli.Options; + +public class LionAbpProTemplateOptions +{ + public LionAbpProTemplateOptions(string key, string name, string description, bool isSource = false) + { + Key = key; + Name = name; + Description = description; + IsSource = isSource; + } + + /// + /// 模板key + /// 对应templates下文件夹名称 + /// + public string Key { get; set; } + + /// + /// cli -t 对应参数 + /// + public string Name { get; set; } + + /// + /// 描述 + /// + public string Description { get; set; } + + /// + /// 需要替换的文件 + /// + public string ReplaceSuffix { get; set; } + + /// + /// 需要排除的文件 + /// + public string ExcludeFiles { get; set; } + + /// + /// 是否源码版本 + /// + public bool IsSource { get; set; } +} \ No newline at end of file diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/ISourceCodeManager.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/ISourceCodeManager.cs new file mode 100644 index 00000000..0263e5f1 --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/ISourceCodeManager.cs @@ -0,0 +1,20 @@ +namespace Lion.AbpPro.Cli.SourceCode; + +public interface ISourceCodeManager +{ + /// + /// 获取源码 + /// + /// 版本 + Task GetAsync(string version); + + /// + /// 解压 + /// + void ExtractProjectZip(SourceCodeContext context); + + /// + /// 替换 + /// + void ReplaceTemplates(SourceCodeContext context); +} \ No newline at end of file diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeContext.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeContext.cs new file mode 100644 index 00000000..e1c01982 --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeContext.cs @@ -0,0 +1,80 @@ +namespace Lion.AbpPro.Cli.SourceCode; + +public class SourceCodeContext +{ + /// + /// 模板信息 + /// + public TemplateFile TemplateFile { get; set; } + + /// + /// 需要替换的文件 + /// + public string ReplaceSuffix { get; set; } + + /// + /// 需要排除的文件 + /// + public string ExcludeFiles { get; set; } + + /// + /// 替换CompanyName + /// + public string OldCompanyName { get; set; } + + /// + /// 替换ProjectName + /// + public string OldProjectName { get; set; } + /// + /// New CompanyName + /// + public string CompanyName { get; set; } + /// + /// New ProjectName + /// + public string ProjectName { get; set; } + /// + /// 输入文件夹 + /// + public string OutputFolder { get; set; } + /// + /// 模板文件夹 + /// + public string TemplateFolder { get; set; } + + /// + /// 模板key + /// + public string TemplateKey { get; set; } + + /// + /// 模板名称 + /// + public string TemplateName { get; set; } + + /// + /// 解压目录 + /// + public string ExtractProjectPath { get; set; } + + /// + /// 是否源码版本 + /// + public bool IsSource { get; set; } + + /// + /// 仓库拥有者 + /// + public string Owner { get; set; } + + /// + /// 仓库Id + /// + public string RepositoryId { get; set; } + + /// + /// Github Token + /// + public string Token { get; set; } +} \ No newline at end of file diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeManager.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeManager.cs new file mode 100644 index 00000000..6a622f0f --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeManager.cs @@ -0,0 +1,135 @@ +namespace Lion.AbpPro.Cli.SourceCode; + +public class SourceCodeManager : ITransientDependency, ISourceCodeManager +{ + private readonly ILogger _logger; + private readonly ILionAbpProManager _lionAbpProManager; + private readonly LionAbpProOptions _options; + + public SourceCodeManager(ILogger logger, IOptions options, ILionAbpProManager lionAbpProManager) + { + _logger = logger; + _lionAbpProManager = lionAbpProManager; + _options = options.Value; + } + + /// + /// 获取源码 + /// + /// 版本 + public async Task GetAsync(string version) + { + var latestVersion = await _lionAbpProManager.GetLatestSourceCodeVersionAsync(); + if (version == null) + { + version = latestVersion ?? throw new Exception("请检查版本是否正确"); + } + else + { + if (!await _lionAbpProManager.CheckSourceCodeVersionAsync(version)) + { + throw new Exception("没有找到指定的版本: " + version); + } + } + + var localCacheFile = Path.Combine(CliPaths.TemplateCache, _options.RepositoryId + "-" + version + ".zip"); + + _logger.LogInformation($"Lion AbpPro Version:{version}"); + _logger.LogInformation($"模板生成中......"); + if (!File.Exists(localCacheFile)) + { + return new TemplateFile(version, localCacheFile, await _lionAbpProManager.DownloadAsync(version, localCacheFile)); + } + else + { + return new TemplateFile(version, localCacheFile, await File.ReadAllBytesAsync(localCacheFile)); + } + } + + + public void ExtractProjectZip(SourceCodeContext context) + { + using (var templateFileStream = new MemoryStream(context.TemplateFile.FileBytes)) + { + using (var zipInputStream = new ZipInputStream(templateFileStream)) + { + var zipEntry = zipInputStream.GetNextEntry(); + while (zipEntry != null) + { + if (string.IsNullOrWhiteSpace(zipEntry.Name)) + { + zipEntry = zipInputStream.GetNextEntry(); + continue; + } + + var fullZipToPath = Path.Combine(CliPaths.TemplateCache, zipEntry.Name); + var directoryName = Path.GetDirectoryName(fullZipToPath); + + if (!string.IsNullOrEmpty(directoryName)) + { + Directory.CreateDirectory(directoryName); + } + + var fileName = Path.GetFileName(fullZipToPath); + if (fileName.Length == 0) + { + zipEntry = zipInputStream.GetNextEntry(); + continue; + } + + var buffer = new byte[4096]; // 4K is optimum + using (var streamWriter = File.Create(fullZipToPath)) + { + StreamUtils.Copy(zipInputStream, streamWriter, buffer); + } + + zipEntry = zipInputStream.GetNextEntry(); + } + } + } + + context.ExtractProjectPath = Path.Combine(CliPaths.TemplateCache, _options.RepositoryId + "-" + context.TemplateFile.Version); + } + + public void MoveTemplate(SourceCodeContext context) + { + // var codePath= Path.Combine(context.OutputFolder, context.CompanyName + "." + context.ProjectName); + // + // DirectoryHelper.DeleteIfExists(codePath,true); + // + // if (context.IsSource) + // { + // context.TemplateFolder = Path.Combine(context.OutputFolder, _options.RepositoryId + "-" + context.TemplateFile.Version); + // } + // else + // { + // // 获取本地源码地址 + // context.TemplateFolder = Path.Combine(context.OutputFolder, _options.RepositoryId + "-" + context.TemplateFile.Version, "templates", context.TemplateKey); + // } + // + // Directory.Move(context.TemplateFolder, codePath); + // context.OutputFolder = codePath; + + DirectoryAndFileHelper.CopyFolder(context.ExtractProjectPath, context.OutputFolder, "docs"); + } + + public void ReplaceTemplates(SourceCodeContext context) + { + ReplaceHelper.ReplaceTemplates(context.ExtractProjectPath, context.OldCompanyName, context.OldProjectName, context.CompanyName, context.ProjectName, context.ReplaceSuffix); + if (context.IsSource) + { + context.TemplateFolder = context.ExtractProjectPath; + } + else + { + // 获取本地源码地址 + context.TemplateFolder = Path.Combine(context.ExtractProjectPath, _options.RepositoryId + "-" + context.TemplateFile.Version, "templates", context.TemplateKey); + } + + context.OutputFolder = Path.Combine(context.OutputFolder, context.CompanyName + "." + context.ProjectName); + DirectoryHelper.DeleteIfExists(context.OutputFolder, true); + DirectoryAndFileHelper.CopyFolder(context.TemplateFolder, context.OutputFolder, context.ExcludeFiles); + DirectoryHelper.DeleteIfExists(context.ExtractProjectPath, true); + _logger.LogInformation($"OutputFolder:{context.OutputFolder}"); + } +} \ No newline at end of file diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/TemplateFile.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/TemplateFile.cs new file mode 100644 index 00000000..ba5b2a72 --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/TemplateFile.cs @@ -0,0 +1,26 @@ +namespace Lion.AbpPro.Cli.SourceCode; + +public class TemplateFile +{ + public TemplateFile(string version, string sourceCodePath, byte[] fileBytes) + { + Version = version; + SourceCodePath = sourceCodePath; + FileBytes = fileBytes; + } + + /// + /// 模板文件字节流 + /// + public byte[] FileBytes { get; } + + /// + /// 版本 + /// + public string Version { get; } + + /// + /// 模板zip压缩包地址 + /// + public string SourceCodePath { get; } +} \ No newline at end of file diff --git a/aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProCoreCliTestBase.cs b/aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProCoreCliTestBase.cs new file mode 100644 index 00000000..078484ee --- /dev/null +++ b/aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProCoreCliTestBase.cs @@ -0,0 +1,13 @@ +using Volo.Abp; +using Volo.Abp.Testing; + +namespace Lion.AbpPro.Core.Cli +{ + public abstract class LionAbpProCoreCliTestBase : AbpIntegratedTest + { + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } + } +} \ No newline at end of file diff --git a/aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProCoreCliTestBaseModule.cs b/aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProCoreCliTestBaseModule.cs new file mode 100644 index 00000000..ca4bd393 --- /dev/null +++ b/aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProCoreCliTestBaseModule.cs @@ -0,0 +1,24 @@ +using Lion.AbpPro.Cli; +using Volo.Abp; +using Volo.Abp.Autofac; +using Volo.Abp.Modularity; +using LionAbpProOptions = Lion.AbpPro.Cli.Options.LionAbpProOptions; + +namespace Lion.AbpPro.Core.Cli +{ + [DependsOn(typeof(AbpTestBaseModule), + typeof(AbpProCliCoreModule))] + public class LionAbpProCoreCliTestBaseModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + + Configure(options => + { + options.Owner = "WangJunZzz"; + options.RepositoryId = "abp-vnext-pro"; + options.Token = "abp-vnext-proghp_47vqiabp-vnext-provNkHKJguOJkdHvnxUabp-vnext-protij7Qbdn1Qy3fUabp-vnext-pro"; + }); + } + } +} \ No newline at end of file diff --git a/aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProManagerTests.cs b/aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProManagerTests.cs new file mode 100644 index 00000000..342b942b --- /dev/null +++ b/aspnet-core/frameworks/test/Lion.AbpPro.Core.Cli.Tests/Lion/AbpPro/Core/Cli/LionAbpProManagerTests.cs @@ -0,0 +1,39 @@ +using Lion.AbpPro.Cli.Github; +using Shouldly; +using Xunit; + +namespace Lion.AbpPro.Core.Cli; + +public sealed class LionAbpProManagerTests : LionAbpProCoreCliTestBase +{ + private readonly ILionAbpProManager _lionAbpProManager; + + public LionAbpProManagerTests() + { + _lionAbpProManager = GetRequiredService(); + } + + [Fact] + public async Task GetLatestSourceCodeVersionAsync() + { + var result= await _lionAbpProManager.GetLatestSourceCodeVersionAsync(); + result.ShouldBe("7.2.2.3"); + } + + [Fact] + public async Task CheckSourceCodeVersionAsync() + { + var result= await _lionAbpProManager.CheckSourceCodeVersionAsync("7.2.2.3"); + result.ShouldBe(true); + + var result1= await _lionAbpProManager.CheckSourceCodeVersionAsync("1.2.2.3"); + result1.ShouldBe(false); + } + + [Fact] + public async Task DownloadAsync() + { + //await _lionAbpProManager.DownloadAsync("7.2.2.3"); + + } +} \ No newline at end of file diff --git a/aspnet-core/global.json b/aspnet-core/global.json index b6ff0a69..065581b4 100644 --- a/aspnet-core/global.json +++ b/aspnet-core/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.102", + "version": "7.0.304", "rollForward": "latestFeature" } } diff --git a/docs/content/about/6.0-7.0.md b/docs/content/about/6.0-7.0.md index 36576361..5d35f32e 100644 --- a/docs/content/about/6.0-7.0.md +++ b/docs/content/about/6.0-7.0.md @@ -7,7 +7,7 @@ ```json { "sdk": { - "version": "7.0.102", + "version": "7.0.304", "rollForward": "latestFeature" } }