UNPKG

code-relation-analyzer

Version:

A TypeScript project dependency analysis tool that generates function-level dependency graphs

248 lines (192 loc) 4.83 kB
# 部署指南 ## 📦 项目部署状态 ✅ **项目构建状态**: 已完成,所有文件正确编译 ✅ **CLI功能验证**: 所有命令正常工作 ✅ **npm包准备**: 已生成发布包 (code-relation-analyzer-1.0.0.tgz) ✅ **部署测试**: 全局安装和功能测试通过 ✅ **Web服务**: 可视化服务器正常运行 (http://localhost:3001) **最新部署时间**: 2025-10-04 21:24 **包大小**: 1.4 MB (压缩后) **解压大小**: 8.1 MB **文件数量**: 262 个文件 ## 🚀 部署方式 ### 1. 本地开发部署 ```bash # 克隆项目 git clone <repository-url> cd code-relation-analyzer # 安装依赖 npm install # 构建项目 npm run build # 本地测试 node dist/cli.cjs --help ``` ### 2. 全局安装部署 #### 方式一:从npm包安装(推荐) ```bash # 发布到npm(需要npm账号) npm publish # 全局安装 npm install -g code-relation-analyzer # 使用 code-relation --help ``` #### 方式二:从本地包安装 ```bash # 打包 npm pack # 全局安装 npm install -g ./code-relation-analyzer-1.0.0.tgz # 使用 code-relation --help ``` ### 3. 项目依赖部署 ```bash # 在其他项目中安装 npm install --save-dev code-relation-analyzer # 在package.json中添加脚本 { "scripts": { "analyze": "code-relation analyze ./src", "visualize": "code-relation visualize ./analysis-result.json", "report": "code-relation report ./analysis-result.json" } } ``` ### 4. 服务器部署(Web界面) ```bash # 生成分析报告 code-relation analyze ./src --output ./reports code-relation report ./reports/analysis-result.json --output ./reports/report.html # 启动Web服务器 code-relation serve ./reports/report.html --port 3000 # 或使用其他Web服务器 npx http-server ./reports -p 3000 ``` ## 🔧 部署配置 ### 环境要求 - Node.js >= 18.0.0 - npm >= 8.0.0 - 内存 >= 2GB(大型项目分析) ### 配置文件 项目支持配置文件 `.code-relation.json`: ```json { "input": "./src", "output": "./analysis", "exclude": ["node_modules", "dist", "build"], "include": ["**/*.ts", "**/*.js", "**/*.vue"], "analysis": { "dependency": true, "inheritance": true, "functionCall": true, "parameterFlow": true, "globalDependency": true }, "visualization": { "theme": "default", "layout": "force", "interactive": true } } ``` ## 📋 部署检查清单 ### 构建检查 - [x] TypeScript编译无错误 - [x] 所有依赖正确安装 - [x] dist目录生成完整 - [x] CLI入口文件可执行 ### 功能检查 - [x] `analyze` 命令正常工作 - [x] `visualize` 命令生成可视化 - [x] `report` 命令生成报告 - [x] `serve` 命令启动服务器 ### 包发布检查 - [x] package.json配置正确 - [x] npm pack生成包文件 - [x] 全局安装测试通过 - [x] 命令行工具可用 ## 🌐 生产环境部署 ### Docker部署 ```dockerfile FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY dist ./dist COPY templates ./templates EXPOSE 3000 CMD ["node", "dist/cli.cjs", "serve", "--port", "3000"] ``` ### CI/CD部署 ```yaml # .github/workflows/deploy.yml name: Deploy on: push: branches: [main] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '18' - run: npm ci - run: npm run build - run: npm test - run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} ``` ## 🔍 故障排除 ### 常见问题 1. **chalk导入错误** ```bash # 已修复:使用 import chalk from 'chalk' ``` 2. **循环依赖警告** ```bash # 非致命错误,不影响功能 ``` 3. **全局安装失败** ```bash # 检查Node.js版本 >= 18.0.0 node --version ``` 4. **分析大型项目内存不足** ```bash # 增加Node.js内存限制 node --max-old-space-size=4096 dist/cli.cjs analyze ``` ## 📊 部署验证 部署完成后,运行以下命令验证: ```bash # 检查版本 code-relation --version # 测试分析功能 code-relation analyze ./test-project --output ./test-output # 测试可视化功能 code-relation visualize ./test-output/analysis-result.json # 测试报告功能 code-relation report ./test-output/analysis-result.json # 测试服务器功能 code-relation serve ./test-output/report.html --port 3000 ``` ## 📈 性能优化 ### 大型项目优化 - 使用 `--exclude` 排除不必要的目录 - 启用缓存机制 - 分批处理文件 - 增加内存限制 ### 服务器优化 - 使用反向代理(nginx) - 启用gzip压缩 - 配置缓存策略 - 监控资源使用 --- **部署状态**: ✅ 就绪 **最后更新**: 2025-10-04 **版本**: 1.0.0