
Lovstudio:Project Port
- 1 installs
- Updated July 13, 2026
- lovstudio/project-port-skill
Generates a stable unique dev-server port (3000-8999) from a project name and updates the project's port configuration.
About
Generates a stable unique dev port from a project name so the same project always maps to the same port, and updates the project's port config. A developer uses it to avoid port collisions across multiple local projects.
- Hashes the project name to a stable port in 3000-8999
- Updates .env, package.json, or vite.config port config with minimal changes
Lovstudio:Project Port by the numbers
- 1 all-time installs (skills.sh)
- Ranked #1,983 of 2,715 Automation & Workflows skills by installs in the Skillselion catalog
- Data as of Jul 14, 2026 (Skillselion catalog sync)
npx skills add https://github.com/lovstudio/project-port-skill --skill lovstudioproject-portAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 1 |
|---|---|
| Last updated | July 13, 2026 |
| Repository | lovstudio/project-port-skill ↗ |
What it does
Generates a stable unique dev-server port (3000-8999) from a project name and updates the project's port configuration.
Files
Project Port Generator
为项目生成稳定唯一的端口号(范围 3000-8999),同一项目名永远返回相同端口。
端口生成算法
def generate_port(project_name: str) -> int:
hash_value = sum(ord(c) * (i + 1) for i, c in enumerate(project_name))
return 3000 + (hash_value % 6000)使用场景
1. 查询项目端口
用户询问端口时,直接计算并告知:
项目 "lovstudio" 的端口号是:79652. 更新项目配置
检测并更新项目中的端口配置文件:
| 文件 | 配置方式 |
|---|---|
.env / .env.local | PORT=<port> |
package.json | scripts 中的 --port <port> |
vite.config.ts | server.port: <port> |
next.config.js | 通常使用 .env |
更新时优先使用 .env 方式,最小侵入性。
3. 启动开发服务器
PORT=$(scripts/hashport.sh) pnpm dev脚本
运行 scripts/hashport.sh [project-name] 生成端口:
# 使用当前目录名
./scripts/hashport.sh
# 输出: 7965
# 指定项目名
./scripts/hashport.sh my-project
# 输出: 5123端口冲突处理
若端口被占用: 1. 提示用户哪个进程占用了端口 2. 建议使用 lsof -i :<port> 查看 3. 可追加后缀生成备用端口:generate_port("project-dev")
#!/bin/bash
# 基于项目名生成稳定端口号
# Usage: hashport.sh [project-name]
# 如不指定项目名,使用当前目录名
name="${1:-$(basename "$PWD")}"
# 计算哈希值
hash=0
for ((i=0; i<${#name}; i++)); do
char="${name:$i:1}"
ord=$(printf '%d' "'$char")
hash=$((hash + ord * (i + 1)))
done
# 生成端口 (范围 3000-8999)
port=$((3000 + (hash % 6000)))
# 检查端口状态
if command -v lsof &>/dev/null && lsof -i :"$port" &>/dev/null; then
proc=$(lsof -i :"$port" | awk 'NR==2 {print $1}')
echo "$port ← $name (occupied by $proc)" >&2
else
echo "$port ← $name" >&2
fi
echo "$port"