-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
47 lines (42 loc) · 1.4 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
'use strict';
const PluginError = require('plugin-error'),
es = require('event-stream'),
through = require('through2'),
compodocModule = require('@compodoc/compodoc'),
PLUGIN_NAME = 'gulp-compodoc';
function compodoc(options) {
var files = [];
options = options || {};
return es.through(function(file) {
files.push(file.path);
}, function() {
var stream = this;
if (files.length === 0) {
stream.emit('error', new PluginError(PLUGIN_NAME, 'No input files for compodoc.'));
stream.emit('end');
return;
} else if (!options.output) {
stream.emit('error', new PluginError(PLUGIN_NAME, 'You must either specify the \'output\' option.'));
stream.emit('end');
return;
} else {
var app = new compodocModule.Application(options);
try {
app.setFiles(files);
app.generate().then(function() {
stream.emit('end');
return;
}, function(error) {
stream.emit('error', new PluginError(PLUGIN_NAME, error));
stream.emit('end');
return;
});
} catch (e) {
stream.emit('error', e);
stream.emit('end');
return;
}
}
});
}
module.exports = compodoc;