Browse Source

fix: 调整code命令

feat/cap 9.0.6.12
Hanpaopao 1 year ago
parent
commit
4e10686168
  1. 19
      aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Commands/CodeCommand.cs

19
aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Commands/CodeCommand.cs

@ -107,7 +107,8 @@ public class CodeCommand : IConsoleCommand, ITransientDependency
GenerateCode(extractPath, sourcePath, "Application.Contracts", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName); GenerateCode(extractPath, sourcePath, "Application.Contracts", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName);
GenerateCode(extractPath, sourcePath, "Application", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName); GenerateCode(extractPath, sourcePath, "Application", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName);
GenerateCode(extractPath, sourcePath, "HttpApi", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName); GenerateCode(extractPath, sourcePath, "HttpApi", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName);
GenerateCode(extractPath, sourcePath, "EntityFrameworkCore", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName); var excludeFiles = $"I{project.Project.ProjectName}DbContext.cs,{project.Project.ProjectName}DbContext.cs,{project.Project.ProjectName}DbContextModelCreatingExtensions.cs";
GenerateCode(extractPath, sourcePath, "EntityFrameworkCore", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName,excludeFiles);
AppendIDbContextCode(extractPath, sourcePath, "EntityFrameworkCore", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName); AppendIDbContextCode(extractPath, sourcePath, "EntityFrameworkCore", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName);
AppendDbContextCode(extractPath, sourcePath, "EntityFrameworkCore", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName); AppendDbContextCode(extractPath, sourcePath, "EntityFrameworkCore", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName);
AppendDbContextModelCreatingExtensionsCode(extractPath, sourcePath, "EntityFrameworkCore", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName); AppendDbContextModelCreatingExtensionsCode(extractPath, sourcePath, "EntityFrameworkCore", item.CodePluralized, project.Project.CompanyName, project.Project.ProjectName);
@ -161,23 +162,23 @@ public class CodeCommand : IConsoleCommand, ITransientDependency
} }
} }
private void GenerateCode(string templateSourceCodePath, string sourcePath, string type, string entityCodePluralized, string companyName, string projectName) private void GenerateCode(string templateSourceCodePath, string sourcePath, string type, string entityCodePluralized, string companyName, string projectName, string excludeFiles = "")
{ {
var sourceCodePath = Path.Combine(templateSourceCodePath, "AspNetCore", "src", type, entityCodePluralized); var sourceCodePath = Path.Combine(templateSourceCodePath, "AspNetCore", "src", type, entityCodePluralized);
var targetCodePath = Path.Combine(sourcePath, $"{companyName}.{projectName}.{type}", entityCodePluralized); var targetCodePath = Path.Combine(sourcePath, $"{companyName}.{projectName}.{type}", entityCodePluralized);
Utils.DirectoryHelper.CopyFolder(sourceCodePath, targetCodePath); Utils.DirectoryHelper.CopyFolder(sourceCodePath, targetCodePath, excludeFiles);
} }
private void AppendIDbContextCode(string templateSourceCodePath, string sourcePath, string type, string entityCodePluralized, string companyName, string projectName) private void AppendIDbContextCode(string templateSourceCodePath, string sourcePath, string type, string entityCodePluralized, string companyName, string projectName)
{ {
var basePath = Path.Combine(templateSourceCodePath, "AspNetCore", "src", type); var basePath = Path.Combine(templateSourceCodePath, "AspNetCore", "src", type, entityCodePluralized);
// 给IDbContext追加dbset // 给IDbContext追加dbset
var sourceCodePath = Path.Combine(basePath, $"I{projectName}DbContext.cs"); var sourceCodePath = Path.Combine(basePath, $"I{projectName}DbContext.cs");
var code = File.ReadAllText(sourceCodePath); var code = File.ReadAllText(sourceCodePath);
var targetCodePath = Path.Combine(sourcePath, $"{companyName}.{projectName}.{type}", type, $"I{projectName}DbContext.cs"); var targetCodePath = Path.Combine(sourcePath, $"{companyName}.{projectName}.{type}", type, $"I{projectName}DbContext.cs");
// 判断代码是否已经生成 // 判断代码是否已经生成
if (CodeHelper.IsExistCode(targetCodePath, code)) if (CodeHelper.IsExistCode(targetCodePath, entityCodePluralized))
{ {
return; return;
} }
@ -188,14 +189,14 @@ public class CodeCommand : IConsoleCommand, ITransientDependency
private void AppendDbContextCode(string templateSourceCodePath, string sourcePath, string type, string entityCodePluralized, string companyName, string projectName) private void AppendDbContextCode(string templateSourceCodePath, string sourcePath, string type, string entityCodePluralized, string companyName, string projectName)
{ {
var basePath = Path.Combine(templateSourceCodePath, "AspNetCore", "src", type); var basePath = Path.Combine(templateSourceCodePath, "AspNetCore", "src", type, entityCodePluralized);
// 给DbContext追加dbset // 给DbContext追加dbset
var dbContextCodePath = Path.Combine(basePath, $"{projectName}DbContext.cs"); var dbContextCodePath = Path.Combine(basePath, $"{projectName}DbContext.cs");
var dbContextCode = File.ReadAllText(dbContextCodePath); var dbContextCode = File.ReadAllText(dbContextCodePath);
var targetDbContextCodePath = Path.Combine(sourcePath, $"{companyName}.{projectName}.{type}", type, $"{projectName}DbContext.cs"); var targetDbContextCodePath = Path.Combine(sourcePath, $"{companyName}.{projectName}.{type}", type, $"{projectName}DbContext.cs");
// 判断代码是否已经生成 // 判断代码是否已经生成
if (CodeHelper.IsExistCode(targetDbContextCodePath, dbContextCode)) if (CodeHelper.IsExistCode(targetDbContextCodePath, entityCodePluralized))
{ {
return; return;
} }
@ -206,13 +207,13 @@ public class CodeCommand : IConsoleCommand, ITransientDependency
private void AppendDbContextModelCreatingExtensionsCode(string templateSourceCodePath, string sourcePath, string type, string entityCodePluralized, string companyName, string projectName) private void AppendDbContextModelCreatingExtensionsCode(string templateSourceCodePath, string sourcePath, string type, string entityCodePluralized, string companyName, string projectName)
{ {
var basePath = Path.Combine(templateSourceCodePath, "AspNetCore", "src", type); var basePath = Path.Combine(templateSourceCodePath, "AspNetCore", "src", type, entityCodePluralized);
// 给ContextModelCreatingExtensions追加ef 配置 // 给ContextModelCreatingExtensions追加ef 配置
var dbContextModelCreatingExtensionsPath = Path.Combine(basePath, $"{projectName}DbContextModelCreatingExtensions.cs"); var dbContextModelCreatingExtensionsPath = Path.Combine(basePath, $"{projectName}DbContextModelCreatingExtensions.cs");
var dbContextModelCreatingExtensionsCode = File.ReadAllText(dbContextModelCreatingExtensionsPath); var dbContextModelCreatingExtensionsCode = File.ReadAllText(dbContextModelCreatingExtensionsPath);
var targetDbContextModelCreatingExtensionsCodePath = Path.Combine(sourcePath, $"{companyName}.{projectName}.{type}", type, $"{projectName}DbContextModelCreatingExtensions.cs"); var targetDbContextModelCreatingExtensionsCodePath = Path.Combine(sourcePath, $"{companyName}.{projectName}.{type}", type, $"{projectName}DbContextModelCreatingExtensions.cs");
// 判断代码是否已经生成 // 判断代码是否已经生成
if (CodeHelper.IsExistCode(targetDbContextModelCreatingExtensionsCodePath, dbContextModelCreatingExtensionsCode)) if (CodeHelper.IsExistCode(targetDbContextModelCreatingExtensionsCodePath, entityCodePluralized))
{ {
return; return;
} }

Loading…
Cancel
Save