Class: Tay::Packager

Inherits:
Object
  • Object
show all
Defined in:
lib/tay/packager.rb

Overview

Takes a Tay::Specification and builds it. It compiles the assets, writes the manifest, and copies everything to the output path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(specification, base_dir, build_dir) ⇒ Packager

Create a new builder. You must pass the specification, full path to the source directory and an optional output directory which defaults to base_dir + ‘/build’



16
17
18
19
20
# File 'lib/tay/packager.rb', line 16

def initialize(specification, base_dir, build_dir)
  @spec = specification
  @base_dir = Pathname.new(base_dir)
  @build_dir = Pathname.new(build_dir)
end

Instance Attribute Details

#specObject (readonly)

Pointer to the relevant Tay::Specification



10
11
12
# File 'lib/tay/packager.rb', line 10

def spec
  @spec
end

Instance Method Details

#extension_idObject

Calculate the extension’s ID from the key Core concepts from supercollider.dk



47
48
49
50
51
52
53
# File 'lib/tay/packager.rb', line 47

def extension_id
  raise Tay::PrivateKeyNotFound.new unless private_key_exists?

  public_key = OpenSSL::PKey::RSA.new(File.read(full_key_path)).public_key.to_der
  hash = Digest::SHA256.hexdigest(public_key)[0...32]
  hash.unpack('C*').map{ |c| c < 97 ? c + 49 : c + 10 }.pack('C*')
end

#full_key_pathObject

Return the absolute path to the private key



63
64
65
# File 'lib/tay/packager.rb', line 63

def full_key_path
  Pathname.new(spec.key_path).expand_path(@base_dir)
end

#private_key_exists?Boolean

Do we have an existing key file?

Returns:

  • (Boolean)


57
58
59
# File 'lib/tay/packager.rb', line 57

def private_key_exists?
  full_key_path.exist?
end

#write_crx(out_path) ⇒ Object

Write a signed crx file to out_path for self hosting



35
36
37
38
39
40
41
42
# File 'lib/tay/packager.rb', line 35

def write_crx(out_path)
  CrxMake.make(
    :ex_dir => @build_dir,
    :pkey   => full_key_path,
    :crx_output => out_path,
    :verbose => false
  )
end

#write_new_keyObject

Generate a key with OpenSSL and write it to the key path



69
70
71
72
73
# File 'lib/tay/packager.rb', line 69

def write_new_key
  File.open(full_key_path, 'w') do |f|
    f.write OpenSSL::PKey::RSA.generate(1024).export()
  end
end

#write_zip(out_path) ⇒ Object

Write a signed zip file to out_path for upload to the Web Store



24
25
26
27
28
29
30
31
# File 'lib/tay/packager.rb', line 24

def write_zip(out_path)
  CrxMake.zip(
    :ex_dir => @build_dir,
    :pkey   => full_key_path,
    :zip_output => out_path,
    :verbose => false
  )
end