-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.ps1
More file actions
98 lines (82 loc) · 3.45 KB
/
Copy pathsetup.ps1
File metadata and controls
98 lines (82 loc) · 3.45 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
88
89
90
91
92
93
94
95
96
97
98
# TaleWeaver Setup Script (PowerShell)
# This script sets up the Python environment, database, and frontend dependencies.
param (
[switch]$SkipStart
)
$ErrorActionPreference = "Stop"
Write-Host "--- TaleWeaver Setup ---" -ForegroundColor Cyan
# 1. Environment Variables (.env)
if (-not (Test-Path ".env")) {
Write-Host "[*] Creating .env from .env.example..." -ForegroundColor Yellow
Copy-Item ".env.example" ".env"
}
$envFile = Get-Content ".env" -Raw
if ($envFile -notmatch "PROJECT_NAME=") {
$envFile = "PROJECT_NAME=`"TaleWeaver`"`r`n" + $envFile
} else {
$envFile = $envFile -replace "PROJECT_NAME=.*", "PROJECT_NAME=`"TaleWeaver`""
}
Set-Content ".env" $envFile
# 2. Python Virtual Environment
if (-not (Test-Path "venv")) {
Write-Host "[*] Creating virtual environment (venv)..." -ForegroundColor Yellow
python -m venv venv
}
# 3. Install Backend Dependencies
Write-Host "[*] Installing backend dependencies..." -ForegroundColor Yellow
.\venv\Scripts\python.exe -m pip install --upgrade pip
.\venv\Scripts\pip.exe install -r requirements.txt
# 4. Security Keys
if (-not (Test-Path "data")) {
Write-Host "[*] Creating data directory..." -ForegroundColor Yellow
New-Item -ItemType Directory -Path "data" | Out-Null
}
# Helper: set or append a key=value pair in .env
# If the key line already exists it is replaced, otherwise appended.
function Set-EnvKey {
param([string]$Key, [string]$Value)
$content = Get-Content ".env" -Raw
if ($content -match "(?m)^${Key}=") {
$content = $content -replace "(?m)^${Key}=.*", "${Key}=${Value}"
} else {
$content = $content.TrimEnd() + "`r`n${Key}=${Value}`r`n"
}
Set-Content ".env" $content -NoNewline
}
$envFile = Get-Content ".env" -Raw
# ENCRYPTION_KEY
if ($envFile -notmatch "(?m)^ENCRYPTION_KEY=[a-zA-Z0-9+/=_-]{20,}") {
Write-Host "[*] Generating ENCRYPTION_KEY..." -ForegroundColor Yellow
$key = .\venv\Scripts\python.exe -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
Set-EnvKey "ENCRYPTION_KEY" $key
Write-Host "[+] ENCRYPTION_KEY written to .env" -ForegroundColor Green
}
# SECRET_KEY
$envFile = Get-Content ".env" -Raw
if ($envFile -notmatch "(?m)^SECRET_KEY=[a-fA-F0-9]{64}") {
Write-Host "[*] Generating SECRET_KEY..." -ForegroundColor Yellow
$skey = .\venv\Scripts\python.exe -c "import secrets; print(secrets.token_hex(32))"
Set-EnvKey "SECRET_KEY" $skey
Write-Host "[+] SECRET_KEY written to .env" -ForegroundColor Green
}
# 5. Database Setup (Migrations)
Write-Host "[*] Running database migrations..." -ForegroundColor Yellow
.\venv\Scripts\python.exe -m alembic upgrade head
# 6. Frontend Setup
Write-Host "[*] Installing frontend dependencies..." -ForegroundColor Yellow
Set-Location frontend
npm install
Set-Location ..
Write-Host "`n--- Setup Complete! ---" -ForegroundColor Green
Write-Host "To start the application:"
Write-Host "Backend: .\venv\Scripts\python.exe -m backend.main"
Write-Host "Frontend: cd frontend; npm run dev`n"
# 7. Start (Optional / Interactive)
if (-not $SkipStart) {
$start = Read-Host "Would you like to start the application now? (y/n)"
if ($start -eq "y") {
Write-Host "[*] Starting backend and frontend in new windows..." -ForegroundColor Cyan
Start-Process powershell -ArgumentList "-NoExit", "-Command", ".\venv\Scripts\python.exe -m backend.main"
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd frontend; npm run dev"
}
}