3 Star 0 Fork 0

mirrors_aspnetboilerplate/eventcloud

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
rename.ps1 3.21 KB
一键复制 编辑 原始数据 按行查看 历史
# set output encoding
$OutputEncoding = [Text.UTF8Encoding]::UTF8
# company name placeholder
$oldCompanyName="AbpCompanyName"
# your company name
$newCompanyName="YourCompanyName"
# project name placeholder
$oldProjectName="EventCloud"
# your project name
$newProjectName="YourProjectName"
# file type
$fileType="FileInfo"
# directory type
$dirType="DirectoryInfo"
# copy
Write-Host 'Start copy folders...'
$newRoot=$newCompanyName+"."+$newProjectName
mkdir $newRoot
Copy-Item -Recurse .\aspnet-core\ .\$newRoot\
Copy-Item -Recurse .\vue\ .\$newRoot\
Copy-Item .gitignore .\$newRoot\
Copy-Item LICENSE .\$newRoot\
Copy-Item README.md .\$newRoot\
# folders to deal with
$slnFolder = (Get-Item -Path "./$newRoot/aspnet-core/" -Verbose).FullName
$vueFolder = (Get-Item -Path "./$newRoot/vue/" -Verbose).FullName
function Rename {
param (
$TargetFolder,
$PlaceHolderCompanyName,
$PlaceHolderProjectName,
$NewCompanyName,
$NewProjectName
)
# file extensions to deal with
$include=@("*.cs","*.cshtml","*.asax","*.ps1","*.ts","*.csproj","*.sln","*.xaml","*.json","*.js","*.xml","*.config","Dockerfile")
$elapsed = [System.Diagnostics.Stopwatch]::StartNew()
Write-Host "[$TargetFolder]Start rename folder..."
# rename folder
Ls $TargetFolder -Recurse | Where { $_.GetType().Name -eq $dirType -and ($_.Name.Contains($PlaceHolderCompanyName) -or $_.Name.Contains($PlaceHolderProjectName)) } | ForEach-Object{
Write-Host 'directory ' $_.FullName
$newDirectoryName=$_.Name.Replace($PlaceHolderCompanyName,$NewCompanyName).Replace($PlaceHolderProjectName,$NewProjectName)
Rename-Item $_.FullName $newDirectoryName
}
Write-Host "[$TargetFolder]End rename folder."
Write-Host '-------------------------------------------------------------'
# replace file content and rename file name
Write-Host "[$TargetFolder]Start replace file content and rename file name..."
Ls $TargetFolder -Include $include -Recurse | Where { $_.GetType().Name -eq $fileType} | ForEach-Object{
$fileText = Get-Content $_ -Raw -Encoding UTF8
if($fileText.Length -gt 0 -and ($fileText.contains($PlaceHolderCompanyName) -or $fileText.contains($PlaceHolderProjectName))){
$fileText.Replace($PlaceHolderCompanyName,$NewCompanyName).Replace($PlaceHolderProjectName,$NewProjectName) | Set-Content $_ -Encoding UTF8
Write-Host 'file(change text) ' $_.FullName
}
If($_.Name.contains($PlaceHolderCompanyName) -or $_.Name.contains($PlaceHolderProjectName)){
$newFileName=$_.Name.Replace($PlaceHolderCompanyName,$NewCompanyName).Replace($PlaceHolderProjectName,$NewProjectName)
Rename-Item $_.FullName $newFileName
Write-Host 'file(change name) ' $_.FullName
}
}
Write-Host "[$TargetFolder]End replace file content and rename file name."
Write-Host '-------------------------------------------------------------'
$elapsed.stop()
write-host "[$TargetFolder]Total Time Cost: $($elapsed.Elapsed.ToString())"
}
Rename -TargetFolder $slnFolder -PlaceHolderCompanyName $oldCompanyName -PlaceHolderProjectName $oldProjectName -NewCompanyName $newCompanyName -NewProjectName $newProjectName
Rename -TargetFolder $vueFolder -PlaceHolderCompanyName $oldCompanyName -PlaceHolderProjectName $oldProjectName -NewCompanyName $newCompanyName -NewProjectName $newProjectName
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_aspnetboilerplate/eventcloud.git
git@gitee.com:mirrors_aspnetboilerplate/eventcloud.git
mirrors_aspnetboilerplate
eventcloud
eventcloud
master

搜索帮助