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

watch Command - watch files/dirs and rerun task on change #33

Closed
wants to merge 21 commits into from
Closed
Changes from 1 commit
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
17 changes: 14 additions & 3 deletions lib/FileWatcher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const chokidar = require('chokidar')
const logger = require('./logger')

Array.prototype.asyncForEach = async function(callback) { // eslint-disable-line
Copy link
Contributor

@tunnckoCore tunnckoCore Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, why? I just really can't believe what i'm looking 🤣

p-map-series or p-map is probably better fit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I missed that. Yeah, probably don't want to modify the prototype.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay thanks @olstenlarck

for (let index = 0; index < this.length; index++) {
await callback(this[index], index, this)
}
}
class FileWatcher {
constructor() {
this.runner = []
Expand All @@ -19,13 +24,19 @@ class FileWatcher {

this.watcher[0]
.on('add', path =>
this.getTaskNames(path).forEach(taskName => runner.runFile(taskName))
this.getTaskNames(path).forEach(async taskName => {
await runner.runFile(taskName)
})
flxwu marked this conversation as resolved.
Show resolved Hide resolved
)
.on('change', path =>
this.getTaskNames(path).forEach(taskName => runner.runFile(taskName))
this.getTaskNames(path).forEach(async taskName => {
await runner.runFile(taskName)
})
)
.on('unlink', path =>
this.getTaskNames(path).forEach(taskName => runner.runFile(taskName))
this.getTaskNames(path).forEach(async taskName => {
await runner.runFile(taskName)
})
)
.on('error', error => logger.log(`Watcher error: ${error}`))
}
Expand Down