#!/usr/bin/env node /** * 在 openapi-ts 生成后恢复 request.ts 文件 * 解决 openapi-ts-request 的 full 模式会删除整个 serversPath 目录的问题 */ import { copyFileSync, existsSync, mkdirSync } from 'fs'; import { dirname, resolve } from 'path'; import { fileURLToPath } from 'url'; const __dirname = dirname(fileURLToPath(import.meta.url)); const rootDir = resolve(__dirname, '..'); const templatePath = resolve(rootDir, 'src/lib/api-request.ts'); const targetPath = resolve(rootDir, 'src/api/request.ts'); console.log('🔄 Restoring request.ts after openapi generation...'); // 确保目标目录存在 const targetDir = dirname(targetPath); if (!existsSync(targetDir)) { mkdirSync(targetDir, { recursive: true }); console.log('📁 Created directory:', targetDir); } // 复制模板文件 if (existsSync(templatePath)) { copyFileSync(templatePath, targetPath); console.log('✅ Restored:', targetPath); } else { console.error('❌ Template not found:', templatePath); process.exit(1); } console.log('🎉 Request file restoration complete!');