From 8fa066190af2b2267a5e8111a41beb6e8af5c340 Mon Sep 17 00:00:00 2001 From: Di Peng Date: Sat, 9 Jul 2011 18:15:40 -0700 Subject: refactor(gen-docs): use q, qq, q-fs (node modules) to write gen-docs - re-write gendocs.js, reader.js and writer.js - all calls are asynchronous --- docs/src/gen-docs.js | 139 +++++++++++++++++++++++---------------------------- 1 file changed, 63 insertions(+), 76 deletions(-) (limited to 'docs/src/gen-docs.js') diff --git a/docs/src/gen-docs.js b/docs/src/gen-docs.js index 8ed0c563..2cbc9267 100755 --- a/docs/src/gen-docs.js +++ b/docs/src/gen-docs.js @@ -3,90 +3,77 @@ require.paths.push('lib'); var reader = require('reader.js'), ngdoc = require('ngdoc.js'), writer = require('writer.js'), - callback = require('callback.js'), SiteMap = require('SiteMap.js').SiteMap, - appCache = require('appCache.js'); + appCache = require('appCache.js').appCache, + Q = require('qq'); -var docs = []; -var start; -var work = callback.chain(function(){ - start = now(); - console.log('Generating Angular Reference Documentation...'); - reader.collect(work.waitMany(function(text, file, line){ - var doc = new ngdoc.Doc(text, file, line); - docs.push(doc); - doc.parse(); - })); +process.on('uncaughtException', function (err) { + console.error(err.stack || err); }); -var writes = callback.chain(function(){ + +var start = now(); +var docs; + +writer.makeDir('build/docs/syntaxhighlighter').then(function() { + console.log('Generating Angular Reference Documentation...'); + return reader.collect(); +}).then(function generateHtmlDocPartials(docs_) { + docs = docs_; ngdoc.merge(docs); + var fileFutures = []; docs.forEach(function(doc){ - writer.output(doc.section + '/' + doc.id + '.html', doc.html(), writes.waitFor()); + fileFutures.push(writer.output(doc.section + '/' + doc.id + '.html', doc.html())); }); + + writeTheRest(fileFutures); + + return Q.deep(fileFutures); +}).then(function generateManifestFile() { + return appCache('build/docs/').then(function(list) { + writer.output('appcache-offline.manifest',list) + }); +}).then(function printStats() { + console.log('DONE. Generated ' + docs.length + ' pages in ' + (now()-start) + 'ms.' ); +}).end(); + + +function writeTheRest(writesFuture) { var metadata = ngdoc.metadata(docs); - writer.output('docs-keywords.js', ['NG_PAGES=', JSON.stringify(metadata).replace(/{/g, '\n{'), ';'], writes.waitFor()); - writer.copyDir('img', writes.waitFor()); - writer.copyDir('examples', writes.waitFor()); - writer.copyTpl('index.html', writes.waitFor()); - writer.copyTpl('.htaccess', writes.waitFor()); - writer.copy('docs/src/templates/index.html', 'build/docs/index-jq.html', writes.waitFor(), - '<-- jquery place holder -->', '