feat: 完成yi-abp模块生成
This commit is contained in:
@@ -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("模块已生成!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user