1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/server/build/replace.js

25 lines
638 B
JavaScript
Raw Normal View History

import mv from 'mv'
2017-02-15 13:03:33 +00:00
import { join } from 'path'
import getConfig from '../config'
2017-02-15 13:03:33 +00:00
export default async function replaceCurrentBuild (dir, buildDir) {
const dist = getConfig(dir).distDir
const buildDist = getConfig(buildDir).distDir
const _dir = join(dir, dist)
const _buildDir = join(buildDir, dist)
const oldDir = join(buildDir, `${buildDist}.old`)
2017-02-15 13:03:33 +00:00
try {
await move(_dir, oldDir)
2017-02-15 13:03:33 +00:00
} catch (err) {
if (err.code !== 'ENOENT') throw err
}
await move(_buildDir, _dir)
2017-02-15 13:03:33 +00:00
return oldDir
}
function move (from, to) {
return new Promise((resolve, reject) =>
mv(from, to, err => err ? reject(err) : resolve()))
}