diff --git a/example/example.js b/example/example.js new file mode 100644 index 0000000..6c55cd8 --- /dev/null +++ b/example/example.js @@ -0,0 +1,24 @@ +import Watcher from '../src/watcher' +import onDeath from 'ondeath' + +(async () => { + let options = {source:'./example/repo/**', ignored:['**/dontwatch.js'],ignoreList:['./example/repo/.gitignore']} + // let options = {source:'./readme.md'} + // let options = {source:'./example/*'} + + let watcher = new Watcher(options) + await watcher.start() + + watcher.on('changed', + (change) => { + console.log(`======= file ${change.file} was ${change.type} ==========`) + }) + + onDeath( () => { + console.log('\nHe\'s dead Jim') + watcher.remove() + }) + +})().catch(err => { + console.error('FATAL: UNABLE TO START SYSTEM!\n',err) +}) diff --git a/example/repo/.gitignore b/example/repo/.gitignore new file mode 100644 index 0000000..0979a6c --- /dev/null +++ b/example/repo/.gitignore @@ -0,0 +1 @@ +**/node_modules/** diff --git a/example/repo/.npmignore b/example/repo/.npmignore new file mode 100644 index 0000000..02078d5 --- /dev/null +++ b/example/repo/.npmignore @@ -0,0 +1,5 @@ +tests/ +test/ +*.test.js +testing/ +example/ diff --git a/example/repo/deletethis b/example/repo/deletethis new file mode 100644 index 0000000..e69de29 diff --git a/example/repo/dontwatch.js b/example/repo/dontwatch.js new file mode 100644 index 0000000..a2dc296 --- /dev/null +++ b/example/repo/dontwatch.js @@ -0,0 +1,3 @@ +this was modified some moreddddddd +modified +changes diff --git a/nodemon.json b/nodemon.json new file mode 100644 index 0000000..93c4534 --- /dev/null +++ b/nodemon.json @@ -0,0 +1,3 @@ +{ + "ignore": ["example/repo/*"] +} diff --git a/package.json b/package.json index 5156ba2..dffc0fc 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,11 @@ { "name": "@uci-utils/watcher", - "version": "0.2.4", + "version": "0.2.5", "description": "File System Watcher Class that emits events", "main": "src/watcher.js", "scripts": { + "example": "node -r esm ./example/example.js", + "exampled": "UCI_ENV=dev UCI_LOG_LEVEL=debug ./node_modules/.bin/nodemon -r esm ./example/example.js", "test": "./node_modules/.bin/mocha -r esm --timeout 30000", "testd": "UCI_ENV=dev ./node_modules/.bin/nodemon --exec './node_modules/.bin/mocha -r esm --timeout 30000' || exit 0", "testdd": "UCI_LOG_LEVEL='trace' npm run testd", @@ -28,14 +30,15 @@ }, "homepage": "https://github.com/uCOMmandIt/uci-utils#readme", "dependencies": { - "@uci-utils/logger": "0.0.13", - "@uci-utils/read-lines": "^0.2.1", - "chokidar": "^2.1.1" + "@uci-utils/logger": "0.0.16", + "@uci-utils/read-lines": "^0.2.2", + "chokidar": "^3.0.2" }, "devDependencies": { "chai": "^4.2.0", - "esm": "^3.2.4", - "mocha": "^5.2.0", - "nodemon": "^1.18.10" + "esm": "^3.2.25", + "mocha": "^6.2.0", + "nodemon": "^1.19.1", + "ondeath": "^1.0.0" } } diff --git a/readme.md b/readme.md index 19f188f..0440a66 100644 --- a/readme.md +++ b/readme.md @@ -1,2 +1,4 @@ ### File System Watcher Class #### a uCOMmandIt Utiltiy Function + +Extends Choikar diff --git a/src/watcher.js b/src/watcher.js index 4ef03e1..792cadc 100644 --- a/src/watcher.js +++ b/src/watcher.js @@ -14,7 +14,7 @@ const READY_TIMEOUT = 2000 class Watcher extends Emitter { constructor(opts={}) { super() - log = logger({ package:'@uci/sync', class:'Watcher', file:'src/watcher.js'}) + log = logger({ package:'@uci-utils/watcher', class:'Watcher', file:'src/watcher.js'}) opts.unlinkDir = Object.hasOwnProperty(opts.unlinkDir) ? opts.unlinkDir : true this.opts = opts this._ignored = [] diff --git a/test/watcher.test.js b/test/watcher.test.js index 62e5ba1..e0c88bb 100644 --- a/test/watcher.test.js +++ b/test/watcher.test.js @@ -12,7 +12,6 @@ describe('Watcher Class Testing ',async ()=> { let watcher = new Watcher(options) await watcher.start() watcher.on('changed', - // debounce( (change) => { console.log(`======= file ${change.file} was ${change.type} ==========`) } @@ -21,15 +20,15 @@ describe('Watcher Class Testing ',async ()=> { }) - it('can watch for file delete' , async function () { - // let [err,res] = await to(remote.exec('cd /opt && pwd')) - // if (err) { - // log.info('error running command aborting test', err) - // return - // } - // log.info(`result of remote command ${res.command} => ${res.reply.toString().trim()}`) - expect('test', 'test failed').to.equal('test') - }) + // it('can watch for file delete' , async function () { + // // let [err,res] = await to(remote.exec('cd /opt && pwd')) + // // if (err) { + // // log.info('error running command aborting test', err) + // // return + // // } + // // log.info(`result of remote command ${res.command} => ${res.reply.toString().trim()}`) + // expect('test', 'test failed').to.equal('test') + // }) })