gulp-rev-all
Advanced tools
Comparing version 0.5.2 to 0.5.3
{ | ||
"name": "gulp-rev-all", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"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", |
73
test.js
@@ -19,2 +19,3 @@ var revall = require("./index"); | ||
var tool; | ||
var stream; | ||
@@ -26,3 +27,3 @@ var base = path.join(__dirname, 'test/fixtures/config1'); | ||
stream.write(new gutil.File({ | ||
path: path.join(__dirname, fileName), | ||
path: path.resolve(fileName), | ||
contents: fs.readFileSync(fileName), | ||
@@ -66,3 +67,2 @@ base: base | ||
file.path.should.not.equal(fileStyleBaseline.path); | ||
console.log(file.path, fileStyleBaseline.path); | ||
@@ -467,6 +467,37 @@ }); | ||
beforeEach(function (done) { | ||
tool = toolFactory({hashLength: 8, ignore: ['favicon.ico'], dirRoot: path.join(__dirname, 'test/fixtures/config1') }); | ||
tool = toolFactory({ hashLength: 8, ignore: ['favicon.ico'], dirRoot: path.join(__dirname, 'test/fixtures/config1') }); | ||
stream = revall(); | ||
done(); | ||
}); | ||
it("should resolve references to regular commonjs include", function(done) { | ||
stream.on('data', function (file) { | ||
var revedReference = path.basename(tool.revisionFile(getFile('test/fixtures/config1/layout.js')).path); | ||
String(file.contents).should.containEql(revedReference); | ||
String(file.contents).should.containEql('./'); | ||
done(); | ||
}); | ||
writeFile(path.join(base, 'application.js')); | ||
}); | ||
it("should resolve references to short style commonjs include", function(done) { | ||
stream.on('data', function (file) { | ||
var revedReference = path.basename(tool.revisionFile(getFile('test/fixtures/config1/short.js')).path); | ||
String(file.contents).should.containEql(revedReference); | ||
String(file.contents).should.containEql('./'); | ||
done(); | ||
}); | ||
writeFile(path.join(base, 'application.js')); | ||
}); | ||
@@ -487,4 +518,40 @@ it("should resolve references to angularjs views", function(done) { | ||
it("should resolve references to compiled templates", function(done) { | ||
stream.on('data', function (file) { | ||
var revedReference = path.basename(tool.revisionFile(getFile('test/fixtures/config1/img/image1.jpg')).path); | ||
String(file.contents).should.containEql(revedReference); | ||
done(); | ||
}); | ||
writeFile(path.join(base, 'application.js')); | ||
}); | ||
}); | ||
describe('tool', function() { | ||
describe('joinPath', function() { | ||
it("should correct windows style slashes", function() { | ||
var pathMock = { | ||
join: function() {} | ||
}; | ||
var joinStub = sinon.stub(pathMock, "join"); | ||
joinStub.returns('\\long\\widows\\path\\images.png'); | ||
var tool = toolFactory({ dirRoot: path.join(__dirname, 'test/fixtures/config1'), path: pathMock }); | ||
tool.joinPath().should.equal('/long/widows/path/images.png'); | ||
}); | ||
}); | ||
}); | ||
}); |
'use strict'; | ||
var Layout = require('./layout.js'); | ||
var Short = require('/short.js'); | ||
define(['app'], function (app) { | ||
@@ -23,2 +26,18 @@ | ||
directives.logo = function () { | ||
return { | ||
restrict: "E", | ||
replace: true, | ||
template: "<img src=\"img/image1.jpg\" />test</h1>", | ||
link: function (scope, element, attrs, interfacePanel) { | ||
}, | ||
controller: function ($scope, $snapshot) { | ||
} | ||
}; | ||
}; | ||
app.directive(directives); | ||
@@ -25,0 +44,0 @@ |
39
tool.js
var gracefulfs = require('graceful-fs'); | ||
var path = require('path'); | ||
var patho = require('path'); | ||
var crypto = require('crypto'); | ||
@@ -12,2 +12,3 @@ var gutil = require('gulp-util'); | ||
var fs = options.fs || gracefulfs; | ||
var path = options.path || patho; | ||
@@ -19,9 +20,9 @@ var joinPathUrl = function (prefix, path) { | ||
}; | ||
this.joinPathUrl = joinPathUrl; | ||
this.joinPathUrl = joinPathUrl; // Make it available to transformPath callback | ||
// Fix slash style for our poor windows brothern | ||
var joinPath = function (directory, filename) { | ||
return path.join(directory, filename).replace('\\', '/'); | ||
return path.join(directory, filename).replace(/\\/g, '/'); | ||
}; | ||
this.joinPath = joinPath; | ||
this.joinPath = joinPath; // Make it available to transformPath callback | ||
@@ -70,2 +71,7 @@ var isFileIgnored = function (file) { | ||
// Add back the relative reference so we don't break commonjs style includes | ||
if (reference.indexOf('./') === 0) { | ||
newPath = './' + newPath; | ||
} | ||
var msg = isRelative ? 'relative' : 'root'; | ||
@@ -86,3 +92,3 @@ gutil.log('gulp-rev-all:', 'Found', msg, 'reference [', reference, '] -> [', newPath, ']'); | ||
var filepathRegex = /.*?(?:\'|\"|\()([a-z0-9_@\-\/\.]+?\.[a-z]{2,4})(?:(?:\?|\#)[^'")]*?|)(?:\'|\"|\)).*?/ig; | ||
var filepathRegex = /(?:\'|\\\"|\"|\()([a-z0-9_@\-\/\.]{2,})/ig; | ||
@@ -107,3 +113,16 @@ if (typeof cache[file.path] === 'undefined') { | ||
gutil.log('gulp-rev-all:', 'Finding references in [', file.path, ']'); | ||
var isBinary = false; | ||
var length = (file.contents.length > 50) ? 50 : file.contents.length; | ||
for (var i = 0; i < length; i++) { | ||
if (file.contents[i] === 0) { | ||
isBinary = true; | ||
break; | ||
} | ||
} | ||
if (isBinary) { | ||
gutil.log('gulp-rev-all:', 'Skipping binary file [', file.path, ']'); | ||
} else { | ||
gutil.log('gulp-rev-all:', 'Finding references in [', file.path, ']'); | ||
} | ||
@@ -115,3 +134,3 @@ // Create a map of file references and their proper revisioned name | ||
while (result = filepathRegex.exec(contents)) { | ||
while ((result = filepathRegex.exec(contents)) && !isBinary) { | ||
@@ -131,6 +150,10 @@ var reference = result[1]; | ||
isRelative: true | ||
}, | ||
{ // Cover common.js short form edge case (find better way for this in the future) | ||
path: joinPath(path.dirname(file.path), reference + '.js'), | ||
isRelative: true | ||
} | ||
]; | ||
// If it starts with slash, assume it's absolute | ||
// If it starts with slash, try absolute first | ||
if (reference.substr(0,1) === '/') referencePaths.reverse(); | ||
@@ -137,0 +160,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
480129
27
636