Created
March 27, 2014 09:21
-
-
Save chrismatheson/9803617 to your computer and use it in GitHub Desktop.
Gulp version things
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function version(prefix) { | |
'use strict'; | |
var stream = require('stream').Transform({objectMode: true}), | |
path = require('path'); | |
stream._transform = function(chunk, enc, next) { | |
if (chunk.isNull()) { | |
this.push(chunk); | |
return next(); | |
} | |
if (!path.extname(chunk.relative).match(/js|css/)) { | |
//skip all other file types | |
this.push(chunk); | |
return next(); | |
} | |
var oldFilename = path.basename(chunk.path); | |
var newFilename = prefix + path.basename(chunk.path); | |
var alteredPath = chunk.path.replace(oldFilename, newFilename); | |
console.log('renaming: ' + chunk.path + ' - to - ' + alteredPath); | |
chunk.path = alteredPath; | |
this.push(chunk); | |
return next(); | |
}; | |
return stream; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment