Comparing version 0.0.3 to 0.0.5
20
index.js
@@ -32,3 +32,4 @@ /** | ||
repeat: 10, | ||
cleanup: true // true means it will clean old files when they are regenerated by new commands (helpful with 'watch' plugin) | ||
cleanup: true, // true means it will clean old files when they are regenerated by new commands (helpful with 'watch' plugin) | ||
hash: true // enable/disable revision hashing. can be helpful during development if you don't want hashes in filenames | ||
}; | ||
@@ -50,3 +51,3 @@ | ||
function md5(str) { | ||
return crypto.createHash('md5').update(str, 'utf8').digest('hex').slice(0, 8); | ||
return defaults.hash ? crypto.createHash('md5').update(str, 'utf8').digest('hex').slice(0, 8) : undefined; | ||
} | ||
@@ -60,3 +61,4 @@ | ||
var assetPath = (opts.assetPath || defaults.assetPath); | ||
var output = assetPath + path.basename(defaults.manifest).replace(ext, '') + '-' + manifestRev + ext; | ||
var basePath = assetPath + path.basename(defaults.manifest).replace(ext, ''); | ||
var output = typeof manifestRev !== 'undefined' ? basePath + '-' + manifestRev + ext : basePath + ext; | ||
return output; | ||
@@ -95,3 +97,4 @@ }; | ||
var ext = path.extname(file.path); | ||
var filename = path.basename(file.path, ext) + '-' + hash + ext; | ||
var basePath = path.basename(file.path, ext); | ||
var filename = typeof hash !== 'undefined' ? basePath + '-' + hash + ext : basePath + ext; | ||
file.path = path.join(path.dirname(file.path), filename); | ||
@@ -103,2 +106,3 @@ | ||
// @TODO: Instead of this it could use "glob" module to regex delete files | ||
// Check for existing value and whether cleanup is set | ||
@@ -109,2 +113,10 @@ var existing = manifest[key]; | ||
fs.unlink(path.join(file.cwd, defaults.dest, existing.src)); | ||
} else if (defaults.cleanup && defaults.hash) { | ||
// Check if cleanup and hash enabled then we can remove any non hashed version from dest directory | ||
var nonHashPath = path.join(path.dirname(originalPath), basePath + ext).replace(base, ''); | ||
var absPath = path.join(file.cwd, defaults.dest, nonHashPath); | ||
fs.exists(absPath, function(exists) { | ||
if (!exists) return; | ||
fs.unlink(absPath); | ||
}); | ||
} | ||
@@ -111,0 +123,0 @@ |
{ | ||
"name": "gulp-asset", | ||
"version": "0.0.3", | ||
"version": "0.0.5", | ||
"description": "Gulp module for managing asset revisions and using multiple domains to server assets.", | ||
"homepage": "https://github.com/inlight-media/gulp-asset", | ||
"keywords": [ | ||
"gulpplugin" | ||
], | ||
"author": { | ||
@@ -7,0 +10,0 @@ "name": "Inlight Media", |
@@ -10,2 +10,4 @@ # gulp-asset | ||
- Assets always loaded from same domain | ||
- Detects broken asset urls during build process | ||
- Template engine agnostic | ||
@@ -50,3 +52,3 @@ Creates revision using md5 hash of file contents and replaces all occurances of path in referencing files. Also allows you to prefix asset urls for balancing across cdn domains. It will also ensure that a single file only ever comes from the one prefix so assets aren't double downloaded. | ||
<img src="assets://img/image.png"> | ||
<img src="asset://img/image.png"> | ||
@@ -53,0 +55,0 @@ Example CSS file |
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
11633
190
62