-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
136 lines (122 loc) · 5.05 KB
/
setup.ps1
File metadata and controls
136 lines (122 loc) · 5.05 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Angular Starter Kit - Project Rename Script (Windows PowerShell)
# Usage: .\setup.ps1 <new-project-name>
param(
[Parameter(Mandatory=$true, HelpMessage="Enter the new project name")]
[string]$NewName
)
$OldName = "angular-starter-project" # ⚠️ CHANGE THIS to your current project name in angular.json
Write-Host ""
Write-Host "╔════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "║ Angular Project Rename Script ║" -ForegroundColor Cyan
Write-Host "╚════════════════════════════════════════╝" -ForegroundColor Cyan
Write-Host ""
Write-Host "🔄 Renaming project from '$OldName' to '$NewName'" -ForegroundColor Yellow
Write-Host ""
# Function to safely replace text in file
function Update-FileContent {
param(
[string]$FilePath,
[string]$OldValue,
[string]$NewValue,
[string]$Description
)
if (Test-Path $FilePath) {
try {
$content = Get-Content $FilePath -Raw
$content = $content -replace [regex]::Escape($OldValue), $NewValue
$content | Set-Content $FilePath -NoNewline
Write-Host "✅ Updated $Description" -ForegroundColor Green
return $true
}
catch {
Write-Host "⚠️ Failed to update $Description : $_" -ForegroundColor Yellow
return $false
}
}
else {
Write-Host "⚠️ $Description not found" -ForegroundColor Yellow
return $false
}
}
# Update package.json
Update-FileContent -FilePath "package.json" `
-OldValue "`"name`": `"$OldName`"" `
-NewValue "`"name`": `"$NewName`"" `
-Description "package.json"
# Update package-lock.json
if (Test-Path "package-lock.json") {
Update-FileContent -FilePath "package-lock.json" `
-OldValue "`"name`": `"$OldName`"" `
-NewValue "`"name`": `"$NewName`"" `
-Description "package-lock.json"
}
# Update angular.json (replace all occurrences)
if (Test-Path "angular.json") {
try {
$content = Get-Content "angular.json" -Raw
$content = $content -replace [regex]::Escape("`"$OldName`""), "`"$NewName`""
$content | Set-Content "angular.json" -NoNewline
Write-Host "✅ Updated angular.json" -ForegroundColor Green
}
catch {
Write-Host "⚠️ Failed to update angular.json: $_" -ForegroundColor Yellow
}
}
# Update index.html title
if (Test-Path "src/index.html") {
try {
$content = Get-Content "src/index.html" -Raw
$content = $content -replace "<title>.*?</title>", "<title>$NewName</title>"
$content | Set-Content "src/index.html" -NoNewline
Write-Host "✅ Updated src/index.html" -ForegroundColor Green
}
catch {
Write-Host "⚠️ Failed to update src/index.html: $_" -ForegroundColor Yellow
}
}
# Update Dockerfile
Update-FileContent -FilePath "Dockerfile" `
-OldValue "/app/dist/$OldName/browser" `
-NewValue "/app/dist/$NewName/browser" `
-Description "Dockerfile"
# Update README.md title
if (Test-Path "README.md") {
try {
$content = Get-Content "README.md" -Raw
$content = $content -replace "# $OldName", "# $NewName"
$content | Set-Content "README.md" -NoNewline
Write-Host "✅ Updated README.md" -ForegroundColor Green
}
catch {
Write-Host "⚠️ Failed to update README.md: $_" -ForegroundColor Yellow
}
}
# Initialize git if not already initialized
if (-not (Test-Path ".git")) {
Write-Host ""
Write-Host "📦 Initializing git repository..." -ForegroundColor Yellow
git init
git add .
git commit -m "Initial commit: $NewName project from angular-starter-kit"
Write-Host "✅ Git repository initialized" -ForegroundColor Green
}
# Remove setup scripts (one-time use)
Write-Host ""
Write-Host "🗑️ Removing setup scripts..." -ForegroundColor Yellow
Remove-Item "setup.sh" -ErrorAction SilentlyContinue
Remove-Item "setup.ps1" -ErrorAction SilentlyContinue
Write-Host ""
Write-Host "╔════════════════════════════════════════╗" -ForegroundColor Green
Write-Host "║ ✨ Project Setup Complete! ║" -ForegroundColor Green
Write-Host "╚════════════════════════════════════════╝" -ForegroundColor Green
Write-Host ""
Write-Host "Project renamed to: " -ForegroundColor Cyan -NoNewline
Write-Host "$NewName" -ForegroundColor Green
Write-Host ""
Write-Host "🚀 Next steps:" -ForegroundColor Cyan
Write-Host " 1. docker-compose up " -ForegroundColor Yellow -NoNewline
Write-Host "# Start development server" -ForegroundColor Cyan
Write-Host " 2. Open http://localhost:4200 " -ForegroundColor Yellow -NoNewline
Write-Host "# View your app" -ForegroundColor Cyan
Write-Host " 3. Start coding! 🎉" -ForegroundColor Yellow
Write-Host ""