UNPKG

715 BJavaScriptView Raw
1var spawn = require('child_process').spawn;
2
3var when = require('when');
4
5function solution(command){
6 if(!command){
7 return;
8 }
9 command = command.split(' ');
10 var cmd = command[0];
11 var args = command.slice(1);
12 if(process.platform === 'win32'){
13 args.unshift('/c', cmd);
14 cmd = 'cmd';
15 }
16
17 if(cmd !== 'npm'){
18 return;
19 }
20
21 var defer = when.defer();
22 var result = '';
23 var child = spawn(cmd, args);
24 child.stdout.setEncoding('utf8');
25 child.stderr.setEncoding('utf8');
26 child.stdout
27 .on('data', function(data){
28 result += data.toString('utf-8');
29 })
30 .on('close', function(code){
31 defer.resolve(result);
32 });
33 return defer.promise;
34}
35
36module.exports = solution;