Merge pull request #392 from bodylabs/event_cwd

Support cwd.event to emit events relative to path
This commit is contained in:
Kyle Robinson Young 2014-11-30 10:43:06 -08:00
commit 2be8b79fbe
2 changed files with 9 additions and 1 deletions

View File

@ -198,6 +198,9 @@ Default: `process.cwd()`
Ability to set the current working directory. Defaults to `process.cwd()`. Can either be a string to set the cwd to match files and spawn tasks. Or an object to set each independently. Such as `options: { cwd: { files: 'match/files/from/here', spawn: 'but/spawn/files/from/here' } }`.
Set `options: { cwd: { files: 'a/path', event: 'a/path' }}` to strip off `a/path` before emitting events. This option is useful for specifying the base directory to use with livereload.
## options.livereloadOnError
Type: `Boolean`
Default: `true`

View File

@ -95,6 +95,11 @@ module.exports = function(grunt) {
target.options.event = [target.options.event];
}
var eventCwd = process.cwd();
if (target.options.cwd && target.options.cwd.event) {
eventCwd = target.options.cwd.event;
}
// Set cwd if options.cwd.file is set
if (typeof target.options.cwd !== 'string' && target.options.cwd.files) {
target.options.cwd = target.options.cwd.files;
@ -128,7 +133,7 @@ module.exports = function(grunt) {
return;
}
filepath = path.relative(process.cwd(), filepath);
filepath = path.relative(eventCwd, filepath);
// Skip empty filepaths
if (filepath === '') {