-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
InitializeTemplate.ps1
143 lines (112 loc) · 5.13 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
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
137
138
139
140
141
142
143
# Copyright (c) Stephen Hodgson. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root for license information.
$InputAuthor = Read-Host "Set Author name: (i.e. your GitHub username)"
$ProjectAuthor = "ProjectAuthor"
$InputName = Read-Host "Enter a name for your new project"
$ProjectName = "ProjectName"
$InputScope = Read-Host "Enter a scope for your new project (optional)"
if (-not [String]::IsNullOrWhiteSpace($InputScope)) {
$InputScope = "$InputScope."
}
$ProjectScope = "ProjectScope."
Write-Host "Your new com.$($InputScope.ToLower())$($InputName.ToLower()) project is being created..."
Remove-Item -Path ".\Readme.md"
Remove-Item -Path ".\$ProjectScope$ProjectName\Assets\Samples"
$oldPackageRoot = ".\$ProjectScope$ProjectName\Packages\com.$($ProjectScope.ToLower())$($ProjectName.ToLower())"
Copy-Item -Path "$oldPackageRoot\Documentation~\Readme.md" `
-Destination ".\Readme.md"
Rename-Item -Path "$oldPackageRoot\Runtime\$ProjectScope$ProjectName.asmdef" `
-NewName "$InputScope$InputName.asmdef"
Rename-Item -Path "$oldPackageRoot\Editor\$ProjectScope$ProjectName.Editor.asmdef" `
-NewName "$InputScope$InputName.Editor.asmdef"
Rename-Item -Path "$oldPackageRoot\Tests\$ProjectScope$ProjectName.Tests.asmdef" `
-NewName "$InputScope$InputName.Tests.asmdef"
Rename-Item -Path "$oldPackageRoot\Samples~\Demo\$ProjectScope$ProjectName.Demo.asmdef" `
-NewName "$InputScope$InputName.Tests.asmdef"
Rename-Item -Path "$oldPackageRoot" `
-NewName "com.$($InputScope.ToLower())$($InputName.ToLower())"
Rename-Item -Path ".\$ProjectScope$ProjectName" `
-NewName ".\$InputScope$InputName"
$excludes = @('*Library*', '*Obj*', '*InitializeTemplate*')
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
if ($fileContent -cmatch $ProjectScope) {
$fileContent -creplace $ProjectScope, $InputScope | Set-Content $($_.FullName) -NoNewline
$updated = $true
}
$fileContent = Get-Content $($_.FullName) -Raw
if ($fileContent -cmatch $ProjectAuthor) {
$fileContent -creplace $ProjectAuthor, $InputAuthor | Set-Content $($_.FullName) -NoNewline
$updated = $true
}
$fileContent = Get-Content $($_.FullName) -Raw
$StephenHodgson = "StephenHodgson"
if ($fileContent -cmatch $StephenHodgson) {
$fileContent -creplace $StephenHodgson, $InputAuthor | 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
if ($fileContent -cmatch $ProjectScope.ToLower()) {
$fileContent -creplace $ProjectScope.ToLower(), $InputScope.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
if ($fileContent -cmatch $ProjectScope.ToUpper()) {
$fileContent -creplace $ProjectScope.ToUpper(), $InputScope.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
}
$fileContent = Get-Content $($_.FullName) -Raw
# Update year
if ($fileContent -match "#CURRENT_YEAR#") {
$fileContent -replace "#CURRENT_YEAR#", (Get-Date).year | 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
}
}
}
}
Set-Location ".\$InputScope$InputName\Assets"
cmd /c mklink /D "Samples" "..\..\$InputScope$InputName\Packages\com.$($InputScope.ToLower())$($InputName.ToLower())\Samples~"
Set-Location "..\.."
Remove-Item -Path "InitializeTemplate.ps1"