Total Complexity | 8 |
Complexity/F | 2.67 |
Lines of Code | 29 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | const fs = require('fs') |
||
2 | const { join } = require('path') |
||
3 | const { Writable } = require('stream') |
||
4 | |||
5 | module.exports = (output, data) => { |
||
6 | if (!data) { |
||
7 | return null |
||
8 | } |
||
9 | if (!output) { |
||
10 | console.log(data) |
||
11 | } else if (typeof output === 'string') { |
||
12 | const path = join(__dirname, '../', output) |
||
13 | fs.open(path, fs.W_OK, err => { |
||
14 | if (err) { |
||
15 | console.error(`Cannot write file to ${path}`) |
||
16 | return |
||
17 | } |
||
18 | // TODO: maybe use appendFile for readStream |
||
19 | fs.writeFileSync(path, data) |
||
20 | }) |
||
21 | } else if (output instanceof Writable) { |
||
22 | output.write(data + '\r\n') |
||
23 | output.on('error', err => { |
||
24 | console.error(err) |
||
25 | }) |
||
26 | } else { |
||
27 | console.error('Invalid Output') |
||
28 | } |
||
29 | } |
||
30 |