@abmaonline/aemsync
Version:
Adobe AEM Synchronization Tool
34 lines (26 loc) • 773 B
JavaScript
const log = require('./log.js')
const mm = require('minimatch')
const chalk = require('chalk')
const watcher = require('simple-watcher')
class Watcher {
watch ({workingDirs, exclude, callback}) {
// Convert to array
if (typeof workingDirs === 'string') {
workingDirs = [workingDirs];
}
log.info(`Scanning: ${chalk.yellow(workingDirs)} ...`)
workingDirs.forEach((dir) => {
watcher(dir, (localPath) => {
log.debug('Changed:', localPath)
// Skip excluded.
if (exclude && mm(localPath, exclude, {dot: true})) {
return
}
callback(localPath)
}, 0)
});
log.info('Awaiting changes ...')
}
}
module.exports = Watcher