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

Commit

Permalink
simplify some code
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 22, 2015
1 parent 2f9d798 commit 26ffe8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 5 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ var gutil = require('gulp-util');
var through = require('through2');
var objectAssign = require('object-assign');
var file = require('vinyl-file');

function md5(str) {
return crypto.createHash('md5').update(str).digest('hex');
}
var revHash = require('rev-hash');
var revPath = require('rev-path');

function relPath(base, filePath) {
if (filePath.indexOf(base) !== 0) {
Expand Down Expand Up @@ -45,11 +43,8 @@ function transformFilename(file) {
// save the old path for later
file.revOrigPath = file.path;
file.revOrigBase = file.base;

var hash = file.revHash = md5(file.contents).slice(0, 8);
var ext = path.extname(file.path);
var filename = path.basename(file.path, ext) + '-' + hash + ext;
file.path = path.join(path.dirname(file.path), filename);
file.revHash = revHash(file.contents).slice(0, 8);
file.path = revPath(file.path, file.revHash);
}

var plugin = function () {
Expand Down Expand Up @@ -98,10 +93,7 @@ var plugin = function () {
file.revOrigBase = file.base;

var hash = pathMap[reverseFilename];
var origPath = path.join(path.dirname(file.path), path.basename(file.path, '.map'));
var ext = path.extname(origPath);
var filename = path.basename(origPath, ext) + '-' + hash + ext + '.map';
file.path = path.join(path.dirname(origPath), filename);
file.path = revPath(file.path.replace(/\.map$/, ''), hash) + '.map';
} else {
transformFilename(file);
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"dependencies": {
"gulp-util": "^3.0.0",
"object-assign": "^2.0.0",
"rev-hash": "^1.0.0",
"rev-path": "^1.0.0",
"through2": "^0.6.1",
"vinyl-file": "^1.1.0"
},
Expand Down

0 comments on commit 26ffe8d

Please sign in to comment.