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
alex newman 9347c8bdd0 Specify a different build directory for #1513 (#1599)
* Update references to `.next`

* Remove console logs and extraneous semi colons

* Remove lint errors

* Update references to .next and update docs

* Update options from nested to flat with `distDir`

* Add integration tests, and update `.gitignore`

* Rename integration folder to dist-dir to match standards
2017-04-06 15:39:26 +05:30

25 lines
638 B
JavaScript

import mv from 'mv'
import { join } from 'path'
import getConfig from '../config'
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`)
try {
await move(_dir, oldDir)
} catch (err) {
if (err.code !== 'ENOENT') throw err
}
await move(_buildDir, _dir)
return oldDir
}
function move (from, to) {
return new Promise((resolve, reject) =>
mv(from, to, err => err ? reject(err) : resolve()))
}