UNPKG

1.85 kBJavaScriptView Raw
1// Generated by LiveScript 1.4.0
2var EventEmitter, fs, yaml, ObservableProcess, path, ServiceInstaller;
3EventEmitter = require('events').EventEmitter;
4fs = require('fs');
5yaml = require('js-yaml');
6ObservableProcess = require('observable-process');
7path = require('path');
8ServiceInstaller = (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));
41module.exports = ServiceInstaller;
42function bind$(obj, key, target){
43 return function(){ return (target || obj)[key].apply(obj, arguments) };
44}
45function 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}
51function 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