-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
35 lines (33 loc) · 1.13 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
'use strict';
const _ = require('lodash');
const through = require('through2');
const Docer = require('react-prop-table');
const PluginError = require('gulp-util').PluginError;
const logger = require('linglog')('gulp-react-prop-table', {
timeFormat: 'HH:mm:ss'
});
const path = require('path');
const DEFAULT_OPTS = {
template: '# <%= path %>\n\n<%= contents %>'
};
module.exports = opts => {
opts = _.defaults(opts || {}, DEFAULT_OPTS);
return through.obj((file, encoding, callback) => {
if (file.isNull()) return callback(null, file);
if (file.isStream()) {
logger.error(`Stream is not supported: ${file.path}`);
return callback(new PluginError('gulp-react-prop-table', `Stream is not supported`));
}
try {
file.contents = new Buffer(_.template(opts.template)({
path: path.relative(process.cwd(), file.path),
contents: Docer.markdown(file.contents.toString(), opts)
}));
file.path = file.path.replace(path.extname(file.path), '.md');
callback(null, file);
} catch (e) {
logger.warn(`Fail on file ${file.path}: ${e.message}`);
callback(null);
}
});
};