From 622bbcb8ea24238cbb34bed2cbd7105f6d4d7351 Mon Sep 17 00:00:00 2001 From: David Graf Date: Thu, 15 May 2014 07:43:59 +0200 Subject: [PATCH 1/6] ignore vim swap files --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 40e6da91c..9bcfe7e12 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,7 @@ build/Release # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git node_modules -theme/javascript/vendors \ No newline at end of file +theme/javascript/vendors + +# vim swapfile +*.swp From 0b0ac46e342d92959099e78c5cf1a8b26d309dbd Mon Sep 17 00:00:00 2001 From: David Graf Date: Thu, 15 May 2014 08:07:24 +0200 Subject: [PATCH 2/6] Introducing option to disable cache manifest generation --- bin/gitbook.js | 1 + lib/generate/site/index.js | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/gitbook.js b/bin/gitbook.js index 88083b96e..1fd87974d 100755 --- a/bin/gitbook.js +++ b/bin/gitbook.js @@ -26,6 +26,7 @@ build.command(prog.command('serve [source_dir]')) .description('Build then serve a gitbook from a directory') .option('-p, --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(); diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index b63f70398..6033fb4d7 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -237,9 +237,13 @@ Generator.prototype.writeCacheManifest = function() { }; Generator.prototype.finish = function() { - return this.copyAssets() - .then(this.writeSearchIndex) - .then(this.writeCacheManifest); + var deferred = this.copyAssets().then(this.writeSearchIndex); + + if (this.options.cache) { + deferred = deferred.then(this.writeCacheManifest); + } + + return deferred; }; module.exports = Generator; From e97d1941dc5196e64ba13e5f2d29fd308b69d29d Mon Sep 17 00:00:00 2001 From: David Graf Date: Thu, 15 May 2014 08:09:02 +0200 Subject: [PATCH 3/6] Introducing livereload server --- bin/gitbook.js | 17 +++++++++++++++++ package.json | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/bin/gitbook.js b/bin/gitbook.js index 1fd87974d..ca68142c9 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(); diff --git a/package.json b/package.json index ed41a967b..781c0c2e0 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "semver": "2.2.1", "gaze": "~0.5.1", "resolve": "0.6.3", - + "tiny-lr-fork": "0.0.5", "gitbook-plugin": "0.0.2", "gitbook-plugin-mixpanel": "0.0.2", "gitbook-plugin-mathjax": "0.0.3" From 9b96ef9baec9a2a46651e94c2069668d2875148f Mon Sep 17 00:00:00 2001 From: David Graf Date: Thu, 15 May 2014 11:41:59 +0200 Subject: [PATCH 4/6] added livereload dependency --- lib/generate/plugin.js | 5 +++-- package.json | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/generate/plugin.js b/lib/generate/plugin.js index 2b06c1504..5804f919c 100644 --- a/lib/generate/plugin.js +++ b/lib/generate/plugin.js @@ -186,7 +186,8 @@ Plugin.fromList = function(names, root) { // Default plugins Plugin.defaults = [ "mixpanel", - "mathjax" + "mathjax", + "livereload" ]; -module.exports = Plugin; \ No newline at end of file +module.exports = Plugin; diff --git a/package.json b/package.json index 781c0c2e0..d8474d819 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "tiny-lr-fork": "0.0.5", "gitbook-plugin": "0.0.2", "gitbook-plugin-mixpanel": "0.0.2", - "gitbook-plugin-mathjax": "0.0.3" + "gitbook-plugin-mathjax": "0.0.3", + "gitbook-plugin-livereload": "git://github.com/davidagraf/gitbookio-plugin-livereload.git" }, "devDependencies": { "mocha": "1.18.2", From 7c65adc9b2c7a1f386a8bd54cdc03bdeac4df5a5 Mon Sep 17 00:00:00 2001 From: David Graf Date: Thu, 15 May 2014 12:07:51 +0200 Subject: [PATCH 5/6] disable cache manifest import if cache is disabled --- theme/templates/site.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/theme/templates/site.html b/theme/templates/site.html index af730300f..a05cf4b7f 100644 --- a/theme/templates/site.html +++ b/theme/templates/site.html @@ -1,6 +1,10 @@ {% extends "layout.html" %} -{% block htmlTag %}manifest="{{ basePath }}/manifest.appcache"{% endblock %} +{% block htmlTag %} + {% if options.cache %} + manifest="{{ basePath }}/manifest.appcache" + {% endif %} +{% endblock %} {% block title %}{{ progress.current.title }}{% parent %}{% endblock %} {% block content %}
From b21fb24a82577f9caf7fc1db2e1559d128dd798f Mon Sep 17 00:00:00 2001 From: David Graf Date: Wed, 21 May 2014 16:35:55 +0200 Subject: [PATCH 6/6] gitbook-plugin-livereload dependency to npm --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e3c7f569..93ff9f3d0 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "gitbook-plugin": "0.0.2", "gitbook-plugin-mixpanel": "0.0.2", "gitbook-plugin-mathjax": "0.0.3", - "gitbook-plugin-livereload": "git://github.com/davidagraf/gitbookio-plugin-livereload.git" + "gitbook-plugin-livereload": "0.0.1" }, "devDependencies": { "mocha": "1.18.2",