Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gulp path as option. Solves #81 #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ nodemon({
})
```

### **{ gulpCmd: string }**

Gulp-nodemon spawns new instance of gulp to execute `tasks` option and it is working fine as long as gulp is installed globaly. If not you are able to provide gulp command as `gulpCmd` parameter.
```javascript
nodemon({
script: 'index.js'
, gulpCmd: './node_modules/.bin/gulp'
, tasks: ['browserify']
})
```

## Events

gulp-nodemon returns a stream just like any other NodeJS stream, **except for the `on` method**, which conveniently accepts gulp task names in addition to the typical function.
Expand Down
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ module.exports = function (options) {

// Our script
var script = nodemon(options)
, gulpCmd = options.gulpCmd || (process.platform === 'win32' ? 'gulp.cmd' : 'gulp')
, originalOn = script.on

// Allow for injection of tasks on file change
if (options.tasks) {
if (options.verbose) {
script.on('log', function (log) {
if (~log.message.indexOf('files triggering change check')) {
if (typeof options.tasks === 'function') run(options.tasks(log.message.split('files triggering change check: ').pop().split(' ')))
else run(options.tasks)
if (typeof options.tasks === 'function') run(gulpCmd, options.tasks(log.message.split('files triggering change check: ').pop().split(' ')))
else run(gulpCmd, options.tasks)
}
})
} else {
script.on('log', function (log) {
if (~log.message.indexOf('restarting due to changes...')) {
run(options.tasks)
run(gulpCmd, options.tasks)
}
})
}
Expand Down Expand Up @@ -58,9 +59,9 @@ module.exports = function (options) {
originalOn(event, function () {
if (Array.isArray(tasks)) {
tasks.forEach(function (task) {
run(task)
run(gulpCmd, task)
})
} else run(tasks)
} else run(gulpCmd, tasks)
})
}
}(tasks[i])
Expand All @@ -73,10 +74,10 @@ module.exports = function (options) {
return script

// Synchronous alternative to gulp.run()
function run(tasks) {
function run(gulpCmd, tasks) {
if (typeof tasks === 'string') tasks = [tasks]
if (tasks.length === 0) return
if (!(tasks instanceof Array)) throw new Error('Expected task name or array but found: ' + tasks)
cp.spawnSync(process.platform === 'win32' ? 'gulp.cmd' : 'gulp', tasks, { stdio: [0, 1, 2] })
cp.spawnSync(gulpCmd, tasks, { stdio: [0, 1, 2] })
}
}