-
Notifications
You must be signed in to change notification settings - Fork 0
/
solhint-watch.js
executable file
·48 lines (39 loc) · 1.01 KB
/
solhint-watch.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
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env node
const chokidar = require('chokidar')
const spawn = require('child_process').spawn
const keypress = require('keypress')
const solhintBinary = 'solhint'
const watchDir = './**/*.sol'
const events = {
add: 'add',
change: 'change'
}
const chokidarOptions = {
ignored: [
'.git/**',
'**/node_modules/**'
],
ignoreInitial: true
};
function runSolhint(path) {
console.clear()
console.log('Running Solhint on: %s', path)
const solhint = spawn(solhintBinary, [path], { stdio: 'inherit' })
solhint.on('close', (code) => console.log(`Solhint exited with code ${code}`))
}
function init() {
chokidar
.watch(watchDir, chokidarOptions)
.on(events.add, (path) => runSolhint(path))
.on(events.change, (path) => runSolhint(path))
.on('error', () => console.log('error'))
console.log('Watching: %o', watchDir);
}
process.stdin.on('keypress', function (ch, key) {
if (key && key.name == 'enter') {
runSolhint(watchDir)
}
});
keypress(process.stdin);
console.clear()
init()