gulp-check-unused-image
Advanced tools
Comparing version 1.0.1 to 1.0.2
54
index.js
@@ -7,5 +7,7 @@ 'use strict'; | ||
var imageObjs = {}, | ||
imageObj = {}, | ||
imageFileObj = {}; | ||
var variable; | ||
var variable, | ||
imageType, | ||
imageCheck; | ||
var imageTypeArray = [".jpg",".gif",".bmp",".png",".tif",".raw","psd"]; | ||
@@ -16,7 +18,14 @@ var checkImageVariable = function(string){ | ||
if( node.type == "Literal" && variable.indexOf('.png')!== - 1 ){ | ||
if(variable.indexOf("http")!== -1){ | ||
if( node.type == "Literal" ){ | ||
imageCheck = isImageFile(variable); | ||
if(imageCheck){ | ||
imageType = imageCheck; | ||
}else if(variable.indexOf("http")!== -1){ | ||
return ; | ||
}else{ | ||
return; | ||
} | ||
variable = variable.substr(0 ,variable.indexOf('.png')+4); | ||
variable = variable.substr(0 ,variable.indexOf(imageType)+4); | ||
variable = variable.substr(variable.lastIndexOf("/")+1,variable.length); | ||
@@ -26,3 +35,3 @@ variable = variable.replace(/'/gi, ''); | ||
if( variable!== ".png" ){ | ||
if( variable!== imageType ){ | ||
if( imageObjs[variable] >= 1 ){ | ||
@@ -39,2 +48,21 @@ imageObjs[variable] ++; | ||
var isImageFile = function( stringFIle ){ | ||
if(stringFIle.indexOf(imageTypeArray[0]) !== -1){ | ||
return imageTypeArray[0]; | ||
}else if(stringFIle.indexOf(imageTypeArray[1]) !== -1){ | ||
return imageTypeArray[1]; | ||
}else if(stringFIle.indexOf(imageTypeArray[2]) !== -1){ | ||
return imageTypeArray[2]; | ||
}else if(stringFIle.indexOf(imageTypeArray[3]) !== -1){ | ||
return imageTypeArray[3]; | ||
}else if(stringFIle.indexOf(imageTypeArray[4]) !== -1){ | ||
return imageTypeArray[4]; | ||
}else if(stringFIle.indexOf(imageTypeArray[5]) !== -1){ | ||
return imageTypeArray[5]; | ||
}else if(stringFIle.indexOf(imageTypeArray[6]) !== -1){ | ||
return imageTypeArray[6]; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
@@ -47,3 +75,3 @@ module.exports = function( file, opt ){ | ||
try { | ||
imageObj = checkImageVariable(file.contents.toString()); | ||
checkImageVariable(file.contents.toString()); | ||
@@ -53,5 +81,9 @@ this.push( file ); | ||
var imageFile = file.relative; | ||
if( imageFile.indexOf(".png")!== -1 ){ | ||
if(isImageFile(imageFile)){ | ||
var imageFileName = imageFile.substr(imageFile.lastIndexOf("\\")+1,imageFile.length); | ||
//console.log("imageFile = "+imageFileName); | ||
if( imageFileObj[imageFileName] >= 1 ){ | ||
@@ -64,7 +96,7 @@ imageFileObj[imageFileName] ++; | ||
} | ||
callback( null, imageObj ); | ||
callback( null ); | ||
}, function( callback ){ | ||
for( var key in imageFileObj ){ | ||
if(!imageObj[key]){ | ||
if(!imageObjs[key]){ | ||
gutil.log('gulp-check-unused-image: Not use file ' + gutil.colors.blue(key) + ' in your project'); | ||
@@ -74,3 +106,3 @@ } | ||
for( var key in imageObj ){ | ||
for( var key in imageObjs ){ | ||
if(!imageFileObj[key]){ | ||
@@ -77,0 +109,0 @@ gutil.log('gulp-check-unused-image: Not use variable ' + gutil.colors.magenta(key) + ' in your project'); |
{ | ||
"name": "gulp-check-unused-image", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Check unused image files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# gulp-check-unused-image | ||
In your project, you will add lots of images you don't know. This plugin will help you check unused image files in your code | ||
Support Type : jpg,gif,bmp,png,tif,raw,psd | ||
``` | ||
//example | ||
// if you have 'sample.png' file, it try to match your code | ||
var image_file = "/image/sample.png"; | ||
``` | ||
## Usage | ||
@@ -36,2 +44,3 @@ | ||
#### 2017/02/07 - 1.0.0 - First release | ||
#### 2017/02/07 - 1.0.1 - Release Readme.md | ||
#### 2017/02/07 - 1.0.1 - Release Readme.md | ||
#### 2017/02/08 - 1.0.2 - Add image types (jpg,gif,bmp,tif,raw,psd) |
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
24969
89
45