Created
November 14, 2014 12:34
-
-
Save monolithed/46e2ed4488efcc2d15b6 to your computer and use it in GitHub Desktop.
Hash-sum file (grunt-dirsum)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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