[update] Debug toggle
This commit is contained in:
+3
-3
@@ -19,7 +19,7 @@ class App
|
|||||||
constructor( _options )
|
constructor( _options )
|
||||||
{
|
{
|
||||||
this.set_options( _options )
|
this.set_options( _options )
|
||||||
this.set_args()
|
this.set_arguments()
|
||||||
this.set_watcher()
|
this.set_watcher()
|
||||||
this.set_socket()
|
this.set_socket()
|
||||||
}
|
}
|
||||||
@@ -45,10 +45,10 @@ class App
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set args
|
* Set arguments
|
||||||
* Test missing arg
|
* Test missing arg
|
||||||
*/
|
*/
|
||||||
set_args()
|
set_arguments()
|
||||||
{
|
{
|
||||||
// Set up
|
// Set up
|
||||||
this.arguments = process.argv.slice( 2 )
|
this.arguments = process.argv.slice( 2 )
|
||||||
|
|||||||
+78
-28
@@ -22,10 +22,8 @@ class App
|
|||||||
*/
|
*/
|
||||||
constructor( _options )
|
constructor( _options )
|
||||||
{
|
{
|
||||||
|
this.set_arguments()
|
||||||
this.set_options( _options )
|
this.set_options( _options )
|
||||||
|
|
||||||
this.domain = 'http://' + ip.address() + ':' + this.options.port
|
|
||||||
|
|
||||||
this.set_express()
|
this.set_express()
|
||||||
this.set_server()
|
this.set_server()
|
||||||
this.set_socket()
|
this.set_socket()
|
||||||
@@ -33,11 +31,61 @@ class App
|
|||||||
this.set_dummy()
|
this.set_dummy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set options
|
||||||
|
*/
|
||||||
|
set_options( _options )
|
||||||
|
{
|
||||||
|
// No option
|
||||||
|
if( typeof _options !== 'object' )
|
||||||
|
{
|
||||||
|
_options = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( typeof _options.port === 'undefined' )
|
||||||
|
{
|
||||||
|
_options.port = 1571
|
||||||
|
}
|
||||||
|
|
||||||
|
if( typeof _options.debug === 'undefined' )
|
||||||
|
{
|
||||||
|
if( this.arguments.length )
|
||||||
|
{
|
||||||
|
_options.debug = this.arguments[ 0 ] === 'true' ? true : false
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_options.debug = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( typeof _options.domain === 'undefined' )
|
||||||
|
{
|
||||||
|
_options.domain = `http://${ip.address()}:${_options.port}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save
|
||||||
|
this.options = _options
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set arguments
|
||||||
|
* Test missing arg
|
||||||
|
*/
|
||||||
|
set_arguments()
|
||||||
|
{
|
||||||
|
// Set up
|
||||||
|
this.arguments = process.argv.slice( 2 )
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Dummy
|
* Set Dummy
|
||||||
*/
|
*/
|
||||||
set_dummy()
|
set_dummy()
|
||||||
{
|
{
|
||||||
|
if( !this.options.debug )
|
||||||
|
return;
|
||||||
|
|
||||||
// Default project
|
// Default project
|
||||||
let project = this.projects.create_project( 'dummy' )
|
let project = this.projects.create_project( 'dummy' )
|
||||||
|
|
||||||
@@ -150,23 +198,7 @@ class App
|
|||||||
set_models()
|
set_models()
|
||||||
{
|
{
|
||||||
// Set up
|
// Set up
|
||||||
this.projects = new Projects( { socket: this.sockets.main } )
|
this.projects = new Projects( { socket: this.sockets.main, debug: this.options.debug } )
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set options
|
|
||||||
*/
|
|
||||||
set_options( _options )
|
|
||||||
{
|
|
||||||
// No option
|
|
||||||
if( typeof _options !== 'object' )
|
|
||||||
_options = {}
|
|
||||||
|
|
||||||
if( typeof _options.port === 'undefined' )
|
|
||||||
_options.port = 1571
|
|
||||||
|
|
||||||
// Save
|
|
||||||
this.options = _options
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,7 +214,7 @@ class App
|
|||||||
this.express.set( 'views', path.join( __dirname, 'views' ) )
|
this.express.set( 'views', path.join( __dirname, 'views' ) )
|
||||||
this.express.use( express.static( path.join( __dirname, 'public' ) ) )
|
this.express.use( express.static( path.join( __dirname, 'public' ) ) )
|
||||||
|
|
||||||
this.express.locals.domain = this.domain
|
this.express.locals.domain = this.options.domain
|
||||||
|
|
||||||
// Controllers
|
// Controllers
|
||||||
this.express.use( '/', require( './controllers/index.js' ) )
|
this.express.use( '/', require( './controllers/index.js' ) )
|
||||||
@@ -202,7 +234,7 @@ class App
|
|||||||
// URL
|
// URL
|
||||||
console.log( colors.green( '---------------------------' ) )
|
console.log( colors.green( '---------------------------' ) )
|
||||||
console.log( 'server'.green.bold + ' - ' + 'started'.cyan )
|
console.log( 'server'.green.bold + ' - ' + 'started'.cyan )
|
||||||
console.log( 'server'.green.bold + ' - ' + this.domain.cyan )
|
console.log( 'server'.green.bold + ' - ' + this.options.domain.cyan )
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,14 +254,20 @@ class App
|
|||||||
// Set up
|
// Set up
|
||||||
let project = null
|
let project = null
|
||||||
|
|
||||||
console.log( 'socket app'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
if( this.options.debug )
|
||||||
|
{
|
||||||
|
console.log( 'socket app'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
||||||
|
}
|
||||||
|
|
||||||
// Start project
|
// Start project
|
||||||
socket.on( 'start_project', ( data ) =>
|
socket.on( 'start_project', ( data ) =>
|
||||||
{
|
{
|
||||||
project = this.projects.create_project( data.name )
|
project = this.projects.create_project( data.name )
|
||||||
|
|
||||||
// console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
if( this.options.debug )
|
||||||
|
{
|
||||||
|
console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
||||||
|
}
|
||||||
} )
|
} )
|
||||||
|
|
||||||
// Update file
|
// Update file
|
||||||
@@ -237,7 +275,10 @@ class App
|
|||||||
{
|
{
|
||||||
project.files.create_version( data.path, data.content )
|
project.files.create_version( data.path, data.content )
|
||||||
|
|
||||||
// console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
if( this.options.debug )
|
||||||
|
{
|
||||||
|
console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
||||||
|
}
|
||||||
} )
|
} )
|
||||||
|
|
||||||
// Create file
|
// Create file
|
||||||
@@ -245,7 +286,10 @@ class App
|
|||||||
{
|
{
|
||||||
project.files.create( data.path, data.content )
|
project.files.create( data.path, data.content )
|
||||||
|
|
||||||
// console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
if( this.options.debug )
|
||||||
|
{
|
||||||
|
console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
||||||
|
}
|
||||||
} )
|
} )
|
||||||
|
|
||||||
// Delete file
|
// Delete file
|
||||||
@@ -253,7 +297,10 @@ class App
|
|||||||
{
|
{
|
||||||
project.files.delete( data.path )
|
project.files.delete( data.path )
|
||||||
|
|
||||||
// console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
if( this.options.debug )
|
||||||
|
{
|
||||||
|
console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
||||||
|
}
|
||||||
} )
|
} )
|
||||||
|
|
||||||
// Disconnect
|
// Disconnect
|
||||||
@@ -261,7 +308,10 @@ class App
|
|||||||
{
|
{
|
||||||
this.projects.delete_project( project.slug )
|
this.projects.delete_project( project.slug )
|
||||||
|
|
||||||
console.log( 'socket app'.green.bold + ' - ' + 'disconnect'.cyan + ' - ' + socket.id.cyan )
|
if( this.options.debug )
|
||||||
|
{
|
||||||
|
console.log( 'socket app'.green.bold + ' - ' + 'disconnect'.cyan + ' - ' + socket.id.cyan )
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,30 @@ let slug = require( 'slug' ),
|
|||||||
|
|
||||||
class Project
|
class Project
|
||||||
{
|
{
|
||||||
constructor( options )
|
constructor( _options )
|
||||||
{
|
{
|
||||||
this.set_name( options.name )
|
this.set_options( _options )
|
||||||
this.set_socket( options.socket )
|
this.set_name( _options.name )
|
||||||
|
this.set_socket( _options.socket )
|
||||||
|
|
||||||
this.files = new Files( { socket: this.socket } )
|
this.files = new Files( { socket: this.socket } )
|
||||||
this.date = new Date()
|
this.date = new Date()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set options
|
||||||
|
*/
|
||||||
|
set_options( _options )
|
||||||
|
{
|
||||||
|
if( typeof _options.debug === 'undefined' )
|
||||||
|
{
|
||||||
|
_options.debug = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save
|
||||||
|
this.options = _options
|
||||||
|
}
|
||||||
|
|
||||||
set_name( _name )
|
set_name( _name )
|
||||||
{
|
{
|
||||||
this.name = _name
|
this.name = _name
|
||||||
@@ -30,9 +45,12 @@ class Project
|
|||||||
// Connection event
|
// Connection event
|
||||||
this.socket.on( 'connection', ( socket ) =>
|
this.socket.on( 'connection', ( socket ) =>
|
||||||
{
|
{
|
||||||
console.log( 'socket projects'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
|
||||||
|
|
||||||
this.socket.emit( 'update_project', this.describe() )
|
this.socket.emit( 'update_project', this.describe() )
|
||||||
|
|
||||||
|
if( this.options.debug )
|
||||||
|
{
|
||||||
|
console.log( 'socket projects'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
||||||
|
}
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,26 @@ let Project = require( './project.class.js' )
|
|||||||
|
|
||||||
class Projects
|
class Projects
|
||||||
{
|
{
|
||||||
constructor( options )
|
constructor( _options )
|
||||||
{
|
{
|
||||||
this.all = {}
|
this.all = {}
|
||||||
|
|
||||||
this.set_socket( options.socket )
|
this.set_options( _options )
|
||||||
|
this.set_socket( _options.socket )
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set options
|
||||||
|
*/
|
||||||
|
set_options( _options )
|
||||||
|
{
|
||||||
|
if( typeof _options.debug === 'undefined' )
|
||||||
|
{
|
||||||
|
_options.debug = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save
|
||||||
|
this.options = _options
|
||||||
}
|
}
|
||||||
|
|
||||||
set_socket( socket )
|
set_socket( socket )
|
||||||
@@ -20,16 +35,19 @@ class Projects
|
|||||||
// Connection event
|
// Connection event
|
||||||
this.socket.on( 'connection', ( socket ) =>
|
this.socket.on( 'connection', ( socket ) =>
|
||||||
{
|
{
|
||||||
console.log( 'socket projects'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
|
||||||
|
|
||||||
this.socket.emit( 'update_projects', this.describe() )
|
this.socket.emit( 'update_projects', this.describe() )
|
||||||
|
|
||||||
|
if( this.options.debug )
|
||||||
|
{
|
||||||
|
console.log( 'socket projects'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
||||||
|
}
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
|
|
||||||
create_project( _name )
|
create_project( _name )
|
||||||
{
|
{
|
||||||
// Create project
|
// Create project
|
||||||
let project = new Project( { name: _name, socket: this.original_socket } ),
|
let project = new Project( { name: _name, socket: this.original_socket, debug: this.options.debug } ),
|
||||||
same_name_project = this.all[ project.slug ]
|
same_name_project = this.all[ project.slug ]
|
||||||
|
|
||||||
// Try to found same name project
|
// Try to found same name project
|
||||||
|
|||||||
Reference in New Issue
Block a user