-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
33 lines (30 loc) · 948 Bytes
/
main.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
const scan = require("./scripts/scan");
require("./scripts/config");
const fs = require('fs');
const md5 = require('md5');
const env = './.env';
let md5Previous = md5(fs.readFileSync(env));
/**
* Watch the .env file for changes and restart the scanner with new options if there is any change
* Time Complexity: O(1): Async event listener, static time
* @param {string} env - Path to the .env file
* @param {event} event - A filesystem event
* @param {string} filename - Name of the file for the filesystem event
*/
fs.watch(env, (event, filename) => {
if (filename) {
const md5Current = md5(fs.readFileSync(env));
if (md5Current === md5Previous) {
return;
}
md5Previous = md5Current;
scan.stop();
scan.start();
console.log(`${filename} file changed.`);
}
});
/**
* Start the scanner when the main script is called
* @param {string} "start"
*/
scan.start();