{"name":"egg-watcher","version":"2.0.0","description":"file watcher plugin for egg","eggPlugin":{"name":"watcher"},"files":["app.js","agent.js","config","lib"],"scripts":{"lint":"eslint --ext js . --fix","test":"egg-bin test","cov":"egg-bin cov","ci":"npm run lint && npm run cov","autod":"autod"},"dependencies":{"detect-port":"^1.1.0","sdk-base":"^3.0.1","wt":"^1.1.1"},"devDependencies":{"autod":"^2.7.1","egg":"*","egg-bin":"^2.0.1","egg-ci":"^1.1.0","egg-mock":"^2.1.0","eslint":"^3.14.0","eslint-config-egg":"^3.2.0","ko-sleep":"^1.0.2","supertest":"^2.0.1"},"homepage":"https://github.com/eggjs/egg-watcher","repository":{"type":"git","url":"git+ssh://git@github.com/eggjs/egg-watcher.git"},"keywords":["egg-watcher","egg","watcher","watch"],"engines":{"node":">= 6.0.0"},"ci":{"version":"6, 7"},"gitHead":"39f9c4315b05ff64c1ab0d5941ce3269b1fa5b91","bugs":{"url":"https://github.com/eggjs/egg-watcher/issues"},"_id":"egg-watcher@2.0.0","_shasum":"87a0df6791c13e6d5c5e48c093f70e834b680b88","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.1","_npmUser":{"name":"popomore","email":"sakura9515@gmail.com"},"dist":{"shasum":"87a0df6791c13e6d5c5e48c093f70e834b680b88","tarball":"http://registry-npm.ywwl.com/egg-watcher/download/egg-watcher-2.0.0.tgz","integrity":"sha512-AxzHV83eToIJzzalI9LoYwTar7Vg8bjIqAWdkKaUZU8oFmabzwRkyWp+5wD6PErpx8TW4otL8pHp4JUL3o1iIg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDJiILecNHWSHSOBtkyYmvb2Pz4gwPpd8nhK8WVXhff8gIgaQQmo++X1ZrsusdMSSF/tEJAzNJxKWXC0PR5A5gno2s="}],"size":4242,"noattachment":false,"key":"/egg-watcher/-/egg-watcher-2.0.0.tgz"},"maintainers":[{"name":"atian25","email":"atian25@qq.com"},{"name":"dead_horse","email":"dead_horse@qq.com"},{"name":"eggjs","email":"fengmk2+eggjs@gmail.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"luckydrq","email":"drqzju@gmail.com"},{"name":"popomore","email":"sakura9515@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/egg-watcher-2.0.0.tgz_1485335567096_0.07604578090831637"},"directories":{},"readme":"# egg-watcher\nFile watcher plugin for egg\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-watcher.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-watcher\n[travis-image]: https://img.shields.io/travis/eggjs/egg-watcher.svg?style=flat-square\n[travis-url]: https://travis-ci.org/eggjs/egg-watcher\n[codecov-image]: https://codecov.io/github/eggjs/egg-watcher/coverage.svg?branch=master\n[codecov-url]: https://codecov.io/github/eggjs/egg-watcher?branch=master\n[david-image]: https://img.shields.io/david/eggjs/egg-watcher.svg?style=flat-square\n[david-url]: https://david-dm.org/eggjs/egg-watcher\n[snyk-image]: https://snyk.io/test/npm/egg-watcher/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-watcher\n[download-image]: https://img.shields.io/npm/dm/egg-watcher.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-watcher\n\n## Usage\n\nIn worker process:\n\n### app.watcher.watch(path, listener)\nStart watching file(s).\n\n- path(String|Array): file path(s)\n- listener(Function): file change callback\n\n### app.watcher.unwatch(path[, listener])\nStop watching file(s).\n\n- path(String|Array): file path(s)\n- listener(Function): file change callback\n\nIn agent process:\n\n### agent.watcher.watch(path, listener)\nStart watching file(s).\n\n- path(String|Array): file path(s)\n- listener(Function): file change callback\n\n### agent.watcher.unwatch(path[, listener])\nStop watching file(s).\n\n- path(String|Array): file path(s)\n- listener(Function): file change callback\n\n## Watching mode\n\n### `development` Mode\n\nThere's a built-in [development mode](https://github.com/eggjs/egg-watcher/blob/master/lib/event-sources/development.js) which works in local(env is `local`). Once files on disk is modified it will emit a `change` event immediately.\n\n### Customize Watching Mode\n\nSay we want to build a custom event source plugin (package name: `egg-watcher-custom`, eggPlugin.name: `watcherCustom`).\n\nFirstly define our custom event source like this:\n\n```js\n// {plugin_root}/lib/custom_event_source.js\nconst Base = require('sdk-base');\n\nclass CustomEventSource extends Base {\n  // `opts` comes from app.config[${eventSourceName}]\n  // `eventSourceName` will be registered later in\n  // `config.watcher.eventSources` as the key shown below\n  constructor(opts) {\n    super(opts);\n    this.ready(true);\n  }\n\n  watch(path) {\n    // replace this with your desired way of watching,\n    // when aware of any change, emit a `change` event\n    // with an info object containing `path` property\n    // specifying the changed directory or file.\n    this._h = setInterval(() => {\n      this.emit('change', { path });\n    }, 1000);\n  }\n\n  unwatch() {\n    // replace this with your implementation\n    if (this._h) {\n      clearInterval(this._h);\n    }\n  }\n}\n\nmodule.exports = CustomEventSource;\n```\n\nEvent source implementations varies according to your running environment. When working with vagrant, docker, samba or such other non-standard way of development, you should use a different watch API specific to what you are working with.\n\nThen add your custom event source to config:\n\n```js\n// config.default.js\nexports.watcher = {\n  eventSources: {\n    custom: require('../lib/custom_event_source'),\n  },\n};\n```\n\nChoose to use your custom watching mode in your desired env.\n\n```js\n// config.${env}.js\nexports.watcher = {\n  type: 'custom',\n};\n\n// this will pass to your CustomEventSource constructor as opts\nexports.watcherCustom = {\n  // foo: 'bar',\n};\n```\n\nIf possible, plugins named like `egg-watcher-${customName}`(`egg-watcher-vagrant` eg.) are recommended.\n\n## Questions & Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues).\n\n## License\n\n[MIT](https://github.com/eggjs/egg-watcher/blob/master/LICENSE)\n","publish_time":1485335568758,"_cnpm_publish_time":1485335568758,"dist-tags":{"latest":"3.1.1"}}