-
Notifications
You must be signed in to change notification settings - Fork 3
/
docs.js
76 lines (71 loc) · 2.27 KB
/
docs.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
'use strict';
var fs = require('fs');
var rimraf = require('rimraf').sync;
var mkdirp = require('mkdirp').sync;
rimraf(__dirname + '/docs');
mkdirp(__dirname + '/docs');
fs.writeFileSync(__dirname + '/docs/README.md', '**WARNING:** This folder is autogenerated by `docs.js` from the files in `/schema`');
fs.readdirSync(__dirname + '/schema').forEach(function (type) {
var schema = require('./schema/' + type);
var lines = [];
var clsName = type[0].toUpperCase() + type.substr(1).replace(/\.js$/, '');
lines.push(
'# ' + clsName
);
lines.push('');
if (schema.desc) {
lines.push(schema.desc);
lines.push('');
}
if (schema.events) {
lines.push('## Events');
lines.push('');
lines.push(
clsName + ' is an event emitter that emits the following events:'
);
schema.events.forEach(function (event) {
lines.push(' - `' + event.name + '` - ' + event.desc);
});
lines.push('');
}
if (schema.properties) {
lines.push('## Properties');
lines.push('');
lines.push(
'Each instance of ' + clsName + ' has the following properties:'
);
schema.properties.forEach(function (prop) {
lines.push(' - `' + prop.name + '` - ' + prop.desc);
});
lines.push('');
}
if (schema.methods) {
lines.push('## Methods');
lines.push('');
Object.keys(schema.methods).forEach(function (name) {
var method = schema.methods[name];
var args = method.args.map(function (arg) {
return (arg.rest ? '...' : '') + arg.name + (('default' in arg) ? ' = ' + JSON.stringify(arg.default) : '');
});
lines.push('### ' + clsName.toLowerCase() + '.' + name + '(' + args.join(', ') + ')');
lines.push('');
if (method.proxy) {
lines.push('Returns [`' + method.returns + '`](' + method.returns.toLowerCase() + '.md)');
} else if (/^Promise/.test(method.returns)) {
lines.push('Returns [`' + method.returns + '`](https://www.promisejs.org/api/)');
} else {
lines.push('Returns `' + method.returns + '`');
}
if (method.desc) {
lines.push('');
lines.push(method.desc);
}
lines.push('');
});
lines.push('');
}
fs.writeFileSync(
__dirname + '/docs/' + type.replace(/\.js$/, '.md'),
lines.join('\n')
);
});