Files
www/output.js
T
paul 146d516f24
Deploy website / deploy (push) Successful in 24s
Refactor site generation into a modular content pipeline
2026-09-22 20:51:13 -04:00

30 lines
874 B
JavaScript

import { mkdtemp, rename, rm, stat } from 'node:fs/promises'
import { dirname, join } from 'node:path'
const exists = async (path) => {
try {
await stat(path)
return true
} catch (error) {
if (error.code === 'ENOENT') return false
throw error
}
}
export const createOutput = (destination) => mkdtemp(join(dirname(destination), '.generated-next-'))
export const publishOutput = async (staging, destination) => {
const previous = `${staging}-previous`
const hadPrevious = await exists(destination)
if (hadPrevious) await rename(destination, previous)
try {
await rename(staging, destination)
} catch (error) {
if (hadPrevious) await rename(previous, destination)
throw error
}
if (hadPrevious) await rm(previous, { recursive: true })
}
export const discardOutput = (staging) => rm(staging, { recursive: true, force: true })