simple-watcher
Advanced tools
Comparing version 0.0.1-alpha to 0.1.0
57
index.js
@@ -1,1 +0,56 @@ | ||
console.log('Work in progress.') | ||
'use strict' | ||
const fs = require('fs') | ||
const path = require('path') | ||
const PLATFORMS = ['win32', 'darwin'] | ||
// OS watcher. | ||
let watchFolder = (workingDir, recursive, callback) => { | ||
let options = { persistent: true, recursive: recursive } | ||
fs.watch(workingDir, options, (event, fileName) => { | ||
callback(path.join(workingDir, fileName)) | ||
}) | ||
} | ||
// Attach watchers recursively. | ||
// This code is synchronous in order to be able tell when it actuall ends. | ||
let watchFolderFallback = (parent, callback) => { | ||
// Skip if not a directory. | ||
if (!fs.statSync(parent).isDirectory()) { | ||
return | ||
} | ||
fs.stat(parent, (err, stats) => { | ||
if (err || !stats.isDirectory()) { | ||
return | ||
} | ||
watchFolder(parent, false, callback) | ||
// Iterate over list of children. | ||
fs.readdir(parent, (err, children) => { | ||
if (err) { | ||
return | ||
} | ||
children.forEach((child) => { | ||
child = path.resolve(parent, child) | ||
watchFolderFallback(child, callback) | ||
}) | ||
}) | ||
}) | ||
} | ||
let watch = (workingDir, callback) => { | ||
workingDir = path.resolve(workingDir) | ||
if (PLATFORMS.indexOf(process.platform) !== -1) { | ||
watchFolder(workingDir, true, callback) | ||
} else { | ||
watchFolderFallback(workingDir, callback) | ||
} | ||
} | ||
module.exports = watch |
{ | ||
"name": "simple-watcher", | ||
"version": "0.0.1-alpha", | ||
"description": "\"A simple file system watcher.\"", | ||
"version": "0.1.0", | ||
"description": "\"A simple recursive directory watcher.\"", | ||
"main": "index.js", | ||
@@ -13,2 +13,4 @@ "repository": { | ||
"system", | ||
"directory", | ||
"recursive", | ||
"watch", | ||
@@ -15,0 +17,0 @@ "watcher" |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
5016
6
49
0
51
0
1