-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
39 lines (35 loc) · 1.14 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
'use strict';
var through = require('through2');
var path = require('path');
var PLUGIN_NAME = 'gulp-rev-outdated';
function plugin(keepQuantity) {
'use strict';
keepQuantity = parseInt(keepQuantity) || 2;
var lists = {};
return through.obj(function (file, enc, cb) {
var regex = new RegExp('^(.*)-[0-9a-f]{8,10}(?:\\.min)?\\' + path.extname(file.path) + '$');
if (regex.test(file.path)) {
var identifier = regex.exec(file.path)[1] + path.extname(file.path);
if (lists[identifier] === undefined) {
lists[identifier] = [];
}
lists[identifier].push({
file: file,
time: file.stat.mtime.getTime()
});
}
cb();
}, function (cb) {
Object.keys(lists).forEach(function (identifier) {
lists[identifier].sort(function (a, b) {
return b.time - a.time;
})
.slice(keepQuantity)
.forEach(function (f) {
this.push(f.file);
}, this);
}, this);
cb();
});
}
module.exports = plugin;