From 39f4e05520efba54c4bb50167d78c3a913df4843 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 10 Apr 2016 03:33:54 -0700 Subject: [PATCH] tools/zip-crx.js --- Gruntfile.coffee | 24 ++++-------------------- tools/zip-crx.js | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 tools/zip-crx.js diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 8e0fa632f..9e2f98180 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -1,6 +1,5 @@ path = require 'path' crx = require 'crx' -JSZip = require 'jszip' module.exports = (grunt) -> grunt.util.linefeed = '\n' @@ -97,6 +96,7 @@ module.exports = (grunt) -> node tools/cat.js src/meta/botproc.js LICENSE src/meta/usestrict.js tmp/script-crx.js testbuilds/crx<%= pkg.channel %>/script.js <%= icons.map(file => `node tools/cp.js src/meta/${file} testbuilds/crx${pkg.channel}/${file}`).join('&&') %> node tools/cp.js tmp/eventPage.js testbuilds/crx<%= pkg.channel %>/eventPage.js + node tools/zip-crx.js <%= pkg.channel %> """.split('\n').join('&&') 'copy-zip': command: 'node tools/cp.js testbuilds/<%= pkg.name %>-noupdate.crx.zip testbuilds/<%= pkg.name %>.zip' @@ -204,33 +204,17 @@ module.exports = (grunt) -> 'concurrent:build' ] - grunt.registerTask 'build-crx-channel', [ - 'shell:crx-channel' - 'zip-crx' - ] - grunt.registerTask 'build-crx', [ 'shell:crx' 'set-channel' - 'build-crx-channel' + 'shell:crx-channel' 'set-channel:-beta' - 'build-crx-channel' + 'shell:crx-channel' 'set-channel:-noupdate' - 'build-crx-channel' + 'shell:crx-channel' 'shell:copy-zip' ] - grunt.registerTask 'zip-crx', 'Pack CRX contents in ZIP file', -> - pkg = grunt.config 'pkg' - zip = new JSZip() - for file in ['eventPage.js', 'icon128.png', 'icon16.png', 'icon48.png', 'manifest.json', 'script.js'] - zip.file file, grunt.file.read("testbuilds/crx#{pkg.channel}/#{file}", {encoding: null}), {date: new Date(pkg.meta.date)} - output = zip.generate - type: 'nodebuffer' - compression: 'DEFLATE' - compressionOptions: {level: 9} - grunt.file.write "testbuilds/#{pkg.name}#{pkg.channel}.crx.zip", output - grunt.registerTask 'sign-channel', 'Sign CRX package', (channel='') -> done = @async() pkg = grunt.config 'pkg' diff --git a/tools/zip-crx.js b/tools/zip-crx.js new file mode 100644 index 000000000..519b0046b --- /dev/null +++ b/tools/zip-crx.js @@ -0,0 +1,21 @@ +var fs = require('fs'); +var JSZip = require('jszip'); + +var pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); +var v = JSON.parse(fs.readFileSync('version.json', 'utf8')); +var channel = process.argv[2] || ''; + +var zip = new JSZip(); +for (file of ['eventPage.js', 'icon128.png', 'icon16.png', 'icon48.png', 'manifest.json', 'script.js']) { + zip.file( + file, + fs.readFileSync(`testbuilds/crx${channel}/${file}`), + {date: new Date(v.date)} + ); +} +output = zip.generate({ + type: 'nodebuffer', + compression: 'DEFLATE', + compressionOptions: {level: 9}, +}); +fs.writeFileSync(`testbuilds/${pkg.name}${channel}.crx.zip`, output);