forked from smysnk/gulp-rev-all
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (40 loc) · 1.4 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
var fs = require('fs');
var path = require('path');
var crypto = require('crypto');
var tools = require('./tools');
var through = require('through2');
var chalk = require('chalk');
var gutil = require('gulp-util');
module.exports = function(optionsIn) {
var options = optionsIn || {};
var first = true;
if(typeof options.hashLength === 'undefined'){
options.hashLength = 8;
}
return through.obj(function (file, enc, callback) {
if (options.rootDir === undefined) options.rootDir = file.base;
if (first) {
gutil.log('gulp-rev-all:', 'Root directory [', options.rootDir, ']');
first = !first;
}
if (file.isNull()) {
callback(null, file);
return;
} else if (file.isStream()) {
throw new Error('Streams are not supported!');
callback(null, file);
return;
}
// Only process references in these types of files, otherwise we'll corrupt images etc
switch(path.extname(file.path)) {
case '.js':
case '.css':
case '.html':
tools.revReferencesInFile(file, options);
}
var filenameReved = path.basename(tools.revFile(file.path, options));
var base = path.dirname(file.path);
file.path = path.join(base, filenameReved);
callback(null, file);
});
};