✨ Send all files at start unless there is more files than the new argument limit
This commit is contained in:
+39
-24
@@ -7,6 +7,7 @@ const opener = require('opener')
|
||||
const nodeNotifier = require('node-notifier')
|
||||
const path = require('path')
|
||||
const chalk = require('chalk')
|
||||
const globby = require('globby')
|
||||
|
||||
/**
|
||||
* Watcher class
|
||||
@@ -26,6 +27,32 @@ class Watcher
|
||||
this.watch()
|
||||
}
|
||||
|
||||
/**
|
||||
* Set exclude regex
|
||||
* Because chakodar doesn't support dot files with glob pattern
|
||||
*/
|
||||
setExcludeRegex()
|
||||
{
|
||||
// Exclude files regex
|
||||
const regexs = []
|
||||
const Minimatch = require('minimatch').Minimatch
|
||||
|
||||
for(const _excludeKey in this.config.exclude)
|
||||
{
|
||||
const _exclude = this.config.exclude[_excludeKey]
|
||||
const minimatch = new Minimatch(_exclude, { dot: true })
|
||||
|
||||
let regex = '' + minimatch.makeRe()
|
||||
|
||||
regex = regex.replace('/^', '')
|
||||
regex = regex.replace('$/', '')
|
||||
|
||||
regexs.push(regex)
|
||||
}
|
||||
|
||||
this.excludeRegex = new RegExp(regexs.join('|'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Set socket
|
||||
*/
|
||||
@@ -45,7 +72,7 @@ class Watcher
|
||||
name = path.parse(this.path).name
|
||||
}
|
||||
|
||||
this.socket.emit('start_project', { name, path: this.path, excludeRegex: '' + this.excludeRegex })
|
||||
this.socket.emit('start_project', { name, path: this.path, exclude: this.config.exclude })
|
||||
|
||||
// Debug
|
||||
if(this.config.debug)
|
||||
@@ -88,41 +115,29 @@ class Watcher
|
||||
})
|
||||
}
|
||||
|
||||
setExcludeRegex()
|
||||
{
|
||||
// Exclude files regex
|
||||
const regexs = []
|
||||
const Minimatch = require('minimatch').Minimatch
|
||||
|
||||
for(const _excludeKey in this.config.exclude)
|
||||
{
|
||||
const _exclude = this.config.exclude[_excludeKey]
|
||||
const minimatch = new Minimatch(_exclude, { dot: true })
|
||||
|
||||
let regex = '' + minimatch.makeRe()
|
||||
|
||||
regex = regex.replace('/^', '')
|
||||
regex = regex.replace('$/', '')
|
||||
|
||||
regexs.push(regex)
|
||||
}
|
||||
|
||||
this.excludeRegex = new RegExp(regexs.join('|'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Watch
|
||||
* Listen to modifications on files and folders
|
||||
*/
|
||||
watch()
|
||||
{
|
||||
const globPattern = ['**', ...this.config.exclude.map((item) => `!${item}`)]
|
||||
const files = globby.sync(globPattern, { dot: true })
|
||||
const ignoreInitial = files.length > this.config.limit
|
||||
|
||||
if(ignoreInitial)
|
||||
{
|
||||
console.log(`${chalk.green.bold('watcher')} - ${chalk.cyan('start wating')} - ${chalk.red(`File limit exceeded (${this.config.limit})`)}`)
|
||||
}
|
||||
|
||||
// Set up
|
||||
this.watcher = chokidar.watch(
|
||||
this.path,
|
||||
{
|
||||
// ignored: /[\/\\]\./,
|
||||
ignored: this.excludeRegex,
|
||||
ignoreInitial: !this.config.initialSend
|
||||
ignoreInitial: ignoreInitial,
|
||||
ignorePermissionErrors: true
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user