-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateProject.ps1
More file actions
141 lines (130 loc) · 4.6 KB
/
Copy pathCreateProject.ps1
File metadata and controls
141 lines (130 loc) · 4.6 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
137
138
139
140
141
# An improved version of getFNA from Caleb Cornett.
function checkDotnet()
{
try { dotnet | Out-Null }
catch [System.Management.Automation.CommandNotFoundException]
{
Write-Output "ERROR: Dotnet is not installed. Please install dotnet to download the t4 tool."
exit
}
}
function checkMsbuild ()
{
try { msbuild | Out-Null }
catch [System.Management.Automation.CommandNotFoundException]
{
Write-Output "ERROR: Msbuild is not available, please ensure msbuild.exe is installed and added to the PATH Environment Variable."
exit
}
}
function check7zip ()
{
if ((Test-Path "C:\Program Files\7-Zip") -eq 0)
{
Write-Output "ERROR: 7zip is not installed, please install 7zip and try again."
exit
}
}
function installT4 ()
{
if (checkDotnet) { Invoke-Expression 'dotnet tool install -g dotnet-t4' }
}
function checkGit ()
{
try { git | Out-Null }
catch [System.Management.Automation.CommandNotFoundException]
{
Write-Output "ERROR: Git is not installed. Please install git to download FNA."
exit
}
}
function downloadFNA()
{
checkGit
git -C $PSScriptRoot clone https://github.com/FNA-XNA/FNA.git --recursive
if ($? -eq 1) { Write-Output "Finished Downloading!" }
else { Write-Output "ERROR: Download failed, try again later?" exit}
}
function updateFNA ()
{
checkGit
Write-Output "Updating to the latest git version of FNA..."
git -C "${PSScriptRoot}\FNA" pull --recurse-submodules
if ($? -eq 1) { Write-Output "Finished updating!" }
else { Write-Output "ERROR: Unable to update." exit}
}
function getLibs ()
{
Write-Output "Downloading the latest FNAlibs..."
Invoke-WebRequest -Uri https://fna.flibitijibibo.com/archive/fnalibs.tar.bz2 -OutFile "${PSScriptRoot}/fnalibs.tar.bz2" if ($? -eq 1) { Write-Output "Finished downloading!" }
else { Write-Output "ERROR: Unable to download successfully." exit}
Write-Output "Decompressing fnalibs..."
check7zip
if ((Test-Path "${PSScriptRoot}\fnalibs") -eq 0)
{
& "C:\Program Files\7-Zip\7z.exe" x "fnalibs.tar.bz2"
if ($? -eq 1){ Remove-Item "fnalibs.tar.bz2"}
else { Write-Output "ERROR: Unable to decompress successfully." exit }
& "C:\Program Files\7-Zip\7z.exe" x "fnalibs.tar" -ofnalibs
if ($? -eq 1)
{
Remove-Item "fnalibs.tar"
Write-Output "Finished decompressing!"
}
else { Write-Output "ERROR: Unable to decompress successfully." exit }
}
}
checkMsbuild
if (Test-Path "${PSScriptRoot}\FNA")
{
#if ((Read-Host -Prompt "Update FNA (y/n)?") -like 'y') { $shouldUpdate = true }
$shouldUpdate = Read-Host -Prompt "Update FNA (y/n)?"
}
else
{
#if ((Read-Host -Prompt "Download FNA (y/n)?") -like 'y') { $shouldDownload = true }
$shouldDownload = Read-Host -Prompt "Download FNA (y/n)?"
}
if (Test-Path "${PSScriptRoot}\fnalibs")
{
#if ((Read-Host -Prompt "Redownload fnalibs (y/n)?") -like 'y') { $shouldDownloadLibs = true }
$shouldDownloadLibs = Read-Host -Prompt "Redownload fnalibs (y/n)?"
}
else
{
#if ((Read-Host -Prompt "Download fnalibs (y/n)?") -like 'y') { $shouldDownloadLibs = true }
$shouldDownloadLibs = Read-Host -Prompt "Download fnalibs (y/n)?"
}
if ((Test-Path "${PSScriptRoot}\#project#") -eq 1)
{
$newProjectName = Read-Host -Prompt "Enter the project name to use for your folder and csproj file or 'exit' to quit: "
}
if ($shouldDownload -like 'y') { downloadFNA }
elseif ($shouldUpdate -like 'y') { updateFNA }
if ($shouldDownloadLibs -like 'y') { getLibs }
installT4
# Only proceed from here if we have not yet renamed the project
if ((Test-Path "${PSScriptRoot}\#project#") -ne 1) { exit }
if ($newProjectName -eq "exit" -or $newProjectName -eq "") { exit }
# More recursiveness in this part of the script.
# Any file that contains
$files = Select-String -Path "${PSScriptRoot}*" -Pattern "#project#" -List | Select-Object -ExpandProperty Path
foreach ($file in $files) {
(Get-Content $file) | ForEach-Object { $_ -replace "#project#", $newProjectName } | Set-Content $file
}
Get-ChildItem -Path ${PSScriptRoot} -Recurse -Filter "*#project#*" -File | ForEach-Object {
Rename-Item $_.FullName ($_.Name -replace "#project#", $newProjectName) -Force
}
git init
git submodule add https://github.com/prime31/Nez.git
Set-Location Nez
git submodule init
git submodule update
"Restoring..."
Set-Location $PSScriptRoot
dotnet restore "Nez/Nez.sln"
"Building..."
msbuild "Nez/Nez.sln"
msbuild -t:restore $newProjectName
msbuild -t:buildcontent $newProjectName
msbuild "${newProjectName}.sln"