mirror of https://github.com/mthenw/frontail.git
Basic version
parent
c7fbe1ac19
commit
bab90d4b60
|
@ -23,6 +23,8 @@
|
|||
"browser": true,
|
||||
|
||||
"globals": {
|
||||
"io": false
|
||||
"io": false,
|
||||
"describe": false,
|
||||
"it": false
|
||||
}
|
||||
}
|
||||
|
|
5
Makefile
5
Makefile
|
@ -1,4 +1,7 @@
|
|||
lint:
|
||||
@./node_modules/.bin/jshint .
|
||||
|
||||
.PHONY: lint
|
||||
test:
|
||||
@./node_modules/.bin/mocha --reporter spec
|
||||
|
||||
.PHONY: lint test
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var util = require('util');
|
||||
var spawn = require('child_process').spawn;
|
||||
|
||||
var Tail = function (path) {
|
||||
EventEmitter.call(this);
|
||||
|
||||
var self = this;
|
||||
var tail = spawn('tail', ['-F'].concat(path));
|
||||
|
||||
tail.stdout.on('data', function (data) {
|
||||
var line = data.toString('utf-8');
|
||||
self.emit('line', line);
|
||||
});
|
||||
};
|
||||
util.inherits(Tail, EventEmitter);
|
||||
|
||||
|
||||
module.exports = function (path) {
|
||||
return new Tail(path);
|
||||
};
|
||||
})();
|
|
@ -15,7 +15,10 @@
|
|||
"cookie": "0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jshint": "~2.1.10"
|
||||
"jshint": "~2.3.0",
|
||||
"should": "~2.0.2",
|
||||
"mocha": "~1.13.0",
|
||||
"temp": "~0.6.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
require('should');
|
||||
|
||||
var fs = require('fs');
|
||||
var tail = require('../lib/tail');
|
||||
var temp = require('temp');
|
||||
|
||||
describe('tail', function () {
|
||||
temp.track();
|
||||
|
||||
it('should call event line if new line appear in file', function (done) {
|
||||
temp.open('test', function (err, info) {
|
||||
tail(info.path).on('line', function (line) {
|
||||
line.should.equal('testline');
|
||||
done();
|
||||
});
|
||||
|
||||
fs.write(info.fd, 'testline');
|
||||
fs.close(info.fd);
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
Loading…
Reference in New Issue