Created
July 14, 2014 23:10
-
-
Save mattallty/dc4be8a95ef06d1d8e06 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 modify(modifiers) { | |
| return through2.obj(function(file, encoding, done) { | |
| var stream = this; | |
| function applyModifiers(content) { | |
| (typeof modifiers === 'function' ? [modifiers] : modifiers).forEach(function(modifier) { | |
| content = modifier(content, file); | |
| }); | |
| return content; | |
| } | |
| function write(data) { | |
| file.contents = new Buffer(data); | |
| stream.push(file); | |
| done(); | |
| } | |
| if (file.isBuffer()) { | |
| write(applyModifiers(String(file.contents))); | |
| } else if (file.isStream()) { | |
| var buffer = ''; | |
| file.contents.on('data', function(chunk) { | |
| buffer += chunk; | |
| }); | |
| file.contents.on('end', function() { | |
| write(applyModifiers(String(buffer))); | |
| }); | |
| } | |
| }); | |
| } |
This file contains hidden or 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
| gulp.src('app.js') | |
| .pipe(modify(version)) | |
| .pipe(modify(swapStuff)) | |
| .pipe(gulp.dest('build/')); | |
| function version(data) { | |
| return data.replace(/__VERSION__/, '0.0.1'); | |
| } | |
| function swapStuff(data) { | |
| return data.replace(/(\w+)\s(\w+)/, '$2, $1'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment