Skip to content

Commit

Permalink
fixed replace revved file in same directory as first
Browse files Browse the repository at this point in the history
  • Loading branch information
leornado committed May 5, 2015
1 parent 0a89f03 commit c9e8f5c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
test/temp
.idea
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# grunt-usemin-wnd
> Modified from grunt-usemin 4 personal use.
Fix usemin. Replace revved file in same directory as first priority.

```shell
|_dir1
|_a.css -> replace with 123456.t.png
|_t.png -> 123456.t.png
|_dir2
|_b.css -> replace with abcdef.t.png
|_t.png -> abcdef.t.png
```


# grunt-usemin [![Linux Build Status](https://img.shields.io/travis/yeoman/grunt-usemin/master.svg?style=flat&label=Linux%20build)](https://travis-ci.org/yeoman/grunt-usemin) [![Windows Build status](https://img.shields.io/appveyor/ci/addyosmani/grunt-usemin/master.svg?style=flat&label=Windows%20build)](https://ci.appveyor.com/project/addyosmani/grunt-usemin/branch/master)
[![Gitter](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/yeoman/grunt-usemin)

Expand Down
6 changes: 3 additions & 3 deletions lib/fileprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ FileProcessor.prototype.replaceWith = function replaceWith(block) {
// Replace reference to scripts, css, images, ... in +lines+ with their revved version
// If +lines+ is not furnished, use instead the cached version (i.e. stored at constructor time)
//
FileProcessor.prototype.replaceWithRevved = function replaceWithRevved(lines, assetSearchPath) {
FileProcessor.prototype.replaceWithRevved = function replaceWithRevved(lines, assetSearchPath, fromFile) {
// Replace script sources
var self = this;
var content = lines;
Expand All @@ -202,7 +202,7 @@ FileProcessor.prototype.replaceWithRevved = function replaceWithRevved(lines, as

debug('Looking for revved version of ' + srcFile + ' in ', assetSearchPath);

var file = self.finder.find(srcFile, assetSearchPath);
var file = self.finder.find(srcFile, assetSearchPath, fromFile);

debug('Found file \'%s\'', file);

Expand Down Expand Up @@ -236,7 +236,7 @@ FileProcessor.prototype.process = function (filename, assetSearchPath) {
this.file.searchPath = assetSearchPath;
}

var content = this.replaceWithRevved(this.replaceBlocks(this.file), this.file.searchPath);
var content = this.replaceWithRevved(this.replaceBlocks(this.file), this.file.searchPath, this.file);

return content;
};
5 changes: 4 additions & 1 deletion lib/revvedfinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ RevvedFinder.prototype.getRevvedCandidates = function (file, searchPaths) {
// name: which is the filename
// base: which is the directory from searchDirs where we found the file
//
RevvedFinder.prototype.find = function find(ofile, searchDirs) {
RevvedFinder.prototype.find = function find(ofile, searchDirs, fromFile) {
var file = ofile;
var searchPaths = searchDirs;
var absolute;
Expand Down Expand Up @@ -180,6 +180,9 @@ RevvedFinder.prototype.find = function find(ofile, searchDirs) {
});
}

if (file.indexOf('/') < 0) {
searchPaths = [fromFile.dir].concat(searchPaths);
}
var filepaths = this.getRevvedCandidates(file, searchPaths);

var filepath = filepaths[0];
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "grunt-usemin",
"version": "3.0.0",
"name": "grunt-usemin-wnd",
"version": "0.0.1",
"license": "BSD-2-Clause",
"author": "The Yeoman Team",
"description": "Replaces references to non-optimized scripts or stylesheets into a set of HTML files (or any templates/views).",
"author": "leornado",
"description": "Modified by grunt-usemin 4 personal use.",
"keywords": [
"gruntplugin",
"usemin",
Expand All @@ -12,13 +12,13 @@
"css",
"optimize"
],
"homepage": "https://github.com/yeoman/grunt-usemin",
"homepage": "https://github.com/leornado/grunt-usemin-wnd",
"repository": {
"type": "git",
"url": "https://github.com/yeoman/grunt-usemin.git"
"url": "https://github.com/leornado/grunt-usemin-wnd.git"
},
"bugs": {
"url": "https://github.com/yeoman/grunt-usemin/issues"
"url": "https://github.com/leornado/grunt-usemin-wnd/issues"
},
"scripts": {
"test": "grunt test"
Expand Down

0 comments on commit c9e8f5c

Please sign in to comment.