Skip to content

Commit 6aa9294

Browse files
Added dev environment setup scripts
1 parent 1187aaf commit 6aa9294

5 files changed

Lines changed: 150 additions & 0 deletions

File tree

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/init-dev-env.ps1

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<#
2+
.SYNOPSIS
3+
Set up the dev environment from a fresh clone of totk-vscode.
4+
.DESCRIPTION
5+
1. Initializes git submodules
6+
2. Installs Node dependencies (root)
7+
3. Creates a Python venv and installs Python dependencies
8+
.PARAMETER PythonPath
9+
Explicit path to a Python 3.10+ interpreter. If omitted, tries py, python3, python.
10+
#>
11+
param(
12+
[string]$PythonPath
13+
)
14+
15+
$ErrorActionPreference = 'Stop'
16+
$root = Split-Path -Parent $PSScriptRoot
17+
18+
Push-Location $root
19+
try {
20+
# ── 1. Git submodules ──────────────────────────────────────────────
21+
Write-Host "`n=== Initializing git submodules ===" -ForegroundColor Cyan
22+
git submodule update --init --recursive
23+
if ($LASTEXITCODE -ne 0) { throw "git submodule update failed" }
24+
25+
# ── 2. Node dependencies ───────────────────────────────────────────
26+
Write-Host "`n=== Installing Node dependencies (root) ===" -ForegroundColor Cyan
27+
npm install
28+
if ($LASTEXITCODE -ne 0) { throw "npm install failed" }
29+
30+
# ── 3. Python venv ─────────────────────────────────────────────────
31+
Write-Host "`n=== Setting up Python virtual environment ===" -ForegroundColor Cyan
32+
33+
if ($PythonPath) {
34+
$py = $PythonPath
35+
} else {
36+
$py = $null
37+
foreach ($candidate in @('py -3', 'python3', 'python')) {
38+
$parts = $candidate -split ' '
39+
$exe = $parts[0]
40+
$args = if ($parts.Length -gt 1) { $parts[1..($parts.Length-1)] } else { @() }
41+
try {
42+
$ver = & $exe @args --version 2>&1
43+
if ($ver -match 'Python 3\.(\d+)' -and [int]$Matches[1] -ge 10) {
44+
$py = $candidate
45+
Write-Host " Found: $ver ($candidate)" -ForegroundColor Green
46+
break
47+
}
48+
} catch {}
49+
}
50+
if (-not $py) { throw "Python 3.10+ not found. Install it or pass -PythonPath." }
51+
}
52+
53+
$venvDir = Join-Path $root '.venv'
54+
if (-not (Test-Path $venvDir)) {
55+
Write-Host " Creating venv at $venvDir"
56+
$parts = $py -split ' '
57+
$exe = $parts[0]
58+
$args = if ($parts.Length -gt 1) { $parts[1..($parts.Length-1)] } else { @() }
59+
& $exe @args -m venv $venvDir
60+
if ($LASTEXITCODE -ne 0) { throw "venv creation failed" }
61+
} else {
62+
Write-Host " venv already exists at $venvDir"
63+
}
64+
65+
$pip = Join-Path $venvDir 'Scripts' 'pip.exe'
66+
Write-Host " Installing Python dependencies"
67+
& $pip install $root --quiet
68+
if ($LASTEXITCODE -ne 0) { throw "pip install failed" }
69+
70+
Write-Host "`n=== Dev Environment Setup complete ===" -ForegroundColor Green
71+
} finally {
72+
Pop-Location
73+
}

scripts/init-dev-env.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Set up the dev environment from a fresh clone of totk-vscode.
4+
#
5+
# 1. Initializes git submodules
6+
# 2. Installs Node dependencies (root)
7+
# 3. Creates a Python venv and installs Python dependencies
8+
#
9+
# Usage:
10+
# ./scripts/init-env.sh
11+
# ./scripts/init-env.sh --python /path/to/python3.12 # explicit python
12+
13+
set -euo pipefail
14+
15+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
16+
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
17+
PYTHON_CMD=""
18+
19+
while [[ $# -gt 0 ]]; do
20+
case "$1" in
21+
--python) PYTHON_CMD="$2"; shift 2 ;;
22+
*) echo "Unknown option: $1"; exit 1 ;;
23+
esac
24+
done
25+
26+
cd "$ROOT"
27+
28+
# ── 1. Git submodules ──────────────────────────────────────────────
29+
echo ""
30+
echo "=== Initializing git submodules ==="
31+
git submodule update --init --recursive
32+
33+
# ── 2. Node dependencies ───────────────────────────────────────────
34+
echo ""
35+
echo "=== Installing Node dependencies (root) ==="
36+
npm install
37+
38+
# ── 3. Python venv ─────────────────────────────────────────────────
39+
echo ""
40+
echo "=== Setting up Python virtual environment ==="
41+
42+
if [[ -z "$PYTHON_CMD" ]]; then
43+
for candidate in python3 python; do
44+
if command -v "$candidate" &>/dev/null; then
45+
ver=$("$candidate" --version 2>&1 || true)
46+
if [[ "$ver" =~ Python\ 3\.([0-9]+) ]] && (( ${BASH_REMATCH[1]} >= 10 )); then
47+
PYTHON_CMD="$candidate"
48+
echo " Found: $ver ($candidate)"
49+
break
50+
fi
51+
fi
52+
done
53+
if [[ -z "$PYTHON_CMD" ]]; then
54+
echo "ERROR: Python 3.10+ not found. Install it or pass --python /path/to/python3."
55+
exit 1
56+
fi
57+
fi
58+
59+
VENV_DIR="$ROOT/.venv"
60+
if [[ ! -d "$VENV_DIR" ]]; then
61+
echo " Creating venv at $VENV_DIR"
62+
"$PYTHON_CMD" -m venv "$VENV_DIR"
63+
else
64+
echo " venv already exists at $VENV_DIR"
65+
fi
66+
67+
PIP="$VENV_DIR/bin/pip"
68+
echo " Installing Python dependencies"
69+
"$PIP" install "$ROOT" --quiet
70+
71+
echo ""
72+
echo "=== Dev Environment Setup complete ==="

0 commit comments

Comments
 (0)