This repository was archived by the owner on Jul 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetProjectName.ps1
More file actions
46 lines (39 loc) · 1.39 KB
/
SetProjectName.ps1
File metadata and controls
46 lines (39 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
param (
[string]$projectName
)
# Function to convert a string to PascalCase
function ConvertTo-PascalCase($str) {
$str -replace '[^a-zA-Z0-9]', ' ' |
ForEach-Object { $_.ToLower() } |
ForEach-Object { $_ -replace '(\s|^)(\w)', { $args[1].ToUpper() } }
}
if (-not $projectName) {
$projectName = Read-Host "What is the name of your project?"
}
$projectName = ConvertTo-PascalCase $projectName
# Get the script directory
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Replace text in files and directories
function Replace-TemplateText {
param (
[string]$path
)
if (Test-Path $path -PathType Container) {
# Replace directory names
Get-ChildItem -Path $path -Recurse -Force | ForEach-Object {
$newName = $_.Name -replace '(?i)TemplateProject', $projectName
if ($_.Name -ne $newName) {
Rename-Item -Path $_.FullName -NewName $newName -Force
}
}
} else {
# Replace content in files
(Get-Content -Path $path) -replace '(?i)TemplateProject', $projectName | Set-Content -Path $path
}
}
# Iterate over all files and directories
Get-ChildItem -Path $scriptDir -Recurse -Force | ForEach-Object {
if ($_.FullName -ne $MyInvocation.MyCommand.Path) {
Replace-TemplateText -path $_.FullName
}
}