Skip to content

Commit 8fa0661

Browse files
Di PengIgorMinar
authored andcommitted
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
1 parent e90b741 commit 8fa0661

File tree

8 files changed

+305
-344
lines changed

8 files changed

+305
-344
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ performance/temp*.html
99
.idea/workspace.xml
1010
*~
1111
angular.js.tmproj
12+
node_modules

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ task :package => [:clean, :compile, :docs] do
246246
f.write text.sub('angular-scenario.js', "angular-scenario-#{version}.js")
247247
end
248248

249-
File.open("#{pkg_dir}/docs-#{version}/app-cache.manifest", File::RDWR) do |f|
249+
File.open("#{pkg_dir}/docs-#{version}/appcache.manifest", File::RDWR) do |f|
250250
text = f.read
251251
f.rewind
252252
f.write text.sub('angular.min.js', "angular-#{version}.min.js")

docs/src/appCache.js

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,73 @@
33
*/
44

55
exports.appCache = appCache;
6-
var fs = require('fs');
6+
var fs = require('q-fs');
7+
var Q = require('qq');
8+
function identity($) {return $;}
79

810
function appCache(path) {
9-
var blackList = [ "offline.html",
10-
"sitemap.xml",
11-
"robots.txt",
12-
"docs-scenario.html",
13-
"docs-scenario.js",
14-
"app-cache.manifest"
11+
if(!path) {
12+
return appCacheTemplate();
13+
}
14+
var blackList = ["offline.html",
15+
"sitemap.xml",
16+
"robots.txt",
17+
"docs-scenario.html",
18+
"docs-scenario.js",
19+
"appcache.manifest"
1520
];
1621

1722
var result = ["CACHE MANIFEST",
18-
"# %TIMESTAMP%",
19-
"",
20-
"# cache all of these",
21-
"CACHE:",
22-
"../angular.min.js"];
23+
"# " + new Date().toISOString(),
24+
"",
25+
"# cache all of these",
26+
"CACHE:",
27+
"../angular.min.js"];
28+
29+
var resultPostfix = ["",
30+
"FALLBACK:",
31+
"/offline.html",
32+
"",
33+
"# allow access to google analytics and twitter when we are online",
34+
"NETWORK:",
35+
"*"];
36+
37+
var promise = fs.listTree(path).then(function(files){
38+
var fileFutures = [];
39+
files.forEach(function(file){
40+
fileFutures.push(fs.isFile(file).then(function(isFile){
41+
if (isFile && blackList.indexOf(file) == -1) {
42+
return file.replace('build/docs/','');
43+
}
44+
}));
45+
});
46+
return Q.deep(fileFutures);
47+
}).then(function(files){
48+
return result.concat(files.filter(identity)).concat(resultPostfix).join('\n');
49+
});
2350

24-
var resultPostfix = [ "",
25-
"FALLBACK:",
26-
"/offline.html",
27-
"",
28-
"# allow access to google analytics and twitter when we are online",
29-
"NETWORK:",
30-
"*"];
31-
walk(path,result,blackList);
32-
return result.join('\n').replace(/%TIMESTAMP%/, (new Date()).toISOString()) + '\n' + resultPostfix.join('\n');
51+
return promise;
3352
}
3453

35-
function walk(path, array, blackList) {
36-
var temp = fs.readdirSync(path);
37-
for (var i=0; i< temp.length; i++) {
38-
if(blackList.indexOf(temp[i]) < 0) {
39-
var currentPath = path + '/' + temp[i];
40-
var stat = fs.statSync(currentPath);
41-
42-
if (stat.isDirectory()) {
43-
walk(currentPath, array, blackList);
44-
}
45-
else {
46-
array.push(currentPath.replace('build/docs/',''));
47-
}
48-
}
49-
}
50-
}
54+
function appCacheTemplate() {
55+
return ["CACHE MANIFEST",
56+
"# " + new Date().toISOString(),
57+
"",
58+
"# cache all of these",
59+
"CACHE:",
60+
"syntaxhighlighter/syntaxhighlighter-combined.js",
61+
"../angular.min.js",
62+
"docs-combined.js",
63+
"docs-keywords.js",
64+
"docs-combined.css",
65+
"syntaxhighlighter/syntaxhighlighter-combined.css",
66+
"img/texture_1.png",
67+
"img/yellow_bkgnd.jpg",
68+
"",
69+
"FALLBACK:",
70+
"/ offline.html",
71+
"",
72+
"# allow access to google analytics and twitter when we are online",
73+
"NETWORK:",
74+
"*"].join('\n');
75+
}

docs/src/callback.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

docs/src/gen-docs.js

Lines changed: 63 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,90 +3,77 @@ require.paths.push('lib');
33
var reader = require('reader.js'),
44
ngdoc = require('ngdoc.js'),
55
writer = require('writer.js'),
6-
callback = require('callback.js'),
76
SiteMap = require('SiteMap.js').SiteMap,
8-
appCache = require('appCache.js');
7+
appCache = require('appCache.js').appCache,
8+
Q = require('qq');
99

10-
var docs = [];
11-
var start;
12-
var work = callback.chain(function(){
13-
start = now();
14-
console.log('Generating Angular Reference Documentation...');
15-
reader.collect(work.waitMany(function(text, file, line){
16-
var doc = new ngdoc.Doc(text, file, line);
17-
docs.push(doc);
18-
doc.parse();
19-
}));
10+
process.on('uncaughtException', function (err) {
11+
console.error(err.stack || err);
2012
});
21-
var writes = callback.chain(function(){
13+
14+
var start = now();
15+
var docs;
16+
17+
writer.makeDir('build/docs/syntaxhighlighter').then(function() {
18+
console.log('Generating Angular Reference Documentation...');
19+
return reader.collect();
20+
}).then(function generateHtmlDocPartials(docs_) {
21+
docs = docs_;
2222
ngdoc.merge(docs);
23+
var fileFutures = [];
2324
docs.forEach(function(doc){
24-
writer.output(doc.section + '/' + doc.id + '.html', doc.html(), writes.waitFor());
25+
fileFutures.push(writer.output(doc.section + '/' + doc.id + '.html', doc.html()));
2526
});
27+
28+
writeTheRest(fileFutures);
29+
30+
return Q.deep(fileFutures);
31+
}).then(function generateManifestFile() {
32+
return appCache('build/docs/').then(function(list) {
33+
writer.output('appcache-offline.manifest',list)
34+
});
35+
}).then(function printStats() {
36+
console.log('DONE. Generated ' + docs.length + ' pages in ' + (now()-start) + 'ms.' );
37+
}).end();
38+
39+
40+
function writeTheRest(writesFuture) {
2641
var metadata = ngdoc.metadata(docs);
27-
writer.output('docs-keywords.js', ['NG_PAGES=', JSON.stringify(metadata).replace(/{/g, '\n{'), ';'], writes.waitFor());
28-
writer.copyDir('img', writes.waitFor());
29-
writer.copyDir('examples', writes.waitFor());
30-
writer.copyTpl('index.html', writes.waitFor());
31-
writer.copyTpl('.htaccess', writes.waitFor());
32-
writer.copy('docs/src/templates/index.html', 'build/docs/index-jq.html', writes.waitFor(),
33-
'<-- jquery place holder -->', '<script src=\"jquery.min.js\"><\/script>');
34-
writer.copyTpl('offline.html', writes.waitFor());
35-
//writer.output('app-cache.manifest',
36-
// appCacheTemplate().replace(/%TIMESTAMP%/, (new Date()).toISOString()),
37-
// writes.waitFor());
38-
writer.merge(['docs.js',
39-
'doc_widgets.js'],
40-
'docs-combined.js',
41-
writes.waitFor());
42-
writer.merge(['docs.css',
43-
'doc_widgets.css'],
44-
'docs-combined.css',
45-
writes.waitFor());
46-
writer.copyTpl('docs-scenario.html', writes.waitFor());
47-
writer.output('docs-scenario.js', ngdoc.scenarios(docs), writes.waitFor());
48-
writer.output('sitemap.xml', new SiteMap(docs).render(), writes.waitFor());
49-
writer.output('robots.txt', 'Sitemap: http://docs.angularjs.org/sitemap.xml\n', writes.waitFor());
50-
writer.merge(['syntaxhighlighter/shCore.js',
51-
'syntaxhighlighter/shBrushJScript.js',
52-
'syntaxhighlighter/shBrushXml.js'],
53-
'syntaxhighlighter/syntaxhighlighter-combined.js',
54-
writes.waitFor());
55-
writer.merge(['syntaxhighlighter/shCore.css',
56-
'syntaxhighlighter/shThemeDefault.css'],
57-
'syntaxhighlighter/syntaxhighlighter-combined.css',
58-
writes.waitFor());
59-
writer.copyTpl('jquery.min.js', writes.waitFor());
60-
writer.output('app-cache.manifest', appCache('build/docs/'), writes.waitFor());
61-
});
62-
writes.onDone(function(){
63-
console.log('DONE. Generated ' + docs.length + ' pages in ' +
64-
(now()-start) + 'ms.' );
65-
});
66-
work.onDone(writes);
67-
writer.makeDir('build/docs/syntaxhighlighter', work);
6842

69-
///////////////////////////////////
70-
function now(){ return new Date().getTime(); }
43+
writesFuture.push(writer.copyDir('img'));
44+
writesFuture.push(writer.copyDir('examples'));
45+
writesFuture.push(writer.copyTpl('index.html'));
46+
writesFuture.push(writer.copy('docs/src/templates/index.html',
47+
'build/docs/index-jq.html',
48+
'<!-- jquery place holder -->',
49+
'<script src=\"jquery.min.js\"><\/script>'));
50+
writesFuture.push(writer.copyTpl('offline.html'));
51+
writesFuture.push(writer.copyTpl('docs-scenario.html'));
52+
writesFuture.push(writer.copyTpl('jquery.min.js'));
7153

54+
writesFuture.push(writer.output('docs-keywords.js',
55+
['NG_PAGES=', JSON.stringify(metadata).replace(/{/g, '\n{'), ';']));
56+
writesFuture.push(writer.output('sitemap.xml', new SiteMap(docs).render()));
57+
writesFuture.push(writer.output('docs-scenario.js', ngdoc.scenarios(docs)));
58+
writesFuture.push(writer.output('robots.txt', 'Sitemap: http://docs.angularjs.org/sitemap.xml\n'));
59+
writesFuture.push(writer.output('appcache.manifest',appCache()));
7260

73-
function appCacheTemplate() {
74-
return ["CACHE MANIFEST",
75-
"# %TIMESTAMP%",
76-
"",
77-
"# cache all of these",
78-
"CACHE:",
79-
"syntaxhighlighter/syntaxhighlighter-combined.js",
80-
"../angular.min.js",
81-
"docs-combined.js",
82-
"docs-keywords.js",
83-
"docs-combined.css",
84-
"syntaxhighlighter/syntaxhighlighter-combined.css",
85-
"",
86-
"FALLBACK:",
87-
"/ offline.html",
88-
"",
89-
"# allow access to google analytics and twitter when we are online",
90-
"NETWORK:",
91-
"*"].join('\n');
61+
writesFuture.push(writer.merge(['docs.js',
62+
'doc_widgets.js'],
63+
'docs-combined.js'));
64+
writesFuture.push(writer.merge(['docs.css',
65+
'doc_widgets.css'],
66+
'docs-combined.css'));
67+
writesFuture.push(writer.merge(['syntaxhighlighter/shCore.js',
68+
'syntaxhighlighter/shBrushJScript.js',
69+
'syntaxhighlighter/shBrushXml.js'],
70+
'syntaxhighlighter/syntaxhighlighter-combined.js'));
71+
writesFuture.push(writer.merge(['syntaxhighlighter/shCore.css',
72+
'syntaxhighlighter/shThemeDefault.css'],
73+
'syntaxhighlighter/syntaxhighlighter-combined.css'));
9274
}
75+
76+
77+
function now(){ return new Date().getTime(); }
78+
79+
function noop(){};

0 commit comments

Comments
 (0)