keeweb/build/tasks/grunt-sign-dist.js

43 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-06-01 16:53:51 +02:00
module.exports = function (grunt) {
grunt.registerMultiTask('sign-dist', 'Creates files signatures', async function () {
2019-01-07 18:33:21 +01:00
const path = require('path');
const crypto = require('crypto');
const sign = require('../util/sign');
const done = this.async();
const opt = this.options();
const results = [];
for (const file of this.files) {
grunt.log.writeln(`Calculating sha256 for ${file.src.length} files...`);
for (const src of file.src) {
const basename = path.basename(src);
const file = grunt.file.read(src, { encoding: null });
const hash = crypto.createHash('sha256');
hash.update(file);
const digest = hash.digest('hex');
const rawSignature = await sign(grunt, file);
const signature = rawSignature.toString('hex');
results.push({ basename, digest, signature });
grunt.log.writeln(basename);
}
2019-08-18 08:05:38 +02:00
grunt.file.write(
file.dest,
2020-06-01 16:53:51 +02:00
results.map((line) => `${line.digest} *${line.basename}`).join('\n')
2019-08-18 08:05:38 +02:00
);
grunt.file.write(
opt.sign,
2020-06-01 16:53:51 +02:00
results.map((line) => `${line.signature} *${line.basename}`).join('\n')
2019-08-18 08:05:38 +02:00
);
2019-01-07 18:33:21 +01:00
}
done();
});
};