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 chalk = require('chalk');
|
10 | var execa = require('execa');
|
11 | var ora = require('ora');
|
12 |
|
13 | function install(packages, currentState) {
|
14 | if (!packages.length) {
|
15 | return _promise2.default.resolve(currentState);
|
16 | }
|
17 |
|
18 | var installer = currentState.get('installer');
|
19 | var color = chalk.supportsColor ? '--color=always' : null;
|
20 |
|
21 | var isYarn = installer === 'yarn';
|
22 |
|
23 | var installGlobal = currentState.get('global') ? isYarn ? 'global' : '--global' : null;
|
24 | var saveExact = currentState.get('saveExact') ? isYarn ? '--exact' : '--save-exact' : null;
|
25 |
|
26 | var installCmd = isYarn ? 'add' : 'install';
|
27 |
|
28 | var npmArgs = [installCmd].concat(installGlobal).concat(saveExact).concat(packages).concat(color).filter(Boolean);
|
29 |
|
30 | console.log('');
|
31 | console.log('$ ' + chalk.green(installer) + ' ' + chalk.green(npmArgs.join(' ')));
|
32 | var spinner = ora('Installing using ' + chalk.green(installer) + '...');
|
33 | spinner.enabled = spinner.enabled && currentState.get('spinner');
|
34 | spinner.start();
|
35 |
|
36 | return execa(installer, npmArgs, { cwd: currentState.get('cwd') }).then(function (output) {
|
37 | spinner.stop();
|
38 | console.log(output.stdout);
|
39 | console.log(output.stderr);
|
40 |
|
41 | return currentState;
|
42 | }).catch(function (err) {
|
43 | spinner.stop();
|
44 | throw err;
|
45 | });
|
46 | }
|
47 |
|
48 | module.exports = install; |
\ | No newline at end of file |