-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made to work with rimraf and npm.commands
- Loading branch information
1 parent
d56e061
commit c545d7d
Showing
4 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"esnext": true | ||
"esnext": true, | ||
"node": true | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# gluttony | ||
|
||
Nukes the project's `node_modules` directory and reinstalls latest dependencies from `package.json`. | ||
|
||
# Usage | ||
|
||
Install | ||
|
||
```bash | ||
npm install -g gluttony | ||
``` | ||
|
||
Use to reinstall dependencies of a project | ||
|
||
```bash | ||
gluttony | ||
``` | ||
|
||
# License | ||
|
||
MIT |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,56 @@ | ||
'use strict'; | ||
|
||
const pjson = require('pjson'), | ||
path = require('path'), | ||
fs = require('fs'), | ||
rimraf = require('rimraf'), | ||
npm = require('npm'), | ||
keys = Object.keys || require('object-keys'); | ||
|
||
console.log(__dirname); | ||
console.log(keys(pjson.dependencies)); | ||
const NODE_MODULES = path.resolve('./node_modules'), | ||
DEPS = pjson.dependencies && keys(pjson.dependencies), | ||
DEV_DEPS = pjson.devDependencies && keys(pjson.devDependencies); | ||
|
||
function reinstall() { | ||
npm.load({}, function (err) { | ||
if (err) { | ||
console.log(err); | ||
return; | ||
} | ||
[DEPS, DEV_DEPS].forEach(function(deps){ | ||
if (deps) { | ||
npm.commands.install(deps, function (err, data) { | ||
if (err) { | ||
return; | ||
} | ||
console.log('Yay! Dependencies reinstalled from scratch.'); | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
fs.stat(NODE_MODULES, function(err, stats) { | ||
if (err) { | ||
switch (err.code) { | ||
case 'ENOENT': | ||
// node_modules doesn't exist: just reinstall | ||
reinstall(); | ||
break; | ||
} | ||
return; | ||
} | ||
// call rm -rf on the NODE_MODULES dir | ||
rimraf(NODE_MODULES, function(err) { | ||
if (err) { | ||
// switch (err.code) { | ||
// case 'ENOENT': | ||
// console.log(''); | ||
// break; | ||
// } | ||
console.log(err); | ||
return; | ||
} | ||
reinstall(); | ||
}); | ||
}); |
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