common/repoquickset.ps1

208 lines
8.2 KiB
PowerShell
Raw Normal View History

2024-07-01 21:40:32 +00:00
<#
2024-07-01 21:28:31 +00:00
.SYNOPSIS
repo quickset script
.DESCRIPTION
script to quickly setup a repository for a game, modelling, design, or generic project with git lfs enabled
.LINK
https://forge.joshwel.co/mark/common
.LINK
https://poissonparler.notion.site/Forge-Resources-d6d6b694a92b4211ac7496dec2b8689d?pvs=4
#>
$GIT_IGNR_UNITY="https://forge.joshwel.co/mark/common/raw/branch/main/Unity.gitignore"
$GIT_ATTR_UNITY="https://forge.joshwel.co/mark/common/raw/branch/main/Unity.gitattributes"
$GIT_ATTR_MODEL="https://forge.joshwel.co/mark/common/raw/branch/main/Modelling.gitattributes"
$GIT_ATTR_GENRC="https://forge.joshwel.co/mark/common/raw/branch/main/Generic.gitattributes"
$GIT_ATTR_DESGN="https://forge.joshwel.co/mark/common/raw/branch/main/Design.gitattributes"
$GIT_ATTR_GITHB="https://forge.joshwel.co/mark/common/raw/branch/main/GitHub.gitattributes"
# functions
function setupSharedRepository {
# ask if the repo will be pushed to github or the forge
Write-Output ("`n!!! will this repo be pushed to github or the forge? (g/f)`n" +
"!!! - [g]ithub: github.com`n" +
"!!! - [f]orge: forge.joshwel.co`n" +
"!!!`n" +
"!!! (this will affect how git lfs is setup, but it will be enabled regardless`n" +
"!!! ---`n" +
"!!! github has a 1gb lfs storage/bandwidth limit, while the forge doesn't care`n" +
"!!! saying 'f' will use actually defined .gitattributes,`n" +
"!!! while saying 'g' will use a basic .gitattributes that MIGHT not wreck your`n" +
"!!! 1gb git lfs allowance as long as you dont commit files bigger than 100mb)")
while ($true) {
$repoHost = Read-Host
if ($repoHost -eq "g" -or $repoHost -eq "f") {
break
}
Write-Output "!!! expected: 'g', 'f'"
}
# re-set variables if the repo will be pushed to the github (use github.gitattributes)
if ($repoHost -eq "g") {
$GIT_ATTR_UNITY=$GIT_ATTR_GITHB
$GIT_ATTR_MODEL=$GIT_ATTR_GITHB
$GIT_ATTR_DESGN=$GIT_ATTR_GITHB
$GIT_ATTR_GENRC=$GIT_ATTR_GITHB
}
# make folders
if (-not (Test-Path -Path "Game")) {
New-Item -ItemType Directory -Name "Game"
}
if (-not (Test-Path -Path "Modelling")) {
New-Item -ItemType Directory -Name "Modelling"
}
if (-not (Test-Path -Path "Design")) {
New-Item -ItemType Directory -Name "Design"
}
# download .gitignore and .gitattributes
Write-Output ">>> shared/game: dl '$GIT_IGNR_UNITY' -> 'Game/.gitignore'"
Invoke-WebRequest -Uri $GIT_IGNR_UNITY -OutFile "Game/.gitignore"
Write-Output ">>> shared/game: dl '$GIT_ATTR_UNITY' -> 'Game/.gitattributes'"
Invoke-WebRequest -Uri $GIT_ATTR_UNITY -OutFile "Game/.gitattributes"
Write-Output ">>> shared/modelling: dl '$GIT_ATTR_MODEL' -> 'Modelling/.gitattributes'"
Invoke-WebRequest -Uri $GIT_ATTR_MODEL -OutFile "Modelling/.gitattributes"
Write-Output ">>> shared/design: dl '$GIT_ATTR_DESGN' -> 'Design/.gitattributes'"
Invoke-WebRequest -Uri $GIT_ATTR_DESGN -OutFile "Design/.gitattributes"
Write-Output ">>> shared/generic: dl '$GIT_ATTR_GENRC' -> '.gitattributes'"
Invoke-WebRequest -Uri $GIT_ATTR_GENRC -OutFile ".gitattributes"
# warn that shared repos cant be pushed to github for free due to git lfs restrictions
Write-Output ("`n!!! the shared repo CANT be pushed to github for free due to git lfs restrictions" +
"`n!!! use the forge instead")
}
function setupSingleRepository {
# ask if it is a maya, unity, design, or other (generic) project
Write-Output ("`n!!! what type of project is this? (m/u/d/g)`n" +
"!!! - [m]odelling: maya, zbrush, substance painter`n" +
"!!! - [u]nity: unity lol`n" +
"!!! - [d]esign: adobe design files, audiovisual files, figma`n" +
"!!! - [g]eneric: other project")
while ($true) {
$projectType = Read-Host
if ($projectType -eq "m" -or $projectType -eq "u" -or $projectType -eq "d" -or $projectType -eq "g") {
break
}
Write-Output "!!! expected: 'm', 'u', 'd', 'g'"
}
Write-Output ""
# ask if the repo will be pushed to github or the forge
Write-Output ("`n!!! will this repo be pushed to github or the forge? (g/f)`n" +
"!!! - [g]ithub: github.com`n" +
"!!! - [f]orge: forge.joshwel.co`n" +
"!!!`n" +
"!!! (this will affect how git lfs is setup, but it will be enabled regardless`n" +
"!!! ---`n" +
"!!! github has a 1gb lfs storage/bandwidth limit, while the forge doesn't care`n" +
"!!! saying 'f' will use actually defined .gitattributes,`n" +
"!!! while saying 'g' will use a basic .gitattributes that MIGHT not wreck your`n" +
"!!! 1gb git lfs allowance as long as you dont commit files bigger than 100mb)")
while ($true) {
$repoHost = Read-Host
if ($repoHost -eq "g" -or $repoHost -eq "f") {
break
}
Write-Output "!!! expected: 'g', 'f'"
}
Write-Output ""
# re-set variables if the repo will be pushed to the github (use github.gitattributes)
if ($repoHost -eq "g") {
$GIT_ATTR_UNITY=$GIT_ATTR_GITHB
$GIT_ATTR_MODEL=$GIT_ATTR_GITHB
$GIT_ATTR_DESGN=$GIT_ATTR_GITHB
$GIT_ATTR_GENRC=$GIT_ATTR_GITHB
}
# download appropriate .gitattribute and .gitignore
if ($projectType -eq "m") {
Write-Output ">>> modelling: dl '$GIT_ATTR_MODEL' -> '.gitattributes'"
Invoke-WebRequest -Uri $GIT_ATTR_MODEL -OutFile ".gitattributes"
} elseif ($projectType -eq "u") {
Write-Output ">>> unity: dl '$GIT_IGNR_UNITY' -> '.gitignore'"
Invoke-WebRequest -Uri $GIT_ATTR_UNITY -OutFile ".gitattributes"
Write-Output ">>> unity: dl '$GIT_ATTR_UNITY' -> '.gitattributes'"
Invoke-WebRequest -Uri $GIT_IGNR_UNITY -OutFile ".gitignore"
} elseif ($projectType -eq "d") {
Write-Output ">>> design: dl '$GIT_ATTR_DESGN' -> '.gitattributes'"
Invoke-WebRequest -Uri $GIT_ATTR_DESGN -OutFile ".gitattributes"
} else {
Write-Output ">>> generic: dl '$GIT_ATTR_GENRC' -> '.gitattributes'"
Invoke-WebRequest -Uri $GIT_ATTR_GENRC -OutFile ".gitattributes"
}
}
# pre-script setup
$oldErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
$OutputEncoding = [System.Text.Encoding]::UTF8
Write-Output ("`nforge/lfs-compatible repo quickstart setup`n" +
"with all my heart, mark 2024`n")
# check if .git exists in current directory
# if not, 'git init' to create a new repository
if (-not (Test-Path -Path ".git")) {
Write-Output ">> 'git init' (.git repo folder not found)"
git init
}
Write-Output ">> 'git lfs install'"
git lfs install
# ask the user if it is a shared or a single repository
# validate the input via a loop
Write-Output ("`n!!! shared repository: multiple projects in one repository`n" +
"!!! |-- .git/`n" +
"!!! |-- Game`n" +
"!!! | |-- .gitignore`n" +
"!!! | |-- .gitattributes`n" +
"!!! | ``-- ...`n" +
"!!! |-- Modelling`n" +
"!!! | |-- .gitattributes`n" +
"!!! | ``-- ...`n" +
"!!! ``-- ...`n" +
"!!!`n" +
"!!! single repository/monorepo: one project`n" +
"!!! |-- .git/`n" +
"!!! |-- .gitignore`n" +
"!!! |-- .gitattributes`n" +
"!!! ``-- ...`n" +
"!!!`n" +
"!!! is this a shared or mono repository? (s/m)")
while ($true) {
$repoType = Read-Host
if ($repoType -eq "s" -or $repoType -eq "m") {
break
}
Write-Output "!!! expected: 's', 'm'"
}
# setup the repository
if ($repoType -eq "s") {
setupSharedRepository
} else {
setupSingleRepository
}
# reset error action preference
$ErrorActionPreference = $oldErrorActionPreference
2024-07-01 21:40:32 +00:00
Write-Output "`n--- done~! ---`n"