-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.js
65 lines (54 loc) · 1.66 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
'use strict';
var pkg = require('./package');
var PluginError = require('plugin-error');
var through = require('through2');
var path = require('path');
var File = require('vinyl');
// consts
module.exports = function(out, options) {
options = options || {};
var fileList = [];
return through.obj(function(file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new PluginError(pkg.name, 'Streams not supported'));
return;
}
var filePath;
if (options.absolute) {
filePath = path.normalize(file.path);
} else if (options.flatten) {
filePath = path.basename(file.path);
} else if (options.relative) {
filePath = file.relative;
} else {
filePath = path.relative(file.cwd, file.path);
}
if (options.removeExtensions) {
var extension = path.extname(filePath);
if (extension.length) {
filePath = filePath.slice(0, -extension.length);
}
}
filePath = filePath.replace(/\\/g, '/');
if (options.destRowTemplate && typeof options.destRowTemplate === 'string') {
fileList.push(options.destRowTemplate.replace(/\@filePath\@/g, filePath));
} else if (options.destRowTemplate && typeof options.destRowTemplate === 'function') {
fileList.push(options.destRowTemplate(filePath));
} else {
fileList.push(filePath);
}
cb();
}, function(cb) {
var buffer = (options.destRowTemplate) ? new Buffer(fileList.join('')) : new Buffer(JSON.stringify(fileList, null, ' '));
var fileListFile = new File({
path: out,
contents: buffer
});
this.push(fileListFile);
cb();
});
};