import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const webDir = path.resolve(__dirname, '..'); const distDir = path.resolve(webDir, 'dist'); const rootDir = path.resolve(webDir, '../..'); const targets = [ path.resolve(rootDir, 'server-java/src/main/resources/static') ]; if (!fs.existsSync(distDir)) { console.error(`[copy-artifacts] 错误: 前端 dist 目录不存在: ${distDir}`); process.exit(1); } for (const targetDir of targets) { try { fs.mkdirSync(targetDir, { recursive: true }); // 清理旧产物,避免遗留老旧的静态资源 hash 文件。 fs.rmSync(targetDir, { recursive: true, force: true }); fs.mkdirSync(targetDir, { recursive: true }); fs.cpSync(distDir, targetDir, { recursive: true }); console.log(`[copy-artifacts] 成功复制前端构建产物到后端静态资源目录: ${targetDir}`); } catch (err) { console.error(`[copy-artifacts] 复制到 ${targetDir} 失败:`, err); process.exit(1); } }