Skip to content

Instantly share code, notes, and snippets.

@monolithed
Created November 14, 2014 12:34
Show Gist options
  • Save monolithed/46e2ed4488efcc2d15b6 to your computer and use it in GitHub Desktop.
Save monolithed/46e2ed4488efcc2d15b6 to your computer and use it in GitHub Desktop.
Hash-sum file (grunt-dirsum)
const fs = require('fs'),
dirsum = require('dirsum')
;
module.exports = function (grunt) {
grunt.registerMultiTask('hash', 'Hash-sum file.', function () {
const done = this.async();
var options = this.options({
algorithm: 'md5'
});
this.files.forEach(function (files) {
var file = files.src[0];
dirsum.digest(file, options.algorithm, function(error, data) {
var json = JSON.stringify(data, null, '\t');
fs.writeFile(files.dest, json, function (error) {
if (error) {
grunt.log.errorlns(error);
}
else {
grunt.log.oklns('File "' + files.dest + '" created');
done();
}
});
});
}, this);
});
};
/*
// Gruntfile config
module.exports = function (grunt, options) {
return {
production: {
options: {
algorithm: 'md5'
},
files: [
{
'build/sum.json': 'build'
}
]
}
};
};
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment