From 46543256fce82f8b20c6d8bb3421328ebeb11bcc Mon Sep 17 00:00:00 2001 From: Jan Aagaard Meier Date: Thu, 23 Jun 2016 18:11:41 +0200 Subject: [PATCH] add(tools): Tool to check the output of a single repo --- bin/watcher.js | 54 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 ++++ views/doclayout.jade | 13 +++++++---- 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 bin/watcher.js diff --git a/bin/watcher.js b/bin/watcher.js new file mode 100644 index 0000000..0f27fac --- /dev/null +++ b/bin/watcher.js @@ -0,0 +1,54 @@ +var gather = require('../lib/gather') + , structure = require('../lib/structure') + , viewParams = require('../lib/view-params') + , Doclet = require('../lib/models/doclet') + , _ = require('underscore') + , jade = require('jade') + , chokidar = require('chokidar') + , path = require('path') + , branch = require('git-branch') + , express = require('express') + , io = require('socket.io') + , http = require('http') + , argv = require('optimist').argv; + +if (argv.h) { + console.log('-p 3000 -d [dir]'); + return; +} + +var app = express() + , server = http.Server(app) + , socket = io(server); + +server.listen(argv.p || 3000); + +var repoPath = path.resolve(argv.d); +var dbEntry = gather.gatherDocletsAndMeta(repoPath, false, branch.sync(repoPath)); + +if (dbEntry.error) { + console.log(dbEntry); + return; +} + +app.get('/', function (req, res) { + res.send(jade.renderFile('./views/api.jade', _.extend({ + doclet: new Doclet({ + data: { + hot: true, + doclets: gather.createDoclets(dbEntry.config, repoPath), + articles: dbEntry.articles + } + }), + moment: require('moment'), + _: _ + }, dbEntry, structure, viewParams))); +}); + +app.use(express.static('assets')); + +var watch = path.join(repoPath, dbEntry.config.dir); +console.log('Watching ', watch); +chokidar.watch(watch).on('all', function () { + socket.emit('change'); +}); diff --git a/package.json b/package.json index 90dd762..78a0d30 100644 --- a/package.json +++ b/package.json @@ -62,12 +62,16 @@ }, "devDependencies": { "acme-jsdoc-example": "lipp/acme-jsdoc-example", + "chokidar": "^1.6.0", "coveralls": "^2.11.6", "csslint": "^0.10.0", + "git-branch": "^0.3.0", "istanbul": "^0.4.1", "mocha": "^2.5.0", + "optimist": "^0.6.1", "request": "^2.72.0", "sinon": "^1.17.2", + "socket.io": "^1.4.6", "standard": "^5.4.1", "taffydb": "^2.7.2" }, diff --git a/views/doclayout.jade b/views/doclayout.jade index 3798a75..fd0136b 100644 --- a/views/doclayout.jade +++ b/views/doclayout.jade @@ -22,7 +22,7 @@ mixin funcdeclx(name, func, isCtor) extends layout -block styles +block styles link(rel="stylesheet", href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/styles/default.min.css") @@ -109,8 +109,13 @@ block scripts //window.location = window.location.href; console.log(window.location.href); }; - - + if doclet.data.hot + script(src = "/socket.io/socket.io.js") + script. + var socket = io.connect('http://localhost:3000'); + socket.on('change', function () { + window.location.reload() + }); block content #title @@ -181,7 +186,7 @@ block content include nav.jade .main block api - + a.big.circular.icon.button#scroll-top(href='#title') i.big.circular.icon.angle.up