Skip to content

Commit 4d74a14

Browse files
committed
fix(core): use Promise from compodoc
fix #4
1 parent 07c39f3 commit 4d74a14

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

index.js

+34-27
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
11
'use strict';
22
const gutil = require('gulp-util'),
3-
PluginError = gutil.PluginError,
4-
es = require('event-stream'),
5-
through = require('through2'),
6-
compodocModule = require('@compodoc/compodoc'),
7-
PLUGIN_NAME = 'gulp-compodoc';
3+
PluginError = gutil.PluginError,
4+
es = require('event-stream'),
5+
through = require('through2'),
6+
compodocModule = require('@compodoc/compodoc'),
7+
PLUGIN_NAME = 'gulp-compodoc';
88

99
function compodoc(options) {
1010
var files = [];
11-
options = options || {};
11+
options = options || {};
1212

1313
return es.through(function(file) {
14-
files.push(file.path);
15-
}, function() {
16-
var stream = this;
14+
files.push(file.path);
15+
}, function() {
16+
var stream = this;
1717

18-
if (files.length === 0) {
19-
stream.emit('error', new PluginError(PLUGIN_NAME, 'No input files for compodoc.'));
20-
stream.emit('end');
21-
return;
22-
} else if (!options.output) {
23-
stream.emit('error', new PluginError(PLUGIN_NAME, 'You must either specify the \'output\' option.'));
24-
stream.emit('end');
25-
return;
26-
} else {
18+
if (files.length === 0) {
19+
stream.emit('error', new PluginError(PLUGIN_NAME, 'No input files for compodoc.'));
20+
stream.emit('end');
21+
return;
22+
} else if (!options.output) {
23+
stream.emit('error', new PluginError(PLUGIN_NAME, 'You must either specify the \'output\' option.'));
24+
stream.emit('end');
25+
return;
26+
} else {
2727
var app = new compodocModule.Application(options);
2828

29-
app.setFiles(files);
30-
app.generate();
31-
32-
process.on('exit', function() {
29+
try {
30+
app.setFiles(files);
31+
app.generate().then(function() {
32+
stream.emit('end');
33+
return;
34+
}, function(error) {
35+
stream.emit('error', new PluginError(PLUGIN_NAME, error));
36+
stream.emit('end');
37+
return;
38+
});
39+
} catch (e) {
40+
stream.emit('error', e);
3341
stream.emit('end');
34-
});
35-
36-
return;
37-
}
38-
});
42+
return;
43+
}
44+
}
45+
});
3946
}
4047

4148
module.exports = compodoc;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"node": ">=5.10.0"
3333
},
3434
"dependencies": {
35-
"@compodoc/compodoc": "^1.0.2",
35+
"@compodoc/compodoc": "^1.0.3",
3636
"event-stream": "^3.3.4",
3737
"gulp-util": "^3.0.7",
3838
"through2": "^2.0.1"

0 commit comments

Comments
 (0)