Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-md5

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-md5 - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

test/fixtures/expand/file1.js

46

Gruntfile.js

@@ -42,3 +42,3 @@ // For testing callbacks.

files: {
'test/fixtures/output/main': 'test/fixtures/test.js'
'test/fixtures/output/main/': 'test/fixtures/test.js'
},

@@ -52,3 +52,3 @@ options: {

files: {
'test/fixtures/output/noExtension': 'test/fixtures/test.js'
'test/fixtures/output/noExtension/': 'test/fixtures/test.js'
},

@@ -62,7 +62,7 @@ options: {

files: {
'test/fixtures/output/noBasename': 'test/fixtures/test.js'
'test/fixtures/output/noBasename/': 'test/fixtures/test.js'
},
options: {
keepExtension: true,
keepBasename: false
keepBasename: false
}

@@ -72,12 +72,42 @@ },

files: {
'test/fixtures/output/noBasenameOrExtension': 'test/fixtures/test.js'
'test/fixtures/output/noBasenameOrExtension/': 'test/fixtures/test.js'
},
options: {
keepExtension: false,
keepBasename: false
keepBasename: false
}
},
internationalCharacters: {
files: {
'test/fixtures/output/internationalCharacters/': 'test/fixtures/international.js'
},
options: {
encoding: 'utf8',
keepExtension: true,
keepBasename: true
}
},
expandFiles: {
files: [
{
expand: true,
cwd: 'test/fixtures/expand/',
src: [
'*.js'
],
dest: 'test/fixtures/output/expand/js/'
},
{
expand: true,
cwd: 'test/fixtures/expand/',
src: [
'*.css'
],
dest: 'test/fixtures/output/expand/css/'
}
]
},
afterEach: {
files: {
'test/fixtures/output/callback': 'test/fixtures/test.js'
'test/fixtures/output/callback/': 'test/fixtures/test.js'
},

@@ -94,3 +124,3 @@ options: {

files: {
'test/fixtures/output/after': ['test/fixtures/test.js', 'test/fixtures/test2.js']
'test/fixtures/output/after/': ['test/fixtures/test.js', 'test/fixtures/test2.js']
},

@@ -97,0 +127,0 @@ options: {

2

package.json
{
"name": "grunt-md5",
"description": "generate md5 filename",
"version": "0.1.7",
"version": "0.1.8",
"homepage": "https://github.com/jney/grunt-md5",

@@ -6,0 +6,0 @@ "author": {

@@ -26,2 +26,3 @@ [![build status](https://secure.travis-ci.org/jney/grunt-md5.png)](http://travis-ci.org/jney/grunt-md5)

options: {
encoding: 'utf8',
keepBasename: true,

@@ -59,5 +60,6 @@ keepExtension: true,

## Release History
* 0.1.7 Grunt 0.4.0 ready. `after` parameter.
* 0.1.8 Encoding option, enhancements in directories management (#12, #13, #14)
* 0.1.7 Grunt 0.4.0 ready. `after` parameter. (#9)
* 0.1.5 Support for keeping the original file's basename
* 0.1.4 Compatibility with grunt 0.4
* 0.1.4 Compatibility with grunt 0.4 (#7, #8)
* 0.1.1 Fixing many files handling

@@ -64,0 +66,0 @@ * 0.0.1 First Release

@@ -21,29 +21,21 @@ /*

grunt.registerMultiTask('md5', 'Generate a md5 filename', function() {
var destDir;
// file object : {newPath: /***/, oldPath: /***/, content: /***/}
var currentFile;
var options = this.options();
var options = this.options({
encoding: 'utf8'
});
grunt.verbose.writeflags(options, 'Options');
this.files.forEach(function(file) {
this.files.forEach(function(filePair) {
var isExpandedPair = filePair.orig.expand || false;
// Keep track of processedFiles so we can call the `after` callback if needed.
var processedFiles = [];
if (typeof file.src === 'undefined') {
if (typeof filePair.src === 'undefined') {
grunt.fail.warn('Files object doesn\'t exist');
}
if (!grunt.file.exists(file.dest)) {
grunt.file.mkdir(file.dest);
grunt.verbose.writeln('Directory \'' + file.dest + '\' created.');
}
var srcFiles = grunt.file.expand(file.src);
var destDir = grunt.file.expand(file.dest)[0];
grunt.verbose.writeln('Files: ' + file.src);
grunt.verbose.writeln('Destination directory: \'' + destDir + '\'');
srcFiles.forEach(function(srcFile) {
filePair.src.forEach(function(srcFile) {
try {

@@ -54,3 +46,3 @@ var basename = '';

var filename;
var srcCode = grunt.file.read(srcFile);
var srcCode = grunt.file.read(srcFile, {encoding: options.encoding});

@@ -70,7 +62,11 @@ // keep extension unless you explicitly tell to not

createHash('md5').
update(srcCode).
update(srcCode, options.encoding).
digest('hex') + ext;
destFile = path.join(file.dest, filename);
var regex = new RegExp(escapeRegExp(path.basename(srcFile)) + "$");
if (detectDestType(filePair.dest) === 'directory') {
destFile = (isExpandedPair) ? filePair.dest.replace(regex, filename) : unixifyPath(path.join(filePair.dest, filename));
} else {
destFile = filePair.dest.replace(regex, filename);
}
grunt.file.copy(srcFile, destFile);

@@ -106,3 +102,26 @@

});
// From grunt-contrib-copy
var detectDestType = function(dest) {
if (grunt.util._.endsWith(dest, '/')) {
return 'directory';
} else {
return 'file';
}
};
// From grunt-contrib-copy
var unixifyPath = function(filepath) {
if (process.platform === 'win32') {
return filepath.replace(/\\/g, '/');
} else {
return filepath;
}
};
// http://stackoverflow.com/a/3561711
var escapeRegExp = function(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
};
};

@@ -12,3 +12,3 @@ 'use strict';

createHash('md5').
update(grunt.file.read('test/fixtures/test.js')).
update(grunt.file.read('test/fixtures/test.js', {encoding: 'utf8'}), 'utf8').
digest('hex') + '.js';

@@ -25,3 +25,3 @@

createHash('md5').
update(grunt.file.read('test/fixtures/test.js')).
update(grunt.file.read('test/fixtures/test.js', {encoding: 'utf8'}), 'utf8').
digest('hex');

@@ -38,3 +38,3 @@

createHash('md5').
update(grunt.file.read('test/fixtures/test.js')).
update(grunt.file.read('test/fixtures/test.js', {encoding: 'utf8'}), 'utf8').
digest('hex') + '.js';

@@ -51,3 +51,3 @@

createHash('md5').
update(grunt.file.read('test/fixtures/test.js')).
update(grunt.file.read('test/fixtures/test.js', {encoding: 'utf8'}), 'utf8').
digest('hex');

@@ -59,2 +59,32 @@

},
internationalCharacters: function(test) {
test.expect(1);
var md5Filename = 'international-' + require('crypto').
createHash('md5').
update(grunt.file.read('test/fixtures/international.js', {encoding: 'utf8'}), 'utf8').
digest('hex') + '.js';
test.ok(grunt.file.exists('test/fixtures/output/internationalCharacters/' + md5Filename),
'should generate correct MD5 filename for contents with international characters');
test.done();
},
expandFiles: function(test) {
test.expect(4);
var filePath = 'test/fixtures/output/expand/js/file1-d41d8cd98f00b204e9800998ecf8427e.js';
test.ok(grunt.file.isFile(filePath), 'should generate js files not directories');
filePath = 'test/fixtures/output/expand/js/file2-d41d8cd98f00b204e9800998ecf8427e.js';
test.ok(grunt.file.isFile(filePath), 'should generate js files not directories');
filePath = 'test/fixtures/output/expand/css/file3-d41d8cd98f00b204e9800998ecf8427e.css';
test.ok(grunt.file.isFile(filePath), 'should generate css files not directories');
filePath = 'test/fixtures/output/expand/css/file4-d41d8cd98f00b204e9800998ecf8427e.css';
test.ok(grunt.file.isFile(filePath), 'should generate css files not directories');
test.done();
},
afterEach: function(test) {

@@ -61,0 +91,0 @@ test.expect(1);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc