Skip to content

Commit 8fc62c7

Browse files
committed
0.0.5: Add support for multiple filename\'s prefixes
2 parents 9d98825 + 2627c72 commit 8fc62c7

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ gulp.task('clean', function() {
4444
});
4545
```
4646

47+
It's also possible to pass in all your asset files at once:
48+
49+
```js
50+
[...]
51+
52+
gulp.task('clean', function() {
53+
gulp.src( ['dist/**/*.*'], {read: false})
54+
.pipe( revOutdated(1) ) // leave 1 latest asset file for every file name prefix.
55+
.pipe( cleaner() );
56+
57+
return;
58+
});
59+
```
60+
4761
gulp.src option read false prevents gulp to read the contents of the file and makes this task a lot faster. If you need the file and it's contents after cleaning in the same stream, do not set the read option to false.
4862

4963
### Works with gulp-rev-outdated
@@ -54,4 +68,4 @@ gulp.src option read false prevents gulp to read the contents of the file and ma
5468

5569
## License
5670

57-
[MIT](http://opensource.org/licenses/MIT) © [Oleksandr Ovcharenko](mailto:shonny.ua@gmail.com)
71+
[MIT](http://opensource.org/licenses/MIT) © [Oleksandr Ovcharenko](mailto:shonny.ua@gmail.com)

index.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,28 @@ function plugin(keepQuantity) {
1313
return through.obj(function (file, enc, cb) {
1414
var regex = new RegExp('^(.*)-[0-9a-f]{8}\\' + path.extname(file.path) + '$');
1515
if (regex.test(file.path)) {
16-
var n = regex.exec(file.path)[1];
17-
if (lists[n] === undefined) {
18-
lists[n] = [];
16+
var identifier = regex.exec(file.path)[1];
17+
if (lists[identifier] === undefined) {
18+
lists[identifier] = [];
1919
}
20-
lists[n].push({
20+
lists[identifier].push({
2121
file: file,
2222
time: file.stat.ctime.getTime()
2323
});
2424
}
2525
cb();
2626
}, function (cb) {
27-
var t = this;
28-
Object.keys(lists).forEach(function (val) {
29-
lists[val].sort(function (a, b) {
30-
return b.time - a.time;
31-
})
27+
Object.keys(lists).forEach(function (identifier) {
28+
lists[identifier].sort(function (a, b) {
29+
return b.time - a.time;
30+
})
3231
.slice(keepQuantity)
3332
.forEach(function (f) {
34-
t.push(f.file);
35-
}, t);
36-
});
33+
this.push(f.file);
34+
}, this);
35+
}, this);
3736
cb();
3837
});
3938
}
4039

41-
module.exports = plugin;
40+
module.exports = plugin;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gulp-rev-outdated",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "Old static asset revision files filter",
55
"license": "MIT",
66
"repository": {

0 commit comments

Comments
 (0)