Created
October 15, 2016 06:35
-
-
Save SomeoneWeird/0a9f102b788f0c704cd491b043c8a7ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node modify.js && yarn install && node modify.js restore && npm install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path') | |
var fs = require('fs') | |
var r = process.argv[2] === 'restore' | |
var pkgPath = path.resolve(process.cwd(), 'package.json') | |
var removedPath = path.resolve(process.cwd(), 'removed.json') | |
var pkg = require(pkgPath) | |
if (r) { | |
// restore saved deps | |
var removed = require(removedPath) | |
for(var k in removed) { | |
pkg.dependencies[k] = removed[k] | |
} | |
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)) | |
fs.unlinkSync(removedPath) | |
} else { | |
// remove | |
var removed = {} | |
for(var k in pkg.dependencies) { | |
if (k.substr(0, 1) === '@') { | |
removed[k] = pkg.dependencies[k] | |
delete pkg.dependencies[k] | |
} | |
} | |
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)) | |
fs.writeFileSync(removedPath, JSON.stringify(removed)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment