Connect app to site with socket
This commit is contained in:
+36
-5
@@ -35,9 +35,8 @@ class App
|
||||
// Set up
|
||||
this.projects = new Projects()
|
||||
|
||||
// Tests
|
||||
var project = this.projects.create_project( 'test' )
|
||||
|
||||
// // Tests
|
||||
// var project = this.projects.create_project( 'test' )
|
||||
// project.create_folder( 'toto' )
|
||||
// project.get_folder( 'toto//tutu/tete', true )
|
||||
// project.create_file( 'coucou/coco.txt', 'content 0' )
|
||||
@@ -46,8 +45,7 @@ class App
|
||||
// project.update_file( 'toto/tata/ipsum.txt', 'content 3' )
|
||||
// project.delete_folder( 'toto/tutu', true )
|
||||
// project.delete_file( 'toto/tata/ipsum.txt' )
|
||||
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
// console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,9 +111,42 @@ class App
|
||||
{
|
||||
console.log( 'socket'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
||||
|
||||
let project = null
|
||||
|
||||
socket.on( 'start_project', ( data ) =>
|
||||
{
|
||||
project = this.projects.create_project( data.slug )
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
} )
|
||||
|
||||
socket.on( 'update_file', ( data ) =>
|
||||
{
|
||||
project.update_file( data.path, data.content )
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
} )
|
||||
|
||||
socket.on( 'create_file', ( data ) =>
|
||||
{
|
||||
project.create_file( data.path, data.content )
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
} )
|
||||
|
||||
socket.on( 'delete_file', ( data ) =>
|
||||
{
|
||||
project.delete_file( data.path )
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
} )
|
||||
|
||||
socket.on( 'create_folder', ( data ) =>
|
||||
{
|
||||
project.create_folder( data.path, data.content )
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
} )
|
||||
|
||||
socket.on( 'delete_folder', ( data ) =>
|
||||
{
|
||||
project.delete_folder( data.path )
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
} )
|
||||
} )
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
// Depedencies
|
||||
let diff = require( 'diff' )
|
||||
|
||||
class File
|
||||
{
|
||||
constructor( _name, _content )
|
||||
@@ -31,4 +34,4 @@ class File
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = File
|
||||
module.exports = File
|
||||
|
||||
@@ -11,9 +11,9 @@ class Project
|
||||
{
|
||||
this.name = name
|
||||
this.folders = {
|
||||
root:
|
||||
'.':
|
||||
{
|
||||
name : 'root',
|
||||
name : '.',
|
||||
files : {},
|
||||
folders: {}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ class Project
|
||||
// Set up
|
||||
let normalize_path = path.normalize( _path ),
|
||||
path_parts = normalize_path.split( path.sep ),
|
||||
folder = this.folders.root
|
||||
folder = this
|
||||
|
||||
for( let _path_part of path_parts )
|
||||
{
|
||||
@@ -156,7 +156,7 @@ class Project
|
||||
|
||||
let normalize_path = path.normalize( _path ),
|
||||
path_parts = normalize_path.split( path.sep ),
|
||||
folder = this.folders.root,
|
||||
folder = this,
|
||||
found = true
|
||||
|
||||
for( let _path_part of path_parts )
|
||||
|
||||
Reference in New Issue
Block a user