-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpt-watcher.js
36 lines (29 loc) · 931 Bytes
/
rpt-watcher.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
var settings = require('./rpt-watcher.config.json');
const fs = require('fs');
const glob = require('glob');
const readLastLines = require('read-last-lines');
var folder = settings.drive + process.env.HOMEPATH + "\\AppData\\Local\\Arma 3";
var lastmtime = "";
var file = "";
glob(folder + '/*.rpt', {}, (err, files)=>{
if( files.length === 0){
throw new Error('No rpt file found in ' + folder);
};
for (var i=0; i<files.length; i++) {
if(i == 0){
//index file
var lastmtime = fs.statSync(files[i]).mtime;
var file = files[i];
}
if(fs.statSync(files[i]).mtime > lastmtime){
var file = files[i];
var lastmtime = fs.statSync(files[i]).mtime;
};
};
console.log("Watchfile: " + file);
fs.watchFile(file, (curr, prev) => {
readLastLines.read(file, settings.lines)
.then((lines) => console.log(lines));
;
});
})