-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuild.thor
executable file
·77 lines (60 loc) · 1.38 KB
/
build.thor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require "rubygems"
require "thor"
require "json"
require "nokogiri"
class Build < Thor::Group
include Thor::Actions
class_option :destination, :type => :string, :default => './build'
def self.source_root
File.dirname(__FILE__)
end
def convert_coffee_files
run 'coffee -c .'
end
def prepare_dir
remove_dir destination
empty_directory destination
end
def copy_icons
copy manifest['icons']
end
def copy_content_scripts
manifest['content_scripts'].each do |scripts|
copy scripts['css']
copy scripts['js']
end
end
def copy_web_accessible_resources
copy manifest['web_accessible_resources']
end
def copy_background_page
copy manifest['background']
end
def copy_background_scripts
doc = Nokogiri::HTML(File.open('background.html'))
doc.css('head script').each do |script|
file = script.attribute('src')
copy_file file, File.join(destination, file)
end
end
def copy_manifest
file = 'manifest.json'
copy_file file, File.join(destination, file)
end
def packaging
run 'zip -r build.zip build'
end
private
def copy(list)
list.each do |k, v|
file = list.is_a?(Hash) ? v : k
copy_file file, File.join(destination, file)
end
end
def destination
options[:destination]
end
def manifest
@manifest ||= JSON.parse(File.read('manifest.json'))
end
end