Merge pull request 'chore(dev): 配置本地开发环境' (#1) from chore/devenv-setup into main
Reviewed-on: #1
This commit is contained in:
commit
62d426bdfb
10
.gitignore
vendored
10
.gitignore
vendored
@ -15,3 +15,13 @@ coverage/
|
||||
.idea
|
||||
.gitignore
|
||||
|
||||
# Devenv
|
||||
.devenv*
|
||||
devenv.local.nix
|
||||
devenv.local.yaml
|
||||
|
||||
# direnv
|
||||
.direnv
|
||||
|
||||
# pre-commit
|
||||
.pre-commit-config.yaml
|
||||
|
||||
65
devenv.lock
Normal file
65
devenv.lock
Normal file
@ -0,0 +1,65 @@
|
||||
{
|
||||
"nodes": {
|
||||
"devenv": {
|
||||
"locked": {
|
||||
"dir": "src/modules",
|
||||
"lastModified": 1778613747,
|
||||
"narHash": "sha256-+FdF9iIvBQIC391Xkoso3IFIl/Iqp2NolSvCOgEIm78=",
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"rev": "c9ee1d61986a6dde1cf45e738b01395cd5bce470",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"dir": "src/modules",
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"inputs": {
|
||||
"nixpkgs-src": "nixpkgs-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1778507786,
|
||||
"narHash": "sha256-HzSQCKMsMr8r55LwM1JuzIOB+8bzk0FEv6sItKvsfoY=",
|
||||
"owner": "cachix",
|
||||
"repo": "devenv-nixpkgs",
|
||||
"rev": "8f24a228a782e24576b155d1e39f0d914b380691",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"ref": "rolling",
|
||||
"repo": "devenv-nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1778274207,
|
||||
"narHash": "sha256-I4puXmX1iovcCHZlRmztO3vW0mAbbRvq4F8wgIMQ1MM=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "b3da656039dc7a6240f27b2ef8cc6a3ef3bccae7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"devenv": "devenv",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
104
devenv.nix
Normal file
104
devenv.nix
Normal file
@ -0,0 +1,104 @@
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
|
||||
{
|
||||
starship = {
|
||||
enable = true;
|
||||
config = {
|
||||
enable = true;
|
||||
path = ./starship.toml;
|
||||
};
|
||||
};
|
||||
|
||||
env = {
|
||||
AI_GATEWAY_DATABASE_NAME = "easyai_ai_gateway";
|
||||
AI_GATEWAY_DATABASE_URL = "host=${config.env.DEVENV_RUNTIME}/postgres dbname=easyai_ai_gateway sslmode=disable";
|
||||
AI_GATEWAY_SKIP_DB_CREATE = "1";
|
||||
};
|
||||
|
||||
packages = with pkgs; [
|
||||
curl
|
||||
docker-client
|
||||
git
|
||||
jq
|
||||
lsof
|
||||
postgresql_18
|
||||
ripgrep
|
||||
watchexec
|
||||
];
|
||||
|
||||
scripts = {
|
||||
dev.exec = "pnpm dev";
|
||||
build.exec = "pnpm build";
|
||||
test-all.exec = "pnpm test";
|
||||
lint.exec = "pnpm lint";
|
||||
migrate.exec = "pnpm migrate";
|
||||
db-create.exec = "pnpm db:create";
|
||||
api-test.exec = "pnpm nx run api:test";
|
||||
web-build.exec = "pnpm nx run web:build";
|
||||
};
|
||||
|
||||
services.postgres = {
|
||||
enable = true;
|
||||
package = pkgs.postgresql_18.withPackages (postgresPackages: [
|
||||
postgresPackages.pgvector
|
||||
]);
|
||||
listen_addresses = "";
|
||||
initialDatabases = [
|
||||
{
|
||||
name = "easyai_ai_gateway";
|
||||
initialSQL = ''
|
||||
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||
CREATE EXTENSION IF NOT EXISTS vector;
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# https://devenv.sh/languages/
|
||||
languages.go = {
|
||||
enable = true;
|
||||
package = pkgs.go;
|
||||
};
|
||||
|
||||
languages.javascript = {
|
||||
enable = true;
|
||||
package = pkgs.nodejs_22;
|
||||
nodejs.enable = true;
|
||||
lsp.enable = true;
|
||||
pnpm = {
|
||||
enable = true;
|
||||
install.enable = true;
|
||||
};
|
||||
};
|
||||
|
||||
enterShell = ''
|
||||
echo ""
|
||||
echo "EasyAI AI Gateway 开发环境已就绪"
|
||||
echo "当前目录:$PWD"
|
||||
echo ""
|
||||
echo "运行时版本:"
|
||||
echo " go: $(go version | awk '{print $3}')"
|
||||
echo " node: $(node --version)"
|
||||
echo " pnpm: $(pnpm --version)"
|
||||
echo " psql: $(psql --version | awk '{print $3}')"
|
||||
echo ""
|
||||
echo "常用命令:"
|
||||
echo " dev 创建/迁移数据库,并启动 API 和 Web"
|
||||
echo " test-all 运行 API 和 Web 测试目标"
|
||||
echo " build 构建 API 和 Web"
|
||||
echo " lint 运行 Web 与 contracts 类型检查"
|
||||
echo " migrate 执行 API 数据库迁移"
|
||||
echo " db-create 创建 AI Gateway 数据库"
|
||||
echo " api-test 只运行 Go API 测试"
|
||||
echo " web-build 只构建 Web 前端"
|
||||
echo ""
|
||||
echo "提示:根 package.json 是唯一脚本入口;上述短命令由 devenv scripts 转发。"
|
||||
echo ""
|
||||
'';
|
||||
}
|
||||
18
devenv.yaml
Normal file
18
devenv.yaml
Normal file
@ -0,0 +1,18 @@
|
||||
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
|
||||
inputs:
|
||||
nixpkgs:
|
||||
url: github:cachix/devenv-nixpkgs/rolling
|
||||
|
||||
# If you're using non-OSS software, you can set allowUnfree to true.
|
||||
# allowUnfree: true
|
||||
|
||||
# If you're not willing to allow unsupported packages:
|
||||
# allowUnsupportedSystem: false
|
||||
|
||||
# If you're willing to use a package that's vulnerable
|
||||
# permittedInsecurePackages:
|
||||
# - "openssl-1.1.1w"
|
||||
|
||||
# If you have more than one devenv you can merge them
|
||||
#imports:
|
||||
# - ./backend
|
||||
@ -68,7 +68,11 @@ export AI_GATEWAY_DATABASE_URL="${AI_GATEWAY_DATABASE_URL:-postgresql://${AI_GAT
|
||||
|
||||
echo "[ai-gateway] using database: ${AI_GATEWAY_DATABASE_URL}"
|
||||
|
||||
scripts/create-database.sh
|
||||
if [[ "${AI_GATEWAY_SKIP_DB_CREATE:-}" == "1" ]]; then
|
||||
echo "[ai-gateway] skipping Docker database creation"
|
||||
else
|
||||
scripts/create-database.sh
|
||||
fi
|
||||
pnpm nx run api:migrate
|
||||
stop_stale_api_processes
|
||||
exec pnpm nx run-many -t dev -p api web --parallel=2
|
||||
|
||||
101
starship.toml
Normal file
101
starship.toml
Normal file
@ -0,0 +1,101 @@
|
||||
# --- 全局结构 (极致紧凑,高信息密度,AI友好) ---
|
||||
format = """
|
||||
$directory\
|
||||
$git_branch\
|
||||
$git_status\
|
||||
$nix_shell\
|
||||
$nodejs\
|
||||
$bun\
|
||||
$rust\
|
||||
$golang\
|
||||
$cmd_duration\
|
||||
$memory_usage\
|
||||
$status\
|
||||
$line_break\
|
||||
$character"""
|
||||
|
||||
# --- 目录 ---
|
||||
[directory]
|
||||
style = "bold cyan"
|
||||
truncation_length = 3
|
||||
truncate_to_repo = false
|
||||
truncation_symbol = ".../"
|
||||
home_symbol = "~"
|
||||
read_only = " [RO]"
|
||||
|
||||
# --- Git 状态 (纯文本,避免解析错误与乱码) ---
|
||||
[git_branch]
|
||||
symbol = "git:"
|
||||
style = "bold purple"
|
||||
format = "[$symbol$branch]($style) "
|
||||
|
||||
[git_status]
|
||||
format = "[$all_status$ahead_behind]($style) "
|
||||
style = "bold red"
|
||||
conflicted = "="
|
||||
ahead = ">"
|
||||
behind = "<"
|
||||
diverged = "<>"
|
||||
untracked = "?"
|
||||
stashed = "*"
|
||||
modified = "!"
|
||||
staged = "+"
|
||||
renamed = "»"
|
||||
deleted = "x"
|
||||
|
||||
# --- 编程语言与环境 (紧凑标签格式) ---
|
||||
[nodejs]
|
||||
symbol = "node:"
|
||||
style = "bold green"
|
||||
format = "[$symbol$version]($style) "
|
||||
detect_files = ["package.json", ".node-version"]
|
||||
|
||||
[bun]
|
||||
symbol = "bun:"
|
||||
style = "bold blue"
|
||||
format = "[$symbol$version]($style) "
|
||||
|
||||
[rust]
|
||||
symbol = "rust:"
|
||||
style = "bold 208"
|
||||
format = "[$symbol$version]($style) "
|
||||
|
||||
[golang]
|
||||
symbol = "go:"
|
||||
style = "bold cyan"
|
||||
format = "[$symbol$version]($style) "
|
||||
|
||||
[nix_shell]
|
||||
symbol = "nix:"
|
||||
style = "bold blue"
|
||||
format = "[$symbol$state]($style) "
|
||||
impure_msg = "impure"
|
||||
pure_msg = "pure"
|
||||
|
||||
# --- AI 辅助决策信息 (性能与状态反馈) ---
|
||||
[cmd_duration]
|
||||
min_time = 2_000
|
||||
format = "took [$duration]($style) "
|
||||
style = "bold yellow"
|
||||
|
||||
[memory_usage]
|
||||
symbol = "mem:"
|
||||
disabled = false
|
||||
threshold = 75
|
||||
format = "[$symbol$ram_pct]($style) "
|
||||
style = "bold dimmed white"
|
||||
|
||||
[status]
|
||||
disabled = false
|
||||
format = "[ERR:$status]($style) "
|
||||
style = "bold red"
|
||||
|
||||
# --- 交互符号 (带明确状态码) ---
|
||||
[character]
|
||||
success_symbol = "[>](bold green)"
|
||||
error_symbol = "[>](bold red)"
|
||||
vicmd_symbol = "[<](bold green)"
|
||||
|
||||
# --- 兼容性补充 ---
|
||||
[package]
|
||||
disabled = true
|
||||
Loading…
Reference in New Issue
Block a user