-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.ps1
70 lines (53 loc) · 2.11 KB
/
Setup.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
$AppName = "Company.Application"
$TemplateName = "Zestware"
function Remove-Directory
{
Param(
[string]$Directory
)
Get-ChildItem $Directory -Recurse | Remove-Item -force -recurse
Remove-Item $Directory -Force
}
function Replace_TextInFile
{
Param(
[string]$FilePath,
[string]$Pattern,
[string]$Replacement
)
[System.IO.File]::WriteAllText(
$FilePath,
([System.IO.File]::ReadAllText($FilePath) -CReplace $Pattern, $Replacement),
[System.Text.Encoding]::UTF8
)
}
#------------------------------------------------
# Copy to new directory with new name
#------------------------------------------------
Get-ChildItem .\* | Copy-Item -Destination ..\$AppName -Recurse -Force
#------------------------------------------------
# Move context to the new directory
#------------------------------------------------
Set-Location ..\$AppName
#------------------------------------------------
# Delete unwanted stuff
#------------------------------------------------
$dirsToDelete=@("*bin*", "*obj*", "*Albums*", "*Artists*", "*Album*.cs", "*Artist*.cs")
get-childitem -Include ($dirsToDelete) -Recurse -force | Remove-Item -Force -Recurse
#------------------------------------------------
# Change file names
#------------------------------------------------
Get-ChildItem -Include Zestware* -Recurse | Rename-Item -NewName { $_.Name -replace $TemplateName, $AppName }
Get-ChildItem -Include *Zestware* -Recurse | Rename-Item -NewName { $_.Name -replace $TemplateName, $AppName }
#------------------------------------------------
# Change instances of app name in code files
#------------------------------------------------
Get-ChildItem -File -Exclude *Setup.ps1 -Recurse | ForEach-Object {
Write-Host $_.FullName
Replace_TextInFile -FilePath $_.FullName -Pattern $TemplateName -Replacement $AppName
Replace_TextInFile -FilePath $_.FullName -Pattern $TemplateName.ToLower() -Replacement $AppName.ToLower()
}
#------------------------------------------------
# Final clean-up
#------------------------------------------------
Remove-Item .\Setup.ps1