forked from nkronlage/JavaScripture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakepage.js
88 lines (68 loc) · 2.02 KB
/
makepage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
var fs = require('fs');
var path = require('path');
var stream = require('stream');
var util = require('util');
var StringDecoder = require('string_decoder').StringDecoder;
var ejs = require('ejs');
var File = require('vinyl');
var template = require('./template.js');
var jsdoc = require('./jsdocparser.js');
var MakePage = function() {
if (!(this instanceof MakePage)) return new MakePage();
stream.Transform.call(this, {
objectMode: true // needed for Vinyl
});
};
util.inherits(MakePage, stream.Transform);
MakePage.prototype._transform = function(file, encoding, callback) {
var apiSets = JSON.parse(fs.readFileSync('tmp/apisets.json', 'utf8'));
var filename = file.path;
var decoder = new StringDecoder('utf8');
var obj = jsdoc.processFileContents(decoder.write(file.contents));
obj.jsdocSourceFile = filename;
for (var setName in apiSets) {
var set = apiSets[setName];
set.forEach(function(type) {
if (type.name === obj.name) {
obj.apiSet = { name: setName };
}
});
}
// Validation
var errors = [];
var all = [].concat(obj.overloads, obj.constructors, obj.instanceProperties, obj.instanceMethods, obj.properties, obj.methods);
all.forEach(function(member) {
if (!member) {
errors.push('undefined member in ' + obj.name);
return;
}
if (!member.spec) {
errors.push('No spec for ' + obj.name + '.' + member.name);
}
if (!member.description) {
errors.push('No description for ' + obj.name + '.' + member.name);
}
if (member.type === 'Function') {
// TODO: check member.parameters
}
});
if (errors.length) {
console.warn(errors.join('\n'));
}
var body = template.render('object', {
obj: obj,
});
var title = obj.name + ' JavaScript API';
var html = template.render('page', {
title: title,
body: body,
obj: obj
});
var output = new File({
path: obj.name + '.html',
contents: new Buffer(html)
});
callback(null, output);
};
module.exports = MakePage;