├── .gitignore ├── README.md ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fastboot FS Notifier 2 | A Fastboot App Server Notifier for watching files on the local disk. 3 | 4 | ```javascript 5 | const FSNotifier = require('fastboot-fs-notifier'); 6 | 7 | let notifier = new FSNotifier({ 8 | targetDir: TARGET_PATH 9 | }); 10 | 11 | let server = new FastBootAppServer({ 12 | notifier: notifier 13 | }); 14 | ``` 15 | 16 | When the notifier is started, it will use the Node Filesystem's [watch 17 | function](https://nodejs.org/docs/latest/api/fs.html#fs_fs_watch_filename_options_listener) to watch the target directory, which should be your directory for your Ember app. On new releases of the application, it will notify the Fastboot App Server and let it know that files have changed and it should be restarted. 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fastboot-fs-notifier", 3 | "version": "0.1.1", 4 | "description": "A Fastboot App Server notifier for the Filesystem", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/iheanyi/fastboot-fs-notifier.git" 12 | }, 13 | "keywords": [ 14 | "ember", 15 | "fastboot", 16 | "notifier", 17 | "fs" 18 | ], 19 | "author": "Iheanyi Ekechukwu ", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/iheanyi/fastboot-fs-notifier/issues" 23 | }, 24 | "homepage": "https://github.com/iheanyi/fastboot-fs-notifier#readme", 25 | "dependencies": { 26 | "debounce": "^1.0.0" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const fs = require('fs'); 4 | const debounce = require('debounce'); 5 | 6 | class FSNotifier { 7 | constructor(options) { 8 | this.ui = options.ui; 9 | this.targetDir = options.targetDir; 10 | } 11 | 12 | subscribe(notify) { 13 | // Debounce Notify so it's only called once, filesystem change will shoot 14 | // off multiple notifiers otherwise. 15 | this.notify = debounce(notify, 200); 16 | 17 | return this.initWatcher(); 18 | } 19 | 20 | initWatcher() { 21 | return new Promise((resolve, reject) => { 22 | fs.watch(this.targetDir, {}, (event, filename) => { 23 | this.hasWatcher = true; 24 | if (event === 'error') { 25 | this.ui.writeError('error while watching target directory'); 26 | reject(err); 27 | } else if (event === 'change') { 28 | this.notify(); 29 | } 30 | }); 31 | 32 | resolve(); 33 | }); 34 | } 35 | } 36 | 37 | module.exports = FSNotifier; 38 | --------------------------------------------------------------------------------