1 | 'use strict';
|
2 |
|
3 | var _regenerator = require('babel-runtime/regenerator');
|
4 |
|
5 | var _regenerator2 = _interopRequireDefault(_regenerator);
|
6 |
|
7 | var _keys = require('babel-runtime/core-js/object/keys');
|
8 |
|
9 | var _keys2 = _interopRequireDefault(_keys);
|
10 |
|
11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12 |
|
13 | var co = require('co');
|
14 | var extend = require('xtend');
|
15 | var ora = require('ora');
|
16 | var getUnusedPackages = require('./get-unused-packages');
|
17 | var createPackageSummary = require('./create-package-summary');
|
18 |
|
19 | module.exports = function (currentState) {
|
20 | return co( _regenerator2.default.mark(function _callee() {
|
21 | var spinner, cwdPackageJson, dependencies, allDependencies, allDependenciesIncludingMissing, arrayOfPackageInfo;
|
22 | return _regenerator2.default.wrap(function _callee$(_context) {
|
23 | while (1) {
|
24 | switch (_context.prev = _context.next) {
|
25 | case 0:
|
26 | dependencies = function dependencies(pkg) {
|
27 | if (currentState.get('global')) {
|
28 | return currentState.get('globalPackages');
|
29 | }
|
30 |
|
31 | if (currentState.get('ignoreDev')) {
|
32 | return pkg.dependencies;
|
33 | }
|
34 |
|
35 | if (currentState.get('devOnly')) {
|
36 | return pkg.devDependencies;
|
37 | }
|
38 |
|
39 | return extend(pkg.dependencies, pkg.devDependencies);
|
40 | };
|
41 |
|
42 | _context.next = 3;
|
43 | return getUnusedPackages(currentState);
|
44 |
|
45 | case 3:
|
46 | spinner = ora('Checking npm registries for updated packages.');
|
47 |
|
48 | spinner.enabled = spinner.enabled && currentState.get('spinner');
|
49 | spinner.start();
|
50 |
|
51 | cwdPackageJson = currentState.get('cwdPackageJson');
|
52 | allDependencies = dependencies(cwdPackageJson);
|
53 | allDependenciesIncludingMissing = (0, _keys2.default)(extend(allDependencies, currentState.get('missingFromPackageJson')));
|
54 | _context.next = 11;
|
55 | return allDependenciesIncludingMissing.map(function (moduleName) {
|
56 | return createPackageSummary(moduleName, currentState);
|
57 | }).filter(Boolean);
|
58 |
|
59 | case 11:
|
60 | arrayOfPackageInfo = _context.sent;
|
61 |
|
62 |
|
63 | currentState.set('packages', arrayOfPackageInfo);
|
64 |
|
65 | spinner.stop();
|
66 | return _context.abrupt('return', currentState);
|
67 |
|
68 | case 15:
|
69 | case 'end':
|
70 | return _context.stop();
|
71 | }
|
72 | }
|
73 | }, _callee, this);
|
74 | }));
|
75 | }; |
\ | No newline at end of file |