-
Notifications
You must be signed in to change notification settings - Fork 14
/
rakefile
149 lines (124 loc) · 4.23 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
require 'rake'
require 'rubygems'
ROOT = File.expand_path('.')
SRC = ROOT
CONTENT = File.join(SRC, 'chrome', 'content')
DST = File.join(ROOT, 'build')
TMP = File.join(ROOT, 'tmp')
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
def red(s); s.red; end
def blue(s); s.blue; end
def yellow(s); s.yellow; end
#
# you can use FileUtils: http://corelib.rubyonrails.org/classes/FileUtils.html
#
require 'find'
def file_color(text); yellow(text); end
def dir_color(text); blue(text); end
def cmd_color(text); green(text); end
# 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 =~ /\/\./
r = fn[src.size..-1]
if File.directory? fn
mkdir File.join(dst,r) unless File.exist? File.join(dst,r)
else
cp(fn, File.join(dst,r))
end
end
end
def cp_file(src, dst)
puts "#{cmd_color('copying')} #{file_color(src)}"
puts " -> #{file_color(dst)}"
cp(src, dst)
end
def dep(src)
s = File.expand_path src
rs = s[SRC.size..-1]
d = File.join(TMP, rs)
puts "#{cmd_color('copying')} #{file_color(s)}"
puts " -> #{file_color(d)}"
cp(s, d)
end
def my_mkdir(dir)
puts "#{cmd_color('creating directory')} #{dir_color(dir)}"
mkdir dir
end
def parse_version()
f = File.new(File.join(SRC, 'install.rdf'))
text = f.read
unless text=~/<em:version>([^<]*)<\/em:version>/
puts "#{red('Version not found')}"
exit
end
$1
end
################################################################################
desc "prepare release XPI"
task :release do
version = parse_version()
$stderr = File.new('/dev/null', 'w') unless ENV["verbose"]
remove_dir(TMP) if File.exists?(TMP) # recursive!
mkdir(TMP)
cp_dir(File.join(SRC, 'chrome'), File.join(TMP, "chrome"))
cp_dir(File.join(SRC, 'defaults'), File.join(TMP, "defaults"))
dep(File.join(SRC, 'chrome.manifest'))
dep(File.join(SRC, 'install.rdf'))
dep(File.join(SRC, 'license.txt'))
`rm -rf "#{File.join(TMP, "chrome", "content", "codemirror")}"` # codemirror files are not needed, scripts should include generated codemirror.js
my_mkdir(DST) unless File.exist?(DST)
res = "#{DST}/firerainbow-#{version}.xpi"
File.unlink(res) if File.exists?(res)
puts "#{cmd_color('zipping')} #{file_color(res)}"
Dir.chdir(TMP) do
puts red('need zip on command line (download http://www.info-zip.org/Zip.html)') unless system("zip -r \"#{res}\" *");
end
remove_dir(TMP) if File.exist?(TMP) # recursive!
end
desc "generate sandboxed codemirror source"
task :sandbox do
sources = ["util.js", "tokenize.js", "tokenizejavascript.js", "parsejavascript.js", "parsecss.js", "parsexml.js", "parsehtmlmixed.js","stringstream.js"]
output = File.join(CONTENT, "codemirror.js")
text = "// !!! DO NOT EDIT THIS FILE (GENERATED) !!!\n"
text += "// this file was generated from codemirror subdirectory by `rake sandbox` task\n"
text += "\n"
text += "\n"
license_lines = File.new(File.join(CONTENT, 'codemirror', 'LICENSE')).readlines
license_lines.map! do |line|
"// " + line
end
text += license_lines.join
text += "\n"
text += "\n"
# isolate codemirror into separate namespace
text += "var codemirror = (function() {\n"
text += "var Editor = {};var indentUnit = 2;var window=this;\n"
sources.each do |source|
text += File.new(File.join(CONTENT, 'codemirror', source)).read + "\n"
end
text += " return this;\n"
text += "})();\n"
# do some souce code hacks
text.gsub!("var JSParser", "this.JSParser")
text.gsub!("var HTMLMixedParser", "this.HTMLMixedParser")
text.gsub!("var XMLParser", "this.XMLParser")
text.gsub!("var CSSParser", "this.CSSParser")
text.gsub!("var stringStream", "this.stringStream")
text.gsub!("var StopIteration", "this.StopIteration")
text.gsub!("function forEach", "this.forEach = function")
File.open(output, 'w') do |f|
f.write(text)
end
end
task :default => :release