grunt-digest
Advanced tools
Comparing version 0.1.2 to 1.0.0
{ | ||
"name": "grunt-digest", | ||
"description": "Create digested copies of assets and add mapping to a manifest. Useful with rails applications", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/zendesk/grunt-digest", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -6,3 +6,3 @@ # grunt-digest | ||
## Getting Started | ||
This plugin requires Grunt `~0.4.1` | ||
This plugin requires Grunt `~0.4.1` and has been tested with Rails 4. | ||
@@ -9,0 +9,0 @@ If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: |
@@ -11,2 +11,4 @@ /* | ||
var fs = require("fs"); | ||
module.exports = function(grunt) { | ||
@@ -20,3 +22,3 @@ | ||
path = require('path'), | ||
filemap = {}, | ||
filemap = { files: {}, assets: {} }, | ||
tally = 0, | ||
@@ -29,7 +31,8 @@ options; | ||
separator: '-', | ||
algorithm: 'md5' | ||
algorithm: 'md5', | ||
basePath: false | ||
}); | ||
this.filesSrc.forEach(function(filepath) { | ||
var data, file, ext, base, digest, fileDigest, filepathDigest; | ||
var data, file, ext, base, digest, stats, fileDigest, filepathDigest, fileWithPath; | ||
@@ -40,6 +43,14 @@ file = path.basename(filepath); | ||
if(options.basePath) { | ||
fileWithPath = path.relative(options.basePath, filepath); | ||
base = fileWithPath.substr(0, fileWithPath.lastIndexOf('.')); | ||
} else { | ||
fileWithPath = file; | ||
} | ||
data = grunt.file.read(filepath); | ||
stats = fs.statSync(filepath); | ||
digest = crypto.createHash(options.algorithm).update(data).digest('hex'); | ||
fileDigest = [base, options.separator, digest, ext].join(''); | ||
filepathDigest = filepath.replace(file, fileDigest); | ||
filepathDigest = filepath.replace([base, ext].join(''), fileDigest); | ||
@@ -50,3 +61,9 @@ //Copy file | ||
//Add file to map | ||
filemap[file] = fileDigest; | ||
filemap.files[fileDigest] = { | ||
digest: digest, | ||
mtime: new Date(stats.mtime).toISOString(), | ||
size: stats.size, | ||
logical_path: file | ||
}; | ||
filemap.assets[fileWithPath] = fileDigest; | ||
grunt.verbose.writeln(file.cyan + ' -> ' + fileDigest.cyan); | ||
@@ -53,0 +70,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
18693
155
0
1
1