UNPKG

bionode

Version:

A Node.js JavaScript library for client and server side bioinformatics

46 lines (42 loc) 1.65 kB
var fs = require('fs') var glob = require('glob') var jsdom = require('jsdom') var async = require('async') var jquery = fs.readFileSync(__dirname + '/jquery.js', 'utf8') var list = '<ul>' var template = '' var header = '<h1>Bionode Documentation</h1><p>This documentation is autogenerated and merges the documentation of each bionode module.</p><p>Usually each module section starts with some usage examples and is then subdivided by the methods the module provides.</p>' glob("node_modules/bionode-*/**/docs/*.html", null, function(err, files) { async.each(files, processFile, done) function processFile(file, cb) { if (file.split('/').length > 5) { return cb() } var html = fs.readFileSync(file, 'utf8') jsdom.env({html: html, src: [jquery], done: function(err, window) { window.$('.sections').each(function() { window.$(this).find('.content').remove() var moduleName = window.$(this).find('h1').html() var sourceURL = [ '<a href="', 'https://rawgit.com/bionode/', moduleName, '/master/docs/', moduleName, '.html">', moduleName, ' <span style="font-size:.5em;">(see source)</a></span>' ].join('') window.$(this).find('h1').html(sourceURL) list += window.$(this).html() }) if (template === '') { window.$('.sections').remove() template = '<html><head>' + window.$('head').html() + '</head>' } cb() }}) } function done() { list += '</ul>' console.log(template + '<body><div id="container">' + header + list + '</div></body></html>') } })