Skip to content

Commit

Permalink
Merge branch 'release/0.4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Holland committed Jul 29, 2014
2 parents e5e9750 + 5638a34 commit 39160c1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = function(grunt) {
},
rename: {
options: {
baseDir: 'tmp/',
baseDir: './tmp',
deleteOriginals: true,
jsonOutput: 'output/replace-cachebuster-map.json',
replaceTerms: [{
Expand Down
15 changes: 8 additions & 7 deletions tasks/cachebust.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,12 @@ module.exports = function(grunt) {
findStaticAssets(markup, filters, isCSS).forEach(function(reference) {
var newFilename;
var newFilePath;
var newReference;

var filePath = (opts.baseDir ? opts.baseDir : path.dirname(filepath)) + '/';
var filename = path.normalize((filePath + reference).split('?')[0]);
var extension = path.extname(filename);

if(opts.dir) {
filename = opts.dir + filename;
}

if(opts.ignorePatterns) {
var matched = opts.ignorePatterns.some(function(pattern) {
return new RegExp(pattern, 'ig').test(filename);
Expand Down Expand Up @@ -245,19 +242,23 @@ module.exports = function(grunt) {
// Create our new filename
newFilename = addHash(filename, hash, extension);

// Create the new reference
newReference = addHash(reference.replace(hashReplaceRegex, ''), hash, extension);

// Update the reference in the markup
markup = markup.replace(new RegExp(regexEscape(reference), 'g'), addHash(reference.replace(hashReplaceRegex, ''), hash, extension));
markup = markup.replace(new RegExp(regexEscape(reference), 'g'), newReference);

// Create our new file
grunt.file.copy(filename, newFilename);
}
} else {
newFilename = reference.split('?')[0] + '?' + generateHash(grunt.file.read(filename));
newReference = newFilename;
markup = markup.replace(new RegExp(regexEscape(reference), 'g'), newFilename);
}

if(newFilename) {
processedFileMap[filename] = newFilename.replace(opts.baseDir, '');
processedFileMap[filename] = newReference;
}
});

Expand All @@ -281,7 +282,7 @@ module.exports = function(grunt) {
var name = typeof opts.jsonOutput === 'string' ? opts.jsonOutput : opts.jsonOutputFilename;

grunt.log.writeln(['File map has been exported to ', opts.baseDir+name, '!'].join(''));
grunt.file.write(opts.baseDir + name, JSON.stringify(processedFileMap));
grunt.file.write(path.normalize(opts.baseDir +'/'+ name), JSON.stringify(processedFileMap));
}
});

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/replace.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h3>Heard what??</h3>

<h1>THE BIRD IS THE WORD!!</h1>

<script defer src="assets/replace.js" type="text/javascript"></script>
<script defer src="/assets/replace.js" type="text/javascript"></script>

</body>
</html>
4 changes: 2 additions & 2 deletions test/fixtures/standard.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h3>Heard what??</h3>

<h1>THE BIRD IS THE WORD!!</h1>

<script defer src="assets/standard.js" type="text/javascript"></script>
<script defer src="/assets/standard.js" type="text/javascript"></script>

</body>
</html>
</html>

0 comments on commit 39160c1

Please sign in to comment.