feat: 完成2.0重构
This commit is contained in:
@@ -14,10 +14,9 @@ namespace Yi.Abp.Tool.Commands
|
|||||||
public string? Description { get; }
|
public string? Description { get; }
|
||||||
public void CommandLineApplication(CommandLineApplication application)
|
public void CommandLineApplication(CommandLineApplication application)
|
||||||
{
|
{
|
||||||
var modulePathOption= application.Option("-modulePath", "模块路径",CommandOptionType.SingleValue);
|
var modulePathOption= application.Option("-p|--modulePath", "模块路径",CommandOptionType.SingleValue);
|
||||||
var solutionOption= application.Option("-s|--solution", "解决方案路径",CommandOptionType.SingleValue);
|
var solutionOption= application.Option("-s|--solution", "解决方案路径",CommandOptionType.SingleValue);
|
||||||
var moduleNameArgument = application.Argument("moduleName", "模块名", null);
|
var moduleNameArgument = application.Argument("moduleName", "模块名", (_) => { });
|
||||||
|
|
||||||
application.OnExecute(() =>
|
application.OnExecute(() =>
|
||||||
{
|
{
|
||||||
var modulePath = "";
|
var modulePath = "";
|
||||||
@@ -27,25 +26,25 @@ namespace Yi.Abp.Tool.Commands
|
|||||||
{
|
{
|
||||||
modulePath = moduleName.ToLower().Replace(".", "-");
|
modulePath = moduleName.ToLower().Replace(".", "-");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//解决方案默认在模块文件夹上一级,也可以通过s进行指定
|
//解决方案默认在模块文件夹上一级,也可以通过s进行指定
|
||||||
var slnPath = string.Empty;
|
var slnPath = string.Empty;
|
||||||
|
|
||||||
if (!solutionOption.HasValue())
|
if (!solutionOption.HasValue())
|
||||||
{
|
{
|
||||||
slnPath = "../";
|
slnPath = "../";
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckFirstSlnPath(slnPath);
|
CheckFirstSlnPath(slnPath);
|
||||||
var dotnetSlnCommandPart1 = $"dotnet sln \"{slnPath}\" add \"{modulePath}\\{moduleName}.";
|
var dotnetSlnCommandPart1 = $"dotnet sln \"{slnPath}\" add \"{modulePath}\\{moduleName}.";
|
||||||
var dotnetSlnCommandPart2 = new List<string>() { "Application", "Application.Contracts", "Domain", "Domain.Shared", "SqlSugarCore" };
|
var dotnetSlnCommandPart2 = new List<string>() { "Application", "Application.Contracts", "Domain", "Domain.Shared", "SqlSugarCore" };
|
||||||
var paths = dotnetSlnCommandPart2.Select(x => $@"{modulePath}\{moduleName}." + x).ToArray();
|
var paths = dotnetSlnCommandPart2.Select(x => $@"{modulePath}\{moduleName}." + x).ToArray();
|
||||||
CheckPathExist(paths);
|
CheckPathExist(paths);
|
||||||
|
|
||||||
var cmdCommands = dotnetSlnCommandPart2.Select(x => dotnetSlnCommandPart1 + x+"\"").ToArray();
|
var cmdCommands = dotnetSlnCommandPart2.Select(x => dotnetSlnCommandPart1 + x+"\"").ToArray();
|
||||||
StartCmd(cmdCommands);
|
StartCmd(cmdCommands);
|
||||||
|
|
||||||
Console.WriteLine("恭喜~模块添加成功!");
|
Console.WriteLine("恭喜~模块添加成功!");
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,65 +26,69 @@ namespace Yi.Abp.Tool.Commands
|
|||||||
|
|
||||||
public void CommandLineApplication(CommandLineApplication application)
|
public void CommandLineApplication(CommandLineApplication application)
|
||||||
{
|
{
|
||||||
var templateTypeOption = application.Option("-t", "模板类型", CommandOptionType.SingleValue);
|
var templateTypeOption = application.Option("-t|--moduleType", "模板类型", CommandOptionType.SingleValue);
|
||||||
var csfOption = application.Option("csf", "是否创建解决方案", CommandOptionType.SingleValue);
|
var csfOption = application.Option("-csf", "是否创建解决方案", CommandOptionType.SingleValue);
|
||||||
var moduleNameArgument = application.Argument("moduleName", "模块名", null);
|
var moduleNameArgument = application.Argument("moduleName", "模块名", (_) => { });
|
||||||
|
|
||||||
|
|
||||||
#region 处理生成类型
|
application.OnExecute(() =>
|
||||||
|
|
||||||
var id = Guid.NewGuid().ToString("N");
|
|
||||||
var zipPath = string.Empty;
|
|
||||||
byte[] fileByteArray;
|
|
||||||
|
|
||||||
var templateType = templateTypeOption.HasValue() ? templateTypeOption.Value() : "module";
|
|
||||||
if (templateType == "module")
|
|
||||||
{
|
{
|
||||||
//代表模块生成
|
#region 处理生成类型
|
||||||
fileByteArray = (_templateGenService.CreateModuleAsync(new TemplateGenCreateInputDto
|
|
||||||
|
var id = Guid.NewGuid().ToString("N");
|
||||||
|
var zipPath = string.Empty;
|
||||||
|
byte[] fileByteArray;
|
||||||
|
|
||||||
|
var templateType = templateTypeOption.HasValue() ? templateTypeOption.Value() : "module";
|
||||||
|
if (templateType == "module")
|
||||||
{
|
{
|
||||||
Name = moduleNameArgument.Value,
|
//代表模块生成
|
||||||
}).Result);
|
fileByteArray = (_templateGenService.CreateModuleAsync(new TemplateGenCreateInputDto
|
||||||
}
|
{
|
||||||
else
|
Name = moduleNameArgument.Value,
|
||||||
{
|
}).Result);
|
||||||
//代表模块生成
|
}
|
||||||
fileByteArray = _templateGenService.CreateProjectAsync(new TemplateGenCreateInputDto
|
else
|
||||||
{
|
{
|
||||||
Name = moduleNameArgument.Value,
|
//代表模块生成
|
||||||
}).Result;
|
fileByteArray = _templateGenService.CreateProjectAsync(new TemplateGenCreateInputDto
|
||||||
}
|
{
|
||||||
|
Name = moduleNameArgument.Value,
|
||||||
zipPath = $"{id}.zip";
|
}).Result;
|
||||||
File.WriteAllBytes(zipPath, fileByteArray);
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 处理解决方案文件夹
|
|
||||||
|
|
||||||
//默认是当前目录
|
|
||||||
var unzipDirPath = "./";
|
|
||||||
//如果创建解决方案文件夹
|
|
||||||
if (csfOption.HasValue())
|
|
||||||
{
|
|
||||||
var moduleName = moduleNameArgument.Value.ToLower().Replace(".", "-");
|
|
||||||
|
|
||||||
if (Directory.Exists(moduleName))
|
|
||||||
{
|
|
||||||
throw new UserFriendlyException($"文件夹[{moduleName}]已存在,请删除后重试");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(moduleName);
|
zipPath = $"{id}.zip";
|
||||||
unzipDirPath = moduleName;
|
File.WriteAllBytes(zipPath, fileByteArray);
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
ZipFile.ExtractToDirectory(zipPath, unzipDirPath);
|
#region 处理解决方案文件夹
|
||||||
//创建压缩包后删除临时目录
|
|
||||||
File.Delete(zipPath);
|
|
||||||
|
|
||||||
Console.WriteLine("恭喜~模块已生成!");
|
//默认是当前目录
|
||||||
|
var unzipDirPath = "./";
|
||||||
|
//如果创建解决方案文件夹
|
||||||
|
if (csfOption.HasValue())
|
||||||
|
{
|
||||||
|
var moduleName = moduleNameArgument.Value.ToLower().Replace(".", "-");
|
||||||
|
|
||||||
|
if (Directory.Exists(moduleName))
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException($"文件夹[{moduleName}]已存在,请删除后重试");
|
||||||
|
}
|
||||||
|
|
||||||
|
Directory.CreateDirectory(moduleName);
|
||||||
|
unzipDirPath = moduleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
ZipFile.ExtractToDirectory(zipPath, unzipDirPath);
|
||||||
|
//创建压缩包后删除临时目录
|
||||||
|
File.Delete(zipPath);
|
||||||
|
|
||||||
|
Console.WriteLine("恭喜~模块已生成!");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,11 +20,13 @@ class Program
|
|||||||
// args = ["clear", "-path", "D:\\code\\csharp\\source\\Yi\\Yi.Abp.Net8\\src"];
|
// args = ["clear", "-path", "D:\\code\\csharp\\source\\Yi\\Yi.Abp.Net8\\src"];
|
||||||
|
|
||||||
//帮助
|
//帮助
|
||||||
args = ["-h"];
|
//args = ["-h"];
|
||||||
//版本
|
//版本
|
||||||
// args = ["-v"];
|
// args = ["-v"];
|
||||||
//清理
|
//清理
|
||||||
// args = ["clear"];
|
// args = ["clear"];
|
||||||
|
//添加模块
|
||||||
|
args = ["add-module", "kkk"];
|
||||||
#endif
|
#endif
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user