fix
This commit is contained in:
+48
-1
@@ -44,6 +44,9 @@ const RESTART_TARGETS = (process.env.PM2_RESTART_TARGETS || 'tssbot-web')
|
||||
.split(',')
|
||||
.map((target) => target.trim())
|
||||
.filter(Boolean)
|
||||
const DIST_DIR = path.join(__dirname, 'dist')
|
||||
const NEXT_DIST_DIR = path.join(__dirname, 'dist-next')
|
||||
const PREVIOUS_DIST_DIR = path.join(__dirname, 'dist-previous')
|
||||
const ALLOWED_REFS = new Set(
|
||||
(process.env.GITHUB_WEBHOOK_REFS || 'refs/heads/main')
|
||||
.split(',')
|
||||
@@ -198,6 +201,49 @@ async function ensureBuildDependencies() {
|
||||
}
|
||||
}
|
||||
|
||||
function copyMissingFiles(fromDir, toDir) {
|
||||
if (!fs.existsSync(fromDir) || !fs.existsSync(toDir)) return
|
||||
|
||||
for (const entry of fs.readdirSync(fromDir, { withFileTypes: true })) {
|
||||
const source = path.join(fromDir, entry.name)
|
||||
const target = path.join(toDir, entry.name)
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
fs.mkdirSync(target, { recursive: true })
|
||||
copyMissingFiles(source, target)
|
||||
continue
|
||||
}
|
||||
|
||||
if (!fs.existsSync(target)) {
|
||||
fs.copyFileSync(source, target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function promoteBuiltDist() {
|
||||
const previousAssetsDir = path.join(DIST_DIR, 'assets')
|
||||
const nextAssetsDir = path.join(NEXT_DIST_DIR, 'assets')
|
||||
let movedCurrentDist = false
|
||||
|
||||
copyMissingFiles(previousAssetsDir, nextAssetsDir)
|
||||
|
||||
fs.rmSync(PREVIOUS_DIST_DIR, { recursive: true, force: true })
|
||||
|
||||
try {
|
||||
if (fs.existsSync(DIST_DIR)) {
|
||||
fs.renameSync(DIST_DIR, PREVIOUS_DIST_DIR)
|
||||
movedCurrentDist = true
|
||||
}
|
||||
|
||||
fs.renameSync(NEXT_DIST_DIR, DIST_DIR)
|
||||
} catch (error) {
|
||||
if (movedCurrentDist && !fs.existsSync(DIST_DIR) && fs.existsSync(PREVIOUS_DIST_DIR)) {
|
||||
fs.renameSync(PREVIOUS_DIST_DIR, DIST_DIR)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
function postDiscordWebhook(payload) {
|
||||
if (!DISCORD_WEBHOOK_URL) return Promise.resolve()
|
||||
|
||||
@@ -360,7 +406,8 @@ async function deploy(push) {
|
||||
await run('git', ['pull', '--ff-only'])
|
||||
diff = await deployDiff(push)
|
||||
await ensureBuildDependencies()
|
||||
await run('npm', ['run', 'build'])
|
||||
await run('npm', ['run', 'build', '--', '--outDir', 'dist-next'])
|
||||
promoteBuiltDist()
|
||||
|
||||
for (const target of RESTART_TARGETS) {
|
||||
await run('pm2', ['reload', target, '--update-env'])
|
||||
|
||||
Reference in New Issue
Block a user