1 | 'use strict';
|
2 |
|
3 | var _promise = require('babel-runtime/core-js/promise');
|
4 |
|
5 | var _promise2 = _interopRequireDefault(_promise);
|
6 |
|
7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8 |
|
9 | var _ = require('lodash');
|
10 | var path = require('path');
|
11 | var globalModulesPath = require('global-modules');
|
12 | var readPackageJson = require('../in/read-package-json');
|
13 | var globalPackages = require('../in/get-installed-packages');
|
14 | var emoji = require('../out/emoji');
|
15 |
|
16 | function init(currentState, userOptions) {
|
17 | return new _promise2.default(function (resolve, reject) {
|
18 | _.each(userOptions, function (value, key) {
|
19 | return currentState.set(key, value);
|
20 | });
|
21 |
|
22 | if (currentState.get('global')) {
|
23 | currentState.set('cwd', globalModulesPath);
|
24 | currentState.set('nodeModulesPath', globalModulesPath);
|
25 | currentState.set('globalPackages', globalPackages(globalModulesPath));
|
26 | } else {
|
27 | var cwd = path.resolve(currentState.get('cwd'));
|
28 | var pkg = readPackageJson(path.join(cwd, 'package.json'));
|
29 | currentState.set('cwdPackageJson', pkg);
|
30 | currentState.set('cwd', cwd);
|
31 | currentState.set('nodeModulesPath', path.join(cwd, 'node_modules'));
|
32 | }
|
33 |
|
34 | emoji.enabled(currentState.get('emoji'));
|
35 |
|
36 | if (currentState.get('cwdPackageJson').error) {
|
37 | return reject(currentState.get('cwdPackageJson').error);
|
38 | }
|
39 |
|
40 | return resolve(currentState);
|
41 | });
|
42 | }
|
43 |
|
44 | module.exports = init; |
\ | No newline at end of file |