extensionator 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2a22eec1dab83496d1e50ee437c061d87330f6b
4
- data.tar.gz: 4abaf7a0a148b4b321ed75ee5f7abc466b930011
3
+ metadata.gz: 06b7a339386fc46ebe5b5e45787bbcef57c3c6fb
4
+ data.tar.gz: f816f69988245cf245a975825861570ecc1b1d9f
5
5
  SHA512:
6
- metadata.gz: 84db3cfaa4567b8772f429ca5788ee1170cf9d12254e0dee7fd4a337bb133551287159e31856fc4bbb4aa3985181c07a7cdb0b5373fc3256d49f2bcc239e6f55
7
- data.tar.gz: 4e943aacfde8127429399cc36eac94fd276217067a8264cdc967b6e12870c1fa12a114dd5d9ec41ce03b851028ab2d541ee6933697daa3ac0042036b3bd87812
6
+ metadata.gz: 44041e56d42bd22c208ccec61d3ac064051f3b4d9a7f18936ae3c2f014dc034d0db56562c3d63d083df03dab2811f87f405f20c50f813cb73c0184e3e5c1b344
7
+ data.tar.gz: 1576bc72c0fca068ed179ed386286c685b9d2719ab18bd9af4a0301062b54b9c9d1d43f67834b79a306ad45bc3fc706a6dcdb22b3ce95514eeaf0dd1ec8224cc
data/README.md CHANGED
@@ -1,4 +1,9 @@
1
- Package Chrome extensions with Ruby. Inspired by (Loosely based on? Stolen from?) [crxmake](https://github.com/Constellation/crxmake). Use the CLI or the Ruby API.
1
+ Package Chrome extensions with Ruby. Inspired by (Loosely based on? Stolen from?) [crxmake][crxmake-url]. Use the CLI or the Ruby API.
2
+
3
+ [![Gem Version][gem-img]][gem-url]
4
+ [![Gem Downloads][gem-dl-img]][gem-url]
5
+ [![Code Climate][code-climate-img]][code-climate-url]
6
+ [![License][license-img]][license-url]
2
7
 
3
8
  # Install
4
9
 
@@ -79,3 +84,15 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
79
84
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
80
85
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
81
86
  THE SOFTWARE.
87
+
88
+ [license-img]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
89
+ [license-url]: http://opensource.org/licenses/MIT
90
+
91
+ [code-climate-img]: https://img.shields.io/codeclimate/github/Zensight/extensionator.svg?style=flat-square
92
+ [code-climate-url]: https://codeclimate.com/github/Zensight/extensionator
93
+
94
+ [gem-img]: https://img.shields.io/gem/v/extensionator.svg?style=flat-square
95
+ [gem-dl-img]: https://img.shields.io/gem/dt/extensionator.svg?style=flat-square
96
+ [gem-url]: https://rubygems.org/gems/extensionator
97
+
98
+ [crxmake-url]: https://github.com/Constellation/crxmake
data/bin/extensionator CHANGED
@@ -1,35 +1,9 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require "slop"
4
-
5
3
  begin
6
- require "extensionator"
7
- rescue LoadError
8
4
  require_relative "../lib/extensionator"
5
+ rescue LoadError
6
+ require "extensionator"
9
7
  end
10
8
 
11
- opts = Slop.parse do |o|
12
- o.string "-d", "--directory", "Directory containing the extension. (Default: .)", default: "."
13
- o.string "-i", "--identity", "Location of the pem file to sign with. (Required)"
14
- o.string "-o", "--output", "Location of the output file. (Default: 'extension.crx')", default: "extension.crx"
15
- o.string "-e", "--exclude", "Regular expression for filenames to exclude. (Default: \.crx$)", default: nil
16
- o.on "-v", "--version", "Extensionator version info." do
17
- puts Extensionator::VERSION
18
- exit
19
- end
20
- o.on "-h", "--help", "Print this message." do
21
- puts o
22
- exit
23
- end
24
- end
25
-
26
- unless opts[:identity]
27
- puts("No identity file specified.")
28
- puts(opts)
29
- exit(-1)
30
- else
31
- Extensionator.create(opts[:directory],
32
- opts[:identity],
33
- opts[:output],
34
- exclude: opts[:exclude] ? Regexp.new(opts[:exclude]) : nil)
35
- end
9
+ Extensionator::CLI.start
data/lib/extensionator.rb CHANGED
@@ -1,71 +1,2 @@
1
- require "digest/sha1"
2
- require "find"
3
- require "openssl"
4
- require "pathname"
5
- require "zip"
6
-
7
- module Extensionator
8
- VERSION = "0.0.8"
9
-
10
- module Impl
11
- def self.create(dir, key_file, dest_filename, opts)
12
- priv_key = read_key(key_file)
13
- zip_str = zip(dir, opts)
14
- sig_bytes = sign(zip_str, priv_key)
15
- write(zip_str, sig_bytes, priv_key, dest_filename)
16
- end
17
-
18
- def self.read_key(key_file)
19
- OpenSSL::PKey::RSA.new(File.read(key_file))
20
- end
21
-
22
- def self.zip(dir, opts = {})
23
- Zip::File.add_buffer do |zip|
24
- Find.find(dir) do |path|
25
- case
26
- when path == dir
27
- next
28
- when (opts[:exclude] && path =~ opts[:exclude])
29
- Find.prune
30
- when File.directory?(path)
31
- zip.mkdir(relative_path(dir, path))
32
- else
33
- zip.add(relative_path(dir, path), path)
34
- end
35
- end
36
- end.string
37
- end
38
-
39
- def self.sign(zip_str, priv_key)
40
- priv_key.sign(OpenSSL::Digest::SHA1.new, zip_str)
41
- end
42
-
43
- def self.write(zip_str, sig_bytes, priv_key, dest_filename)
44
- pub_key_bytes = priv_key.public_key.to_der
45
-
46
- #See https://developer.chrome.com/extensions/crx for the format description
47
- File.open(dest_filename, "wb") do |file|
48
- file << "Cr24"
49
- file << format_size(2)
50
- file << format_size(pub_key_bytes.size)
51
- file << format_size(sig_bytes.size)
52
- file << pub_key_bytes
53
- file << sig_bytes
54
- file << zip_str
55
- end
56
- end
57
-
58
- def self.relative_path(base, target)
59
- from, to = [base, target].map(&Pathname.method(:new))
60
- to.relative_path_from(from).to_s
61
- end
62
-
63
- def self.format_size(num)
64
- [num].pack("V")
65
- end
66
- end
67
-
68
- def self.create(dir, key_file, dest_filename, opts = {exclude: /\.crx$/})
69
- Impl.create(dir, key_file, dest_filename, opts)
70
- end
71
- end
1
+ require_relative "extensionator/extensionator"
2
+ require_relative "extensionator/cli"
@@ -0,0 +1,33 @@
1
+ require "slop"
2
+
3
+ module Extensionator
4
+ module CLI
5
+ def self.start
6
+ opts = Slop.parse do |o|
7
+ o.string "-d", "--directory", "Directory containing the extension. (Default: .)", default: "."
8
+ o.string "-i", "--identity", "Location of the pem file to sign with. (Required)"
9
+ o.string "-o", "--output", "Location of the output file. (Default: 'extension.crx')", default: "extension.crx"
10
+ o.string "-e", "--exclude", "Regular expression for filenames to exclude. (Default: \.crx$)", default: nil
11
+ o.on "-v", "--version", "Extensionator version info." do
12
+ puts Extensionator::VERSION
13
+ exit
14
+ end
15
+ o.on "-h", "--help", "Print this message." do
16
+ puts o
17
+ exit
18
+ end
19
+ end
20
+
21
+ unless opts[:identity]
22
+ puts("No identity file specified.")
23
+ puts(opts)
24
+ exit(-1)
25
+ else
26
+ Extensionator.create(opts[:directory],
27
+ opts[:identity],
28
+ opts[:output],
29
+ exclude: opts[:exclude] ? Regexp.new(opts[:exclude]) : nil)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,71 @@
1
+ require "digest/sha1"
2
+ require "find"
3
+ require "openssl"
4
+ require "pathname"
5
+ require "zip"
6
+
7
+ module Extensionator
8
+ VERSION = "0.0.9"
9
+
10
+ module Impl
11
+ def self.create(dir, key_file, dest_filename, opts)
12
+ priv_key = read_key(key_file)
13
+ zip_str = zip(dir, opts)
14
+ sig_bytes = sign(zip_str, priv_key)
15
+ write(zip_str, sig_bytes, priv_key, dest_filename)
16
+ end
17
+
18
+ def self.read_key(key_file)
19
+ OpenSSL::PKey::RSA.new(File.read(key_file))
20
+ end
21
+
22
+ def self.zip(dir, opts = {})
23
+ Zip::File.add_buffer do |zip|
24
+ Find.find(dir) do |path|
25
+ case
26
+ when path == dir
27
+ next
28
+ when (opts[:exclude] && path =~ opts[:exclude])
29
+ Find.prune
30
+ when File.directory?(path)
31
+ zip.mkdir(relative_path(dir, path))
32
+ else
33
+ zip.add(relative_path(dir, path), path)
34
+ end
35
+ end
36
+ end.string
37
+ end
38
+
39
+ def self.sign(zip_str, priv_key)
40
+ priv_key.sign(OpenSSL::Digest::SHA1.new, zip_str)
41
+ end
42
+
43
+ def self.write(zip_str, sig_bytes, priv_key, dest_filename)
44
+ pub_key_bytes = priv_key.public_key.to_der
45
+
46
+ #See https://developer.chrome.com/extensions/crx for the format description
47
+ File.open(dest_filename, "wb") do |file|
48
+ file << "Cr24"
49
+ file << format_size(2)
50
+ file << format_size(pub_key_bytes.size)
51
+ file << format_size(sig_bytes.size)
52
+ file << pub_key_bytes
53
+ file << sig_bytes
54
+ file << zip_str
55
+ end
56
+ end
57
+
58
+ def self.relative_path(base, target)
59
+ from, to = [base, target].map(&Pathname.method(:new))
60
+ to.relative_path_from(from).to_s
61
+ end
62
+
63
+ def self.format_size(num)
64
+ [num].pack("V")
65
+ end
66
+ end
67
+
68
+ def self.create(dir, key_file, dest_filename, opts = {exclude: /\.crx$/})
69
+ Impl.create(dir, key_file, dest_filename, opts)
70
+ end
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extensionator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Cambron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-19 00:00:00.000000000 Z
11
+ date: 2015-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -64,6 +64,8 @@ files:
64
64
  - bin/extensionator
65
65
  - extensionator.gemspec
66
66
  - lib/extensionator.rb
67
+ - lib/extensionator/cli.rb
68
+ - lib/extensionator/extensionator.rb
67
69
  homepage: http://github.com/zensight/extensionator/
68
70
  licenses:
69
71
  - MIT