Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-rev-all

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-rev-all - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

2

package.json
{
"name": "gulp-rev-all",
"version": "0.2.2",
"version": "0.3.0",
"description": "Static asset revisioning by appending content hash to filenames: unicorn.css => unicorn-098f6bcd.css, also re-writes references in each file to new reved name.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -109,3 +109,3 @@ # [gulp](https://github.com/wearefractal/gulp)-rev-all [![Build Status](https://travis-ci.org/smysnk/gulp-rev-all.png?branch=master)](https://travis-ci.org/smysnk/gulp-rev-all)

Change the length of the hash appended to the end of each file:
Change the length of the hash appended to the end of each revisioned file (use `options.transformFilename` for more complicated scenarios).

@@ -125,3 +125,3 @@ ```js

Prefixes matched files with a string (use `options.transform` for more complicated scenarios). Useful for adding a full url path to files.
Prefixes matched files with a string (use `options.transformReference` for more complicated scenarios). Useful for adding a full url path to files.

@@ -136,3 +136,3 @@ ```js

#### options.transform
#### options.transformPath

@@ -154,3 +154,3 @@ Type: `function (rev, source, path)`

.pipe(revall({
transform: function (rev, source, path) {
transformPath: function (rev, source, path) {
// on the remote server, image files are served from `/images`

@@ -164,2 +164,28 @@ return rev.replace('/img', '/images');

#### options.transformFilename
Type: `function (filePath)`
Default: `none`
If the default naming convention does not suite your needs, you can specify a custom filename transform.
The function takes one argument:
- `filePath` - path to file to be revisioned
```js
var path = require('path');
gulp.task('default', function () {
gulp.src('dist/**')
.pipe(revall({
transformFilename: function (filePath) {
var contents = fs.readFileSync(filePath).toString();
var hash = this.md5(contents).slice(0, 5);
var ext = path.extname(filePath);
return hash + '.' + path.basename(filePath, ext) + ext; // 3410c.filename.ext
}
}))
.pipe(gulp.dest('dist'))
});
```
## Tips

@@ -166,0 +192,0 @@

@@ -66,5 +66,5 @@ var revall = require("../index");

describe("hash length", function() {
describe("filename", function() {
it("should have proper length when specified", function(done) {
it("should have proper hash length when specified", function(done) {

@@ -81,2 +81,23 @@ stream = revall({rootDir: 'test/fixtures/config1', hashLength: 4, ignore: []});

it("should be transformed when transform function is specified", function(done) {
stream = revall({
rootDir: 'test/fixtures/config1',
ignore: [],
transformFilename: function (filePath) {
var contents = fs.readFileSync(filePath).toString();
var hash = this.md5(contents).slice(0, 5);
var ext = path.extname(filePath);
return hash + '.' + path.basename(filePath, ext) + ext; // 3410c.filename.ext
}
});
stream.on('data', function (file) {
path.basename(file.path).should.match(/[a-z0-9]{5}\..*\.[a-z]{2,4}$/);
});
stream.on('end', done);
writeFile();
});
});

@@ -200,3 +221,3 @@

rootDir:'test/fixtures/config1',
transform: function (reved, source, path) {
transformPath: function (reved, source, path) {
return this.joinUrlPath('//images.example.com/', reved.replace('img/', ''));

@@ -203,0 +224,0 @@ }

@@ -43,3 +43,4 @@ var fs = require('fs');

filenameReved,
ext = path.extname(filePath);
ext = path.extname(filePath),
self = this;

@@ -49,5 +50,9 @@ if (isFileIgnored(filePath)) {

} else {
var contents = fs.readFileSync(filePath).toString();
var hash = md5(contents).slice(0, options.hashLength);
filename = path.basename(filePath, ext) + '.rev.' + hash + ext;
if (options.transformFilename) {
filename = options.transformFilename.call(self, filePath);
} else {
var contents = fs.readFileSync(filePath).toString();
var hash = md5(contents).slice(0, options.hashLength);
filename = path.basename(filePath, ext) + '.' + hash + ext;
}
}

@@ -70,4 +75,4 @@

var newPath = path.join(path.dirname(source), path.basename(self.revFile(fullpath)));
if (options.transform) {
newPath = options.transform.call(self, newPath, source, fullpath);
if (options.transformPath) {
newPath = options.transformPath.call(self, newPath, source, fullpath);
} else if (!relative && options.prefix) {

@@ -118,2 +123,3 @@ newPath = self.joinUrlPath(options.prefix, newPath);

return {
md5: md5,
joinUrlPath: joinUrlPath,

@@ -120,0 +126,0 @@ revFile: revFile,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc