Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

176 lines (154 sloc) 4.929 kb
ROOT = File.expand_path('.')
ADDON = File.expand_path(File.join(ROOT))
FIREFOX = File.join(ADDON, 'firefox')
DST = File.join(ROOT, 'build')
TMP = File.join(ROOT, 'tmp')
SUPPORT = File.join(ROOT, 'support')
TEST = File.join(ROOT, 'test')
JQUERY_DIR = File.join(ROOT, 'jquery')
require 'rubygems'
begin
require 'colored'
rescue LoadError
raise 'You must "gem install colored" to use terminal colors'
end
def file_color(text); text.yellow; end
def dir_color(text); text.blue; end
def cmd_color(text); text.magenta; end
#
# you can use FileUtils: http://corelib.rubyonrails.org/classes/FileUtils.html
#
require 'find'
# copies directory tree without .svn, .git and other temporary files
def cp_dir(src, dst)
puts "#{cmd_color('copying')} #{dir_color(src)}"
puts " -> #{dir_color(dst)}"
Find.find(src) do |fn|
next if fn =~ /\/\./
next if fn =~ /Thumbs\.db/
r = fn[src.size..-1]
if File.directory? fn
mkdir(File.join(dst, r), {:verbose => false}) unless File.exist? File.join(dst,r)
else
cp(fn, File.join(dst, r), {:verbose => false})
end
end
end
def cp_file(src, dst)
puts "#{cmd_color('copying')} #{file_color(src)}"
puts " -> #{file_color(dst)}"
cp(src, dst, {:verbose => false})
end
def dep(src)
s = File.expand_path src
rs = s[FIREFOX.size..-1]
d = File.join(TMP, rs)
puts "#{cmd_color('copying')} #{file_color(s)}"
puts " -> #{file_color(d)}"
cp(s, d, {:verbose => false})
end
def dep2(src, add='')
s = File.expand_path src
rs = s[ROOT.size..-1]
d = File.join(TMP, add, rs)
puts "#{cmd_color('copying')} #{file_color(s)}"
puts " -> #{file_color(d)}"
cp(s, d, {:verbose => false})
end
def my_mkdir(dir)
puts "#{cmd_color('creating directory')} #{dir_color(dir)}"
mkdir(dir, {:verbose => false})
end
def parse_version()
f = File.new(File.join(FIREFOX, 'install.rdf'))
text = f.read
unless text=~/<em:version>([^<]*)<\/em:version>/
puts "#{'Version not found'.red}"
exit
end
$1
end
def die(s)
puts(s.red)
exit(1)
end
def patch(filepath, matcher, replacer)
puts "Patching #{filepath[ROOT.size+1..-1].blue} with #{replacer.to_s.yellow}"
applied = false
lines = []
File.open(filepath, 'r') do |f|
f.each do |line|
lines << line.gsub(matcher, replacer)
applied ||= lines[-1]!=line
end
end
File.open(filepath, "w") do |f|
f << lines.join
end
applied
end
def check_if_addon_exists()
die("firequery not found!\n expected to be in #{ADDON}") unless File.exists?(ADDON)
end
def sys(cmd)
puts ("> "+cmd).blue
system(cmd)
end
################################################################################
desc "Prepare XPI"
task :default do
check_if_addon_exists()
version = parse_version()
remove_dir(TMP) if File.exists?(TMP) # recursive!
mkdir(TMP, {:verbose => false})
cp_dir(File.join(FIREFOX, 'chrome'), File.join(TMP, "chrome"))
cp_dir(File.join(FIREFOX, 'defaults'), File.join(TMP, "defaults"))
dep(File.join(FIREFOX, 'chrome.manifest'))
dep(File.join(FIREFOX, 'install.rdf'))
dep(File.join(FIREFOX, 'license.txt'))
my_mkdir(DST) unless File.exist?(DST)
firequery_js_path = File.join(TMP, "chrome", "content", "firequery.js")
patch(firequery_js_path, /(dbg\(.*\);)/, "/*\\1*/")
res = "#{DST}/firequery-#{version}.xpi"
File.unlink(res) if File.exists?(res)
puts "#{cmd_color('zipping')} #{file_color(res)}"
Dir.chdir(TMP) do
puts ('need zip on command line (download http://www.info-zip.org/Zip.html)').red unless system("zip -r \"#{res}\" *");
end
remove_dir(TMP) if File.exist?(TMP) # recursive!
puts "\ninstaller is in #{res.yellow}, enjoy!"
end
desc "Resets version in all relevant sources"
task :version do
check_if_addon_exists()
version = ARGV[1] or die("Please specify a version as first parameter")
firequery_js_path = File.join(FIREFOX, 'chrome', 'content', 'firequery.js')
if not patch(firequery_js_path, /version: '([0-9\.])+'/, "version: '#{version}'")
puts " #{"patching had no effect".red}"
end
install_rdf_path = File.join(FIREFOX, 'install.rdf')
if not patch(install_rdf_path, /<em:version>([0-9\.])+<\/em:version>/, "<em:version>#{version}</em:version>")
puts " #{"patching had no effect".red}"
end
exit(0)
end
desc "Updates jquery in test project"
task :update_jquery do
if File.exists? JQUERY_DIR then
Dir.chdir JQUERY_DIR do
sys("svn up")
end
else
Dir.chdir ROOT do
sys("svn co http://jqueryjs.googlecode.com/svn/trunk jquery")
end
end
Dir.chdir File.join(JQUERY_DIR, 'jquery') do
sys("make jquery")
end
js = File.join(JQUERY_DIR, 'jquery', 'dist', 'jquery.js')
test = File.join(TEST, 'jquery.js')
content = File.join(FIREFOX, 'chrome', 'resources', 'jquery.js')
sys("cp \"#{js}\" \"#{test}\"")
sys("cp \"#{js}\" \"#{content}\"")
end
Jump to Line
Something went wrong with that request. Please try again.