forked from broccolijs/broccoli-yuidoc
/
index.js
56 lines (44 loc) · 1.23 KB
/
index.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
'use strict';
var merge = require('merge');
var yuidoc = require('yuidocjs');
var rsvp = require('rsvp');
var fs = require('fs');
var path = require('path');
var CachingWriter = require('broccoli-caching-writer');
var defaultOpts = {
srcDir: 'app',
destDir: 'docs',
yuidoc: {
linkNatives: true,
quiet: true,
parseOnly: false,
lint: false
}
};
var BroccoliYuidoc = CachingWriter.extend({
init: function(inputTree) {
this.inputTree = inputTree;
this.yuidoc = merge(defaultOpts, this.yuidoc);
},
updateCache: function(srcPaths, destDir) {
var options = this.yuidoc;
options.paths = options.paths || srcPaths;
options.outdir = [destDir, this.destDir].join('/');
try {
var json = (new yuidoc.YUIDoc(options)).run();
} catch(e) {
throw e;
}
options = yuidoc.Project.mix(json, options);
if (options.parseOnly) {
fs.writeFileSync(path.join(options.outdir, 'data.json'), JSON.stringify(json, null, 4));
return;
}
var builder = new yuidoc.DocBuilder(options, json);
var self = this;
return new rsvp.Promise(function(resolve) {
builder.compile(function() { resolve(); });
});
}
});
module.exports = BroccoliYuidoc;