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;
}
}
}
}
}