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", "name": "@uci-utils/watcher",
"version": "0.2.3", "version": "0.2.4",
"description": "File System Watcher Class that emits events", "description": "File System Watcher Class that emits events",
"main": "src/watcher.js", "main": "src/watcher.js",
"scripts": { "scripts": {

View File

@ -35,8 +35,9 @@ class Watcher extends Emitter {
this._watcher = watch(opts.source,opts) this._watcher = watch(opts.source,opts)
this._watcher.on('error', error => { this._watcher.on('error', error => {
log.error({error:error, msg:'Watcher error'}) log.error({error:error, msg:'Watcher error'})
reject({error:error, msg:'Watcher error'})
}) })
this._watcher.on('ready', () => { this._watcher.once('ready', () => {
clearTimeout(readyTimeout) clearTimeout(readyTimeout)
log.info('initial scan sucessful, ready to start') log.info('initial scan sucessful, ready to start')
this._ready=true this._ready=true
@ -44,13 +45,13 @@ class Watcher extends Emitter {
resolve() resolve()
}) })
let readyTimeout = setTimeout(() =>{ 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') reject('timeout during intial scan')
},READY_TIMEOUT) },READY_TIMEOUT)
} }
else { else {
log.fatal('MUST provide a source directory(s) option to watch') 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._watcher) await this.init(opts)
if (this._ready) { if (this._ready) {
log.debug({watching:this._watcher.getWatched(),msg:'initial files watched'})
log.info(`now watching ${this.opts.source}`) log.info(`now watching ${this.opts.source}`)
this._watcher.removeAllListeners() // just in case this._watcher.removeAllListeners() // just in case
this.watching = true this.watching = true
@ -116,12 +118,9 @@ class Watcher extends Emitter {
} }
async getIgnoreLists(lists) { async getIgnoreLists(lists) {
// console.log('ignore lists', lists)
if (typeof lists === 'string') lists=[lists] if (typeof lists === 'string') lists=[lists]
let ignored = await ignores(lists) let ignored = await ignores(lists)
// console.log('==ignores from lists', ignored)
this._ignored = [...this._ignored,...ignored] this._ignored = [...this._ignored,...ignored]
// console.log(this._ignored)
} }
addIgnore(ignore) { addIgnore(ignore) {