From 233670ecbdf3c161c63e566bbc479ac835056552 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Sun, 17 Feb 2019 14:37:59 -0800 Subject: [PATCH] 0.2.4 add reject to on error, removed console.log, some other cleanup and logging --- package.json | 2 +- src/watcher.js | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 358a91f..5156ba2 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/watcher.js b/src/watcher.js index a6abe35..4ef03e1 100644 --- a/src/watcher.js +++ b/src/watcher.js @@ -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) {