crxmake 1.0.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/Rakefile +2 -10
  2. data/bin/crxmake +26 -1
  3. data/lib/crxmake.rb +68 -5
  4. data/test/crxmake_test.rb +28 -5
  5. metadata +2 -2
data/Rakefile CHANGED
@@ -6,11 +6,8 @@ require 'rake/testtask'
6
6
  require 'rake/packagetask'
7
7
  require 'rake/gempackagetask'
8
8
  require 'rake/rdoctask'
9
- require 'rake/contrib/rubyforgepublisher'
10
9
  require 'rake/contrib/sshpublisher'
11
- require 'fileutils'
12
10
  require 'lib/crxmake'
13
- include FileUtils
14
11
 
15
12
  $version = CrxMake::VERSION
16
13
  $readme = 'README.rdoc'
@@ -78,14 +75,9 @@ task :gemspec do
78
75
  end
79
76
  end
80
77
 
81
- desc "gem build"
82
- task :build => [:gemspec] do
83
- sh "gem build #{$name}.gemspec"
84
- end
85
-
86
78
  desc "gem install"
87
- task :install => [:build] do
88
- sh "sudo gem install #{$name}-#{$version}.gem --local"
79
+ task :install => [:gem] do
80
+ sh "sudo gem install pkg/#{$name}-#{$version}.gem --local"
89
81
  end
90
82
 
91
83
  desc "gem uninstall"
data/bin/crxmake CHANGED
@@ -16,6 +16,11 @@ option not valid
16
16
  optional opt
17
17
  --extension-output=<extension output path>
18
18
  crx output path (default: ./<extension dirname>.crx)
19
+ --zip-output=<zip output path>
20
+ zip output path (default: ./<extension dirname>.zip)
21
+ if it isn't defined, crxmake is working on crx mode.
22
+ --mode=<zip or crx>
23
+ if it is defined, this value mode is priority.
19
24
  --pack-extension-key=<pem path>
20
25
  pem key path
21
26
  --key-output=<key path>
@@ -43,6 +48,16 @@ OptionParser.new('Packaging Chromium Extension') do |opt|
43
48
  opt.on('--extension-output CRX') do |crx|
44
49
  data[:crx_output] = crx
45
50
  end
51
+ opt.on('--zip-output ZIP') do |zip|
52
+ data[:zip_output] = zip
53
+ end
54
+ opt.on('--mode CORZ') do |corz|
55
+ if corz == 'zip'
56
+ data[:zip_flag] = true
57
+ elsif corz == 'crx'
58
+ data[:crx_flag] = true
59
+ end
60
+ end
46
61
  opt.on('--ignore-file FILE') do |file|
47
62
  data[:ignorefile] = Regexp.new file
48
63
  end
@@ -60,7 +75,17 @@ OptionParser.new('Packaging Chromium Extension') do |opt|
60
75
  end
61
76
 
62
77
  begin
63
- CrxMake.make(data)
78
+ if data[:crx_flag]
79
+ CrxMake.make data
80
+ elsif data[:zip_flag]
81
+ CrxMake.zip data
82
+ else
83
+ if data[:zip_output]
84
+ CrxMake.zip data
85
+ else
86
+ CrxMake.make data
87
+ end
88
+ end
64
89
  rescue => e
65
90
  puts e.message
66
91
  puts usage
data/lib/crxmake.rb CHANGED
@@ -9,7 +9,7 @@ require 'find'
9
9
  require 'pathname'
10
10
 
11
11
  class CrxMake < Object
12
- VERSION = '1.0.2'
12
+ VERSION = '2.0.0'
13
13
  @@magic = [?C, ?r, ?2, ?4].pack('C*')
14
14
  # this is chromium extension version
15
15
  @@version = [2].pack('L')
@@ -17,8 +17,13 @@ class CrxMake < Object
17
17
  # CERT_PUBLIC_KEY_INFO struct
18
18
  @@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*')
19
19
  @@key_size = 1024
20
+
20
21
  def initialize opt
21
- check_valid_option(opt)
22
+ @opt = opt
23
+ end
24
+
25
+ def make
26
+ check_valid_option @opt
22
27
  if @pkey
23
28
  read_key
24
29
  else
@@ -31,6 +36,18 @@ class CrxMake < Object
31
36
  final
32
37
  end
33
38
 
39
+ def zip
40
+ check_valid_option_zip @opt
41
+ unless @pkey
42
+ generate_key
43
+ @pkey = @pkey_o
44
+ end
45
+ create_zip do |zip|
46
+ puts "include pem key: \"#{@pkey}\"" if @verbose
47
+ zip.add_file('key.pem', @pkey)
48
+ end
49
+ end
50
+
34
51
  private
35
52
  def check_valid_option o
36
53
  @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]
@@ -66,12 +83,51 @@ class CrxMake < Object
66
83
  break unless File.directory?(@crx)
67
84
  end
68
85
  end
69
- @crx_dir = File.dirname(@crx)
70
86
  puts <<-EOS if @verbose
71
87
  crx output dir: \"#{@crx}\"
72
88
  ext dir: \"#{@exdir}\"
73
89
  EOS
74
- @zip = File.join(@crx_dir, 'extension.zip')
90
+ @zip = File.join(File.dirname(@crx), 'extension.zip')
91
+ end
92
+
93
+ def check_valid_option_zip o
94
+ @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]
95
+ @exdir = File.expand_path(@exdir) if @exdir
96
+ raise "extension dir not exist" if !@exdir || !File.exist?(@exdir) || !File.directory?(@exdir)
97
+ @pkey = File.expand_path(@pkey) if @pkey
98
+ raise "private key not exist" if @pkey && (!File.exist?(@pkey) || !File.file?(@pkey))
99
+ if @pkey_o
100
+ @pkey_o = File.expand_path(@pkey_o)
101
+ raise "private key output path is directory" if File.directory?(@pkey_o)
102
+ else
103
+ count = 0
104
+ loop do
105
+ if count.zero?
106
+ @pkey_o = File.expand_path("./#{File.basename(@exdir)}.pem")
107
+ else
108
+ @pkey_o = File.expand_path("./#{File.basename(@exdir)}-#{count+=1}.pem")
109
+ end
110
+ break unless File.directory?(@pkey_o)
111
+ end
112
+ end
113
+ if @zip
114
+ @zip = File.expand_path(@zip)
115
+ raise "crx path is directory" if File.directory?(@zip)
116
+ else
117
+ count = 0
118
+ loop do
119
+ if count.zero?
120
+ @zip = File.expand_path("./#{File.basename(@exdir)}.zip")
121
+ else
122
+ @zip = File.expand_path("./#{File.basename(@exdir)}-#{count+=1}.zip")
123
+ end
124
+ break unless File.directory?(@zip)
125
+ end
126
+ end
127
+ puts <<-EOS if @verbose
128
+ zip output dir: \"#{@zip}\"
129
+ ext dir: \"#{@exdir}\"
130
+ EOS
75
131
  end
76
132
 
77
133
  def read_key
@@ -113,6 +169,7 @@ ext dir: \"#{@exdir}\"
113
169
  end
114
170
  end
115
171
  end
172
+ yield zip if block_given?
116
173
  end
117
174
  puts <<-EOS if @verbose
118
175
  create zip...done
@@ -159,7 +216,13 @@ zip file at \"#{@zip}\"
159
216
  end
160
217
 
161
218
  class << self
162
- alias make new
219
+ def make opt
220
+ new(opt).make
221
+ end
222
+
223
+ def zip opt
224
+ new(opt).zip
225
+ end
163
226
  end
164
227
  end
165
228
 
data/test/crxmake_test.rb CHANGED
@@ -6,8 +6,9 @@ require 'open-uri'
6
6
 
7
7
  class CrxMakeTest < Test::Unit::TestCase
8
8
  def setup
9
- @dir = File.expand_path('tmp')
9
+ @dir = File.expand_path(@method_name)
10
10
  FileUtils.mkdir @dir
11
+ puts @dir
11
12
  # chromefullfeed compile
12
13
  open("http://chromefullfeed.googlecode.com/files/package.tar") do |file|
13
14
  File.open(File.join(@dir, 'package.tar'), 'wb') do |f|
@@ -22,14 +23,36 @@ class CrxMakeTest < Test::Unit::TestCase
22
23
  def test_create_crx
23
24
  CrxMake.make(
24
25
  :ex_dir => File.join(@dir, 'src'),
25
- :pkey_output => File.join(@dir, 'test.pem'),
26
- :crx_output => File.join(@dir, 'test.crx'),
26
+ :pkey_output => File.join(@dir, 'test_crx.pem'),
27
+ :crx_output => File.join(@dir, 'test_crx.crx'),
27
28
  :verbose => true,
28
29
  :ignorefile => /\.swp$/,
29
30
  :ignoredir => /^\.(?:svn|git|cvs)$/
30
31
  )
31
- assert(File.exist?(File.join(@dir, 'test.crx')))
32
- assert(File.exist?(File.join(@dir, 'test.pem')))
32
+ assert(File.exist?(File.join(@dir, 'test_crx.crx')))
33
+ assert(File.exist?(File.join(@dir, 'test_crx.pem')))
34
+ end
35
+ def test_create_zip
36
+ CrxMake.zip(
37
+ :ex_dir => File.join(@dir, 'src'),
38
+ :pkey_output => File.join(@dir, 'test_zip.pem'),
39
+ :zip_output => File.join(@dir, 'test_zip.zip'),
40
+ :verbose => true,
41
+ :ignorefile => /\.swp$/,
42
+ :ignoredir => /^\.(?:svn|git|cvs)$/
43
+ )
44
+ assert(File.exist?(File.join(@dir, 'test_zip.zip')))
45
+ assert(File.exist?(File.join(@dir, 'test_zip.pem')))
46
+ end
47
+ def test_create_crx_command
48
+ 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")
49
+ assert(File.exist?(File.join(@dir, 'test_crx.crx')))
50
+ assert(File.exist?(File.join(@dir, 'test_crx.pem')))
51
+ end
52
+ def test_create_zip_command
53
+ 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")
54
+ assert(File.exist?(File.join(@dir, 'test_zip.zip')))
55
+ assert(File.exist?(File.join(@dir, 'test_zip.pem')))
33
56
  end
34
57
  end
35
58
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crxmake
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Constellation
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-09 00:00:00 +09:00
12
+ date: 2009-12-03 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency