forked from joaomfrebelo/atws
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpstan.js
More file actions
41 lines (33 loc) · 1013 Bytes
/
phpstan.js
File metadata and controls
41 lines (33 loc) · 1013 Bytes
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
37
38
39
40
41
const {exec} = require("child_process");
const path = require("path");
const chokidar = require("chokidar");
const srcdir = "./src/";
const testdir = "./test/";
const wconf = {
ignoreInitial: true,
delay: 200,
queue: true
};
let lastTime = 0;
let lastPath = "";
chokidar.watch([srcdir + "**/*.php", testdir + "**/*.php"], wconf)
.on("change", (phpfilepath) => {
let now = new Date();
let dif = now.getTime() - lastTime;
let sameFile = lastPath === phpfilepath;
lastTime = now.getTime();
lastPath = phpfilepath;
if (dif < 9000 && sameFile) {
return;
}
const stanpath = path.join(__dirname, "vendor", "bin", "phpstan");
const comm = `${stanpath} analyse ${phpfilepath}`;
console.log(`Checking file ${phpfilepath} - ${now.toISOString()}`);
exec(comm, {maxBuffer: 1024 * 1024 * 1024}, (error, stdout, stderr) => {
if (stdout === "" || stdout === null) {
console.log(stderr);
} else {
console.log(stdout);
}
});
});