Skip to content

Commit

Permalink
* version 2.0.0
Browse files Browse the repository at this point in the history
* creating zip file for Google Chrome Extension Gallery is available
  • Loading branch information
Constellation committed Dec 3, 2009
1 parent c484ffe commit cbc653c
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pkg/
*.swp
*.bak
*.orig
12 changes: 2 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/contrib/rubyforgepublisher'
require 'rake/contrib/sshpublisher'
require 'fileutils'
require 'lib/crxmake'
include FileUtils

$version = CrxMake::VERSION
$readme = 'README.rdoc'
Expand Down Expand Up @@ -78,14 +75,9 @@ task :gemspec do
end
end

desc "gem build"
task :build => [:gemspec] do
sh "gem build #{$name}.gemspec"
end

desc "gem install"
task :install => [:build] do
sh "sudo gem install #{$name}-#{$version}.gem --local"
task :install => [:gem] do
sh "sudo gem install pkg/#{$name}-#{$version}.gem --local"
end

desc "gem uninstall"
Expand Down
27 changes: 26 additions & 1 deletion bin/crxmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ option not valid
optional opt
--extension-output=<extension output path>
crx output path (default: ./<extension dirname>.crx)
--zip-output=<zip output path>
zip output path (default: ./<extension dirname>.zip)
if it isn't defined, crxmake is working on crx mode.
--mode=<zip or crx>
if it is defined, this value mode is priority.
--pack-extension-key=<pem path>
pem key path
--key-output=<key path>
Expand Down Expand Up @@ -43,6 +48,16 @@ OptionParser.new('Packaging Chromium Extension') do |opt|
opt.on('--extension-output CRX') do |crx|
data[:crx_output] = crx
end
opt.on('--zip-output ZIP') do |zip|
data[:zip_output] = zip
end
opt.on('--mode CORZ') do |corz|
if corz == 'zip'
data[:zip_flag] = true
elsif corz == 'crx'
data[:crx_flag] = true
end
end
opt.on('--ignore-file FILE') do |file|
data[:ignorefile] = Regexp.new file
end
Expand All @@ -60,7 +75,17 @@ OptionParser.new('Packaging Chromium Extension') do |opt|
end

begin
CrxMake.make(data)
if data[:crx_flag]
CrxMake.make data
elsif data[:zip_flag]
CrxMake.zip data
else
if data[:zip_output]
CrxMake.zip data
else
CrxMake.make data
end
end
rescue => e
puts e.message
puts usage
Expand Down
73 changes: 68 additions & 5 deletions lib/crxmake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
require 'pathname'

class CrxMake < Object
VERSION = '1.0.2'
VERSION = '2.0.0'
@@magic = [?C, ?r, ?2, ?4].pack('C*')
# this is chromium extension version
@@version = [2].pack('L')

# CERT_PUBLIC_KEY_INFO struct
@@key_algo = %w(30 81 9F 30 0D 06 09 2A 86 48 86 F7 0D 01 01 01 05 00 03 81 8D 00).map{|s| s.hex}.pack('C*')
@@key_size = 1024

def initialize opt
check_valid_option(opt)
@opt = opt
end

def make
check_valid_option @opt
if @pkey
read_key
else
Expand All @@ -31,6 +36,18 @@ def initialize opt
final
end

def zip
check_valid_option_zip @opt
unless @pkey
generate_key
@pkey = @pkey_o
end
create_zip do |zip|
puts "include pem key: \"#{@pkey}\"" if @verbose
zip.add_file('key.pem', @pkey)
end
end

private
def check_valid_option o
@exdir, @pkey, @pkey_o, @crx, @verbose, @ignorefile, @ignoredir = o[:ex_dir], o[:pkey], o[:pkey_output], o[:crx_output], o[:verbose], o[:ignorefile], o[:ignoredir]
Expand Down Expand Up @@ -66,12 +83,51 @@ def check_valid_option o
break unless File.directory?(@crx)
end
end
@crx_dir = File.dirname(@crx)
puts <<-EOS if @verbose
crx output dir: \"#{@crx}\"
ext dir: \"#{@exdir}\"
EOS
@zip = File.join(@crx_dir, 'extension.zip')
@zip = File.join(File.dirname(@crx), 'extension.zip')
end

def check_valid_option_zip o
@exdir, @pkey, @pkey_o, @zip, @verbose, @ignorefile, @ignoredir = o[:ex_dir], o[:pkey], o[:pkey_output], o[:zip_output], o[:verbose], o[:ignorefile], o[:ignoredir]
@exdir = File.expand_path(@exdir) if @exdir
raise "extension dir not exist" if !@exdir || !File.exist?(@exdir) || !File.directory?(@exdir)
@pkey = File.expand_path(@pkey) if @pkey
raise "private key not exist" if @pkey && (!File.exist?(@pkey) || !File.file?(@pkey))
if @pkey_o
@pkey_o = File.expand_path(@pkey_o)
raise "private key output path is directory" if File.directory?(@pkey_o)
else
count = 0
loop do
if count.zero?
@pkey_o = File.expand_path("./#{File.basename(@exdir)}.pem")
else
@pkey_o = File.expand_path("./#{File.basename(@exdir)}-#{count+=1}.pem")
end
break unless File.directory?(@pkey_o)
end
end
if @zip
@zip = File.expand_path(@zip)
raise "crx path is directory" if File.directory?(@zip)
else
count = 0
loop do
if count.zero?
@zip = File.expand_path("./#{File.basename(@exdir)}.zip")
else
@zip = File.expand_path("./#{File.basename(@exdir)}-#{count+=1}.zip")
end
break unless File.directory?(@zip)
end
end
puts <<-EOS if @verbose
zip output dir: \"#{@zip}\"
ext dir: \"#{@exdir}\"
EOS
end

def read_key
Expand Down Expand Up @@ -113,6 +169,7 @@ def create_zip
end
end
end
yield zip if block_given?
end
puts <<-EOS if @verbose
create zip...done
Expand Down Expand Up @@ -159,7 +216,13 @@ def final
end

class << self
alias make new
def make opt
new(opt).make
end

def zip opt
new(opt).zip
end
end
end

Expand Down
33 changes: 28 additions & 5 deletions test/crxmake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

class CrxMakeTest < Test::Unit::TestCase
def setup
@dir = File.expand_path('tmp')
@dir = File.expand_path(@method_name)
FileUtils.mkdir @dir
puts @dir
# chromefullfeed compile
open("http://chromefullfeed.googlecode.com/files/package.tar") do |file|
File.open(File.join(@dir, 'package.tar'), 'wb') do |f|
Expand All @@ -22,14 +23,36 @@ def teardown
def test_create_crx
CrxMake.make(
:ex_dir => File.join(@dir, 'src'),
:pkey_output => File.join(@dir, 'test.pem'),
:crx_output => File.join(@dir, 'test.crx'),
:pkey_output => File.join(@dir, 'test_crx.pem'),
:crx_output => File.join(@dir, 'test_crx.crx'),
:verbose => true,
:ignorefile => /\.swp$/,
:ignoredir => /^\.(?:svn|git|cvs)$/
)
assert(File.exist?(File.join(@dir, 'test.crx')))
assert(File.exist?(File.join(@dir, 'test.pem')))
assert(File.exist?(File.join(@dir, 'test_crx.crx')))
assert(File.exist?(File.join(@dir, 'test_crx.pem')))
end
def test_create_zip
CrxMake.zip(
:ex_dir => File.join(@dir, 'src'),
:pkey_output => File.join(@dir, 'test_zip.pem'),
:zip_output => File.join(@dir, 'test_zip.zip'),
:verbose => true,
:ignorefile => /\.swp$/,
:ignoredir => /^\.(?:svn|git|cvs)$/
)
assert(File.exist?(File.join(@dir, 'test_zip.zip')))
assert(File.exist?(File.join(@dir, 'test_zip.pem')))
end
def test_create_crx_command
system("bin/crxmake --pack-extension='#{File.join(@dir, 'src')}' --extension-output='#{File.join(@dir, 'test_crx.crx')}' --key-output='#{File.join(@dir, 'test_crx.pem')}' --verbose")
assert(File.exist?(File.join(@dir, 'test_crx.crx')))
assert(File.exist?(File.join(@dir, 'test_crx.pem')))
end
def test_create_zip_command
system("bin/crxmake --pack-extension='#{File.join(@dir, 'src')}' --zip-output='#{File.join(@dir, 'test_zip.zip')}' --key-output='#{File.join(@dir, 'test_zip.pem')}' --verbose")
assert(File.exist?(File.join(@dir, 'test_zip.zip')))
assert(File.exist?(File.join(@dir, 'test_zip.pem')))
end
end

0 comments on commit cbc653c

Please sign in to comment.