🎨 Move opener to the watcher class

This commit is contained in:
brunosimon
2017-12-24 13:18:40 +01:00
parent da39a3065f
commit 034f6910fb
2 changed files with 14 additions and 26 deletions
+1 -26
View File
@@ -6,7 +6,6 @@ const Projects = require('./projects.js')
const socketIo = require('socket.io')
const util = require('util')
const colors = require('colors')
const opener = require('opener')
const fs = require('fs')
const path = require('path')
const packageJson = require('../package.json')
@@ -34,12 +33,6 @@ class App
this.setServer()
}
// If host is specified, show URL open in browser
if(this.config.host)
{
this.showUrlAndOpen()
}
// If not started as a server
// Start watching files
if(!this.config.server)
@@ -239,11 +232,7 @@ class App
console.log(util.inspect(project.files.describe(), { depth: null, colors: true }))
}
// If not server, show URL open in browser
if(!this.config.server)
{
this.showUrlAndOpen()
}
socket.emit('started')
})
// Update file
@@ -327,20 +316,6 @@ class App
{
this.watcher = new Watcher(this.config)
}
/**
* Show URL and open it if should
*/
showUrlAndOpen()
{
const url = this.config.domain
console.log('app'.green.bold + ' - ' + url.yellow)
if(this.config.open)
{
opener(url)
}
}
}
module.exports = App
+13
View File
@@ -3,6 +3,7 @@ const chokidar = require('chokidar')
const fs = require('fs')
const mime = require('mime')
const socketIoClient = require('socket.io-client')
const opener = require('opener')
/**
* Watcher class
@@ -51,6 +52,18 @@ class Watcher
console.log('watcher > socket'.green.bold + ' - ' + 'disconnect'.cyan)
}
})
// Started event
this.socket.on('started', () =>
{
const url = this.config.domain
console.log('app'.green.bold + ' - ' + url.yellow)
if(this.config.open)
{
opener(url)
}
})
}
setExcludeRegex()