Skip to content

Commit

Permalink
Implements custom recursive watch for linux (#39)
Browse files Browse the repository at this point in the history
* Implements custom recursive watch for linux

* Only use custom watch on linux
  • Loading branch information
lukejacksonn authored Feb 11, 2020
1 parent f58ddd2 commit 11b31b5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion servor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ const os = require('os');
const net = require('net');
const cwd = process.cwd();

const watch =
process.platform === 'linux'
? (path, cb) => {
if (fs.statSync(path).isDirectory()) {
fs.watch(path, cb);
fs.readdirSync(path).forEach(entry => watch(`${path}/${entry}`, cb));
}
}
: (path, cb) => fs.watch(path, { recursive: true }, cb);

const fport = (p = 0) =>
new Promise((resolve, reject) => {
const s = net.createServer();
Expand Down Expand Up @@ -122,7 +132,7 @@ module.exports = async ({
// Notify livereload clients on file change

reload &&
fs.watch(root, { recursive: true }, () => {
watch(root, () => {
while (clients.length > 0)
sendMessage(clients.pop(), 'message', 'reload');
});
Expand Down

0 comments on commit 11b31b5

Please sign in to comment.