modules/solution/Install-Frontend.ps1
|
param( [string]$ProjectName, [string]$OrmMode, [string]$OutputPath, [string]$Platform = "Web", [bool]$SkipNpm = $false ) . (Join-Path (Split-Path $MyInvocation.MyCommand.Path) "..\core\Utils.ps1") # 1. Determine paths $WebPath = if ($Platform -match "Web|Both") { Join-Path $OutputPath "$ProjectName-web" } else { $null } $MobilePath = if ($Platform -match "Mobile|Both") { Join-Path $OutputPath "$ProjectName-mobile" } else { $null } # 2. Write Web files if Web is selected if ($WebPath) { if (-not $Global:DryRun -and -not (Test-Path $WebPath)) { New-Item -ItemType Directory -Path $WebPath -Force | Out-Null } $pkg = @{ name = "$($ProjectName.ToLower())-web" private = $true version = "0.1.0" type = "module" scripts = @{ dev = "vite" build = "tsc && vite build" preview = "vite preview" } dependencies = @{ "react" = "^18.3.1" "react-dom" = "^18.3.1" "react-router-dom" = "^7.5.0" "axios" = "^1.9.0" "@tanstack/react-query" = "^5.101.0" } devDependencies = @{ "@types/react" = "^18.3.20" "@types/react-dom" = "^18.3.6" "@vitejs/plugin-react" = "^4.5.0" "typescript" = "~5.8.0" "vite" = "^6.3.0" } } $pkgJson = $pkg | ConvertTo-Json -Depth 10 Write-CoreFile (Join-Path $WebPath "package.json") $pkgJson Write-CoreFile (Join-Path $WebPath "vite.config.ts") "import { defineConfig } from 'vite';`nimport react from '@vitejs/plugin-react';`nexport default defineConfig({ plugins: [react()] });" Write-CoreFile (Join-Path $WebPath "tsconfig.json") @' { "compilerOptions": { "target": "ESNext", "useDefineForClassFields": true, "lib": ["DOM", "DOM.Iterable", "ESNext"], "allowJs": false, "skipLibCheck": true, "esModuleInterop": false, "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "module": "ESNext", "moduleResolution": "Node", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx" }, "include": ["./**/*.ts", "./**/*.tsx"], "exclude": ["node_modules", "vite.config.ts"], "references": [{ "path": "./tsconfig.node.json" }] } '@ Write-CoreFile (Join-Path $WebPath "tsconfig.node.json") @' { "compilerOptions": { "composite": true, "skipLibCheck": true, "module": "ESNext", "moduleResolution": "Node", "allowSyntheticDefaultImports": true }, "include": ["vite.config.ts"] } '@ } if (-not $Global:DryRun -and -not $SkipNpm -and $WebPath) { $targets = @($WebPath) foreach ($npmTarget in $targets) { Write-Host "Running npm install in: $npmTarget" -ForegroundColor Cyan Push-Location $npmTarget try { Invoke-Cmd "npm" "install --prefer-offline --no-audit --no-fund" } catch { Write-Warn "npm install failed in $npmTarget - project files are still valid." Write-Warn "Run 'npm install' manually in: $npmTarget" } Pop-Location } } |