diff --git a/Yi.Abp.Net8/tool/Yi.Abp.Tool.Application.Contracts/ITemplateGenService.cs b/Yi.Abp.Net8/tool/Yi.Abp.Tool.Application.Contracts/ITemplateGenService.cs index b8f8fffb..09658494 100644 --- a/Yi.Abp.Net8/tool/Yi.Abp.Tool.Application.Contracts/ITemplateGenService.cs +++ b/Yi.Abp.Net8/tool/Yi.Abp.Tool.Application.Contracts/ITemplateGenService.cs @@ -6,7 +6,7 @@ namespace Yi.Abp.Tool.Application.Contracts { public interface ITemplateGenService: IApplicationService { - Task CreateModuleAsync(TemplateGenCreateInputDto moduleCreateInputDto); - Task CreateProjectAsync(TemplateGenCreateInputDto moduleCreateInputDto); + Task CreateModuleAsync(TemplateGenCreateInputDto moduleCreateInputDto); + Task CreateProjectAsync(TemplateGenCreateInputDto moduleCreateInputDto); } } diff --git a/Yi.Abp.Net8/tool/Yi.Abp.Tool.Application/TemplateGenService.cs b/Yi.Abp.Net8/tool/Yi.Abp.Tool.Application/TemplateGenService.cs index ab8638b1..7cd03b35 100644 --- a/Yi.Abp.Net8/tool/Yi.Abp.Tool.Application/TemplateGenService.cs +++ b/Yi.Abp.Net8/tool/Yi.Abp.Tool.Application/TemplateGenService.cs @@ -25,7 +25,7 @@ namespace Yi.Abp.Tool.Application /// 下载模块文件 /// /// - public async Task CreateModuleAsync(TemplateGenCreateInputDto moduleCreateInputDto) + public async Task CreateModuleAsync(TemplateGenCreateInputDto moduleCreateInputDto) { moduleCreateInputDto.SetNameReplace(); @@ -33,17 +33,17 @@ namespace Yi.Abp.Tool.Application input.SetTemplateFilePath(_templateGenManager._toolOptions.ModuleTemplateFilePath); var filePath = await _templateGenManager.CreateTemplateAsync(input); - //考虑从路径中获取 - var fileContentType = MimeHelper.GetMimeMapping(Path.GetFileName(filePath)); + ////考虑从路径中获取 + //var fileContentType = MimeHelper.GetMimeMapping(Path.GetFileName(filePath)); //设置附件下载,下载名称 - return new FileContentResult(await File.ReadAllBytesAsync(filePath), fileContentType); + return await File.ReadAllBytesAsync(filePath); } /// /// 下载模块文件 /// /// - public async Task CreateProjectAsync(TemplateGenCreateInputDto moduleCreateInputDto) + public async Task CreateProjectAsync(TemplateGenCreateInputDto moduleCreateInputDto) { moduleCreateInputDto.SetNameReplace(); @@ -52,9 +52,9 @@ namespace Yi.Abp.Tool.Application var filePath = await _templateGenManager.CreateTemplateAsync(input); //考虑从路径中获取 - var fileContentType = MimeHelper.GetMimeMapping(Path.GetFileName(filePath)); + // var fileContentType = MimeHelper.GetMimeMapping(Path.GetFileName(filePath)); //设置附件下载,下载名称 - return new FileContentResult(await File.ReadAllBytesAsync(filePath), fileContentType); + return await File.ReadAllBytesAsync(filePath); } } } diff --git a/Yi.Abp.Net8/tool/Yi.Abp.Tool.Web/Yi.Abp.Tool.Web.csproj b/Yi.Abp.Net8/tool/Yi.Abp.Tool.Web/Yi.Abp.Tool.Web.csproj index 8c2119ac..1197cde3 100644 --- a/Yi.Abp.Net8/tool/Yi.Abp.Tool.Web/Yi.Abp.Tool.Web.csproj +++ b/Yi.Abp.Net8/tool/Yi.Abp.Tool.Web/Yi.Abp.Tool.Web.csproj @@ -19,6 +19,7 @@ + diff --git a/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/NewCommand.cs b/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/NewCommand.cs index 6a812d00..5adca498 100644 --- a/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/NewCommand.cs +++ b/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/NewCommand.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO.Compression; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -22,6 +23,7 @@ namespace Yi.Abp.Tool.Commands public async Task InvokerAsync(Dictionary options, string[] args) { + var id = Guid.NewGuid().ToString("N"); //只有一个new if (args.Length <= 1) { @@ -30,22 +32,22 @@ namespace Yi.Abp.Tool.Commands string name = args[1]; options.TryGetValue("t", out var templateType); - + var zipPath = string.Empty; if (templateType == "module") { //代表模块生成 - var fileResult = await _templateGenService.CreateModuleAsync(new TemplateGenCreateInputDto + var fileByteArray = await _templateGenService.CreateModuleAsync(new TemplateGenCreateInputDto { Name = name, }); - var fileContent = fileResult as FileContentResult; - File.WriteAllText("./", Encoding.UTF8.GetString(fileContent.FileContents)); + zipPath = $"{id}.zip"; + await File.WriteAllBytesAsync(zipPath, fileByteArray); } else { //暂未实现 - throw new NotImplementedException(); + throw new NotImplementedException("暂未实现"); //代表模块生成 var fileResult = await _templateGenService.CreateProjectAsync(new TemplateGenCreateInputDto { @@ -53,8 +55,26 @@ namespace Yi.Abp.Tool.Commands }); } + //默认是当前目录 + var unzipDirPath = "./"; + //如果创建解决方案文件夹 + if (templateType == "module"&&options.TryGetValue("csf", out _)) + { + var moduleName = name.ToLower().Replace(".", "-"); + + if (Directory.Exists(moduleName)) + { + throw new UserFriendlyException($"文件夹[{moduleName}]已存在,请删除后重试"); + } + Directory.CreateDirectory(moduleName); + unzipDirPath = moduleName; + } + ZipFile.ExtractToDirectory(zipPath, unzipDirPath); + //创建压缩包后删除临时目录 + File.Delete(zipPath); + await Console.Out.WriteLineAsync("模块已生成!"); } } } diff --git a/Yi.Abp.Net8/tool/Yi.Abp.Tool/Program.cs b/Yi.Abp.Net8/tool/Yi.Abp.Tool/Program.cs index d04c735e..b10626aa 100644 --- a/Yi.Abp.Net8/tool/Yi.Abp.Tool/Program.cs +++ b/Yi.Abp.Net8/tool/Yi.Abp.Tool/Program.cs @@ -15,7 +15,8 @@ class Program //args = ["-h"]; //args = []; //args = ["12312"]; - args = ["new", "Acme.Book","-t", "module", "-csf"]; + //args = ["new", "Acme.Book","-t", "module", "-csf"]; + //args = ["new", "Acme.Book", "-t", "module"]; #endif try { @@ -26,8 +27,6 @@ class Program }) .UseAutofac() .Build(); - - var sss= host.Services.GetRequiredService(); var commandSelector = host.Services.GetRequiredService(); await commandSelector.SelectorAsync(args); } @@ -36,7 +35,6 @@ class Program Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } - Console.ReadKey(); } } \ No newline at end of file