-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
66 lines (52 loc) · 1.55 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* gulp-license-finder
* https://github.com/iandotkelly/gulp-license-finder
*
* Copyright (c) 2014 Ian Kelly
* Licensed under the MIT license.
*/
var gutil = require('gulp-util');
var File = gutil.File;
var nlf = require('nlf');
var path = require('path');
var PluginError = gutil.PluginError;
var Stream = require('stream');
// Consts
var PLUGIN_NAME = 'gulp-license-finder';
function licenseFinder(filename, options) {
// if the filename is an object, then
// we will assume this is just an options
// object
if (typeof filename === 'object') {
options = filename;
filename = options.filename;
}
// set default options
filename = filename || 'licenses.txt';
options = options || {};
options.directory = options.directory || process.cwd();
options.production = options.production || false;
options.csv = options.csv || false;
options.depth = options.depth; // undefined is the default
options.summaryMode = options.summaryMode || 'simple';
var stream = new Stream();
nlf.find(options, function (err, data) {
if (err) {
throw new gutil.PluginError(PLUGIN_NAME, err, {showStack: true});
}
var formatter = options.csv ? nlf.csvFormatter : nlf.standardFormatter;
formatter.render(data, options,function (err, output) {
if (err) {
throw new gutil.PluginError(PLUGIN_NAME, err, {showStack: true});
}
var file = new File({
path: path.join(process.cwd(), filename),
contents: new Buffer(output)
});
stream.emit('data', file);
stream.emit('finish');
});
});
return stream;
}
module.exports = licenseFinder;