[update] Global installation
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
let App = require( './app.class.js' ),
|
||||
app = new App()
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"name": "code-spectator-app",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/brunosimon/code-spectactor"
|
||||
},
|
||||
"author": "Bruno Simon",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/brunosimon/code-spectactor/issues"
|
||||
},
|
||||
"homepage": "https://github.com/brunosimon/code-spectactor",
|
||||
"dependencies": {
|
||||
"chokidar": "^1.5.1",
|
||||
"colors": "^1.1.2",
|
||||
"ip": "^1.1.3",
|
||||
"socket.io-client": "^1.4.6"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict'
|
||||
|
||||
let Keppler = require( './keppler.class.js' ),
|
||||
keppler = new Keppler();
|
||||
@@ -0,0 +1,104 @@
|
||||
'use strict'
|
||||
|
||||
// Depedencies
|
||||
let path = require( 'path' ),
|
||||
colors = require( 'colors' ),
|
||||
ip = require( 'ip' ),
|
||||
Site = require( '../site/site.class.js' ),
|
||||
Watcher = require( '../watcher/watcher.class.js' )
|
||||
|
||||
/**
|
||||
* Keppler class
|
||||
*/
|
||||
class Keppler
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
constructor( _options )
|
||||
{
|
||||
this.set_arguments()
|
||||
this.set_options( _options )
|
||||
this.set_site()
|
||||
this.set_watcher()
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options
|
||||
*/
|
||||
set_options( _options )
|
||||
{
|
||||
// No option
|
||||
if( typeof _options !== 'object' )
|
||||
_options = {}
|
||||
|
||||
// Defaults
|
||||
if( typeof _options.debug === 'undefined' )
|
||||
{
|
||||
if( this.arguments.length )
|
||||
{
|
||||
_options.debug = this.arguments[ this.arguments.length - 1 ] === 'true' ? true : false
|
||||
}
|
||||
else
|
||||
{
|
||||
_options.debug = false
|
||||
}
|
||||
}
|
||||
|
||||
if( typeof _options.port === 'undefined' )
|
||||
_options.port = 1571
|
||||
|
||||
if( typeof _options.domain === 'undefined' )
|
||||
_options.domain = `http://${ip.address()}:${_options.port}`
|
||||
|
||||
// Save
|
||||
this.options = _options
|
||||
}
|
||||
|
||||
/**
|
||||
* Set arguments
|
||||
* Retrieve arguments and test if missing
|
||||
*/
|
||||
set_arguments()
|
||||
{
|
||||
// Set up
|
||||
this.arguments = process.argv.slice( 2 )
|
||||
|
||||
// Missing project name
|
||||
if( this.arguments.length === 0 )
|
||||
{
|
||||
// Stop process
|
||||
console.log( 'Missing arguments: first argument should be the projet name'.red )
|
||||
process.exit()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set site
|
||||
* Instantiate site
|
||||
*/
|
||||
set_site()
|
||||
{
|
||||
this.site = new Site( {
|
||||
port : this.options.port,
|
||||
domain: this.options.domain,
|
||||
debug : this.options.debug
|
||||
} )
|
||||
}
|
||||
|
||||
/**
|
||||
* Set watcher
|
||||
* Instantiate watcher
|
||||
*/
|
||||
set_watcher()
|
||||
{
|
||||
this.watcher = new Watcher( {
|
||||
port : this.options.port,
|
||||
domain: this.options.domain,
|
||||
debug : this.options.debug,
|
||||
name : this.arguments[ 0 ]
|
||||
} )
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Keppler
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "keppler",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"bin": {
|
||||
"keppler": "bin/index.js"
|
||||
},
|
||||
"main": "bin/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/brunosimon/keppler"
|
||||
},
|
||||
"author": "Bruno Simon",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/brunosimon/keppler/issues"
|
||||
},
|
||||
"homepage": "https://github.com/brunosimon/keppler",
|
||||
"dependencies": {
|
||||
"chokidar": "^1.5.1",
|
||||
"socket.io-client": "^1.4.6",
|
||||
"colors": "^1.1.2",
|
||||
"diff": "^2.2.3",
|
||||
"express": "^4.13.4",
|
||||
"helmet": "^2.1.0",
|
||||
"ip": "^1.1.3",
|
||||
"pug": "^2.0.0-beta4",
|
||||
"slug": "^0.9.1",
|
||||
"socket.io": "^1.4.6"
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ The project URL appears. Share it with the viewers on the same wifi.
|
||||
|
||||
### Futur features
|
||||
|
||||
- Log project URL and open in default browser
|
||||
- 404
|
||||
- Retractable sidebar
|
||||
- Open multiple files
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
let App = require( './app.class.js' ),
|
||||
app = new App()
|
||||
let Site = require( './site.class.js' ),
|
||||
site = new Site()
|
||||
|
||||
@@ -16,7 +16,7 @@ class Event_Emitter
|
||||
*/
|
||||
on( names, callback )
|
||||
{
|
||||
let that = this;
|
||||
let that = this
|
||||
|
||||
// Errors
|
||||
if( typeof names === 'undefined' || names === '' )
|
||||
|
||||
@@ -47,6 +47,7 @@ class Project
|
||||
{
|
||||
this.socket.emit( 'update_project', this.describe() )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( 'socket projects'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
||||
|
||||
@@ -91,7 +91,7 @@ class Projects
|
||||
{
|
||||
// Delete
|
||||
delete this.all[ _slug ]
|
||||
project.destructor();
|
||||
project.destructor()
|
||||
|
||||
// Emit
|
||||
this.socket.emit( 'update_projects', this.describe() )
|
||||
|
||||
@@ -13,16 +13,15 @@ let express = require( 'express' ),
|
||||
fs = require( 'fs' )
|
||||
|
||||
/**
|
||||
* App class
|
||||
* Site class
|
||||
*/
|
||||
class App
|
||||
class Site
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
constructor( _options )
|
||||
{
|
||||
this.set_arguments()
|
||||
this.set_options( _options )
|
||||
this.set_express()
|
||||
this.set_server()
|
||||
@@ -38,53 +37,29 @@ class App
|
||||
{
|
||||
// No option
|
||||
if( typeof _options !== 'object' )
|
||||
{
|
||||
_options = {}
|
||||
}
|
||||
|
||||
// Defaults
|
||||
if( typeof _options.debug === 'undefined' )
|
||||
_options.debug = false
|
||||
|
||||
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()
|
||||
{
|
||||
if( !this.options.debug )
|
||||
return;
|
||||
return
|
||||
|
||||
// Default project
|
||||
let project = this.projects.create_project( 'dummy' )
|
||||
@@ -228,6 +203,24 @@ class App
|
||||
// Set up
|
||||
this.server = http.createServer( this.express )
|
||||
|
||||
// Error event
|
||||
this.server.on( 'error', ( error ) =>
|
||||
{
|
||||
// Server already running
|
||||
if( error.code === 'EADDRINUSE' )
|
||||
{
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( 'server already running'.green.bold )
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
console.log( error.message )
|
||||
} )
|
||||
|
||||
// Start
|
||||
this.server.listen( this.options.port, () =>
|
||||
{
|
||||
@@ -254,6 +247,7 @@ class App
|
||||
// Set up
|
||||
let project = null
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( 'socket app'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
||||
@@ -264,6 +258,7 @@ class App
|
||||
{
|
||||
project = this.projects.create_project( data.name )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
||||
@@ -275,6 +270,7 @@ class App
|
||||
{
|
||||
project.files.create_version( data.path, data.content )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
||||
@@ -286,6 +282,7 @@ class App
|
||||
{
|
||||
project.files.create( data.path, data.content )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
||||
@@ -297,6 +294,7 @@ class App
|
||||
{
|
||||
project.files.delete( data.path )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
|
||||
@@ -308,13 +306,14 @@ class App
|
||||
{
|
||||
this.projects.delete_project( project.slug )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( 'socket app'.green.bold + ' - ' + 'disconnect'.cyan + ' - ' + socket.id.cyan )
|
||||
}
|
||||
} );
|
||||
} )
|
||||
} )
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = App
|
||||
module.exports = Site
|
||||
@@ -0,0 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
let Watcher = require( './watcher.class.js' ),
|
||||
watcher = new Watcher()
|
||||
@@ -9,9 +9,9 @@ let chokidar = require( 'chokidar' ),
|
||||
fs = require( 'fs' )
|
||||
|
||||
/**
|
||||
* App class
|
||||
* Watcher class
|
||||
*/
|
||||
class App
|
||||
class Watcher
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
@@ -19,7 +19,6 @@ class App
|
||||
constructor( _options )
|
||||
{
|
||||
this.set_options( _options )
|
||||
this.set_arguments()
|
||||
this.set_watcher()
|
||||
this.set_socket()
|
||||
}
|
||||
@@ -34,42 +33,19 @@ class App
|
||||
_options = {}
|
||||
|
||||
// Defaults
|
||||
if( typeof _options.domain === 'undefined' )
|
||||
_options.domain = ip.address()
|
||||
if( typeof _options.debug === 'undefined' )
|
||||
_options.debug = false
|
||||
|
||||
if( typeof _options.port === 'undefined' )
|
||||
_options.port = 1571
|
||||
|
||||
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 )
|
||||
|
||||
// Missing project name
|
||||
if( this.arguments.length === 0 )
|
||||
{
|
||||
// Stop process
|
||||
console.log( 'Missing arguments: first argument should be the projet name'.red )
|
||||
process.exit()
|
||||
}
|
||||
|
||||
// // Wrong project name
|
||||
// if( !this.arguments[ 0 ].match( /^[a-z_-][a-z0-9_-]+$/ ) )
|
||||
// {
|
||||
// // Stop process
|
||||
// console.log( 'Wrong arguments: projet name'.red )
|
||||
// process.exit()
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Set socket
|
||||
* Connect to site
|
||||
@@ -77,13 +53,18 @@ class App
|
||||
set_socket()
|
||||
{
|
||||
// Set up
|
||||
this.socket = socket_io_client( `http://${this.options.domain}:${this.options.port}/app` )
|
||||
this.socket = socket_io_client( `${this.options.domain}/app` )
|
||||
|
||||
// Connect event
|
||||
this.socket.on( 'connect', () =>
|
||||
{
|
||||
console.log( 'connected'.green )
|
||||
this.socket.emit( 'start_project', { name: this.arguments[ 0 ] } )
|
||||
this.socket.emit( 'start_project', { name: this.options.name } )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( 'connected'.green.bold )
|
||||
}
|
||||
} )
|
||||
}
|
||||
|
||||
@@ -108,14 +89,18 @@ class App
|
||||
// Set up
|
||||
let relative_path = _path.replace( process.cwd(), '.' )
|
||||
|
||||
console.log( 'add:'.green.bold, relative_path )
|
||||
|
||||
// Read
|
||||
fs.readFile( _path, ( error, data ) =>
|
||||
{
|
||||
// Send
|
||||
this.socket.emit( 'create_file', { path: relative_path, content: data.toString() } )
|
||||
} )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( 'add:'.green.bold, relative_path )
|
||||
}
|
||||
} )
|
||||
|
||||
// Change event
|
||||
@@ -124,14 +109,18 @@ class App
|
||||
// Set up
|
||||
let relative_path = _path.replace( process.cwd(), '.' )
|
||||
|
||||
console.log( 'change:'.green.bold, relative_path )
|
||||
|
||||
// Read
|
||||
fs.readFile( _path, ( error, data ) =>
|
||||
{
|
||||
// Send
|
||||
this.socket.emit( 'update_file', { path: relative_path, content: data.toString() } )
|
||||
} )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( 'change:'.green.bold, relative_path )
|
||||
}
|
||||
} )
|
||||
|
||||
// Unlink event
|
||||
@@ -140,10 +129,14 @@ class App
|
||||
// Set up
|
||||
let relative_path = _path.replace( process.cwd(), '.' )
|
||||
|
||||
console.log( 'unlink:'.green.bold, relative_path )
|
||||
|
||||
// Send
|
||||
this.socket.emit( 'delete_file', { path: relative_path } )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( 'unlink:'.green.bold, relative_path )
|
||||
}
|
||||
} )
|
||||
|
||||
// AddDir event
|
||||
@@ -152,10 +145,14 @@ class App
|
||||
// Set up
|
||||
let relative_path = _path.replace( process.cwd(), '.' )
|
||||
|
||||
console.log( 'addDir:'.green.bold, relative_path )
|
||||
|
||||
// Send
|
||||
this.socket.emit( 'create_folder', { path: relative_path } )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( 'addDir:'.green.bold, relative_path )
|
||||
}
|
||||
} )
|
||||
|
||||
// UnlinkDir event
|
||||
@@ -164,12 +161,16 @@ class App
|
||||
// Set up
|
||||
let relative_path = _path.replace( process.cwd(), '.' )
|
||||
|
||||
console.log( 'unlinkDir:'.green.bold, relative_path )
|
||||
|
||||
// Send
|
||||
this.socket.emit( 'delete_folder', { path: relative_path } )
|
||||
|
||||
// Debug
|
||||
if( this.options.debug )
|
||||
{
|
||||
console.log( 'unlinkDir:'.green.bold, relative_path )
|
||||
}
|
||||
} )
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = App
|
||||
module.exports = Watcher
|
||||
Reference in New Issue
Block a user