tools/zip-crx.js

This commit is contained in:
ccd0 2016-04-10 03:33:54 -07:00
parent 14f32a7dec
commit 39f4e05520
2 changed files with 25 additions and 20 deletions

View File

@ -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'

21
tools/zip-crx.js Normal file
View File

@ -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);