-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathinto.js
More file actions
52 lines (43 loc) · 1.41 KB
/
into.js
File metadata and controls
52 lines (43 loc) · 1.41 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
'use strict'
const defaults = require('./defaults')
const LogDraft = require('./LogDraft')
const LineCountStream = require('./LineCountStream')
/*
* Injects DraftLog into a console object
* call with a second parameter as 'true' to
* Mock installation, and add only the `draft` method
* as a alias to `console.log`
*/
module.exports = function into(console, extra) {
// If extra is set to `true`, it's production mode
var production = (extra === true ? true : false)
// If production mode, mock api
if (production) {
// Mock draft and set is as console.log
console.draft = function draft() {
// Log this
console.log.apply(null, arguments)
// Return usual console.log method
return console.log.bind(console)
}
return
}
// Transform stdout from console to LineCounter
var lineCountStream = LineCountStream(console._stdout)
console._stdout = lineCountStream
// Can it bind to process.stdin automatically?
if (defaults.stdinAutoBind) {
lineCountStream.addLineListener(process.stdin)
}
// Add "draft" to console
console.draft = console.draft || function draft() {
// Create Draft at this point in time
var logDraft = new LogDraft(console, 'log')
// Log first
logDraft.write.apply(logDraft, arguments)
// Return update function
return logDraft.update.bind(logDraft)
}
// Return the created Transform Stream
return lineCountStream
}