Code files
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "watching-with-chokidar",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "David Mark Clements",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"chokidar": "^1.6.0",
|
||||
"human-time": "0.0.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict'
|
||||
|
||||
const chokidar = require('chokidar')
|
||||
const human = require('human-time')
|
||||
const watcher = chokidar.watch(process.argv[2] || '.', {
|
||||
alwaysStat: true
|
||||
})
|
||||
|
||||
watcher.on('ready', () => {
|
||||
watcher
|
||||
.on('add', (file, stat) => {
|
||||
console.log(`${file} created ${human((stat.birthtime))}`)
|
||||
})
|
||||
.on('unlink', (file) => {
|
||||
console.log(`${file} removed`)
|
||||
})
|
||||
.on('change', (file, stat) => {
|
||||
const msg = (+stat.ctime === +stat.mtime) ? 'updated' : 'modified'
|
||||
console.log(`${file} ${msg} ${human((stat.ctime))}`)
|
||||
})
|
||||
.on('addDir', (dir, stat) => {
|
||||
console.log(`${dir} folder created ${human((stat.birthtime))}`)
|
||||
})
|
||||
.on('unlinkDir', (dir) => {
|
||||
console.log(`${dir} folder removed`)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user