-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
74 lines (53 loc) · 1.89 KB
/
Rakefile
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
require 'rubygems'
require 'zip'
desc "Extensio build script"
task :build, :version do |t, args|
### Version
version = args[:version]
output_path = 'product'
product_name = 'tabkit-mouse-gestures'
# Default read file from install.rdf
if version.nil?
meta_file = File.read('install.rdf')
version_from_file = meta_file.match(/<(?:em:)?version>([\w\.]+)<\/(?:em:)?version>/i)[1] # Match data in brackets start at one
version = version_from_file
end
### Files to include
# ["content/bindings.xml"]
everything = Dir.glob "**/*"
excluded_regexp = /(\.(xpi|zip)|Rakefile|Gemfile.*|#{output_path})$/i
included = everything.select do |path|
path !~ excluded_regexp
end
input_filenames = included
no_of_files = input_filenames.size
### Folder
# Create Dir if not exist
Dir.mkdir(output_path) unless File.exists?(output_path)
### File name
product_filename = "#{product_name} #{version}"
product_ext = '.xpi'
# To avoid override, add time after version
if File.exists?(File.join(output_path, "#{product_filename}#{product_ext}"))
product_filename << " - "
product_filename << Time.now.strftime("%F")
end
final_filename = "#{product_filename}#{product_ext}"
# Still exists? properly development use, just overwrite
if File.exists?(File.join(output_path, final_filename))
puts "Deleting should be development version"
File.delete(File.join(output_path, final_filename))
end
### Zip
puts "About to build #{final_filename} with #{no_of_files} files"
Zip::File.open(File.join(output_path, final_filename), Zip::File::CREATE) do |zipfile|
input_filenames.each do |filename|
# Two arguments:
# - The name of the file as it will appear in the archive
# - The original file, including the output_path to find it
zipfile.add(filename, filename)
end
end
puts "#{final_filename} Built"
end
task default: :build