mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
21 lines
761 B
JavaScript
21 lines
761 B
JavaScript
const fs = require('fs-extra')
|
|
const path = require('path')
|
|
|
|
module.exports = function(packagePath) {
|
|
const nodeModulesPath = path.join(packagePath, 'node_modules')
|
|
const nodeModulesBackupPath = path.join(packagePath, 'node_modules.bak')
|
|
if (fs.existsSync(nodeModulesBackupPath)) {
|
|
throw new Error("Cannot back up " + nodeModulesPath + "; " + nodeModulesBackupPath + " already exists")
|
|
}
|
|
|
|
fs.copySync(nodeModulesPath, nodeModulesBackupPath)
|
|
|
|
return function restoreNodeModules() {
|
|
if (!fs.existsSync(nodeModulesBackupPath)) {
|
|
throw new Error("Cannot restore " + nodeModulesPath + "; " + nodeModulesBackupPath + " does not exist")
|
|
}
|
|
fs.removeSync(nodeModulesPath)
|
|
fs.renameSync(nodeModulesBackupPath, nodeModulesPath)
|
|
}
|
|
}
|