🎨 Finish restructuring app
This commit is contained in:
+34
-111
@@ -7,9 +7,7 @@ const http = require('http')
|
||||
const colors = require('colors')
|
||||
const util = require('util')
|
||||
const path = require('path')
|
||||
const Projects = require('./projects.js')
|
||||
const fs = require('fs')
|
||||
const opener = require('opener')
|
||||
|
||||
/**
|
||||
* Site class
|
||||
@@ -19,14 +17,15 @@ class Site
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
constructor(_config)
|
||||
constructor(_config, _success, _alreadyRunning, _error)
|
||||
{
|
||||
this.config = _config
|
||||
this.success = _success
|
||||
this.alreadyRunning = _alreadyRunning
|
||||
this.error = _error
|
||||
|
||||
this.setExpress()
|
||||
this.setServer()
|
||||
// this.setSocket()
|
||||
// this.setModels()
|
||||
// this.setDummy()
|
||||
}
|
||||
|
||||
@@ -145,15 +144,6 @@ class Site
|
||||
// // console.log(util.inspect(project.files.describe(), { depth: null, colors: true }))
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Set models
|
||||
// */
|
||||
// setModels()
|
||||
// {
|
||||
// // Set up
|
||||
// this.projects = new Projects({ socket: this.sockets.main, debug: this.config.debug })
|
||||
// }
|
||||
|
||||
/**
|
||||
* Set express
|
||||
* Start express and set controllers
|
||||
@@ -181,24 +171,48 @@ class Site
|
||||
// Server already running
|
||||
if(error.code === 'EADDRINUSE')
|
||||
{
|
||||
// Debug
|
||||
if(this.config.debug)
|
||||
if(this.config.debug >= 1)
|
||||
{
|
||||
console.log('site already running'.green.bold)
|
||||
console.log('site'.green.bold + ' - ' + 'already running'.cyan)
|
||||
}
|
||||
|
||||
// Callback
|
||||
if(typeof this.alreadyRunning === 'function')
|
||||
{
|
||||
this.alreadyRunning()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this.config.debug >= 1)
|
||||
{
|
||||
console.log('site'.green.bold + ' - ' + 'unknow error'.cyan)
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
console.log(error.message)
|
||||
// Callback
|
||||
if(typeof this.error === 'function')
|
||||
{
|
||||
this.alreadyRunning()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Start
|
||||
this.server.listen(this.config.port, () =>
|
||||
{
|
||||
// URL
|
||||
console.log(colors.green('---------------------------'))
|
||||
console.log('site'.green.bold + ' - ' + 'started'.cyan)
|
||||
if(this.config.debug >= 1)
|
||||
{
|
||||
console.log('site'.green.bold + ' - ' + 'started'.cyan)
|
||||
}
|
||||
|
||||
if(typeof this.success === 'function')
|
||||
{
|
||||
this.success()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -214,97 +228,6 @@ class Site
|
||||
|
||||
this.express.use('/' + _slug + '/files', express.static(_path))
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Set socket
|
||||
// */
|
||||
// setSocket()
|
||||
// {
|
||||
// // Set up
|
||||
// this.sockets = {}
|
||||
// this.sockets.main = socketIo.listen(this.server)
|
||||
// this.sockets.app = this.sockets.main.of('/app')
|
||||
|
||||
// // App connection event
|
||||
// this.sockets.app.on('connection', (socket) =>
|
||||
// {
|
||||
// // Set up
|
||||
// let project = null
|
||||
|
||||
// // Debug
|
||||
// if(this.config.debug)
|
||||
// {
|
||||
// console.log('socket app'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan)
|
||||
// }
|
||||
|
||||
// // Start project
|
||||
// socket.on('start_project', (data) =>
|
||||
// {
|
||||
// project = this.projects.createProject(data.name)
|
||||
|
||||
// const url = this.config.url
|
||||
|
||||
// console.log('site'.green.bold + ' - ' + url.cyan)
|
||||
|
||||
// // Open in browser
|
||||
// opener(url)
|
||||
|
||||
// // Debug
|
||||
// if(this.config.debug)
|
||||
// {
|
||||
// console.log(util.inspect(project.files.describe(), { depth: null, colors: true }))
|
||||
// }
|
||||
// })
|
||||
|
||||
// // Update file
|
||||
// socket.on('update_file', (data) =>
|
||||
// {
|
||||
// project.files.createVersion(data.path, data.content)
|
||||
|
||||
// // Debug
|
||||
// if(this.config.debug)
|
||||
// {
|
||||
// console.log(util.inspect(project.files.describe(), { depth: null, colors: true }))
|
||||
// }
|
||||
// })
|
||||
|
||||
// // Create file
|
||||
// socket.on('create_file', (data) =>
|
||||
// {
|
||||
// project.files.create(data.path, data.content)
|
||||
|
||||
// // Debug
|
||||
// if(this.config.debug)
|
||||
// {
|
||||
// console.log(util.inspect(project.files.describe(), { depth: null, colors: true }))
|
||||
// }
|
||||
// })
|
||||
|
||||
// // Delete file
|
||||
// socket.on('delete_file', (data) =>
|
||||
// {
|
||||
// project.files.delete(data.path)
|
||||
|
||||
// // Debug
|
||||
// if(this.config.debug)
|
||||
// {
|
||||
// console.log(util.inspect(project.files.describe(), { depth: null, colors: true }))
|
||||
// }
|
||||
// })
|
||||
|
||||
// // Disconnect
|
||||
// socket.on('disconnect', () =>
|
||||
// {
|
||||
// this.projects.delete_project(project.slug)
|
||||
|
||||
// // Debug
|
||||
// if(this.config.debug)
|
||||
// {
|
||||
// console.log('socket app'.green.bold + ' - ' + 'disconnect'.cyan + ' - ' + socket.id.cyan)
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
}
|
||||
|
||||
module.exports = Site
|
||||
|
||||
Reference in New Issue
Block a user