diff options
author | David Graf <davidagraf@gmail.com> | 2014-05-15 08:09:02 +0200 |
---|---|---|
committer | David Graf <davidagraf@gmail.com> | 2014-05-15 08:09:02 +0200 |
commit | e97d1941dc5196e64ba13e5f2d29fd308b69d29d (patch) | |
tree | bfc094ea634b28a9ee96aecb1a7bfb154554fdf1 /bin/gitbook.js | |
parent | 0b0ac46e342d92959099e78c5cf1a8b26d309dbd (diff) | |
download | gitbook-e97d1941dc5196e64ba13e5f2d29fd308b69d29d.zip gitbook-e97d1941dc5196e64ba13e5f2d29fd308b69d29d.tar.gz gitbook-e97d1941dc5196e64ba13e5f2d29fd308b69d29d.tar.bz2 |
Introducing livereload server
Diffstat (limited to 'bin/gitbook.js')
-rwxr-xr-x | bin/gitbook.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/bin/gitbook.js b/bin/gitbook.js index 1fd8797..ca68142 100755 --- a/bin/gitbook.js +++ b/bin/gitbook.js @@ -4,6 +4,7 @@ var Q = require('q'); var _ = require('lodash'); var path = require('path'); var prog = require('commander'); +var tinylr = require('tiny-lr-fork'); var pkg = require('../package.json'); var generators = require("../lib/generate").generators; @@ -30,6 +31,15 @@ build.command(prog.command('serve [source_dir]')) .action(function(dir, options) { var server = new Server(); + // init livereload server + var lrOptions = {port: 35729}; + var lrServer = tinylr(lrOptions); + var lrPath = undefined; + lrServer.listen(lrOptions.port, function(err) { + if (err) { return console.log(err); } + console.log('Live reload server started on port: ' + lrOptions.port); + }); + var generate = function() { if (server.isRunning()) console.log("Stopping server"); @@ -44,9 +54,16 @@ build.command(prog.command('serve [source_dir]')) .then(function() { console.log('Serving book on http://localhost:'+options.port); + if (lrPath) { + // trigger livereload + lrServer.changed({body:{files:[lrPath]}}) + } + if (!options.watch) return; return utils.watch(_options.input) .then(function(filepath) { + // set livereload path + lrPath = filepath; console.log("Restart after change in files"); console.log(''); return generate(); |