generated from template/router-template
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
/**
|
|
* 将 dist 目录的内容复制到 backend/public 目录, 使用bun运行
|
|
*
|
|
* @tags build, deploy, copy
|
|
* @description 构建后将前端静态资源复制到后端公共目录,复制前会删除已有内容
|
|
* @title 前端资源复制脚本
|
|
* @createdAt 2025-11-24
|
|
*/
|
|
import { existsSync, rmSync, cpSync } from 'node:fs';
|
|
import { resolve, dirname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
const distPath = resolve(__dirname, 'dist');
|
|
const backendPath = resolve(__dirname, '../backend/public');
|
|
const frontendPath = resolve(backendPath, 'root/daily-question');
|
|
// 删除已有的 backend/public 目录内容
|
|
if (existsSync(backendPath)) {
|
|
console.log('删除已有的 backend/public 目录...');
|
|
rmSync(backendPath, { recursive: true, force: true });
|
|
console.log('✓ 已删除旧内容');
|
|
}
|
|
|
|
// 复制 dist 内容到 backend/public
|
|
if (existsSync(distPath)) {
|
|
console.log('复制 dist 内容到 backend/public...');
|
|
cpSync(distPath, frontendPath, { recursive: true });
|
|
console.log('✓ 复制完成');
|
|
} else {
|
|
console.error('错误: dist 目录不存在,请先运行构建命令');
|
|
process.exit(1);
|
|
}
|