Skip to content

Commit

Permalink
minor style tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 8, 2014
1 parent 58f9ee5 commit 1db39e6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
42 changes: 20 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var plugin = function () {
return cb();
}

// Save the old path for later...
// save the old path for later
file.revOrigPath = file.path;

var hash = md5(file.contents.toString()).slice(0, 8);
Expand All @@ -36,28 +36,26 @@ plugin.manifest = function () {
var manifest = {};
var firstFile = null;

return through.obj(
function (file, enc, cb) {
// Ignore all non-rev'd files.
if (file.path && file.revOrigPath) {
firstFile = firstFile || file;
manifest[file.revOrigPath.replace(firstFile.base, '')] = file.path.replace(firstFile.base, '');
}
cb();
},

function (cb) {
if (firstFile) {
this.push(new gutil.File({
cwd: firstFile.cwd,
base: firstFile.base,
path: path.join(firstFile.base, 'rev-manifest.json'),
contents: new Buffer(JSON.stringify(manifest, null, ' '))
}));
}
cb();
return through.obj(function (file, enc, cb) {
// ignore all non-rev'd files
if (file.path && file.revOrigPath) {
firstFile = firstFile || file;
manifest[file.revOrigPath.replace(firstFile.base, '')] = file.path.replace(firstFile.base, '');
}

cb();
}, function (cb) {
if (firstFile) {
this.push(new gutil.File({
cwd: firstFile.cwd,
base: firstFile.base,
path: path.join(firstFile.base, 'rev-manifest.json'),
contents: new Buffer(JSON.stringify(manifest, null, ' '))
}));
}
);

cb();
});
};

module.exports = plugin;
14 changes: 6 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [gulp](https://github.com/wearefractal/gulp)-rev [![Build Status](https://secure.travis-ci.org/sindresorhus/gulp-rev.png?branch=master)](http://travis-ci.org/sindresorhus/gulp-rev)
# [gulp](https://github.com/wearefractal/gulp)-rev [![Build Status](https://travis-ci.org/sindresorhus/gulp-rev.png?branch=master)](https://travis-ci.org/sindresorhus/gulp-rev)

> Static asset revisioning by appending content hash to filenames
`unicorn.css` => `unicorn-098f6bcd.css`
Expand All @@ -8,10 +8,8 @@ Make sure to set the files to [never expire](http://developer.yahoo.com/performa

## Install

Install with [npm](https://npmjs.org/package/gulp-rev)

```
npm install --save-dev gulp-rev
```bash
$ npm install --save-dev gulp-rev
```


Expand All @@ -28,7 +26,7 @@ gulp.task('default', function () {
});
```

Options are intentionally missing as the default should work in most cases.
*Options are intentionally missing as the default should work in most cases.*


### Original path
Expand All @@ -55,11 +53,11 @@ An asset manifest, mapping the original paths to the revisioned paths, will be w

```json
{
"unicorn.css": "unicorn-098f6bcd.css"
"unicorn.css": "unicorn-098f6bcd.css"
}
```


## License

MIT © [Sindre Sorhus](http://sindresorhus.com)
[MIT](http://opensource.org/licenses/MIT) © [Sindre Sorhus](http://sindresorhus.com)
5 changes: 3 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ it('should rev files', function (cb) {
}));
});

it('should build a rev manifest file', function(cb) {
it('should build a rev manifest file', function (cb) {
var stream = rev.manifest();

stream.on('data', function (newFile) {
assert.equal(newFile.relative, 'rev-manifest.json');
assert.deepEqual(
JSON.parse(String(newFile.contents)),
JSON.parse(newFile.contents.toString()),
{'unicorn.css': 'unicorn-d41d8cd9.css'}
);
cb();
Expand All @@ -34,6 +34,7 @@ it('should build a rev manifest file', function(cb) {
path: 'unicorn-d41d8cd9.css',
contents: new Buffer('')
});

file.revOrigPath = 'unicorn.css';

stream.write(file);
Expand Down

0 comments on commit 1db39e6

Please sign in to comment.