1 | var common = require('./common');
|
2 | var fs = require('fs');
|
3 | var path = require('path');
|
4 |
|
5 | common.register('toEnd', _toEnd, {
|
6 | pipeOnly: true,
|
7 | wrapOutput: false,
|
8 | });
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | function _toEnd(options, file) {
|
22 | if (!file) common.error('wrong arguments');
|
23 |
|
24 | if (!fs.existsSync(path.dirname(file))) {
|
25 | common.error('no such file or directory: ' + path.dirname(file));
|
26 | }
|
27 |
|
28 | try {
|
29 | fs.appendFileSync(file, this.stdout || this.toString(), 'utf8');
|
30 | return this;
|
31 | } catch (e) {
|
32 |
|
33 | common.error('could not append to file (code ' + e.code + '): ' + file, { continue: true });
|
34 | }
|
35 | }
|
36 | module.exports = _toEnd;
|