ConceptPortal-public/scripts/dev/RunServer.ps1

73 lines
1.8 KiB
PowerShell
Raw Normal View History

# Run local server
2023-07-15 17:46:19 +03:00
Param(
[switch] $freshStart
)
$backend = Resolve-Path -Path "$PSScriptRoot\..\..\rsconcept\backend"
$frontend = Resolve-Path -Path "$PSScriptRoot\..\..\rsconcept\frontend"
$pyExec = "$backend\venv\Scripts\python.exe"
$djangoSrc = "$backend\manage.py"
2023-08-25 22:51:20 +03:00
$initialData = "fixtures/InitialData.json"
2023-07-15 17:46:19 +03:00
function RunServer() {
BackendRun
FrontendRun
2023-07-15 17:46:19 +03:00
Start-Sleep -Seconds 1
Start-Process "http://localhost:8000/"
Start-Process "http://localhost:3000/"
2023-07-15 17:46:19 +03:00
}
function BackendRun() {
Set-Location $backend
2023-07-15 17:46:19 +03:00
if ($freshStart) {
FlushData
DoMigrations
PrepareStatic -clearPrevious
2023-08-25 22:51:20 +03:00
AddInitialData
2023-07-15 17:46:19 +03:00
AddAdmin
} else {
DoMigrations
PrepareStatic
}
Invoke-Expression "cmd /c start powershell -Command { `$Host.UI.RawUI.WindowTitle = 'django'; & $pyExec $djangoSrc runserver }"
}
function FrontendRun() {
Set-Location $frontend
& npm install
Invoke-Expression "cmd /c start powershell -Command { `$Host.UI.RawUI.WindowTitle = 'react'; & npm run dev }"
2023-07-15 17:46:19 +03:00
}
function FlushData {
2023-08-25 22:51:20 +03:00
& $pyExec $djangoSrc flush --noinput
$dbPath = "$backend\db.sqlite3"
2023-07-29 15:37:52 +03:00
if (Test-Path -Path $dbPath -PathType Leaf) {
Remove-Item $dbPath
}
2023-07-15 17:46:19 +03:00
}
2023-08-25 22:51:20 +03:00
function AddInitialData {
& $pyExec manage.py loaddata $initialData
}
2023-07-15 17:46:19 +03:00
function AddAdmin {
$env:DJANGO_SUPERUSER_USERNAME = 'admin'
$env:DJANGO_SUPERUSER_PASSWORD = '1234'
$env:DJANGO_SUPERUSER_EMAIL = 'admin@admin.com'
2023-08-05 15:45:18 +03:00
& $pyExec $djangoSrc createsuperuser --noinput
2023-07-15 17:46:19 +03:00
}
function DoMigrations {
& $pyExec $djangoSrc makemigrations
& $pyExec $djangoSrc migrate
}
function PrepareStatic([switch]$clearPrevious) {
if ($clearPrevious) {
& $pyExec $djangoSrc collectstatic --noinput --clear
} else {
& $pyExec $djangoSrc collectstatic --noinput
}
}
RunServer