extensionator 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0982a1e409bdfb2925c89460766736c640d197f
4
+ data.tar.gz: eb3265de4354a1d3ed035b9133abfceae6ecda6f
5
+ SHA512:
6
+ metadata.gz: da1f07552fecc765f2ae2fccec22465cdfaaf777b6435a7f3c4744a54b601f23373e40a614c4acf73bc1746fba13c26eb8e399f3d89e9830c02be24836c1b6c0
7
+ data.tar.gz: 669a3f6f9cef4f9a0883cefb00718c7c0b81f561111dc111b8baa53668db577bd71d5bbae972c0eb8a4cb1d354d31a4bfd70380138fd77242374eb8355cd26fe
@@ -0,0 +1,27 @@
1
+ Package Chrome extensions with Ruby. Based on [crxmake](https://github.com/Constellation/crxmake).
2
+
3
+ # Install
4
+
5
+ ```
6
+ gem install extensionator
7
+ ```
8
+
9
+ # Use
10
+
11
+ You need a private key so sign the extension with, and this is a BYOK (bring your own key) library. So first, you need a PEM file. If you have one, cool. If not, do this:
12
+
13
+ ```
14
+ openssl genrsa -out key.pem 2048
15
+ ```
16
+
17
+ You'll also need a directory to package up. Extensionator doesn't pay any attention to the contents; it just repackages them. So if you're misssing a `manifest.json` or your files are encoded wrong or whatever, you won't find out until you tried to load the packed extension into Chrome. Then:
18
+
19
+ ```rb
20
+ Extensionator.create("directory_with_extension", "key.pem", "output_file.crx")
21
+ ```
22
+
23
+ You can also exclude files with a regex:
24
+
25
+ ```rb
26
+ Extensionator.create("dir", "key.pem", "output_file.crx", exclude: /\.md$/)
27
+ ```
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "extensionator"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.add_dependency "rubyzip"
7
+ spec.add_development_dependency "bundler", "~> 1.0"
8
+ spec.authors = ["Isaac Cambron"]
9
+ spec.description = "A Ruby tool for packaging Chrome extensions"
10
+ spec.email = ["isaac@isaaccambron.com"]
11
+ spec.files = %w(README.md extensionator.gemspec) + Dir["lib/**/*.rb"]
12
+ spec.homepage = "http://icambron.github.com/extensionator/"
13
+ spec.licenses = %w(MIT)
14
+ spec.name = "extensionator"
15
+ spec.require_paths = %w(lib)
16
+ spec.required_ruby_version = ">= 1.9.3"
17
+ spec.required_rubygems_version = ">= 1.3.5"
18
+ spec.summary = spec.description
19
+ spec.version = Extensionator::VERSION
20
+ end
@@ -0,0 +1,66 @@
1
+ require "digest/sha1"
2
+ require "find"
3
+ require "openssl"
4
+ require "pathname"
5
+ require "zip"
6
+
7
+ module Extensionator
8
+ VERSION = "0.0.1"
9
+
10
+ def self.create(dir, key_file, dest_filename, opts = {})
11
+ priv_key = read_key(key_file)
12
+ zip_str = zip(dir, opts)
13
+ sig_bytes = sign(zip_str, priv_key)
14
+ write(zip_str, sig_bytes, priv_key, dest_filename)
15
+ end
16
+
17
+ def self.read_key(key_file)
18
+ OpenSSL::PKey::RSA.new(File.read(key_file))
19
+ end
20
+
21
+ def self.zip(dir, opts = {})
22
+ Zip::File.add_buffer do |zip|
23
+ Find.find(dir) do |path|
24
+ case
25
+ when path == dir
26
+ next
27
+ when (opts[:exclude] && path =~ opts[:exclude])
28
+ Find.prune
29
+ when File.directory?(path)
30
+ zip.mkdir(relative_path(dir, path))
31
+ else
32
+ zip.add(relative_path(dir, path), path)
33
+ end
34
+ end
35
+ end.string
36
+ end
37
+
38
+ def self.sign(zip_str, priv_key)
39
+ priv_key.sign(OpenSSL::Digest::SHA1.new, zip_str)
40
+ end
41
+
42
+ def self.write(zip_str, sig_bytes, priv_key, dest_filename)
43
+ pub_key_bytes = priv_key.public_key.to_der
44
+
45
+ #See https://developer.chrome.com/extensions/crx for the format description
46
+ File.open(dest_filename, "wb") do |file|
47
+ file << "Cr24"
48
+ file << format_size(2)
49
+ file << format_size(pub_key_bytes.size)
50
+ file << format_size(sig_bytes.size)
51
+ file << pub_key_bytes
52
+ file << sig_bytes
53
+ file << zip_str
54
+ end
55
+ end
56
+
57
+ def self.relative_path(base, target)
58
+ from = Pathname.new(base)
59
+ to = Pathname.new(target)
60
+ to.relative_path_from(from).to_s
61
+ end
62
+
63
+ def self.format_size(num)
64
+ return [num].pack("V")
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: extensionator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Isaac Cambron
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: A Ruby tool for packaging Chrome extensions
42
+ email:
43
+ - isaac@isaaccambron.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - extensionator.gemspec
50
+ - lib/extensionator.rb
51
+ homepage: http://icambron.github.com/extensionator/
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.9.3
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.5
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.2.2
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: A Ruby tool for packaging Chrome extensions
75
+ test_files: []