When using steal in production, you sometimes want to 'cache bust' your images in your CSS. Below is a script that you can add to your build script to accomplish this.
var window = (function() {
return this;
}).call(null, 0);
var modifyCss = function(css, str) {
str = str || Date.now().toString();
css = css.replace(/url\(['"]*([^"')]*)['"]*\)/g, function(match) {
return match.substring(0, match.length - 1) + '?v=' + str + ')';
});
return css;
},
fingerprint = function(path, str) {
var text = modifyCss( readFile(path), str );
steal.File(path).save(text);
}
var dir = new java.io.File('packages'),
files = (dir.isDirectory() && dir.listFiles().slice(0)) || [],
file, i;
if (dir) {
files.unshift('production.css');
for (i = 0; i < files.length && (file = files[i]); i++) {
if (/\.css$/.test(file)) {
steal.print('Fingerprinting ' + file);
fingerprint(file);
}
}
}