[tail] added TailVinyl class
This commit is contained in:
@@ -6,6 +6,7 @@ const through = require('through2');
|
|||||||
const Sdk = require('./sdk');
|
const Sdk = require('./sdk');
|
||||||
const Vinyl = require('vinyl');
|
const Vinyl = require('vinyl');
|
||||||
const run = require('../run/index');
|
const run = require('../run/index');
|
||||||
|
const {TailVinyl} = require('./tail');
|
||||||
|
|
||||||
|
|
||||||
class FlashPlayer extends Sdk {
|
class FlashPlayer extends Sdk {
|
||||||
@@ -99,7 +100,11 @@ class FlashPlayer extends Sdk {
|
|||||||
FlashPlayer.enableLog();
|
FlashPlayer.enableLog();
|
||||||
return run(`${this.flashPlayerBin} ${filename}`, params).exec()
|
return run(`${this.flashPlayerBin} ${filename}`, params).exec()
|
||||||
.pipe(through.obj(function (file, enc, callback) {
|
.pipe(through.obj(function (file, enc, callback) {
|
||||||
this.push(new Vinyl({path: FlashPlayer.log}));
|
const log = new TailVinyl({
|
||||||
|
path: FlashPlayer.log,
|
||||||
|
});
|
||||||
|
this.on('end', () => log.dispose());
|
||||||
|
this.push(log);
|
||||||
callback();
|
callback();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,25 @@
|
|||||||
const through = require('through2');
|
const through = require('through2');
|
||||||
const {Tail} = require('tail');
|
|
||||||
const {Writable} = require('stream');
|
const {Writable} = require('stream');
|
||||||
const {StringDecoder} = require('string_decoder');
|
const {StringDecoder} = require('string_decoder');
|
||||||
|
const Vinyl = require('vinyl');
|
||||||
|
const {Tail} = require('tail');
|
||||||
|
const {Transform} = require('stream');
|
||||||
|
|
||||||
|
|
||||||
|
class TailVinyl extends Vinyl {
|
||||||
|
|
||||||
|
constructor(params) {
|
||||||
|
params.contents = new Transform();
|
||||||
|
super(params);
|
||||||
|
this.tail = new Tail(params.path);
|
||||||
|
this.tail.on('line', data => this.contents.write(data + '\n'));
|
||||||
|
this.tail.on('error', error => this.contents.write('error: ' + error));
|
||||||
|
}
|
||||||
|
|
||||||
|
dispose() {
|
||||||
|
this.tail.unwatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class StringWritable extends Writable {
|
class StringWritable extends Writable {
|
||||||
@@ -32,17 +50,15 @@ class StringWritable extends Writable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = (handler) => {
|
module.exports = (handler) => {
|
||||||
return through.obj(function (file, enc, callback) {
|
return through.obj(function (file, enc, callback) {
|
||||||
if (file.contents && file.contents.pipe) {
|
if (file.contents && file.contents.pipe) {
|
||||||
file.contents.pipe(new StringWritable(handler));
|
file.contents.pipe(new StringWritable(handler));
|
||||||
} else {
|
|
||||||
const tail = new Tail(file.path);
|
|
||||||
tail.on('line', data => handler(data));
|
|
||||||
tail.on('error', error => handler('[ERROR]: ', error));
|
|
||||||
this.on('end', () => tail.unwatch());
|
|
||||||
}
|
}
|
||||||
this.push(file);
|
this.push(file);
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.TailVinyl = TailVinyl;
|
||||||
|
|||||||
Reference in New Issue
Block a user