feat: 完成yi-abp模块生成

This commit is contained in:
橙子
2024-06-02 14:12:37 +08:00
parent bca3ce1e5f
commit d9c9db332c
5 changed files with 37 additions and 18 deletions

View File

@@ -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<string, string> 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("模块已生成!");
}
}
}

View File

@@ -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<ITemplateGenService>();
var commandSelector = host.Services.GetRequiredService<CommandSelector>();
await commandSelector.SelectorAsync(args);
}
@@ -36,7 +35,6 @@ class Program
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
Console.ReadKey();
}
}