114 lines
3.6 KiB
Markdown
114 lines
3.6 KiB
Markdown
# Environment Detection Rules
|
|
|
|
How to detect the runtime environment and guide the user through setup in `/follow`.
|
|
|
|
## Language Detection from Config
|
|
|
|
Check these files in order. The first match is the primary language.
|
|
|
|
| Config file | Language | Runtime check | Install command |
|
|
|---|---|---|---|
|
|
| `package.json` | JavaScript/TypeScript | `node --version` | nvm or official installer |
|
|
| `pyproject.toml` | Python | `python --version` | pyenv or python.org |
|
|
| `go.mod` | Go | `go version` | golang.org/dl |
|
|
| `Cargo.toml` | Rust | `rustc --version` | rustup |
|
|
| `pom.xml` | Java | `java -version` | SDKMAN or official |
|
|
| `build.gradle` / `build.gradle.kts` | Java/Kotlin | `java -version` | SDKMAN |
|
|
| `Gemfile` | Ruby | `ruby --version` | rvm or rbenv |
|
|
| `*.csproj` | C#/.NET | `dotnet --version` | .NET SDK |
|
|
| `CMakeLists.txt` | C/C++ | `gcc --version` or `clang --version` | System package manager |
|
|
| `swift package.json` | Swift | `swift --version` | Xcode or swift.org |
|
|
|
|
## Dependency Installation
|
|
|
|
Once language is detected, guide the user:
|
|
|
|
### JavaScript/TypeScript
|
|
```bash
|
|
# Check which package manager is used
|
|
if [ -f "yarn.lock" ]; then yarn install
|
|
elif [ -f "pnpm-lock.yaml" ]; then pnpm install
|
|
elif [ -f "bun.lockb" ] || [ -f "bun.lock" ]; then bun install
|
|
else npm install
|
|
fi
|
|
```
|
|
|
|
### Python
|
|
```bash
|
|
# Modern Python projects
|
|
pip install -e .
|
|
# Or with requirements
|
|
pip install -r requirements.txt
|
|
# Or with poetry
|
|
poetry install
|
|
# Or with uv
|
|
uv pip install -r requirements.txt
|
|
```
|
|
|
|
### Go
|
|
```bash
|
|
go mod download
|
|
```
|
|
|
|
### Rust
|
|
```bash
|
|
cargo build
|
|
```
|
|
|
|
### Java (Maven)
|
|
```bash
|
|
mvn install
|
|
```
|
|
|
|
### Java (Gradle)
|
|
```bash
|
|
./gradlew build
|
|
# or
|
|
gradle build
|
|
```
|
|
|
|
## Run Command Detection
|
|
|
|
How to start the project:
|
|
|
|
| Source | Command |
|
|
|---|---|
|
|
| `package.json` → `scripts.dev` | `npm run dev` |
|
|
| `package.json` → `scripts.start` | `npm start` |
|
|
| `Makefile` → `dev` target | `make dev` |
|
|
| `Makefile` → `run` target | `make run` |
|
|
| `pyproject.toml` (Poetry) | `poetry run python main.py` |
|
|
| `go.mod` → `package main` | `go run main.go` |
|
|
| `Cargo.toml` → `[[bin]]` | `cargo run` |
|
|
| `docker-compose.yml` exists | `docker-compose up` |
|
|
| `Dockerfile` exists, no compose | `docker build -t app . && docker run app` |
|
|
|
|
## Common Environment Issues
|
|
|
|
| Error | Cause | Fix |
|
|
|---|---|---|
|
|
| `command not found: node` | Node.js not installed | Install Node.js (recommend LTS) |
|
|
| `ModuleNotFoundError` | Python deps not installed | Run `pip install -r requirements.txt` |
|
|
| `EACCES: permission denied` | Global install without sudo | Use nvm/fnm, or prefix with sudo |
|
|
| `ENOENT: no such file` | Wrong working directory | `cd` to project root first |
|
|
| `port already in use` | Another process on same port | Kill the process or use different port |
|
|
| `go: cannot find main module` | Outside Go module | `cd` to directory with `go.mod` |
|
|
| `error: could not find Cargo.toml` | Outside Rust project | `cd` to directory with `Cargo.toml` |
|
|
| `java.lang.UnsupportedClassVersionError` | Wrong Java version | Match JDK version to project requirement |
|
|
| `npm ERR! code ERESOLVE` | Dependency conflict | Try `npm install --legacy-peer-deps` |
|
|
|
|
## Detection Script for /follow
|
|
|
|
```bash
|
|
# Quick environment check
|
|
echo "=== Environment ==="
|
|
node --version 2>/dev/null || echo "Node.js: not installed"
|
|
python --version 2>/dev/null || echo "Python: not installed"
|
|
go version 2>/dev/null || echo "Go: not installed"
|
|
rustc --version 2>/dev/null || echo "Rust: not installed"
|
|
java -version 2>/dev/null || echo "Java: not installed"
|
|
echo "PWD: $(pwd)"
|
|
```
|
|
|
|
Run this at the start of `/follow` Step 1 to understand what's available.
|