Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Dec 15, 2013
0 parents commit 64604d2
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# editorconfig.org
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
20 changes: 20 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true
}
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- '0.10'
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
var crypto = require('crypto');
var path = require('path');
var es = require('event-stream');

function md5(str) {
return crypto.createHash('md5').update(str, 'utf8').digest('hex');
}

module.exports = function (data, options) {
return es.map(function (file, cb) {
var filename = md5(file.contents.toString()).slice(0, 8) + '.' + path.basename(file.path);
file.path = path.join(path.dirname(file.path), filename);
cb(null, file);
});
};
42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "gulp-rev",
"version": "0.0.0",
"description": "Static asset revisioning by prepending content hash to filenames: unicorn.css => 098f6bcd.unicorn.css",
"license": "MIT",
"repository": "sindresorhus/gulp-rev",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "http://sindresorhus.com"
},
"engines": {
"node": ">=0.8.0"
},
"scripts": {
"test": "mocha"
},
"files": [
"index.js"
],
"keywords": [
"gulpplugin",
"rev",
"revision",
"hash",
"optimize",
"version",
"versioning",
"cache",
"expire",
"static",
"asset",
"assets"
],
"dependencies": {
"event-stream": "~3.0.20"
},
"devDependencies": {
"gulp-util": "~2.1.3",
"mocha": "*"
}
}
34 changes: 34 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# [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)

> Static asset revisioning by prepending content hash to filenames
`unicorn.css` => `098f6bcd.unicorn.css`
Make sure to set the files to [never expire](http://developer.yahoo.com/performance/rules.html#expires) for this to have an effect.


## Install

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

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


## Example

```js
var gulp = require('gulp');
var rev = require('gulp-rev');

gulp.task('default', function () {
gulp.src('src/*.css')
.pipe(rev())
.pipe(gulp.dest('dist'));
});
```


## License

MIT © [Sindre Sorhus](http://sindresorhus.com)
19 changes: 19 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';
var assert = require('assert');
var path = require('path');
var gutil = require('gulp-util');
var rev = require('./index');

it('should rev files', function (cb) {
var stream = rev();

stream.on('data', function (data) {
assert.equal(data.path, '~/dev/foo/098f6bcd.unicorn.css');
cb();
});

stream.write(new gutil.File({
path: '~/dev/foo/unicorn.css',
contents: 'test'
}));
});

0 comments on commit 64604d2

Please sign in to comment.