-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathsanitize.js
51 lines (42 loc) · 1.67 KB
/
sanitize.js
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
// call this script to sanitize output of the command
// AFTER converting ANSI escape codes into HTML tags
const arg = require('arg')
const args = arg({
'--type': String,
})
const sanitizeCliInfo = () => {
const chromiumVersion = /- Version: (<.+>)(\d{2,3}.\d\.\d+.\d+)(<.+>)/g
const firefoxVersion = /- Version: (<.+>)(\d{2,3}.\d\.\d+|\d+\.[0-9a-z])(<.+>)+/g
const browserArgument = /--browser (\w+:?\w+)/g
// there is only a single line with memory usage
const systemMemory = /System Memory: (<.+>)([\w.]+ \w+)(<.+>) free (<.+>)([\w.]+ \w+)(<.+>)/
const replaceChromiumVersion = (match, openTag, version, closeTag) => {
return `- Version: ${openTag}***chromium version***${closeTag}`
}
const replaceFirefoxVersion = (match, openTag, version, closeTag) => {
return `- Version: ${openTag}***firefox version***${closeTag}`
}
const replaceBrowserArgument = (match, browserName) => {
return '--browser ***name:channel***'
}
const replaceSystemMemory = (match, tag1, total, tag2, tag3, free, tag4) => {
return `System Memory: ${tag1}***total memory***${tag2} free ${tag3}***free memory***${tag4}`
}
const sanitize = (chunk) => {
return chunk.replace(chromiumVersion, replaceChromiumVersion)
.replace(firefoxVersion, replaceFirefoxVersion)
.replace(browserArgument, replaceBrowserArgument)
.replace(systemMemory, replaceSystemMemory)
}
process.stdin.setEncoding('utf8')
process.stdin.on('data', function (chunk) {
return process.stdout.write(sanitize(chunk))
})
}
switch (args['--type']) {
case 'cli-info':
sanitizeCliInfo()
break
default:
throw new Error(`Unknown STDOUT type to sanitize "${args['--type']}"`)
}