This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
InitializeTemplate.ps1
75 lines (57 loc) · 2.41 KB
/
InitializeTemplate.ps1
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
# Copyright (c) XRTK. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root for license information.
$InputName = Read-Host "Enter a name for your new project"
$ProjectName = "ProjectName"
Write-Host "Your new $InputName project is being created..."
$excludes = @('*com.xrtk.core*', '*Library*', '*Obj*','*InitializeTemplate*')
# Rename any directories before we crawl the folders
Rename-Item -Path ".\XRTK.ProjectName" -NewName ".\XRTK.$InputName"
Rename-Item -Path ".\XRTK.$InputName\Packages\com.xrtk.projectname" -NewName "com.xrtk.$($InputName.ToLower())"
#TODO Rename any individual files with updated name
Get-ChildItem -Path "*" -File -Recurse -Exclude $excludes | ForEach-Object -Process {
$isValid = $true
foreach ($exclude in $excludes) {
if ((Split-Path -Path $_.FullName -Parent) -ilike $exclude) {
$isValid = $false
break
}
}
if ($isValid) {
Get-ChildItem -Path $_ -File | ForEach-Object -Process {
$updated = $false;
$fileContent = Get-Content $($_.FullName) -Raw
# Rename all PascalCase instances
if ($fileContent -cmatch $ProjectName) {
$fileContent -creplace $ProjectName, $InputName | Set-Content $($_.FullName) -NoNewline
$updated = $true
}
$fileContent = Get-Content $($_.FullName) -Raw
# Rename all lowercase instances
if ($fileContent -cmatch $ProjectName.ToLower()) {
$fileContent -creplace $ProjectName.ToLower(), $InputName.ToLower() | Set-Content $($_.FullName) -NoNewline
$updated = $true
}
$fileContent = Get-Content $($_.FullName) -Raw
# Rename all uppercase instances
if ($fileContent -cmatch $ProjectName.ToUpper()) {
$fileContent -creplace $ProjectName.ToUpper(), $InputName.ToUpper() | Set-Content $($_.FullName) -NoNewline
$updated = $true
}
$fileContent = Get-Content $($_.FullName) -Raw
# Update guids
if ($fileContent -match "#INSERT_GUID_HERE#") {
$fileContent -replace "#INSERT_GUID_HERE#", [guid]::NewGuid() | Set-Content $($_.FullName) -NoNewline
$updated = $true
}
# Rename files
if ($_.Name -match $ProjectName) {
Rename-Item -LiteralPath $_.FullName -NewName ($_.Name -replace ($ProjectName, $InputName))
$updated = $true
}
if ($updated) {
Write-Host $_.Name
}
}
}
}
Remove-Item -Path "InitializeTemplate.ps1"