2017-02-16 14:16:02 +00:00
|
|
|
import mv from 'mv'
|
2017-02-15 13:03:33 +00:00
|
|
|
import { join } from 'path'
|
2017-04-06 10:09:26 +00:00
|
|
|
import getConfig from '../config'
|
2017-02-14 23:14:30 +00:00
|
|
|
|
2017-02-15 13:03:33 +00:00
|
|
|
export default async function replaceCurrentBuild (dir, buildDir) {
|
2017-04-06 10:09:26 +00:00
|
|
|
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-14 23:14:30 +00:00
|
|
|
|
2017-02-15 13:03:33 +00:00
|
|
|
try {
|
2017-02-16 14:16:02 +00:00
|
|
|
await move(_dir, oldDir)
|
2017-02-15 13:03:33 +00:00
|
|
|
} catch (err) {
|
|
|
|
if (err.code !== 'ENOENT') throw err
|
|
|
|
}
|
2017-02-16 14:16:02 +00:00
|
|
|
await move(_buildDir, _dir)
|
2017-02-15 13:03:33 +00:00
|
|
|
return oldDir
|
2017-02-14 23:14:30 +00:00
|
|
|
}
|
2017-02-16 14:16:02 +00:00
|
|
|
|
|
|
|
function move (from, to) {
|
|
|
|
return new Promise((resolve, reject) =>
|
|
|
|
mv(from, to, err => err ? reject(err) : resolve()))
|
|
|
|
}
|