diff options
Diffstat (limited to 'bin/gitbook.js')
-rwxr-xr-x | bin/gitbook.js | 18 |
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(); |