1 |
|
2 | var fs, mustache, path;
|
3 |
|
4 | module.exports = {
|
5 | ssh: null,
|
6 | handler: function(options) {
|
7 | if (!options.stream) {
|
8 | throw Error('Missing option: "stream"');
|
9 | }
|
10 | if (!options.serializer) {
|
11 | throw Error('Missing option: "serializer"');
|
12 | }
|
13 | if (options.end == null) {
|
14 | options.end = true;
|
15 | }
|
16 | return this.call(function() {
|
17 | var close;
|
18 | close = function() {
|
19 | return setTimeout(function() {
|
20 | if (options.end) {
|
21 | return options.stream.close();
|
22 | }
|
23 | }, 100);
|
24 | };
|
25 | this.on('text', function(log) {
|
26 | var data;
|
27 | if (!options.serializer.text) {
|
28 | return;
|
29 | }
|
30 | data = options.serializer.text(log);
|
31 | if (data != null) {
|
32 | return options.stream.write(data);
|
33 | }
|
34 | });
|
35 | this.on('header', function(log) {
|
36 | var data;
|
37 | if (!options.serializer.header) {
|
38 | return;
|
39 | }
|
40 | data = options.serializer.header(log);
|
41 | if (data != null) {
|
42 | return options.stream.write(data);
|
43 | }
|
44 | });
|
45 | this.on('stdin', function(log) {
|
46 | var data;
|
47 | if (!options.serializer.stdin) {
|
48 | return;
|
49 | }
|
50 | data = options.serializer.stdin(log);
|
51 | if (data != null) {
|
52 | return options.stream.write(data);
|
53 | }
|
54 | });
|
55 | this.on('diff', function(log) {
|
56 | var data;
|
57 | if (!options.serializer.diff) {
|
58 | return;
|
59 | }
|
60 | data = options.serializer.diff(log);
|
61 | if (data != null) {
|
62 | return options.stream.write(data);
|
63 | }
|
64 | });
|
65 | this.on('handled', function(log) {
|
66 | var data;
|
67 | if (!options.serializer.handled) {
|
68 | return;
|
69 | }
|
70 | data = options.serializer.handled(log);
|
71 | if (data != null) {
|
72 | return options.stream.write(data);
|
73 | }
|
74 | });
|
75 | this.on('stdout_stream', function(log) {
|
76 | var data;
|
77 | if (!options.serializer.stdout_stream) {
|
78 | return;
|
79 | }
|
80 | data = options.serializer.stdout_stream(log);
|
81 | if (data != null) {
|
82 | return options.stream.write(data);
|
83 | }
|
84 | });
|
85 | this.on('stderr', function(log) {
|
86 | var data;
|
87 | if (!options.serializer.stderr) {
|
88 | return;
|
89 | }
|
90 | data = options.serializer.stderr(log);
|
91 | if (data != null) {
|
92 | return options.stream.write(data);
|
93 | }
|
94 | });
|
95 | this.on('end', function() {
|
96 | var data;
|
97 | if (!options.serializer.end) {
|
98 | return;
|
99 | }
|
100 | data = options.serializer.end(log);
|
101 | if (data != null) {
|
102 | options.stream.write(data);
|
103 | }
|
104 | return close();
|
105 | });
|
106 | return this.on('error', function(err) {
|
107 | var data;
|
108 | if (!options.serializer.error) {
|
109 | return;
|
110 | }
|
111 | data = options.serializer.error(log);
|
112 | if (data != null) {
|
113 | options.stream.write(data);
|
114 | }
|
115 | return close();
|
116 | });
|
117 | });
|
118 | }
|
119 | };
|
120 |
|
121 | fs = require('fs');
|
122 |
|
123 | path = require('path');
|
124 |
|
125 | mustache = require('mustache');
|