-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unused feature #166
base: master
Are you sure you want to change the base?
Changes from 9 commits
49cfdfe
56468cf
eb9a0b9
c57acb8
9f430b8
3f19295
4f7e8a4
3e50a14
d9a15ab
b96dd18
0b48d7c
44b47f1
94b3ad5
1bc0e1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/.idea/ | ||
/node_modules/ | ||
/*.log | ||
/*.log | ||
lib-es5 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const exec = require('child_process').exec; | ||
const ora = require('ora'); | ||
const skipUnused = require('./skip-unused-packages'); | ||
const _ = require('lodash'); | ||
|
||
function skipAutoRemove(currentState) { | ||
return skipUnused(currentState) || !currentState.get('removeUnused'); | ||
} | ||
|
||
function removeUnused(currentState) { | ||
const dependenciesToRemove = currentState.get('unusedDependencies'); | ||
if (skipAutoRemove(currentState) || _.isEmpty(dependenciesToRemove)) { | ||
return new Promise(resolve => resolve(currentState)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need |
||
const spinner = ora(`Remove unused dependencies. --skip-unused if you don't want this.`); | ||
spinner.enabled = spinner.enabled && currentState.get('spinner'); | ||
spinner.start(); | ||
|
||
return new Promise(resolve => { | ||
const removeCommand = 'npm remove --save ' + dependenciesToRemove.join(' '); | ||
exec(removeCommand, {cwd: currentState.get('cwd')}, (error, stdout, stderr) => { | ||
if (error || !_.isEmpty(stderr)) { | ||
currentState.set('removeUnusedError', error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be set to undefined if there is no error but |
||
} | ||
resolve(currentState); | ||
}); | ||
}).then(result => { | ||
spinner.stop(); | ||
return currentState; | ||
}); | ||
} | ||
} | ||
|
||
module.exports = removeUnused; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
function skipUnused(currentState) { | ||
return currentState.get('skipUnused') || // manual option to ignore this | ||
currentState.get('global') || // global modules | ||
currentState.get('update') || // in the process of doing an update | ||
!currentState.get('cwdPackageJson').name; // there's no package.json | ||
} | ||
|
||
module.exports = skipUnused; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add leading and trailing slash to this line