diff --git a/Gruntfile.js b/Gruntfile.js index 1603816e..c156a67a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -348,6 +348,14 @@ module.exports = function(grunt) { options: { archive: 'dist/desktop/UpdateDesktop.zip' }, files: [{ cwd: 'tmp/desktop/app', src: '**', expand: true }] } + }, + 'validate-desktop-update': { + desktop: { + options: { + file: 'dist/desktop/UpdateDesktop.zip', + expected: ['main.js', 'app.js', 'index.html', 'package.json', 'node_modules/node-stream-zip/node_stream_zip.js'] + } + } } }); @@ -376,6 +384,7 @@ module.exports = function(grunt) { 'copy:desktop_app_content', 'string-replace:desktop_html', 'compress:desktop_update', + 'validate-desktop-update', 'electron', 'electron_builder', 'compress:linux', diff --git a/grunt/tasks/grunt-validate-desktop-update.js b/grunt/tasks/grunt-validate-desktop-update.js new file mode 100644 index 00000000..17246313 --- /dev/null +++ b/grunt/tasks/grunt-validate-desktop-update.js @@ -0,0 +1,31 @@ +'use strict'; + +module.exports = function (grunt) { + grunt.registerMultiTask('validate-desktop-update', 'Validates desktop update package', function () { + var path = require('path'); + var done = this.async(); + var StreamZip = require(path.resolve(__dirname, '../../electron/node_modules/node-stream-zip')); + var zip = new StreamZip({ file: this.options().file, storeEntries: true }); + var expFiles = this.options().expected; + zip.on('error', function(err) { + grunt.warn(err); + }); + zip.on('ready', function() { + var valid = true; + expFiles.forEach(function(entry) { + try { + if (!zip.entryDataSync(entry)) { + grunt.warn('Corrupted entry in desktop update archive: ' + entry); + valid = false; + } + } catch (e) { + grunt.warn('Entry not found in desktop update archive: ' + entry); + valid = false; + } + }); + if (valid) { + done(); + } + }); + }); +};