-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
51 lines (38 loc) · 1.15 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
var through = require('through2');
var ESDoc = require('esdoc').default;
var publisher = require('esdoc/out/src/Publisher/publish').default;
var gutil = require('gulp-util');
var fs = require('fs'),
path = require('path');
const PLUGIN_NAME = 'gulp-esdoc';
function gulpESDoc(config) {
if (!config) {
var cfgPath = path.join(process.cwd(), 'esdoc.json'),
data;
if (fs.existsSync(cfgPath)) {
data = fs.readFileSync(cfgPath, { encoding: 'utf8' });
config = !data ? {} : JSON.parse(data);
} else {
config = {};
}
}
var transform = function(file, encode, callback) {
if (!config.destination) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Must specify config.destination'));
return callback();
}
if (file.isStream()) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
return callback();
}
config.source = config.source || file.path;
callback();
};
var flush = function(callback) {
ESDoc.generate(config, publisher);
callback();
};
return through.obj(transform, flush);
}
// Export
module.exports = gulpESDoc;