1 |
|
2 | var EventEmitter, fs, yaml, ObservableProcess, path, ServiceInstaller;
|
3 | EventEmitter = require('events').EventEmitter;
|
4 | fs = require('fs');
|
5 | yaml = require('js-yaml');
|
6 | ObservableProcess = require('observable-process');
|
7 | path = require('path');
|
8 | ServiceInstaller = (function(superclass){
|
9 | var prototype = extend$((import$(ServiceInstaller, superclass).displayName = 'ServiceInstaller', ServiceInstaller), superclass).prototype, constructor = ServiceInstaller;
|
10 | function ServiceInstaller(name, config){
|
11 | this.name = name;
|
12 | this.config = config;
|
13 | this._log = bind$(this, '_log', prototype);
|
14 | this.start = bind$(this, 'start', prototype);
|
15 | this.serviceConfig = yaml.safeLoad(fs.readFileSync(path.join(this.config.root, 'config.yml'), 'utf8'));
|
16 | }
|
17 | prototype.start = function(done){
|
18 | var this$ = this;
|
19 | this.emit('start', this.name);
|
20 | return new ObservableProcess(this.serviceConfig.setup, {
|
21 | cwd: this.config.root,
|
22 | verbose: true,
|
23 | console: {
|
24 | log: this._log,
|
25 | error: this._log
|
26 | },
|
27 | onExit: function(){
|
28 | this$.emit('finished', this$.name);
|
29 | return done();
|
30 | }
|
31 | });
|
32 | };
|
33 | prototype._log = function(text){
|
34 | return this.emit('output', {
|
35 | name: this.name,
|
36 | text: text
|
37 | });
|
38 | };
|
39 | return ServiceInstaller;
|
40 | }(EventEmitter));
|
41 | module.exports = ServiceInstaller;
|
42 | function bind$(obj, key, target){
|
43 | return function(){ return (target || obj)[key].apply(obj, arguments) };
|
44 | }
|
45 | function extend$(sub, sup){
|
46 | function fun(){} fun.prototype = (sub.superclass = sup).prototype;
|
47 | (sub.prototype = new fun).constructor = sub;
|
48 | if (typeof sup.extended == 'function') sup.extended(sub);
|
49 | return sub;
|
50 | }
|
51 | function import$(obj, src){
|
52 | var own = {}.hasOwnProperty;
|
53 | for (var key in src) if (own.call(src, key)) obj[key] = src[key];
|
54 | return obj;
|
55 | } |
\ | No newline at end of file |