✨ Send all files at start unless there is more files than the new argument limit
This commit is contained in:
+20
-15
@@ -71,19 +71,19 @@ class App
|
||||
})
|
||||
.option('exclude', {
|
||||
alias: 'e',
|
||||
describe: 'Files to exclude',
|
||||
describe: 'Files to exclude (glob pattern)',
|
||||
default:
|
||||
[
|
||||
'**/.DS_Store',
|
||||
'node_modules/**',
|
||||
'vendor/**',
|
||||
'.git',
|
||||
'.vscode',
|
||||
'.env',
|
||||
'.log',
|
||||
'**/node_modules/**',
|
||||
'**/vendor/**',
|
||||
'**/.git',
|
||||
'**/.vscode',
|
||||
'**/.env',
|
||||
'**/.log',
|
||||
'.idea/**',
|
||||
'*___jb_old___',
|
||||
'*___jb_tmp___'
|
||||
'**/*___jb_old___',
|
||||
'**/*___jb_tmp___'
|
||||
],
|
||||
type: 'array'
|
||||
})
|
||||
@@ -99,11 +99,11 @@ class App
|
||||
default: false,
|
||||
type: 'boolean'
|
||||
})
|
||||
.option('initial-send', {
|
||||
alias: 'i',
|
||||
describe: 'Send files in folder at start',
|
||||
default: false,
|
||||
type: 'boolean'
|
||||
.option('limit', {
|
||||
alias: 'l',
|
||||
describe: 'Limit of files above which nothing will be sent at start',
|
||||
default: 99,
|
||||
type: 'number'
|
||||
})
|
||||
.option('max-file-size', {
|
||||
alias: 'm',
|
||||
@@ -131,11 +131,16 @@ class App
|
||||
config.exclude = args.exclude
|
||||
config.open = args.open
|
||||
config.test = args.test
|
||||
config.initialSend = args['initial-send']
|
||||
config.limit = args.limit
|
||||
config.maxFileSize = args['max-file-size']
|
||||
config.server = args.server
|
||||
config.host = args.host
|
||||
|
||||
if(config.limit === -1)
|
||||
{
|
||||
config.limit = Infinity
|
||||
}
|
||||
|
||||
if(config.name === '')
|
||||
{
|
||||
if(args._.length > 0 && typeof args._[0] === 'string' && args._[0] !== '')
|
||||
|
||||
+6
-5
@@ -3,7 +3,7 @@ const slug = require('slug')
|
||||
const Files = require('./files.js')
|
||||
const Chat = require('./chat.js')
|
||||
const JSZip = require('jszip')
|
||||
const glob = require('glob')
|
||||
const globby = require('globby')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const chalk = require('chalk')
|
||||
@@ -15,11 +15,11 @@ class Project
|
||||
this.config = _config
|
||||
this.path = _options.path
|
||||
this.watcherSocket = _options.watcherSocket
|
||||
this.exclude = _options.exclude
|
||||
|
||||
this.setName(_options.name)
|
||||
this.setSocket()
|
||||
|
||||
this.excludeRegex = new RegExp(_options.excludeRegex)
|
||||
this.zipNeedsUpdate = true
|
||||
this.files = new Files(this.config, { projectSocket: this.projectSocket })
|
||||
this.chat = new Chat(this.config, { slug: this.slug, watcherSocket: this.watcherSocket })
|
||||
@@ -71,9 +71,10 @@ class Project
|
||||
}
|
||||
|
||||
// Search files with glob
|
||||
const files = glob.sync(this.path + '/**', { dot: true })
|
||||
const globPattern = ['**', ...this.exclude.map((item) => `!${item}`)]
|
||||
const files = globby.sync(globPattern, { dot: true })
|
||||
|
||||
// // Create a zip file
|
||||
// Create a zip file
|
||||
const zip = new JSZip()
|
||||
|
||||
// Add files to zip
|
||||
@@ -82,7 +83,7 @@ class Project
|
||||
const stats = fs.lstatSync(_file)
|
||||
|
||||
// Ignore if folder or exluded
|
||||
if(stats.isFile() && !_file.match(this.excludeRegex))
|
||||
if(stats.isFile())
|
||||
{
|
||||
const basename = path.basename(_file)
|
||||
const relativePath = _file.replace(basename, '').replace(this.path, '')
|
||||
|
||||
+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