-
Notifications
You must be signed in to change notification settings - Fork 10
/
os.js
48 lines (35 loc) · 838 Bytes
/
os.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
const path = require('path')
const commands = {
// windows
win32: `"${path.join(
__dirname,
'bin',
`du${process.arch === 'x64' ? '64' : ''}.exe`
)}" -nobanner -accepteula -q -c .`,
// macos
darwin: `du -sk .`,
// any linux
linux: `du -sb .`,
}
const processOutput = {
// windows
win32(stdout) {
// query stats indexes from the end since path can contain commas as well
const stats = stdout.split('\n')[1].split(',')
const bytes = +stats.slice(-2)[0]
return bytes
},
// macos
darwin(stdout) {
const match = /^(\d+)/.exec(stdout)
const bytes = Number(match[1]) * 1024
return bytes
},
// any linux
linux(stdout) {
const match = /^(\d+)/.exec(stdout)
const bytes = Number(match[1])
return bytes
},
}
module.exports = { commands, processOutput }