description and source-codegulp-todo = function (options) {
options = defaults(options || {}, {
fileName: 'TODO.md',
verbose: false,
absolute: false,
skipUnsupported: false,
reporter: 'markdown'
});
var config = omit(options, ['fileName', 'verbose', 'absolute']);
var firstFile;
var comments = [];
return through.obj(function collectTodos(file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new PluginError(pluginName, 'Streaming not supported'));
return;
}
firstFile = firstFile || file;
//get extension - assume .js as default
var ext = path.extname(file.path) || '.js';
//check if parser for filetype exists
if (!leasot.isExtSupported(ext)) {
if (!options.skipUnsupported) {
var msg = ['File:', file.path, '- Extension', gutil.colors.red(ext),
'is not supported'
].join(' ');
cb(new PluginError(pluginName, msg));
return;
} else if (options.verbose) {
var msg = ['Skipping file', file.path, 'with extension',
gutil.colors.red(ext), 'as it is unsupported'].join(' ');
gutil.log(msg);
}
cb();
return;
}
var filePath;
if (options.absolute) {
filePath = file.path;
} else {
filePath = file.path && file.relative || file.path;
}
var _comments = leasot.parse({
ext: ext,
content: file.contents.toString('utf8'),
fileName: filePath,
customTags: config.customTags,
withInlineFiles: config.withInlineFiles
});
if (options.verbose) {
logCommentsToConsole(_comments);
}
comments = comments.concat(_comments);
cb();
},
function reportTodos(cb) {
if (!firstFile) {
cb();
return;
}
var newContents;
try {
newContents = leasot.reporter(comments, config);
} catch (e) {
cb(new gutil.PluginError(pluginName, e));
return;
}
var todoFile = new gutil.File({
cwd: firstFile.cwd,
base: firstFile.base,
path: path.join(firstFile.base, options.fileName),
contents: new Buffer(newContents)
});
// also pass along comments object for future reporters
todoFile.todos = comments;
this.push(todoFile);
cb();
});
}