2023-07-15 17:46:19 +03:00
|
|
|
# Run local server
|
|
|
|
Param(
|
|
|
|
[switch] $freshStart
|
|
|
|
)
|
|
|
|
|
|
|
|
$pyExec = "$PSScriptRoot\backend\venv\Scripts\python.exe"
|
|
|
|
$djangoSrc = "$PSScriptRoot\backend\manage.py"
|
|
|
|
|
|
|
|
function RunServer() {
|
|
|
|
RunBackend
|
|
|
|
RunFrontend
|
|
|
|
Start-Sleep -Seconds 1
|
2023-07-26 23:11:00 +03:00
|
|
|
Start-Process "http://localhost:8000/"
|
|
|
|
Start-Process "http://localhost:3000/"
|
2023-07-15 17:46:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function RunBackend() {
|
|
|
|
Set-Location $PSScriptRoot\backend
|
|
|
|
if ($freshStart) {
|
|
|
|
FlushData
|
|
|
|
DoMigrations
|
|
|
|
PrepareStatic -clearPrevious
|
|
|
|
AddAdmin
|
|
|
|
} else {
|
|
|
|
DoMigrations
|
|
|
|
PrepareStatic
|
|
|
|
}
|
|
|
|
Invoke-Expression "cmd /c start powershell -Command { `$Host.UI.RawUI.WindowTitle = 'django'; & $pyExec $djangoSrc runserver }"
|
|
|
|
}
|
|
|
|
|
|
|
|
function RunFrontend() {
|
|
|
|
Set-Location $PSScriptRoot\frontend
|
2023-07-26 23:11:00 +03:00
|
|
|
& 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-07-29 15:37:52 +03:00
|
|
|
& $pyExec $djangoSrc flush --no-input\
|
|
|
|
$dbPath = "$PSScriptRoot\backend\db.sqlite3"
|
|
|
|
if (Test-Path -Path $dbPath -PathType Leaf) {
|
|
|
|
Remove-Item $dbPath
|
|
|
|
}
|
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
|