mirror of https://github.com/abpframework/abp.git
7 changed files with 126 additions and 60 deletions
@ -0,0 +1,60 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using Volo.Abp.Cli.ProjectBuilding.Files; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps |
||||
|
{ |
||||
|
public static class RenameHelper |
||||
|
{ |
||||
|
public static void RenameAll(List<FileEntry> entries, string placeHolder, string name) |
||||
|
{ |
||||
|
RenameDirectoryRecursively(entries, placeHolder, name); |
||||
|
RenameAllFiles(entries, placeHolder, name); |
||||
|
ReplaceContent(entries, placeHolder, name); |
||||
|
} |
||||
|
|
||||
|
private static void RenameDirectoryRecursively(List<FileEntry> entries, string placeHolder, string name) |
||||
|
{ |
||||
|
foreach (var entry in entries.Where(e => e.IsDirectory)) |
||||
|
{ |
||||
|
if (entry.Name.Contains(placeHolder)) |
||||
|
{ |
||||
|
entry.SetName(entry.Name.Replace(placeHolder, name)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static void RenameAllFiles(List<FileEntry> entries, string placeHolder, string name) |
||||
|
{ |
||||
|
foreach (var entry in entries.Where(e => !e.IsDirectory)) |
||||
|
{ |
||||
|
if (entry.Name.Contains(placeHolder)) |
||||
|
{ |
||||
|
entry.SetName(entry.Name.Replace(placeHolder, name)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static void ReplaceContent(List<FileEntry> entries, string placeHolder, string name) |
||||
|
{ |
||||
|
foreach (var entry in entries.Where(e => !e.IsDirectory)) |
||||
|
{ |
||||
|
if (entry.Content.Length < placeHolder.Length) |
||||
|
{ |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (entry.IsBinaryFile) |
||||
|
{ |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
var newContent = entry.Content.Replace(placeHolder, name); |
||||
|
if (newContent != entry.Content) |
||||
|
{ |
||||
|
entry.SetContent(newContent); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
using Volo.Abp.Cli.ProjectBuilding.Building; |
||||
|
using Volo.Abp.Cli.ProjectBuilding.Building.Steps; |
||||
|
|
||||
|
namespace Volo.Abp.Cli.ProjectBuilding.Templates.Mvc |
||||
|
{ |
||||
|
public class MvcTemplateProjectRenameStep : ProjectBuildPipelineStep |
||||
|
{ |
||||
|
private readonly string _oldProjectName; |
||||
|
private readonly string _newProjectName; |
||||
|
private readonly string _folder; |
||||
|
|
||||
|
public MvcTemplateProjectRenameStep( |
||||
|
string oldProjectName, |
||||
|
string newProjectName, |
||||
|
string folder = "/src/") |
||||
|
{ |
||||
|
_oldProjectName = oldProjectName; |
||||
|
_newProjectName = newProjectName; |
||||
|
_folder = folder; |
||||
|
} |
||||
|
|
||||
|
public override void Execute(ProjectBuildContext context) |
||||
|
{ |
||||
|
ReplaceInFile( |
||||
|
context, |
||||
|
"/MyCompanyName.MyProjectName.sln", |
||||
|
_oldProjectName, |
||||
|
_newProjectName |
||||
|
); |
||||
|
|
||||
|
RenameHelper.RenameAll(context.Files, _oldProjectName, _newProjectName); |
||||
|
} |
||||
|
|
||||
|
public void ReplaceInFile( |
||||
|
ProjectBuildContext context, |
||||
|
string filePath, |
||||
|
string oldText, |
||||
|
string newText) |
||||
|
{ |
||||
|
var file = context.GetFile(filePath); |
||||
|
file.NormalizeLineEndings(); |
||||
|
file.SetContent(file.Content.Replace(oldText, newText)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue