:zap:🚧 Remove internal socket and improve general structure
This commit is contained in:
+74
-12
@@ -4,6 +4,11 @@
|
||||
const ip = require('ip')
|
||||
const Site = require('./site')
|
||||
const Watcher = require('./watcher.js')
|
||||
const Projects = require('./projects.js')
|
||||
const socketIo = require('socket.io')
|
||||
const util = require('util')
|
||||
const colors = require('colors')
|
||||
const opener = require('opener')
|
||||
|
||||
/**
|
||||
* App class
|
||||
@@ -17,6 +22,12 @@ class App
|
||||
{
|
||||
this.setConfig()
|
||||
// this.setSite()
|
||||
|
||||
this.socket = socketIo.listen()
|
||||
|
||||
this.projects = new Projects({ socket: this.socket, debug: this.config.debug })
|
||||
this.project = this.projects.createProject(this.config.name)
|
||||
|
||||
this.setWatcher()
|
||||
}
|
||||
|
||||
@@ -101,11 +112,7 @@ class App
|
||||
*/
|
||||
setSite()
|
||||
{
|
||||
this.site = new Site({
|
||||
port: this.config.port,
|
||||
domain: this.config.domain,
|
||||
debug: this.config.debug
|
||||
})
|
||||
this.site = new Site(this.config)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,14 +121,69 @@ class App
|
||||
*/
|
||||
setWatcher()
|
||||
{
|
||||
this.watcher = new Watcher({
|
||||
port: this.config.port,
|
||||
domain: this.config.domain,
|
||||
debug: this.config.debug,
|
||||
maxFileSize: this.config.maxFileSize,
|
||||
exclude: this.config.exclude,
|
||||
name: this.config.name
|
||||
this.watcher = new Watcher(this.config)
|
||||
|
||||
const url = this.config.domain + '/project/' + this.project.slug
|
||||
|
||||
console.log('server'.green.bold + ' - ' + url.cyan)
|
||||
|
||||
// Open in browser
|
||||
opener(url)
|
||||
|
||||
// Debug
|
||||
if(this.config.debug)
|
||||
{
|
||||
console.log(util.inspect(this.project.files.describe(), { depth: null, colors: true }))
|
||||
}
|
||||
|
||||
// Update file
|
||||
this.watcher.on('update_file', (data) =>
|
||||
{
|
||||
console.log(data)
|
||||
this.project.files.createVersion(data.path, data.content)
|
||||
|
||||
// Debug
|
||||
if(this.config.debug)
|
||||
{
|
||||
console.log(util.inspect(this.project.files.describe(), { depth: null, colors: true }))
|
||||
}
|
||||
})
|
||||
|
||||
// Create file
|
||||
this.watcher.on('create_file', (data) =>
|
||||
{
|
||||
this.project.files.create(data.path, data.content)
|
||||
|
||||
// Debug
|
||||
if(this.config.debug)
|
||||
{
|
||||
console.log(util.inspect(this.project.files.describe(), { depth: null, colors: true }))
|
||||
}
|
||||
})
|
||||
|
||||
// Delete file
|
||||
this.watcher.on('delete_file', (data) =>
|
||||
{
|
||||
this.project.files.delete(data.path)
|
||||
|
||||
// Debug
|
||||
if(this.config.debug)
|
||||
{
|
||||
console.log(util.inspect(this.project.files.describe(), { depth: null, colors: true }))
|
||||
}
|
||||
})
|
||||
|
||||
// // Disconnect
|
||||
// this.watcher.on('disconnect', () =>
|
||||
// {
|
||||
// this.projects.delete_project(this.project.slug)
|
||||
|
||||
// // Debug
|
||||
// if(this.config.debug)
|
||||
// {
|
||||
// console.log('socket app'.green.bold + ' - ' + 'disconnect'.cyan + ' - ' + socket.id.cyan)
|
||||
// }
|
||||
// })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user