feat: 去除sample

This commit is contained in:
chenchun
2024-11-08 11:10:45 +08:00
parent d5ca8ddf1e
commit f9a018638b
49 changed files with 58 additions and 858 deletions

View File

@@ -15,18 +15,21 @@ namespace Yi.Abp.Tool.Domain
{
private readonly ToolOptions _toolOptions;
private readonly GiteeManager _giteeManager;
public TemplateGenManager(IOptionsMonitor<ToolOptions> toolOptions, GiteeManager giteeManager)
{
_giteeManager = giteeManager;
_toolOptions = toolOptions.CurrentValue;
}
public async Task<string> CreateTemplateAsync(TemplateGenCreateDto input)
{
//这里判断gitee上是否有这个分支
if (await _giteeManager.IsExsitBranchAsync(input.GiteeRef))
if (!await _giteeManager.IsExsitBranchAsync(input.GiteeRef))
{
throw new UserFriendlyException($"Gitee分支未找到{input.GiteeRef},请检查,[{input.GiteeRef}]分支是否存在");
}
if (string.IsNullOrEmpty(_toolOptions.TempDirPath))
{
throw new UserFriendlyException($"临时目录路径无法找到,请检查,[{_toolOptions.TempDirPath}]路径");
@@ -39,35 +42,50 @@ namespace Yi.Abp.Tool.Domain
Directory.CreateDirectory(tempFileDirPath);
}
//下载的模板存放文件路径
var downloadFilePath = Path.Combine(_toolOptions.TempDirPath,"download" ,$"{id}.zip");
var gitSteam= await _giteeManager.DownLoadFileAsync(input.GiteeRef);
using (FileStream fileStream = new FileStream(downloadFilePath, FileMode.Create, FileAccess.Write))
{
await gitSteam.CopyToAsync(fileStream);
}
var downloadPath = Path.Combine(_toolOptions.TempDirPath, "download");
if (!Directory.Exists(downloadPath))
{
Directory.CreateDirectory(downloadPath);
}
var downloadFilePath = Path.Combine(downloadPath, $"{id}.zip");
var gitSteam = await _giteeManager.DownLoadFileAsync(input.GiteeRef);
using (FileStream fileStream = new FileStream(downloadFilePath, FileMode.Create, FileAccess.Write))
{
await gitSteam.CopyToAsync(fileStream);
}
//文件解压覆盖,将刚刚下载的模板,解压即可
ZipFile.ExtractToDirectory(downloadFilePath, tempFileDirPath, true);
await ReplaceContentAsync(tempFileDirPath, input.ReplaceStrData);
var tempFilePath = Path.Combine(_toolOptions.TempDirPath, $"{id}.zip");
ZipFile.CreateFromDirectory(tempFileDirPath, tempFilePath);
//注意这里下载的zip包其实多了一层我们进行操作的时候要将操作目录进一步
var operPath = Directory.GetDirectories(tempFileDirPath)[0];
await ReplaceContentAsync(operPath, input.ReplaceStrData);
var tempFilePath = Path.Combine(_toolOptions.TempDirPath, $"{id}.zip");
ZipFile.CreateFromDirectory(operPath, tempFilePath);
//创建压缩包后删除临时目录
Directory.Delete(tempFileDirPath, true);
return tempFilePath;
}
/// <summary>
/// 获取全部模板列表
/// </summary>
/// <returns></returns>
public async Task<List<string>> GetAllTemplatesAsync()
{
return await _giteeManager.GetAllBranchAsync();
var refs = await _giteeManager.GetAllBranchAsync();
//移除主分支
refs.Remove("master");
return refs;
}
/// <summary>
/// 替换内容,key为要替换的内容value为替换成的内容
/// </summary>
@@ -132,6 +150,5 @@ namespace Yi.Abp.Tool.Domain
return directoryPath;
}
}
}
}
}

View File

@@ -19,6 +19,7 @@
<ItemGroup>
<Folder Include="wwwroot\" />
<Folder Include="wwwroot\temp\" />
</ItemGroup>
<ItemGroup>
@@ -33,4 +34,8 @@
</Content>
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="wwwroot\temp\download\d5bb6f4c5ca24da29ebe1b67e1e4595d.zip" />
</ItemGroup>
</Project>

View File

@@ -31,7 +31,7 @@ namespace Yi.Abp.Tool.Commands
var pathOption = application.Option("-p|--path", "创建路径", CommandOptionType.SingleValue);
var csfOption = application.Option("-csf", "是否创建解决方案文件夹", CommandOptionType.NoValue);
var soureOption = application.Option("-s|--soure", "模板来源gitee模板库分支名称: 默认值`defualt`",
var soureOption = application.Option("-s|--soure", "模板来源gitee模板库分支名称: 默认值`default`",
CommandOptionType.SingleValue);
var moduleNameArgument = application.Argument("moduleName", "模块名", (_) => { });
@@ -56,13 +56,27 @@ namespace Yi.Abp.Tool.Commands
application.OnExecute(() =>
{
var path = string.Empty;
if (pathOption.HasValue())
{
path = pathOption.Value();
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
return 0;
}
}
#region
var id = Guid.NewGuid().ToString("N");
var zipPath = string.Empty;
byte[] fileByteArray;
var soure= soureOption.HasValue() ? soureOption.Value() : "defualt";
var soure= soureOption.HasValue() ? soureOption.Value() : "default";
var templateType = templateTypeOption.HasValue() ? templateTypeOption.Value() : "module";
if (templateType == "module")
@@ -83,11 +97,7 @@ namespace Yi.Abp.Tool.Commands
}).Result;
}
var path = string.Empty;
if (pathOption.HasValue())
{
path = pathOption.Value();
}
zipPath = Path.Combine(path, $"{id}.zip");
File.WriteAllBytes(zipPath, fileByteArray);

View File

@@ -19,9 +19,9 @@ class Program
// args = ["clear"];
//创建模块
//args = ["new","oooo", "-t","module","-p","D:\\temp","-csf"];
args = ["new","oooo", "-t","module","-p","D:\\temp","-csf"];
//查看模板列表
args = ["new","list"];
//args = ["new","list"];
//添加模块
//args = ["add-module", "kkk"];

View File

@@ -15,8 +15,8 @@ namespace Yi.Abp.Tool
Configure<AbpRemoteServiceOptions>(options =>
{
options.RemoteServices.Default =
// new RemoteServiceConfiguration("https://ccnetcore.com:19009");
new RemoteServiceConfiguration("http://localhost:19002");
new RemoteServiceConfiguration("https://ccnetcore.com:19009");
// new RemoteServiceConfiguration("http://localhost:19002");
});
}
}