136 lines
6.2 KiB
PowerShell
136 lines
6.2 KiB
PowerShell
<#
|
|
Creates a new project from a Library template, or refreshes the kit copy in an existing one.
|
|
|
|
New project (folder D:\Oculusquest\Projekt\<Name>):
|
|
.\new-project.ps1 -Name "Particle Panic" # HTML game (default)
|
|
.\new-project.ps1 -Name "Star Miner" -Type mobile # Vite + TS + Capacitor
|
|
options: -Root <parent folder> -NoGit -NoGenerator -Force (allow an existing EMPTY-ish folder)
|
|
|
|
Refresh kit files after improving them in the Library:
|
|
.\new-project.ps1 -UpdateKit -Path D:\Oculusquest\Projekt\Pipefix2
|
|
|
|
Placeholders in template files: {{NAME}} {{SLUG}} {{IDENT}} {{DATE}} {{YEAR}}
|
|
#>
|
|
param(
|
|
[string]$Name,
|
|
[ValidateSet('webgame', 'mobile')][string]$Type = 'webgame',
|
|
[string]$Root = 'D:\Oculusquest\Projekt',
|
|
[string]$Path,
|
|
[switch]$UpdateKit,
|
|
[switch]$NoGit,
|
|
[switch]$NoGenerator,
|
|
[switch]$Force
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$lib = $PSScriptRoot
|
|
$comfyTemplate = Join-Path (Split-Path $lib -Parent) 'ComfyGen\template'
|
|
$utf8 = New-Object System.Text.UTF8Encoding($false)
|
|
|
|
function KitTarget([string]$dir, [string]$kind) {
|
|
if ($kind -eq 'mobile') { return Join-Path $dir 'src\kit' }
|
|
return Join-Path $dir 'game\kit'
|
|
}
|
|
|
|
function Copy-Kit([string]$dir, [string]$kind) {
|
|
$src = Join-Path $lib "$(if ($kind -eq 'mobile') { 'mobile' } else { 'web' })\kit"
|
|
$dst = KitTarget $dir $kind
|
|
New-Item -ItemType Directory -Force $dst | Out-Null
|
|
$files = Get-ChildItem $src -File
|
|
foreach ($f in $files) { Copy-Item $f.FullName (Join-Path $dst $f.Name) -Force }
|
|
"Kit -> $dst ($($files.Count) Dateien: $(($files | ForEach-Object Name) -join ', '))"
|
|
}
|
|
|
|
# ---------------------------------------------------------------- update kit only
|
|
if ($UpdateKit) {
|
|
if (-not $Path) { $Path = (Get-Location).Path }
|
|
$Path = (Resolve-Path $Path).Path
|
|
if (Test-Path (Join-Path $Path 'game\kit')) { $kind = 'webgame' }
|
|
elseif (Test-Path (Join-Path $Path 'src\kit')) { $kind = 'mobile' }
|
|
else { throw "Kein game\kit oder src\kit in $Path gefunden." }
|
|
Copy-Kit $Path $kind
|
|
'Unterschiede pruefen: git diff -- ' + $(if ($kind -eq 'mobile') { 'src/kit' } else { 'game/kit' })
|
|
exit 0
|
|
}
|
|
|
|
# ---------------------------------------------------------------- new project
|
|
if (-not $Name) { throw 'Parameter -Name fehlt (z. B. -Name "Particle Panic").' }
|
|
$slug = ($Name.ToLowerInvariant() -replace '[^a-z0-9]', '')
|
|
if (-not $slug) { throw "Aus '$Name' laesst sich kein Kurzname bilden (nur a-z, 0-9)." }
|
|
$ident = (($Name -split '[^A-Za-z0-9]+') | Where-Object { $_ } | ForEach-Object { $_.Substring(0, 1).ToUpperInvariant() + $_.Substring(1) }) -join ''
|
|
if ($ident -match '^[0-9]') { $ident = 'G' + $ident }
|
|
|
|
$dest = Join-Path $Root $Name
|
|
if (Test-Path $dest) {
|
|
$existing = Get-ChildItem $dest -Force | Where-Object { $_.Name -notin '.claude', '.dashboard.json' }
|
|
if ($existing -and -not $Force) { throw "$dest existiert und ist nicht leer. Anderer Name oder -Force." }
|
|
}
|
|
New-Item -ItemType Directory -Force $dest | Out-Null
|
|
|
|
$tpl = Join-Path $lib "$(if ($Type -eq 'mobile') { 'mobile' } else { 'web' })\template"
|
|
# copy file by file, skipping build output an editor may have created inside the template
|
|
$skip = '\\(bin|obj|node_modules|dist|release)(\\|$)'
|
|
Get-ChildItem $tpl -Recurse -File -Force | Where-Object { $_.FullName.Substring($tpl.Length) -notmatch $skip } | ForEach-Object {
|
|
# *.template = file an IDE must not pick up inside the Library (e.g. Launcher.csproj.template)
|
|
$target = Join-Path $dest ($_.FullName.Substring($tpl.Length + 1) -replace '\.template$', '')
|
|
New-Item -ItemType Directory -Force (Split-Path $target -Parent) | Out-Null
|
|
Copy-Item $_.FullName $target -Force
|
|
}
|
|
|
|
# placeholders
|
|
$now = Get-Date
|
|
$map = @{
|
|
'{{NAME}}' = $Name; '{{SLUG}}' = $slug; '{{IDENT}}' = $ident
|
|
'{{DATE}}' = $now.ToString('yyyy-MM-dd'); '{{YEAR}}' = $now.ToString('yyyy')
|
|
}
|
|
$textExt = '.html', '.js', '.mjs', '.ts', '.css', '.json', '.md', '.ps1', '.cs', '.csproj', '.py', '.txt', '.gitignore'
|
|
Get-ChildItem $dest -Recurse -File -Force | Where-Object { $textExt -contains $_.Extension -or $_.Name -eq '.gitignore' } | ForEach-Object {
|
|
$t = [IO.File]::ReadAllText($_.FullName, $utf8)
|
|
$n = $t
|
|
foreach ($k in $map.Keys) { $n = $n.Replace($k, $map[$k]) }
|
|
if ($n -ne $t) { [IO.File]::WriteAllText($_.FullName, $n, $utf8) }
|
|
}
|
|
|
|
Copy-Kit $dest $Type
|
|
|
|
# asset folders (ComfyGen adopt writes to ASSETS_DIR\Sprites and \Audio)
|
|
$assetRel = if ($Type -eq 'mobile') { 'public\assets' } else { 'game\assets' }
|
|
foreach ($sub in 'Sprites', 'Audio', 'Fonts') { New-Item -ItemType Directory -Force (Join-Path $dest "$assetRel\$sub") | Out-Null }
|
|
|
|
# sprite generator (ComfyGen project)
|
|
if (-not $NoGenerator -and (Test-Path $comfyTemplate)) {
|
|
$gen = Join-Path $dest 'sprite-generator'
|
|
New-Item -ItemType Directory -Force $gen | Out-Null
|
|
Get-ChildItem $comfyTemplate -File | ForEach-Object { Copy-Item $_.FullName $gen -Force }
|
|
$cfgFile = Join-Path $gen 'config.py'
|
|
$parts = ($assetRel -split '\\' | ForEach-Object { '"' + $_ + '"' }) -join ', '
|
|
$cfg = [IO.File]::ReadAllText($cfgFile, $utf8)
|
|
$cfg = [regex]::Replace($cfg, '(?m)^ASSETS_DIR\s*=.*$', "ASSETS_DIR = os.path.join(PROJECT_ROOT, $parts)")
|
|
[IO.File]::WriteAllText($cfgFile, $cfg, $utf8)
|
|
"Generator -> $gen (ASSETS_DIR = $assetRel)"
|
|
}
|
|
|
|
# project dashboard entry
|
|
$dash = Join-Path $dest '.dashboard.json'
|
|
if (-not (Test-Path $dash)) {
|
|
$d = [ordered]@{ status = 'active'; priority = 'medium'; notes = "Vorlage $Type aus _Tools\Library"; tags = @($Type);
|
|
tasks = @(); thumbnail = ''; start = ''; updatedAt = $now.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffZ') }
|
|
[IO.File]::WriteAllText($dash, ($d | ConvertTo-Json -Depth 3), $utf8)
|
|
}
|
|
|
|
# git (init only - the first commit is up to the user)
|
|
if (-not $NoGit -and (Get-Command git -ErrorAction SilentlyContinue) -and -not (Test-Path (Join-Path $dest '.git'))) {
|
|
git -C $dest init -q -b main 2>$null
|
|
if ($LASTEXITCODE -ne 0) { git -C $dest init -q }
|
|
'git init (noch kein Commit)'
|
|
}
|
|
|
|
''
|
|
"Fertig: $dest (Typ $Type, Kurzname $slug, Ident $ident)"
|
|
if ($Type -eq 'webgame') {
|
|
" Spielen: $dest\game\index.html"
|
|
" Release: cd `"$dest`"; .\build.ps1"
|
|
} else {
|
|
" cd `"$dest`"; npm install; npm start"
|
|
" Android: npx cap add android; npm run android"
|
|
}
|