forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrundartpackage.js
More file actions
44 lines (41 loc) · 1.21 KB
/
rundartpackage.js
File metadata and controls
44 lines (41 loc) · 1.21 KB
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
var util = require('./util');
var Q = require('q');
var spawn = require('child_process').spawn;
var readline = require('readline');
module.exports = function(gulp, plugins, config) {
return function() {
return isInstalled().then(function(installed) {
if (!installed) {
return util.processToPromise(spawn(config.pub,
['global', 'activate', config.packageName, '--no-executables'], {
stdio: 'inherit'
}));
}
}).then(function() {
return util.processToPromise(spawn(config.pub, ['global', 'run'].concat(config.args), {
stdio: 'inherit'
}));
});
};
function isInstalled() {
var subProcess = spawn(config.pub, ['global', 'list'], {
// inherit stdin and stderr, but filter stdout
stdio: [process.stdin, 'pipe', process.stderr]
});
var rl = readline.createInterface({
input: subProcess.stdout,
output: process.stdout,
terminal: false
});
var found = false;
rl.on('line', function(line) {
if (line.indexOf(config.packageName) !== -1) {
found = true;
}
console.log(line);
});
return util.processToPromise(subProcess).then( function() {
return found;
});
}
};