-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (31 loc) · 1.06 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
'use strict';
const through = require('through2');
const modifyFilename = require('modify-filename');
const util = require('gulp-util');
module.exports = (option) => {
return through.obj(transform, flush);
function transform(file, encoding, callback) {
if (file.isNull()) {
callback(null, file);
return;
}
if ((file.revOrigPath === undefined) || (file.revHash === undefined)) {
callback(new util.PluginError('gulp-rev-format-re', 'File was not passed through "gulp-rev"'));
return;
}
if (typeof (option) !== 'string') {
callback(new util.PluginError('gulp-rev-format-re', 'option should be string with accepted values.'));
return;
}
file.path = modifyFilename(file.revOrigPath, function (originalName, ext) {
let filename = option;
filename = filename.replace(/\[\%\s*?filename\s*?\%\]/, originalName);
filename = filename.replace(/\[\%\s*?rev\s*?\%\]/, file.revHash);
return filename + ext;
});
callback(null, file);
}
function flush(callback) {
callback();
}
};