├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .verb.md ├── LICENSE ├── index.js ├── package.json ├── readme.md ├── test ├── fixtures │ └── foo.txt └── test.js └── utils.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | end_of_line = lf 7 | charset = utf-8 8 | indent_size = 2 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | insert_final_newline = false 15 | 16 | [test/**] 17 | trim_trailing_whitespace = false 18 | insert_final_newline = false 19 | 20 | [templates/**] 21 | trim_trailing_whitespace = false 22 | insert_final_newline = false 23 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | "env": { 7 | "browser": false, 8 | "es6": true, 9 | "node": true, 10 | "mocha": true 11 | }, 12 | "globals": { 13 | "document": false, 14 | "navigator": false, 15 | "window": false 16 | }, 17 | "rules": { 18 | "accessor-pairs": 2, 19 | "arrow-spacing": [ 20 | 2, 21 | { 22 | "before": true, 23 | "after": true 24 | } 25 | ], 26 | "block-spacing": [ 27 | 2, 28 | "always" 29 | ], 30 | "brace-style": [ 31 | 2, 32 | "1tbs", 33 | { 34 | "allowSingleLine": true 35 | } 36 | ], 37 | "comma-dangle": [ 38 | 2, 39 | "never" 40 | ], 41 | "comma-spacing": [ 42 | 2, 43 | { 44 | "before": false, 45 | "after": true 46 | } 47 | ], 48 | "comma-style": [ 49 | 2, 50 | "last" 51 | ], 52 | "constructor-super": 2, 53 | "curly": [ 54 | 2, 55 | "multi-line" 56 | ], 57 | "dot-location": [ 58 | 2, 59 | "property" 60 | ], 61 | "eol-last": 2, 62 | "eqeqeq": [ 63 | 2, 64 | "allow-null" 65 | ], 66 | "generator-star-spacing": [ 67 | 2, 68 | { 69 | "before": true, 70 | "after": true 71 | } 72 | ], 73 | "handle-callback-err": [ 74 | 2, 75 | "^(err|error)$" 76 | ], 77 | "indent": [ 78 | 2, 79 | 2, 80 | { 81 | "SwitchCase": 1 82 | } 83 | ], 84 | "key-spacing": [ 85 | 2, 86 | { 87 | "beforeColon": false, 88 | "afterColon": true 89 | } 90 | ], 91 | "new-cap": [ 92 | 2, 93 | { 94 | "newIsCap": true, 95 | "capIsNew": false 96 | } 97 | ], 98 | "new-parens": 2, 99 | "no-array-constructor": 2, 100 | "no-caller": 2, 101 | "no-class-assign": 2, 102 | "no-cond-assign": 2, 103 | "no-const-assign": 2, 104 | "no-control-regex": 2, 105 | "no-debugger": 2, 106 | "no-delete-var": 2, 107 | "no-dupe-args": 2, 108 | "no-dupe-class-members": 2, 109 | "no-dupe-keys": 2, 110 | "no-duplicate-case": 2, 111 | "no-empty-character-class": 2, 112 | "no-empty-label": 2, 113 | "no-eval": 2, 114 | "no-ex-assign": 2, 115 | "no-extend-native": 2, 116 | "no-extra-bind": 2, 117 | "no-extra-boolean-cast": 2, 118 | "no-extra-parens": [ 119 | 2, 120 | "functions" 121 | ], 122 | "no-fallthrough": 2, 123 | "no-floating-decimal": 2, 124 | "no-func-assign": 2, 125 | "no-implied-eval": 2, 126 | "no-inner-declarations": [ 127 | 2, 128 | "functions" 129 | ], 130 | "no-invalid-regexp": 2, 131 | "no-irregular-whitespace": 2, 132 | "no-iterator": 2, 133 | "no-label-var": 2, 134 | "no-labels": 2, 135 | "no-lone-blocks": 2, 136 | "no-mixed-spaces-and-tabs": 2, 137 | "no-multi-spaces": 2, 138 | "no-multi-str": 2, 139 | "no-multiple-empty-lines": [ 140 | 2, 141 | { 142 | "max": 1 143 | } 144 | ], 145 | "no-native-reassign": 2, 146 | "no-negated-in-lhs": 2, 147 | "no-new": 2, 148 | "no-new-func": 2, 149 | "no-new-object": 2, 150 | "no-new-require": 2, 151 | "no-new-wrappers": 2, 152 | "no-obj-calls": 2, 153 | "no-octal": 2, 154 | "no-octal-escape": 2, 155 | "no-proto": 0, 156 | "no-redeclare": 2, 157 | "no-regex-spaces": 2, 158 | "no-return-assign": 2, 159 | "no-self-compare": 2, 160 | "no-sequences": 2, 161 | "no-shadow-restricted-names": 2, 162 | "no-spaced-func": 2, 163 | "no-sparse-arrays": 2, 164 | "no-this-before-super": 2, 165 | "no-throw-literal": 2, 166 | "no-trailing-spaces": 0, 167 | "no-undef": 2, 168 | "no-undef-init": 2, 169 | "no-unexpected-multiline": 2, 170 | "no-unneeded-ternary": [ 171 | 2, 172 | { 173 | "defaultAssignment": false 174 | } 175 | ], 176 | "no-unreachable": 2, 177 | "no-unused-vars": [ 178 | 2, 179 | { 180 | "vars": "all", 181 | "args": "none" 182 | } 183 | ], 184 | "no-useless-call": 0, 185 | "no-with": 2, 186 | "one-var": [ 187 | 0, 188 | { 189 | "initialized": "never" 190 | } 191 | ], 192 | "operator-linebreak": [ 193 | 0, 194 | "after", 195 | { 196 | "overrides": { 197 | "?": "before", 198 | ":": "before" 199 | } 200 | } 201 | ], 202 | "padded-blocks": [ 203 | 0, 204 | "never" 205 | ], 206 | "quotes": [ 207 | 2, 208 | "single", 209 | "avoid-escape" 210 | ], 211 | "radix": 2, 212 | "semi": [ 213 | 2, 214 | "always" 215 | ], 216 | "semi-spacing": [ 217 | 2, 218 | { 219 | "before": false, 220 | "after": true 221 | } 222 | ], 223 | "space-after-keywords": [ 224 | 2, 225 | "always" 226 | ], 227 | "space-before-blocks": [ 228 | 2, 229 | "always" 230 | ], 231 | "space-before-function-paren": [ 232 | 2, 233 | "never" 234 | ], 235 | "space-before-keywords": [ 236 | 2, 237 | "always" 238 | ], 239 | "space-in-parens": [ 240 | 2, 241 | "never" 242 | ], 243 | "space-infix-ops": 2, 244 | "space-return-throw-case": 2, 245 | "space-unary-ops": [ 246 | 2, 247 | { 248 | "words": true, 249 | "nonwords": false 250 | } 251 | ], 252 | "spaced-comment": [ 253 | 0, 254 | "always", 255 | { 256 | "markers": [ 257 | "global", 258 | "globals", 259 | "eslint", 260 | "eslint-disable", 261 | "*package", 262 | "!", 263 | "," 264 | ] 265 | } 266 | ], 267 | "use-isnan": 2, 268 | "valid-typeof": 2, 269 | "wrap-iife": [ 270 | 2, 271 | "any" 272 | ], 273 | "yoda": [ 274 | 2, 275 | "never" 276 | ] 277 | } 278 | } 279 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | *.sublime-* 3 | _gh_pages 4 | bower_components 5 | node_modules 6 | npm-debug.log 7 | actual 8 | test/actual 9 | temp 10 | tmp 11 | TODO.md 12 | vendor 13 | .idea 14 | benchmark 15 | coverage 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "stable" 5 | - "5" 6 | - "4" 7 | - "0.12" 8 | - "0.10" 9 | matrix: 10 | fast_finish: true 11 | allow_failures: 12 | - node_js: "0.10" 13 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | **Heads up** this plugin requires the [base-tasks][] plugin to be registered first. 2 | 3 | ## Usage 4 | 5 | ```js 6 | var watch = require('{%= name %}'); 7 | 8 | var Base = require('base'); 9 | var base = new Base(); 10 | 11 | base.use(watch()); 12 | ``` 13 | 14 | If you're using [assemble][] or [assemble-core][] you can add the plugin like this: 15 | 16 | **[assemble][]** 17 | 18 | ```js 19 | var watch = require('{%= name %}'); 20 | 21 | var assemble = require('assemble'); 22 | var app = assemble(); 23 | 24 | app.use(watch()); 25 | ``` 26 | 27 | **[assemble-core][]** 28 | 29 | ```js 30 | var watch = require('{%= name %}'); 31 | 32 | var assemble = require('assemble-core'); 33 | var app = assemble(); 34 | 35 | app.use(watch()); 36 | ``` 37 | 38 | ## API 39 | {%= apidocs('index.js') %} 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016, Brian Woodward. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * base-watch 3 | * 4 | * Copyright (c) 2016, Brian Woodward. 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var utils = require('./utils'); 11 | 12 | /** 13 | * Adds a [watch](#watch) method to your app that takes a file, directory, or glob pattern and watches for changes 14 | * to those files. When a change occurs, the specified task(s) or function will execute. 15 | * 16 | * If no task(s) or function is specified, only the instance of `FSWatcher` is returned and can be used directly. 17 | * See [chokidar.watch](https://github.com/paulmillr/chokidar#api) for more information. 18 | * 19 | * ```js 20 | * app.use(watch()); 21 | * ``` 22 | * @return {Function} Returns the plugin function to be used in a [base][] application. 23 | * @api public 24 | */ 25 | 26 | module.exports = function(config) { 27 | return function(app) { 28 | if (this.isRegistered('base-watch')) { 29 | return; 30 | } 31 | 32 | /** 33 | * Watch a file, directory, or glob pattern for changes and build a task 34 | * or list of tasks when changes are made. Watch is powered by [chokidar][] 35 | * so arguments can be anything supported by [chokidar.watch](https://github.com/paulmillr/chokidar#api). 36 | * 37 | * ```js 38 | * var watcher = app.watch('templates/pages/*.hbs', ['site']); 39 | * ``` 40 | * @name watch 41 | * @param {String|Array} `glob` Filename, Directory name, or glob pattern to watch 42 | * @param {Object} `options` Additional options to be passed to [chokidar][] 43 | * @param {String|Array|Function} `tasks` Tasks that are passed to `.build` when files in the glob are changed. 44 | * @return {Object} Returns an instance of `FSWatcher` from [chokidar][] 45 | * @api public 46 | */ 47 | 48 | this.define('watch', function(glob, options/*, fns/tasks */) { 49 | var self = this; 50 | var len = arguments.length - 1, i = 0; 51 | var args = new Array(len + 1); 52 | while (len--) args[i] = arguments[++i]; 53 | args[i] = cb; 54 | 55 | var opts = {}; 56 | if (typeof options === 'object' && !Array.isArray(options)) { 57 | args.shift(); 58 | opts = utils.extend({}, options); 59 | } 60 | 61 | opts = utils.extend({}, config, opts); 62 | 63 | var building = true; 64 | function cb(err) { 65 | building = false; 66 | if (err) console.error(err); 67 | } 68 | 69 | var watch = utils.chokidar.watch(glob, opts); 70 | 71 | // only contains our `cb` function 72 | if (args.length === 1) { 73 | return watch; 74 | } 75 | 76 | watch 77 | .on('ready', function() { 78 | building = false; 79 | }) 80 | .on('all', function() { 81 | if (building) return; 82 | building = true; 83 | self.build.apply(self, args); 84 | }); 85 | 86 | return watch; 87 | }); 88 | }; 89 | }; 90 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "base-watch", 3 | "description": "Watch plugin for base applications.", 4 | "version": "0.1.3", 5 | "homepage": "https://github.com/node-base/base-watch", 6 | "author": "Brian Woodward (https://github.com/doowb)", 7 | "repository": "node-base/base-watch", 8 | "bugs": { 9 | "url": "https://github.com/node-base/base-watch/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js", 14 | "utils.js" 15 | ], 16 | "main": "index.js", 17 | "engines": { 18 | "node": ">=0.10.0" 19 | }, 20 | "scripts": { 21 | "test": "mocha" 22 | }, 23 | "dependencies": { 24 | "chokidar": "^1.4.2", 25 | "extend-shallow": "^2.0.1", 26 | "lazy-cache": "^1.0.3" 27 | }, 28 | "devDependencies": { 29 | "base": "^0.6.7", 30 | "base-tasks": "^0.2.0", 31 | "gulp-format-md": "^0.1.5", 32 | "mocha": "*" 33 | }, 34 | "verb": { 35 | "toc": false, 36 | "layout": "default", 37 | "tasks": [ 38 | "readme" 39 | ], 40 | "plugins": [ 41 | "gulp-format-md" 42 | ], 43 | "related": { 44 | "list": [ 45 | "base", 46 | "base-generators", 47 | "base-tasks", 48 | "chokidar", 49 | "composer" 50 | ] 51 | }, 52 | "reflinks": [ 53 | "assemble", 54 | "assemble-core", 55 | "composer" 56 | ] 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # base-watch [![NPM version](https://img.shields.io/npm/v/base-watch.svg)](https://www.npmjs.com/package/base-watch) [![Build Status](https://img.shields.io/travis/node-base/base-watch.svg)](https://travis-ci.org/node-base/base-watch) 2 | 3 | > Watch plugin for base applications. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | ```sh 10 | $ npm install base-watch --save 11 | ``` 12 | 13 | **Heads up** this plugin requires the [base-tasks][] plugin to be registered first. 14 | 15 | ## Usage 16 | 17 | ```js 18 | var watch = require('base-watch'); 19 | 20 | var Base = require('base'); 21 | var base = new Base(); 22 | 23 | base.use(watch()); 24 | ``` 25 | 26 | If you're using [assemble](https://github.com/assemble/assemble) or [assemble-core](https://github.com/assemble/assemble-core) you can add the plugin like this: 27 | 28 | **[assemble](https://github.com/assemble/assemble)** 29 | 30 | ```js 31 | var watch = require('base-watch'); 32 | 33 | var assemble = require('assemble'); 34 | var app = assemble(); 35 | 36 | app.use(watch()); 37 | ``` 38 | 39 | **[assemble-core](https://github.com/assemble/assemble-core)** 40 | 41 | ```js 42 | var watch = require('base-watch'); 43 | 44 | var assemble = require('assemble-core'); 45 | var app = assemble(); 46 | 47 | app.use(watch()); 48 | ``` 49 | 50 | ## API 51 | 52 | If no task(s) or function is specified, only the instance of `FSWatcher` is returned and can be used directly. 53 | See [chokidar.watch](https://github.com/paulmillr/chokidar#api) for more information. 54 | 55 | * `returns` **{Function}**: Returns the plugin function to be used in a [base][] application. 56 | 57 | **Example** 58 | 59 | ```js 60 | app.use(watch()); 61 | ``` 62 | 63 | ### [watch](index.js#L48) 64 | 65 | Watch a file, directory, or glob pattern for changes and build a task or list of tasks when changes are made. Watch is powered by [chokidar][] so arguments can be anything supported by [chokidar.watch](https://github.com/paulmillr/chokidar#api). 66 | 67 | **Params** 68 | 69 | * `glob` **{String|Array}**: Filename, Directory name, or glob pattern to watch 70 | * `options` **{Object}**: Additional options to be passed to [chokidar][] 71 | * `tasks` **{String|Array|Function}**: Tasks that are passed to `.build` when files in the glob are changed. 72 | * `returns` **{Object}**: Returns an instance of `FSWatcher` from [chokidar][] 73 | 74 | **Example** 75 | 76 | ```js 77 | var watcher = app.watch('templates/pages/*.hbs', ['site']); 78 | ``` 79 | 80 | ## Related projects 81 | 82 | * [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://www.npmjs.com/package/base) | [homepage](https://github.com/node-base/base) 83 | * [base-generators](https://www.npmjs.com/package/base-generators): Adds project-generator support to your `base` application. | [homepage](https://github.com/node-base/base-generators) 84 | * [base-tasks](https://www.npmjs.com/package/base-tasks): base-methods plugin that provides a very thin wrapper around [https://github.com/jonschlinkert/composer](https://github.com/jonschlinkert/composer) for adding task methods to… [more](https://www.npmjs.com/package/base-tasks) | [homepage](https://github.com/jonschlinkert/base-tasks) 85 | * [chokidar](https://www.npmjs.com/package/chokidar): A neat wrapper around node.js fs.watch / fs.watchFile / fsevents. | [homepage](https://github.com/paulmillr/chokidar) 86 | * [composer](https://www.npmjs.com/package/composer): API-first task runner with three methods: task, run and watch. | [homepage](https://github.com/doowb/composer) 87 | 88 | ## Contributing 89 | 90 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/doowb/base-watch/issues/new). 91 | 92 | ## Building docs 93 | 94 | Generate readme and API documentation with [verb][]: 95 | 96 | ```sh 97 | $ npm install verb && npm run docs 98 | ``` 99 | 100 | Or, if [verb][] is installed globally: 101 | 102 | ```sh 103 | $ verb 104 | ``` 105 | 106 | ## Running tests 107 | 108 | Install dev dependencies: 109 | 110 | ```sh 111 | $ npm install -d && npm test 112 | ``` 113 | 114 | ## Author 115 | 116 | **Brian Woodward** 117 | 118 | * [github/doowb](https://github.com/doowb) 119 | * [twitter/doowb](http://twitter.com/doowb) 120 | 121 | ## License 122 | 123 | verb © 2016, [Brian Woodward](https://github.com/doowb). 124 | Released under the [MIT license](https://github.com/node-base/base-watch/blob/master/LICENSE). 125 | 126 | *** 127 | 128 | _This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on April 06, 2016._ -------------------------------------------------------------------------------- /test/fixtures/foo.txt: -------------------------------------------------------------------------------- 1 | bar -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * base-watch 3 | * 4 | * Copyright (c) 2016 . 5 | * Licensed under the MIT license. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | require('mocha'); 11 | var assert = require('assert'); 12 | var path = require('path'); 13 | var fs = require('fs'); 14 | 15 | var Base = require('base'); 16 | var tasks = require('base-tasks'); 17 | var plugin = require('../'); 18 | var app, watch; 19 | 20 | describe('base-watch', function() { 21 | beforeEach(function() { 22 | app = new Base(); 23 | app.use(tasks()); 24 | app.use(plugin()); 25 | app.on('error', console.log); 26 | }); 27 | 28 | afterEach(function() { 29 | if (watch && watch.close) { 30 | watch.close(); 31 | } 32 | }); 33 | 34 | it('should watch files and run a task when files change', function(done) { 35 | if (process.env.CI) return done(); 36 | var count = 0; 37 | app.task('default', function(cb) { 38 | count++; 39 | cb(); 40 | }); 41 | 42 | app.task('close', function(cb) { 43 | cb(); 44 | app.emit('close'); 45 | }); 46 | 47 | app.task('watch', function(cb) { 48 | app.on('close', cb); 49 | watch = app.watch(path.join(__dirname, 'fixtures/foo.txt'), ['default', 'close']); 50 | fs.writeFileSync(path.join(__dirname, 'fixtures/foo.txt'), 'bar'); 51 | }); 52 | 53 | app.build(['watch'], function(err) { 54 | if (err) return done(err); 55 | assert.equal(count, 1); 56 | done(); 57 | }); 58 | }); 59 | 60 | it('should watch files with given options and run a task when files change', function(done) { 61 | if (process.env.CI) return done(); 62 | var count = 0; 63 | app.task('default', function(cb) { 64 | count++; 65 | cb(); 66 | }); 67 | 68 | app.task('close', function(cb) { 69 | cb(); 70 | app.emit('close'); 71 | }); 72 | 73 | app.task('watch', function(cb) { 74 | app.on('close', cb); 75 | watch = app.watch('foo.txt', {cwd: path.join(__dirname, 'fixtures')}, ['default', 'close']); 76 | fs.writeFileSync(path.join(__dirname, 'fixtures/foo.txt'), 'bar'); 77 | }); 78 | 79 | app.build(['watch'], function(err) { 80 | if (err) return done(err); 81 | assert.equal(count, 1); 82 | done(); 83 | }); 84 | }); 85 | 86 | it('should watch files without given tasks', function(done) { 87 | if (process.env.CI) return done(); 88 | var count = 0; 89 | app.task('default', function(cb) { 90 | count++; 91 | cb(); 92 | }); 93 | 94 | app.task('watch', function(cb) { 95 | watch = app.watch(path.join(__dirname, 'fixtures/foo.txt')); 96 | watch.on('change', function() { 97 | app.build(['default'], cb); 98 | }); 99 | fs.writeFileSync(path.join(__dirname, 'fixtures/foo.txt'), 'bar'); 100 | }); 101 | 102 | app.build(['watch'], function(err) { 103 | if (err) return done(err); 104 | assert.equal(count, 1); 105 | done(); 106 | }); 107 | }); 108 | 109 | it('should watch files without given tasks and with given options', function(done) { 110 | if (process.env.CI) return done(); 111 | var count = 0; 112 | app.task('default', function(cb) { 113 | count++; 114 | cb(); 115 | }); 116 | 117 | app.task('watch', function(cb) { 118 | watch = app.watch('foo.txt', {cwd: path.join(__dirname, 'fixtures'), ignoreInitial: true}); 119 | watch.on('all', function() { 120 | app.build(['default'], cb); 121 | }); 122 | fs.writeFileSync(path.join(__dirname, 'fixtures/foo.txt'), 'bar'); 123 | }); 124 | 125 | app.build(['watch'], function(err) { 126 | if (err) return done(err); 127 | assert.equal(count, 1); 128 | done(); 129 | }); 130 | }); 131 | }); 132 | 133 | -------------------------------------------------------------------------------- /utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Module dependencies 5 | */ 6 | 7 | var utils = require('lazy-cache')(require); 8 | var fn = require; 9 | require = utils; 10 | 11 | /** 12 | * Lazily required module dependencies 13 | */ 14 | 15 | require('chokidar'); 16 | require('extend-shallow', 'extend'); 17 | require = fn; 18 | 19 | /** 20 | * Expose `utils` modules 21 | */ 22 | 23 | module.exports = utils; 24 | --------------------------------------------------------------------------------