0.2.4 add reject to on error, removed console.log, some other cleanup and logging

master
David Kebler 2019-02-17 14:37:59 -08:00
parent 0d65514630
commit 233670ecbd
2 changed files with 7 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@uci-utils/watcher",
"version": "0.2.3",
"version": "0.2.4",
"description": "File System Watcher Class that emits events",
"main": "src/watcher.js",
"scripts": {

View File

@ -35,8 +35,9 @@ class Watcher extends Emitter {
this._watcher = watch(opts.source,opts)
this._watcher.on('error', error => {
log.error({error:error, msg:'Watcher error'})
reject({error:error, msg:'Watcher error'})
})
this._watcher.on('ready', () => {
this._watcher.once('ready', () => {
clearTimeout(readyTimeout)
log.info('initial scan sucessful, ready to start')
this._ready=true
@ -44,13 +45,13 @@ class Watcher extends Emitter {
resolve()
})
let readyTimeout = setTimeout(() =>{
log.fatal({options:opts, timeout:READY_TIMEOUT, msg:'Timeout: unabled to complete initial scan'})
log.fatal({options:opts, timeout:READY_TIMEOUT, msg:'Timeout: unable to complete initial scan'})
reject('timeout during intial scan')
},READY_TIMEOUT)
}
else {
log.fatal('MUST provide a source directory(s) option to watch')
reject('no source provided')
reject('watching - no source provided')
}
})
}
@ -63,6 +64,7 @@ class Watcher extends Emitter {
}
if (!this._watcher) await this.init(opts)
if (this._ready) {
log.debug({watching:this._watcher.getWatched(),msg:'initial files watched'})
log.info(`now watching ${this.opts.source}`)
this._watcher.removeAllListeners() // just in case
this.watching = true
@ -80,7 +82,7 @@ class Watcher extends Emitter {
this.emit('install', f)
}
// user might want to run debounce on the listener for this event
log.debug({file:f, type:type, msg:'file system changed, emitting'})
log.debug({file:f, type:type, msg:'file system changed, emitting'})
this.emit('changed', {file:f, type:type})
} // end handler
@ -116,12 +118,9 @@ class Watcher extends Emitter {
}
async getIgnoreLists(lists) {
// console.log('ignore lists', lists)
if (typeof lists === 'string') lists=[lists]
let ignored = await ignores(lists)
// console.log('==ignores from lists', ignored)
this._ignored = [...this._ignored,...ignored]
// console.log(this._ignored)
}
addIgnore(ignore) {