-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
87 lines (69 loc) · 2.53 KB
/
Copy pathstart.ps1
File metadata and controls
87 lines (69 loc) · 2.53 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
$ErrorActionPreference = "Stop"
$rootDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$backendDir = Join-Path $rootDir "Back_end"
$frontendDir = Join-Path $rootDir "Front_end"
function Assert-Directory {
param(
[string]$Path,
[string]$Name
)
if (-not (Test-Path -LiteralPath $Path -PathType Container)) {
throw "Missing $Name directory: $Path"
}
}
function Assert-Command {
param([string]$Name)
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
throw "Missing required command: $Name"
}
}
function Convert-ToPowerShellLiteral {
param([string]$Value)
return "'" + $Value.Replace("'", "''") + "'"
}
function Convert-ToEncodedCommand {
param([string]$Command)
return [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($Command))
}
Assert-Directory $backendDir "backend"
Assert-Directory $frontendDir "frontend"
Assert-Command "java"
Assert-Command "mvn"
Assert-Command "node"
Assert-Command "npm"
$powerShellExe = (Get-Process -Id $PID).Path
if (-not $powerShellExe) {
$powerShellExe = "powershell.exe"
}
$backendDirLiteral = Convert-ToPowerShellLiteral $backendDir
$frontendDirLiteral = Convert-ToPowerShellLiteral $frontendDir
$backendCommand = @"
`$ErrorActionPreference = 'Stop'
Set-Location -LiteralPath $backendDirLiteral
Write-Host '[XinKe backend] Starting Spring Boot: http://127.0.0.1:8080/api/v1'
mvn spring-boot:run
"@
$frontendCommand = @"
`$ErrorActionPreference = 'Stop'
Set-Location -LiteralPath $frontendDirLiteral
if (-not (Test-Path -LiteralPath 'node_modules' -PathType Container)) {
Write-Host '[XinKe frontend] node_modules not found, installing dependencies...'
if (Test-Path -LiteralPath 'package-lock.json' -PathType Leaf) {
npm ci
} else {
npm install
}
}
Write-Host '[XinKe frontend] Starting Vite: http://127.0.0.1:5173'
npm run dev
"@
Start-Process -FilePath $powerShellExe `
-ArgumentList @("-NoExit", "-ExecutionPolicy", "Bypass", "-EncodedCommand", (Convert-ToEncodedCommand $backendCommand)) `
-WorkingDirectory $backendDir
Start-Sleep -Seconds 2
Start-Process -FilePath $powerShellExe `
-ArgumentList @("-NoExit", "-ExecutionPolicy", "Bypass", "-EncodedCommand", (Convert-ToEncodedCommand $frontendCommand)) `
-WorkingDirectory $frontendDir
Write-Host "[XinKe] Backend window launched: http://127.0.0.1:8080/api/v1"
Write-Host "[XinKe] Frontend window launched: http://127.0.0.1:5173"
Write-Host "[XinKe] Close the backend/frontend windows, or press Ctrl+C in them, to stop services."