# vx init - 初始化项目
在当前目录初始化VX项目配置。
## 语法
```bash
vx init [options]
```
## 描述
`vx init` 命令在当前目录创建 `.vx.toml` 配置文件,自动检测项目类型并建议合适的工具版本配置。
## 选项
- `--interactive` - 交互式初始化,逐步配置选项
- `--template <template>` - 使用预定义模板
- `--tools <tools>` - 指定要包含的工具列表
- `--force` - 强制覆盖已存在的配置文件
- `--dry-run` - 预览将要创建的配置,不实际创建文件
## 示例
### 基本初始化
```bash
# 自动检测项目类型并初始化
vx init
# 交互式初始化
vx init --interactive
# 使用模板初始化
vx init --template node
vx init --template python
vx init --template rust
```
### 指定工具
```bash
# 指定特定工具
vx init --tools node,uv,go
# 指定工具和版本
vx init --tools node@18.17.0,uv@latest
```
### 高级选项
```bash
# 强制覆盖现有配置
vx init --force
# 预览配置内容
vx init --dry-run
```
## 项目类型检测
VX 会自动检测项目类型并建议相应配置:
### Node.js 项目
检测文件:`package.json`
```bash
$ vx init
🔍 Detected Node.js project
📦 Found package.json with engines.node: ">=18.0.0"
Suggested configuration:
[tools]
node = "18.17.0"
npm = "latest"
[settings]
auto_install = true
Create .vx.toml with this configuration? (Y/n)
```
### Python 项目
检测文件:`pyproject.toml`, `requirements.txt`, `setup.py`
```bash
$ vx init
🔍 Detected Python project
🐍 Found pyproject.toml with requires-python: ">=3.11"
Suggested configuration:
[tools]
python = "3.11"
uv = "latest"
[settings]
auto_install = true
Create .vx.toml with this configuration? (Y/n)
```
### Rust 项目
检测文件:`Cargo.toml`
```bash
$ vx init
🔍 Detected Rust project
🦀 Found Cargo.toml with rust-version: "1.75"
Suggested configuration:
[tools]
rust = "1.75.0"
cargo = "latest"
[settings]
auto_install = true
Create .vx.toml with this configuration? (Y/n)
```
### Go 项目
检测文件:`go.mod`
```bash
$ vx init
🔍 Detected Go project
🐹 Found go.mod with go version: "1.21"
Suggested configuration:
[tools]
go = "1.21.6"
[settings]
auto_install = true
Create .vx.toml with this configuration? (Y/n)
```
### 混合项目
```bash
$ vx init
🔍 Detected mixed project (Node.js + Python)
📦 Found package.json and pyproject.toml
Suggested configuration:
[tools]
node = "18.17.0"
python = "3.11"
uv = "latest"
[settings]
auto_install = true
Create .vx.toml with this configuration? (Y/n)
```
## 交互式初始化
```bash
$ vx init --interactive
🚀 VX Project Initialization
Project name: my-awesome-project
Description: A sample project
Select tools to include:
[x] node (18.17.0)
[ ] python (3.11)
[x] uv (latest)
[ ] go (1.21.6)
[ ] rust (1.75.0)
Additional settings:
[x] Enable auto-install
[x] Enable update checks
[ ] Include development tools
Scripts to include:
[x] dev - Development server
[x] test - Run tests
[x] build - Build project
[ ] deploy - Deploy project
Environment variables:
NODE_ENV = development
DEBUG = true
✅ Configuration created successfully!
```
## 模板系统
### 可用模板
```bash
# 列出可用模板
vx init --list-templates
Available templates:
node - Node.js project with npm/yarn
python - Python project with uv
rust - Rust project with cargo
go - Go project
fullstack - Full-stack project (Node.js + Python)
minimal - Minimal configuration
```
### 使用模板
```bash
# Node.js 模板
vx init --template node
# 生成包含 node, npm 的配置
# Python 模板
vx init --template python
# 生成包含 python, uv 的配置
# 全栈模板
vx init --template fullstack
# 生成包含 node, python, uv 的配置
```
## 生成的配置文件
### 基本配置
```toml
# VX Project Configuration
# This file defines the tools and versions required for this project.
# Run 'vx sync' to install all required tools.
[tools]
node = "18.17.0"
uv = "latest"
[settings]
auto_install = true
cache_duration = "7d"
```
### 完整配置
```toml
# VX Project Configuration
# Generated by: vx init --interactive
[tools]
node = "18.17.0"
python = "3.11"
uv = "latest"
[settings]
auto_install = true
cache_duration = "7d"
parallel_install = true
[scripts]
dev = "vx node server.js"
test = "vx uv run pytest"
build = "vx node build.js"
[env]
NODE_ENV = "development"
PYTHONPATH = "./src"
DEBUG = "true"
```
## 初始化后步骤
```bash
$ vx init
✅ Created .vx.toml configuration file
Next steps:
1. Review the configuration: cat .vx.toml
2. Install tools: vx sync
3. Start using tools: vx node --version
Optional:
- Add to version control: git add .vx.toml
- Customize configuration: vx config edit --local
```
## 故障排除
### 初始化失败
```bash
# 检查目录权限
ls -la .
# 强制重新初始化
vx init --force
# 检查现有配置
cat .vx.toml
```
### 检测错误
```bash
# 手动指定工具
vx init --tools node@18.17.0,python@3.11
# 使用模板
vx init --template node
# 跳过自动检测
vx init --no-detect
```
## 相关命令
- [sync](./sync.md) - 同步安装工具
- [config](./config.md) - 配置管理
- [list](./list.md) - 列出可用工具