更新
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 将 frontend/dist、frontend-admin/dist 复制到 backend/public
|
||||
* 用法:
|
||||
* node scripts/deploy-static.js # 两端都部署
|
||||
* node scripts/deploy-static.js member # 仅会员端
|
||||
* node scripts/deploy-static.js admin # 仅管理端
|
||||
*/
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const publicDir = path.join(root, 'backend', 'public')
|
||||
const memberDist = path.join(root, 'frontend', 'dist')
|
||||
const adminDist = path.join(root, 'frontend-admin', 'dist')
|
||||
const adminPublic = path.join(publicDir, 'admin')
|
||||
|
||||
const target = (process.argv[2] || 'all').toLowerCase()
|
||||
if (!['all', 'member', 'admin'].includes(target)) {
|
||||
console.error(`未知目标: ${target},可用: all | member | admin`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const keepInPublic = new Set([
|
||||
'index.php',
|
||||
'router.php',
|
||||
'robots.txt',
|
||||
'nginx.htaccess',
|
||||
'.htaccess',
|
||||
'static'
|
||||
])
|
||||
|
||||
function assertDir(dir, label) {
|
||||
if (!fs.existsSync(dir)) {
|
||||
throw new Error(`${label} 不存在,请先执行对应前端的 npm run build`)
|
||||
}
|
||||
}
|
||||
|
||||
function rmPath(targetPath) {
|
||||
if (!fs.existsSync(targetPath)) return
|
||||
fs.rmSync(targetPath, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
function copyDir(src, dest) {
|
||||
fs.mkdirSync(dest, { recursive: true })
|
||||
for (const name of fs.readdirSync(src)) {
|
||||
const from = path.join(src, name)
|
||||
const to = path.join(dest, name)
|
||||
if (fs.statSync(from).isDirectory()) {
|
||||
copyDir(from, to)
|
||||
} else {
|
||||
fs.copyFileSync(from, to)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cleanMemberStatic() {
|
||||
if (!fs.existsSync(publicDir)) {
|
||||
fs.mkdirSync(publicDir, { recursive: true })
|
||||
return
|
||||
}
|
||||
for (const name of fs.readdirSync(publicDir)) {
|
||||
if (keepInPublic.has(name) || name === 'admin') continue
|
||||
rmPath(path.join(publicDir, name))
|
||||
}
|
||||
}
|
||||
|
||||
function deployMember() {
|
||||
assertDir(memberDist, '会员端 dist')
|
||||
cleanMemberStatic()
|
||||
copyDir(memberDist, publicDir)
|
||||
console.log('✓ 会员端已部署到 backend/public/')
|
||||
}
|
||||
|
||||
function deployAdmin() {
|
||||
assertDir(adminDist, '管理端 dist')
|
||||
rmPath(adminPublic)
|
||||
copyDir(adminDist, adminPublic)
|
||||
console.log('✓ 管理端已部署到 backend/public/admin/')
|
||||
}
|
||||
|
||||
if (target === 'all' || target === 'member') {
|
||||
deployMember()
|
||||
}
|
||||
if (target === 'all' || target === 'admin') {
|
||||
deployAdmin()
|
||||
}
|
||||
Reference in New Issue
Block a user