-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.js
More file actions
64 lines (51 loc) · 1.51 KB
/
cli.js
File metadata and controls
64 lines (51 loc) · 1.51 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var AggregateFiles = require('./lib/aggregate_files').AggregateFiles;
var streams = require('./lib/streams'),
p = require('./lib/pipeline');
var ConstructFlow = p.ConstructFlow,
ConstructPipeline = p.ConstructPipeline,
IPCChannel = streams.IPCChannel,
Tap = streams.Tap,
Sink = streams.Sink;
// global for now
var isChild = process.env['SSEJ_CHILD'] == 'true';
var program = require('./lib/configuration').program;
// Prepare pipe
var pipeline = (function () {
if (isChild) {
return ConstructPipeline(program.definition);
} else {
return ConstructFlow(program.definition);
}
}());
// Prepare input
var ls = new streams.LineStream();
var input = (function () {
if (program.files.length > 0) {
var aggFiles = new(AggregateFiles)(program.files);
return aggFiles.pipe(ls);
} else if (isChild) {
return new IPCChannel();
} else {
process.stdin.setEncoding('utf8');
var stdin = new(Tap)('STDIN', process.stdin);
stdin.pipe(ls);
process.stdin.resume();
return ls;
}
}());
// Setup output
var outputHandler = (function () {
if (isChild) {
return new(Sink)('IPC OUT', function (data) {
process.send(data);
});
} else {
return new(Sink)('STD OUT', console.log);
}
}());
var title = isChild ? 'CHILD' : 'PARENT';
input.pipe(pipeline.head);
pipeline.tail.pipe(outputHandler);
if (program.flags.indexOf('-d') > -1) {
console.log(title, ':', pipeline.head.debug());
}