Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jun 07, 2012
@napcs napcs Updated to work with the most recent LiveReload
Switched out websocket for websocket.io library and ensured
things work like guard-livereload. Also cleaned up a couple
of deprecation warnings and bumped the version number.
c219b8d
Commits on Jun 08, 2012
@napcs napcs Updated readme and package.json for new release
Filled out the readme.md file with usage instructions, updated
the repository locations and authors in the package, and changed
the default LiveReload API version to 1.6.
4ecd7ee
View
2  Cakefile
@@ -1,4 +1,4 @@
-{print} = require 'sys'
+{print} = require 'util'
{spawn} = require 'child_process'
task 'build', 'Build CoffeeScript source files', ->
View
31 README.md
@@ -1,17 +1,23 @@
node-livereload
===============
-An implementation of the LiveReload server in Node.js.
+An implementation of the LiveReload server in Node.js. It's an alternative to the graphical [http://livereload.com/](http://livereload.com/) application, which monitors files for changes and reloads your web browser.
-Install the browser plugin and read more about the project at [mockko/livereload](https://github.com/mockko/livereload).
+# Example Usage
-# Example
+First, install the LiveReload browser plugins by visiting [http://help.livereload.com/kb/general-use/browser-extensions](http://help.livereload.com/kb/general-use/browser-extensions).
+
+Then install the livereload module with `npm`:
+
+ $ npm install livereload
+
+Then, simply create a server and fire it up.
livereload = require('livereload');
server = livereload.createServer();
server.watch(__dirname + "/public");
-Use with a connect server:
+You can also use this with a Connect server:
connect = require('connect');
connect.createServer(
@@ -23,12 +29,23 @@ Use with a connect server:
server = livereload.createServer({exts: ['less']});
server.watch(__dirname + "/public");
-# Installation
+# Options
- $ npm install livereload
+The `createServer()` method supports a few basic options, passed as a JavaScript object:
+
+* `port` is the listening port. It defaults to `35729` which is what the LiveReload extensions use currently.
+* `exts` is an array of extensions you want to observe. The default extensions are `html`, `css`, `js`, `png`, `gif`, `jpg`,
+ `php`, `php5`, `py`, `rb`, and `erb`
+* `applyJSLive` tells LiveReload to reload JavaScript files in the background instead of reloading the page. The default for this is `false`.
+* `applyCSSLive` tells LiveReload to reload CSS files in the background instead of refreshing the page. The default for this is `true`.
+* `exclusions` lets you specify files to ignore. By default, this includes `.git/`, `.svn/`, and `.hg/`
+
+# Limitations
+
+Right now this is extremely simple. It relies on polling so there's a delay in refreshing the browser. It could be faster.
# License
-Copyright (c) 2010 Joshua Peek.
+Copyright (c) 2010-2012 Joshua Peek and Brian P. Hogan.
Released under the MIT license. See `LICENSE` for details.
View
31 livereload.coffee
@@ -1,8 +1,8 @@
fs = require 'fs'
path = require 'path'
-ws = require 'websocket-server'
+ws = require 'websocket.io'
-version = '1.5'
+version = '1.6'
defaultPort = 35729
defaultExts = [
@@ -28,23 +28,27 @@ class Server
@config.applyJSLive ?= false
@config.applyCSSLive ?= true
- @server = ws.createServer()
+ @sockets = []
+
+ listen: ->
+ @debug "LiveReload is waiting for browser to connect."
+
+ @server = ws.listen(@config.port)
@server.on 'connection', @onConnection.bind @
@server.on 'close', @onClose.bind @
- listen: ->
- @debug "LiveReload is waiting for browser to connect."
- @server.listen @config.port
- onConnection: (connection) ->
+ onConnection: (socket) ->
@debug "Browser connected."
- connection.write "!!ver:#{@config.version}"
+ socket.send "!!ver:#{@config.version}"
- connection.on 'message', (message) =>
+ socket.on 'message', (message) =>
@debug "Browser URL: #{message}"
- onClose: (connection) ->
+ @sockets.push socket
+
+ onClose: (socket) ->
@debug "Browser disconnected."
walkTree: (dirname, callback) ->
@@ -80,15 +84,18 @@ class Server
refresh: (path) ->
@debug "Refresh: #{path}"
- @server.broadcast JSON.stringify ['refresh',
+ data = JSON.stringify ['refresh',
path: path,
apply_js_live: @config.applyJSLive,
apply_css_live: @config.applyCSSLive
]
+ for socket in @sockets
+ socket.send data
+
debug: (str) ->
if @config.debug
- process.binding('stdio').writeError "#{str}\n"
+ console.log "#{str}\n"
exports.createServer = (args...) ->
server = new Server args...
View
125 livereload.js
@@ -1,44 +1,74 @@
+// Generated by CoffeeScript 1.3.2
(function() {
- var Server, defaultExclusions, defaultExts, defaultPort, fs, path, version, ws;
- var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __slice = Array.prototype.slice;
+ var Server, defaultExclusions, defaultExts, defaultPort, fs, path, version, ws,
+ __slice = [].slice;
+
fs = require('fs');
+
path = require('path');
- ws = require('websocket-server');
- version = '1.5';
+
+ ws = require('websocket.io');
+
+ version = '1.6';
+
defaultPort = 35729;
+
defaultExts = ['html', 'css', 'js', 'png', 'gif', 'jpg', 'php', 'php5', 'py', 'rb', 'erb'];
+
defaultExclusions = ['.git/', '.svn/', '.hg/'];
+
Server = (function() {
+
function Server(config) {
- var _base, _base2, _base3, _base4, _base5, _base6, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
+ var _base, _base1, _base2, _base3, _base4, _base5, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6;
this.config = config;
- (_ref = this.config) != null ? _ref : this.config = {};
- (_ref2 = (_base = this.config).version) != null ? _ref2 : _base.version = version;
- (_ref3 = (_base2 = this.config).port) != null ? _ref3 : _base2.port = defaultPort;
- (_ref4 = (_base3 = this.config).exts) != null ? _ref4 : _base3.exts = [];
- (_ref5 = (_base4 = this.config).exclusions) != null ? _ref5 : _base4.exclusions = [];
+ if ((_ref = this.config) == null) {
+ this.config = {};
+ }
+ if ((_ref1 = (_base = this.config).version) == null) {
+ _base.version = version;
+ }
+ if ((_ref2 = (_base1 = this.config).port) == null) {
+ _base1.port = defaultPort;
+ }
+ if ((_ref3 = (_base2 = this.config).exts) == null) {
+ _base2.exts = [];
+ }
+ if ((_ref4 = (_base3 = this.config).exclusions) == null) {
+ _base3.exclusions = [];
+ }
this.config.exts = this.config.exts.concat(defaultExts);
this.config.exclusions = this.config.exclusions.concat(defaultExclusions);
- (_ref6 = (_base5 = this.config).applyJSLive) != null ? _ref6 : _base5.applyJSLive = false;
- (_ref7 = (_base6 = this.config).applyCSSLive) != null ? _ref7 : _base6.applyCSSLive = true;
- this.server = ws.createServer();
- this.server.on('connection', this.onConnection.bind(this));
- this.server.on('close', this.onClose.bind(this));
+ if ((_ref5 = (_base4 = this.config).applyJSLive) == null) {
+ _base4.applyJSLive = false;
+ }
+ if ((_ref6 = (_base5 = this.config).applyCSSLive) == null) {
+ _base5.applyCSSLive = true;
+ }
+ this.sockets = [];
}
+
Server.prototype.listen = function() {
this.debug("LiveReload is waiting for browser to connect.");
- return this.server.listen(this.config.port);
+ this.server = ws.listen(this.config.port);
+ this.server.on('connection', this.onConnection.bind(this));
+ return this.server.on('close', this.onClose.bind(this));
};
- Server.prototype.onConnection = function(connection) {
+
+ Server.prototype.onConnection = function(socket) {
+ var _this = this;
this.debug("Browser connected.");
- connection.write("!!ver:" + this.config.version);
- return connection.on('message', __bind(function(message) {
- return this.debug("Browser URL: " + message);
- }, this));
+ socket.send("!!ver:" + this.config.version);
+ socket.on('message', function(message) {
+ return _this.debug("Browser URL: " + message);
+ });
+ return this.sockets.push(socket);
};
- Server.prototype.onClose = function(connection) {
+
+ Server.prototype.onClose = function(socket) {
return this.debug("Browser disconnected.");
};
+
Server.prototype.walkTree = function(dirname, callback) {
var exclusions, exts, walk;
exts = this.config.exts;
@@ -58,17 +88,18 @@
}
}
return fs.stat(filename, function(err, stats) {
- var ext, _i, _len, _results;
+ var ext, _j, _len1, _results;
if (!err && stats.isDirectory()) {
return walk(filename);
} else {
_results = [];
- for (_i = 0, _len = exts.length; _i < _len; _i++) {
- ext = exts[_i];
- if (filename.match("\." + ext + "$")) {
- callback(err, filename);
- break;
+ for (_j = 0, _len1 = exts.length; _j < _len1; _j++) {
+ ext = exts[_j];
+ if (!(filename.match("\." + ext + "$"))) {
+ continue;
}
+ callback(err, filename);
+ break;
}
return _results;
}
@@ -78,44 +109,60 @@
};
return walk(dirname, callback);
};
+
Server.prototype.watch = function(dirname) {
- return this.walkTree(dirname, __bind(function(err, filename) {
+ var _this = this;
+ return this.walkTree(dirname, function(err, filename) {
if (err) {
throw err;
}
- return fs.watchFile(filename, __bind(function(curr, prev) {
+ return fs.watchFile(filename, function(curr, prev) {
if (curr.mtime > prev.mtime) {
- return this.refresh(filename);
+ return _this.refresh(filename);
}
- }, this));
- }, this));
+ });
+ });
};
+
Server.prototype.refresh = function(path) {
+ var data, socket, _i, _len, _ref, _results;
this.debug("Refresh: " + path);
- return this.server.broadcast(JSON.stringify([
+ data = JSON.stringify([
'refresh', {
path: path,
apply_js_live: this.config.applyJSLive,
apply_css_live: this.config.applyCSSLive
}
- ]));
+ ]);
+ _ref = this.sockets;
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ socket = _ref[_i];
+ _results.push(socket.send(data));
+ }
+ return _results;
};
+
Server.prototype.debug = function(str) {
if (this.config.debug) {
- return process.binding('stdio').writeError("" + str + "\n");
+ return console.log("" + str + "\n");
}
};
+
return Server;
+
})();
+
exports.createServer = function() {
var args, server;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
server = (function(func, args, ctor) {
ctor.prototype = func.prototype;
- var child = new ctor, result = func.apply(child, args);
- return typeof result === "object" ? result : child;
- })(Server, args, function() {});
+ var child = new ctor, result = func.apply(child, args), t = typeof result;
+ return t == "object" || t == "function" ? result || child : child;
+ })(Server, args, function(){});
server.listen();
return server;
};
+
}).call(this);
View
15 package.json
@@ -1,18 +1,21 @@
{ "name": "livereload"
, "description": "LiveReload server"
-, "version": "0.2.0"
-, "author": "Joshua Peek"
+, "version": "0.3.0"
+, "contributors": [
+ { "name": "Joshua Peek" }
+ , { "name": "Brian P. Hogan", "email": "brianhogan@napcs.com" }
+ ]
, "licenses": [
{ "type": "MIT"
- , "url": "https://github.com/josh/node-livereload/blob/master/LICENSE"
+ , "url": "https://github.com/napcs/node-livereload/blob/master/LICENSE"
}]
, "repository":
{ "type": "git"
- , "url": "http://github.com/josh/node-livereload.git"
+ , "url": "http://github.com/napcs/node-livereload.git"
}
, "main": "./livereload.js"
, "dependencies": {
- "websocket-server": ">= 1.1.00"
+ "websocket.io": ">= 0.1.0"
}
-, "engines" : { "node" : ">=0.2.0" }
+, "engines" : { "node" : ">=0.4.0" }
}

No commit comments for this range

Something went wrong with that request. Please try again.