summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-05-21 17:17:08 +0200
committerSamy Pessé <samypesse@gmail.com>2014-05-21 17:17:08 +0200
commit8d6923ce2cb0d6508a95435afb0cc51045cacaf6 (patch)
tree235edd547d180b55e68a21e290ccee7b5225723b /bin
parent0e1717f4bb979ebdbba5500dd5ae85f7f10f3528 (diff)
parentb21fb24a82577f9caf7fc1db2e1559d128dd798f (diff)
downloadgitbook-8d6923ce2cb0d6508a95435afb0cc51045cacaf6.zip
gitbook-8d6923ce2cb0d6508a95435afb0cc51045cacaf6.tar.gz
gitbook-8d6923ce2cb0d6508a95435afb0cc51045cacaf6.tar.bz2
Merge pull request #234 from davidagraf/livereload
Livereload
Diffstat (limited to 'bin')
-rwxr-xr-xbin/gitbook.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/bin/gitbook.js b/bin/gitbook.js
index 88083b9..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;
@@ -26,9 +27,19 @@ build.command(prog.command('serve [source_dir]'))
.description('Build then serve a gitbook from a directory')
.option('-p, --port <port>', 'Port for server to listen on', 4000)
.option('--no-watch', 'Disable restart with file watching')
+.option('--no-cache', 'Disable cache manifest generation')
.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");
@@ -43,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();