-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from mklabs/dev
ES6 rewrite: Merge dev branch into master
- Loading branch information
Showing
24 changed files
with
584 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": ["es2015"], | ||
|
||
"plugins": [ | ||
"add-module-exports" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src* | ||
*node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"env": { | ||
"es6": true, | ||
"mocha": true | ||
}, | ||
|
||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
|
||
"extends": "standard", | ||
|
||
"rules": { | ||
"semi": ["error", "always"], | ||
"no-multi-spaces": ["error", { "exceptions": { "VariableDeclarator": true, "ImportDeclaration": true } }], | ||
"promise/param-names": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
node_modules/* | ||
|
||
tmp/phantomjs.log | ||
node_modules | ||
src* | ||
tiny-lr.pid |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- '5' | ||
- '4' | ||
- '0.12' | ||
- '0.10' | ||
- '6' | ||
# - '5' | ||
# - '4' | ||
# - '0.12' | ||
# - '0.10' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
Copyright (c) 2012-2013 Mickael Daniel | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
Copyright (c) 2012-2016 Mickael Daniel | ||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
all: help | ||
|
||
help: | ||
make -h | ||
|
||
babel: | ||
babel lib/ -d src/ | ||
babel test/ -d src_test/ | ||
|
||
test: eslint mocha | ||
|
||
mocha: babel | ||
mocha --reporter spec src_test/ | ||
|
||
serve: | ||
node examples/express/server.js | ||
|
||
eslint: | ||
eslint . --debug | ||
|
||
fix: | ||
eslint . --fix | ||
|
||
watch: | ||
watchd lib/**.js test/wd/index.js package.json -c 'make test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
var port = process.env.LR_PORT || process.env.PORT || 35729; | ||
const port = process.env.LR_PORT || process.env.PORT || 35729; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var express = require('express'); | ||
var tinylr = require('../..'); | ||
var body = require('body-parser'); | ||
var debug = require('debug')('tinylr:server'); | ||
const debug = require('debug')('tinylr:server'); | ||
|
||
process.env.DEBUG = process.env.DEBUG || 'tinylr*'; | ||
|
||
var app = require('./app'); | ||
const app = require('./app'); | ||
|
||
app.listen(port, function(err) { | ||
app.listen(port, function (err) { | ||
if (err) throw err; | ||
debug('listening on %d', port); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,92 @@ | ||
import events from 'events'; | ||
import WebSocket from 'faye-websocket'; | ||
|
||
var util = require('util'); | ||
var events = require('events'); | ||
var WebSocket = require('faye-websocket'); | ||
const debug = require('debug')('tinylr:client'); | ||
|
||
module.exports = Client; | ||
let idCounter = 0; | ||
|
||
function Client(req, socket, head, options) { | ||
options = this.options = options || {}; | ||
this.ws = new WebSocket(req, socket, head); | ||
this.ws.onmessage = this.message.bind(this); | ||
this.ws.onclose = this.close.bind(this); | ||
this.id = this.uniqueId('ws'); | ||
} | ||
|
||
util.inherits(Client, events.EventEmitter); | ||
export default class Client extends events.EventEmitter { | ||
|
||
Client.prototype.message = function message(event) { | ||
var data = this.data(event); | ||
if(this[data.command]) return this[data.command](data); | ||
}; | ||
constructor (req, socket, head, options = {}) { | ||
super(); | ||
this.options = options; | ||
this.ws = new WebSocket(req, socket, head); | ||
this.ws.onmessage = this.message.bind(this); | ||
this.ws.onclose = this.close.bind(this); | ||
this.id = this.uniqueId('ws'); | ||
} | ||
|
||
Client.prototype.close = function close(event) { | ||
if(this.ws) { | ||
this.ws.close(); | ||
this.ws = null; | ||
message (event) { | ||
let data = this.data(event); | ||
if (this[data.command]) return this[data.command](data); | ||
} | ||
|
||
this.emit('end', event); | ||
}; | ||
close (event) { | ||
if (this.ws) { | ||
this.ws.close(); | ||
this.ws = null; | ||
} | ||
|
||
// Commands | ||
this.emit('end', event); | ||
} | ||
|
||
Client.prototype.hello = function hello() { | ||
this.send({ | ||
command: 'hello', | ||
protocols: [ | ||
'http://livereload.com/protocols/official-7' | ||
], | ||
serverName: 'tiny-lr' | ||
}); | ||
}; | ||
// Commands | ||
hello () { | ||
this.send({ | ||
command: 'hello', | ||
protocols: [ | ||
'http://livereload.com/protocols/official-7' | ||
], | ||
serverName: 'tiny-lr' | ||
}); | ||
} | ||
|
||
Client.prototype.info = function info(data) { | ||
this.plugins = data.plugins; | ||
this.url = data.url; | ||
}; | ||
info (data) { | ||
if (data) { | ||
debug('Info', data); | ||
this.emit('info', Object.assign({}, data, { id: this.id })); | ||
this.plugins = data.plugins; | ||
this.url = data.url; | ||
} | ||
|
||
// Server commands | ||
return Object.assign({}, data || {}, { id: this.id, url: this.url }); | ||
} | ||
|
||
Client.prototype.reload = function reload(files) { | ||
files.forEach(function(file) { | ||
// Server commands | ||
reload (files) { | ||
files.forEach(function (file) { | ||
this.send({ | ||
command: 'reload', | ||
path: file, | ||
liveCSS: this.options.liveCSS !== false, | ||
liveImg: this.options.liveImg !== false | ||
}); | ||
}, this); | ||
} | ||
|
||
alert (message) { | ||
this.send({ | ||
command: 'reload', | ||
path: file, | ||
liveCSS: this.options.liveCSS !== false, | ||
liveImg: this.options.liveImg !== false | ||
command: 'alert', | ||
message: message | ||
}); | ||
}, this); | ||
}; | ||
|
||
Client.prototype.alert = function alert(message) { | ||
this.send({ | ||
command: 'alert', | ||
message: message | ||
}); | ||
}; | ||
|
||
// Utilities | ||
} | ||
|
||
Client.prototype.data = function _data(event) { | ||
var data = {}; | ||
try { | ||
data = JSON.parse(event.data); | ||
} catch (e) {} | ||
return data; | ||
}; | ||
// Utilities | ||
data (event) { | ||
let data = {}; | ||
try { | ||
data = JSON.parse(event.data); | ||
} catch (e) {} | ||
return data; | ||
} | ||
|
||
Client.prototype.send = function send(data) { | ||
this.ws.send(JSON.stringify(data)); | ||
}; | ||
send (data) { | ||
if (!this.ws) return; | ||
this.ws.send(JSON.stringify(data)); | ||
} | ||
|
||
var idCounter = 0; | ||
Client.prototype.uniqueId = function uniqueId(prefix) { | ||
var id = idCounter++; | ||
return prefix ? prefix + id : id; | ||
}; | ||
uniqueId (prefix) { | ||
let id = idCounter++; | ||
return prefix ? prefix + id : id; | ||
} | ||
} |
Oops, something went wrong.