|  | 
| 1 | 1 | 'use strict'; | 
| 2 | 2 | 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'; | 
| 8 | 8 | 
 | 
| 9 | 9 | function compodoc(options) { | 
| 10 | 10 |  var files = []; | 
| 11 |  | -options = options || {}; | 
|  | 11 | +options = options || {}; | 
| 12 | 12 | 
 | 
| 13 | 13 |  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; | 
| 17 | 17 | 
 | 
| 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 { | 
| 27 | 27 |  var app = new compodocModule.Application(options); | 
| 28 | 28 | 
 | 
| 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); | 
| 33 | 41 |  stream.emit('end'); | 
| 34 |  | - }); | 
| 35 |  | - | 
| 36 |  | -			return; | 
| 37 |  | -		} | 
| 38 |  | -	}); | 
|  | 42 | + return; | 
|  | 43 | + } | 
|  | 44 | + } | 
|  | 45 | + }); | 
| 39 | 46 | } | 
| 40 | 47 | 
 | 
| 41 | 48 | module.exports = compodoc; | 
0 commit comments