forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpm-task.js
64 lines (52 loc) · 1.7 KB
/
npm-task.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*eslint-disable no-console */
'use strict';
// Runs `npm install` in cwd
var chalk = require('chalk');
var Task = require('ember-cli/lib/models/task');
var npm = require('../utilities/npm');
module.exports = Task.extend({
// The command to run: can be 'install' or 'uninstall'
command: '',
// Message to send to ui.startProgress
startProgressMessage: '',
// Message to send to ui.writeLine on completion
completionMessage: '',
init: function() {
this.npm = this.npm || require('npm');
},
// Options: Boolean verbose
run: function(options) {
this.ui.startProgress(chalk.green(this.startProgressMessage), chalk.green('.'));
var npmOptions = {
loglevel: options.verbose ? 'verbose' : 'error',
progress: false,
logstream: this.ui.outputStream,
color: 'always',
// by default, do install peoples optional deps
'optional': 'optional' in options ? options.optional : true,
'save-dev': !!options['save-dev'],
'save-exact': !!options['save-exact']
};
var packages = options.packages || [];
// npm otherwise is otherwise noisy, already submitted PR for npm to fix
// misplaced console.log
this.disableLogger();
return npm(this.command, packages, npmOptions, this.npm).
finally(this.finally.bind(this)).
then(this.announceCompletion.bind(this));
},
announceCompletion: function() {
this.ui.writeLine(chalk.green(this.completionMessage));
},
finally: function() {
this.ui.stopProgress();
this.restoreLogger();
},
disableLogger: function() {
this.oldLog = console.log;
console.log = function() {};
},
restoreLogger: function() {
console.log = this.oldLog; // Hack, see above
}
});