🎨 Finish restructuring app

This commit is contained in:
brunosimon
2017-07-30 01:53:52 +02:00
parent fd18099109
commit ef8d9279af
8 changed files with 173 additions and 230 deletions
+32 -17
View File
@@ -28,8 +28,8 @@ class Watcher
*/
setSocket()
{
// Set up
this.socket = socketIoClient(`${this.config.domain}/app`)
// Connect to watcher socket
this.socket = socketIoClient(`${this.config.domain}/watcher`)
// Connect event
this.socket.on('connect', () =>
@@ -39,7 +39,17 @@ class Watcher
// Debug
if(this.config.debug)
{
console.log('connected'.green.bold)
console.log('watcher > socket'.green.bold + ' - ' + 'connect'.cyan)
}
})
// Disconnect event
this.socket.on('disconnect', () =>
{
// Debug
if(this.config.debug)
{
console.log('watcher > socket'.green.bold + ' - ' + 'disconnect'.cyan)
}
})
}
@@ -51,7 +61,7 @@ class Watcher
watch()
{
// Create ignored regex
const regexs = []
const regexs = []
const Minimatch = require('minimatch').Minimatch
for(const _excludeKey in this.config.exclude)
@@ -73,12 +83,17 @@ class Watcher
this.watcher = chokidar.watch(
this.path,
{
// ignored : /[\/\\]\./,
ignored : regex,
// ignored: /[\/\\]\./,
ignored: regex,
ignoreInitial: true
}
)
if(this.config.debug >= 1)
{
console.log('watcher'.green.bold + ' - ' + 'start watching'.cyan + ' - ' + this.path.cyan)
}
// Add event
this.watcher.on('add', (_path) =>
{
@@ -119,9 +134,9 @@ class Watcher
})
// Debug
if(this.config.debug)
if(this.config.debug >= 1)
{
console.log('add:'.green.bold, relativePath)
console.log('watcher'.green.bold + ' - ' + 'add'.cyan + ' - ' + relativePath.cyan)
}
})
@@ -165,9 +180,9 @@ class Watcher
})
// Debug
if(this.config.debug)
if(this.config.debug >= 1)
{
console.log('change:'.green.bold, relativePath)
console.log('watcher'.green.bold + ' - ' + 'change'.cyan + ' - ' + relativePath.cyan)
}
})
@@ -178,12 +193,12 @@ class Watcher
const relativePath = _path.replace(this.path, '.')
// Emit
this.socket.emit('delete_file', relativePath)
this.socket.emit('delete_file', { path: relativePath })
// Debug
if(this.config.debug)
if(this.config.debug >= 1)
{
console.log('unlink:'.green.bold, relativePath)
console.log('watcher'.green.bold + ' - ' + 'unlink'.cyan + ' - ' + relativePath.cyan)
}
})
@@ -197,9 +212,9 @@ class Watcher
this.socket.emit('create_folder', { path: relativePath })
// Debug
if(this.config.debug)
if(this.config.debug >= 1)
{
console.log('addDir:'.green.bold, relativePath)
console.log('watcher'.green.bold + ' - ' + 'addDir'.cyan + ' - ' + relativePath.cyan)
}
})
@@ -213,9 +228,9 @@ class Watcher
this.socket.emit('delete_folder', { path: relativePath })
// Debug
if(this.config.debug)
if(this.config.debug >= 1)
{
console.log('unlinkDir:'.green.bold, relativePath)
console.log('watcher'.green.bold + ' - ' + 'unlinkDir'.cyan + ' - ' + relativePath.cyan)
}
})
}