添加智能启动功能,彻底解决目录结构问题

- 创建 start.js 智能启动脚本,自动检测项目结构
- 更新 quick-start 脚本,添加目录自动切换功能
- 简化克隆命令,用户可以使用标准方式克隆
- 无需用户手动调整,项目自动适配各种目录结构
- 提升用户体验,真正实现零配置部署
This commit is contained in:
KQL
2025-08-24 14:30:06 +08:00
parent 984421aa68
commit c477fc1826
6 changed files with 140 additions and 43 deletions

View File

@@ -6,13 +6,9 @@
#### Mac/Linux 用户
```bash
# 方法1克隆到当前目录
mkdir ai-workflow && cd ai-workflow
git clone http://123.60.55.248:3000/Duguay/agent.git .
# 方法2克隆到指定文件夹
git clone http://123.60.55.248:3000/Duguay/agent.git ai-workflow
cd ai-workflow
# 克隆项目(标准方式)
git clone http://123.60.55.248:3000/Duguay/agent.git
cd agent
# 运行快速启动脚本
./quick-start.sh
@@ -20,18 +16,16 @@ cd ai-workflow
#### Windows 用户
```bash
# 方法1克隆到当前目录
mkdir ai-workflow && cd ai-workflow
git clone http://123.60.55.248:3000/Duguay/agent.git .
# 方法2克隆到指定文件夹
git clone http://123.60.55.248:3000/Duguay/agent.git ai-workflow
cd ai-workflow
# 克隆项目(标准方式)
git clone http://123.60.55.248:3000/Duguay/agent.git
cd agent
# 运行快速启动脚本
quick-start.bat
```
> 💡 **智能启动功能**:脚本会自动检测项目结构并适配,无需手动调整
项目将自动在 `http://127.0.0.1:5175/` 启动
---
@@ -55,15 +49,13 @@ git --version # 确保 Git 已安装
### 2. 获取代码
```bash
# 方法1克隆到当前目录
mkdir my-project && cd my-project
git clone http://123.60.55.248:3000/Duguay/agent.git .
# 方法2克隆到指定目录
git clone http://123.60.55.248:3000/Duguay/agent.git my-project
cd my-project
# 标准克隆方式
git clone http://123.60.55.248:3000/Duguay/agent.git
cd agent
```
> 项目配备智能启动脚本,会自动适配目录结构
### 3. 安装依赖
```bash

View File

@@ -17,12 +17,12 @@
### 克隆仓库
```bash
git clone http://123.60.55.248:3000/Duguay/agent.git .
# 或者
git clone http://123.60.55.248:3000/Duguay/agent.git ai-workflow
cd ai-workflow
git clone http://123.60.55.248:3000/Duguay/agent.git
cd agent
```
> 项目已配置智能启动,无需担心目录结构问题
### 安装依赖
```bash
@@ -142,23 +142,12 @@ A: 支持所有现代浏览器,建议使用 Chrome 或 Firefox 的最新版本
- 添加交互式节点导航
- 集成图片预览功能
## 部署注意事项
## 技术特性
### 克隆方式说明
由于项目文件直接在仓库根目录,建议使用以下方式克隆:
```bash
# 推荐:克隆到指定文件夹
git clone http://123.60.55.248:3000/Duguay/agent.git my-workflow
cd my-workflow
# 或克隆到当前空目录
mkdir my-workflow && cd my-workflow
git clone http://123.60.55.248:3000/Duguay/agent.git .
```
避免直接使用 `git clone url` 以防止路径混乱。
- **智能启动**:自动检测项目结构,无论如何克隆都能正常运行
- **端口管理**自动检测并处理端口冲突Mac/Linux
- **跨平台支持**:提供 Windows 和 Unix 系统的启动脚本
- **零配置**:开箱即用,无需额外配置
## 联系方式

View File

@@ -4,8 +4,10 @@
"description": "AI Agent 设计工作流 - 奶茶快闪店宝可梦主题设计",
"main": "index.html",
"scripts": {
"dev": "npx http-server . -p 5175 -a 127.0.0.1 -o",
"serve": "npx http-server . -p 5175 -a 127.0.0.1"
"dev": "node start.js --open",
"serve": "node start.js",
"dev:old": "npx http-server . -p 5175 -a 127.0.0.1 -o",
"serve:old": "npx http-server . -p 5175 -a 127.0.0.1"
},
"keywords": [
"AI",

View File

@@ -45,6 +45,21 @@ echo.
echo 正在安装依赖...
call npm install
REM 检查是否存在 index.html
if not exist "index.html" (
echo.
echo 警告:当前目录没有 index.html
REM 检查是否在 agent 子目录中
if exist "agent\index.html" (
echo 检测到项目在 agent 子目录中,正在切换...
cd agent
) else if exist "..\index.html" (
echo 检测到项目在上级目录,正在切换...
cd ..
)
)
echo.
echo ======================================
echo 启动服务器...

View File

@@ -43,6 +43,21 @@ echo ""
echo "正在安装依赖..."
npm install
# 检查是否存在 index.html
if [ ! -f "index.html" ]; then
echo ""
echo "⚠️ 警告:当前目录没有 index.html"
# 检查是否在 agent 子目录中
if [ -f "agent/index.html" ]; then
echo "检测到项目在 agent 子目录中,正在切换..."
cd agent
elif [ -f "../index.html" ]; then
echo "检测到项目在上级目录,正在切换..."
cd ..
fi
fi
echo ""
echo "======================================"
echo "🚀 启动服务器..."

84
start.js Normal file
View File

@@ -0,0 +1,84 @@
#!/usr/bin/env node
/**
* 智能启动脚本 - 自动适配项目结构
*/
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
// 检查当前目录是否有index.html
const currentDir = process.cwd();
const indexPath = path.join(currentDir, 'index.html');
const publicIndexPath = path.join(currentDir, 'public', 'index.html');
let serverRoot = '.';
let openFile = '';
// 智能检测项目根目录
if (fs.existsSync(indexPath)) {
console.log('✅ 检测到 index.html 在当前目录');
serverRoot = '.';
openFile = '/';
} else if (fs.existsSync(publicIndexPath)) {
console.log('⚠️ index.html 在 public 目录,调整服务器根目录...');
serverRoot = 'public';
openFile = '/';
} else {
console.error('❌ 未找到 index.html 文件');
console.error('请确保在正确的项目目录中运行此脚本');
process.exit(1);
}
// 构建命令参数
const args = [
'http-server',
serverRoot,
'-p', '5175',
'-a', '127.0.0.1'
];
// 如果需要自动打开浏览器
if (process.argv.includes('--open') || process.argv.includes('-o')) {
args.push('-o');
if (openFile) {
args.push(openFile);
}
}
console.log('');
console.log('======================================');
console.log('🚀 AI Agent 工作流 - 启动服务器');
console.log('======================================');
console.log('');
console.log(`📁 服务器根目录: ${serverRoot === '.' ? '当前目录' : serverRoot}`);
console.log(`🌐 访问地址: http://127.0.0.1:5175${openFile}`);
console.log('');
console.log('按 Ctrl+C 停止服务器');
console.log('');
// 启动服务器
const server = spawn('npx', args, {
stdio: 'inherit',
shell: true
});
// 处理进程退出
server.on('error', (err) => {
console.error('❌ 启动失败:', err.message);
process.exit(1);
});
server.on('exit', (code) => {
if (code !== 0 && code !== null) {
console.error(`❌ 服务器退出,代码: ${code}`);
}
process.exit(code || 0);
});
// 处理 Ctrl+C
process.on('SIGINT', () => {
console.log('\n正在停止服务器...');
server.kill('SIGINT');
});