1 | 'use strict';
|
2 | const co = require('co');
|
3 | const extend = require('xtend');
|
4 | const ora = require('ora');
|
5 | const getUnusedPackages = require('./get-unused-packages');
|
6 | const createPackageSummary = require('./create-package-summary');
|
7 |
|
8 | module.exports = function (currentState) {
|
9 | return co(function *() {
|
10 | yield getUnusedPackages(currentState);
|
11 |
|
12 | const spinner = ora(`Checking npm registries for updated packages.`);
|
13 | spinner.enabled = spinner.enabled && currentState.get('spinner');
|
14 | spinner.start();
|
15 |
|
16 | const cwdPackageJson = currentState.get('cwdPackageJson');
|
17 |
|
18 | function dependencies(pkg) {
|
19 | if (currentState.get('global')) {
|
20 | return currentState.get('globalPackages');
|
21 | }
|
22 |
|
23 | if (currentState.get('ignoreDev')) {
|
24 | return pkg.dependencies;
|
25 | }
|
26 |
|
27 | if (currentState.get('devOnly')) {
|
28 | return pkg.devDependencies;
|
29 | }
|
30 |
|
31 | return extend(pkg.dependencies, pkg.devDependencies);
|
32 | }
|
33 |
|
34 | const allDependencies = dependencies(cwdPackageJson);
|
35 | const allDependenciesIncludingMissing = Object.keys(extend(allDependencies, currentState.get('missingFromPackageJson')));
|
36 |
|
37 | const arrayOfPackageInfo = yield allDependenciesIncludingMissing
|
38 | .map(moduleName => createPackageSummary(moduleName, currentState))
|
39 | .filter(Boolean);
|
40 |
|
41 | currentState.set('packages', arrayOfPackageInfo);
|
42 |
|
43 | spinner.stop();
|
44 | return currentState;
|
45 | });
|
46 | };
|