|
1 | 1 | # encoding: UTF-8
|
2 | 2 |
|
3 |
| -# chrome/src/manifest.json depends on VERSION and chrome/src/images/icon##.png (at least their names) |
4 |
| -# build/#{chrome_package} depends on chrome/src/manifest.json, chrome/src/images/*, @parser, @script |
5 |
| - |
6 |
| -# build/#{safari_packge} depends on safari/src/*; safari/src/Info.plist depends on VERSION |
7 |
| - |
8 |
| -# in chrome_dev, images/ and manifest.json depend on chrome/src/* |
9 |
| - |
10 |
| -# :automatch depends on @automatch and @script -- need some way to detect if already inserted, or figure out how to do use both without just shoving it in |
11 |
| - |
12 |
| -# how to organize? dev:automatch, dev:chrome, dev:safari, build, build:chrome, build:safari, version, etc. |
13 |
| - |
14 | 3 | require 'rake/clean'
|
15 | 4 |
|
16 |
| -CLEAN.include Dir.glob('./**/*~') |
17 |
| -CLEAN.include Dir.glob('./**/.*~') |
18 |
| -CLEAN.include 'images/' |
19 |
| -CLEAN.include 'manifest.json' |
20 |
| -CLEAN.include 'chrome/src/*.js' |
| 5 | +CLEAN.include 'tmp/*' |
| 6 | +CLEAN.include 'build/*/' |
21 | 7 | CLOBBER.include 'build/*'
|
22 | 8 |
|
23 |
| -@script = 'Goko_Live_Log_Viewer.user.js' |
24 |
| -@parser = 'set_parser.js' |
25 |
| -@automatch = '../goko-dominion-tools/web/Goko_automatch.user.js' |
26 |
| - |
27 |
| -# first line inside the main function of @script |
28 |
| -@start_of_foo = 13 |
29 |
| -@end_of_foo = 1204 |
30 |
| - |
31 |
| -# content of the first line in @parser to import @script |
32 |
| -@import_start = " script.src = 'http://dom.retrobox.eu/js/1.0.0/set_parser.js'; |
33 |
| -" |
34 |
| - |
35 |
| -# content of the first line in @script after the importing of @parser is complete |
36 |
| -@after_import_end = " script.textContent = '('+ fn +')();'; |
37 |
| -" |
38 |
| - |
39 |
| -@host_line = ' host = "http://gokologs.drunkensailor.org"; |
40 |
| -' |
41 |
| - |
42 |
| -@localhost_line = ' host = "http://localhost"; |
43 |
| -' |
| 9 | +SCRIPT = 'src/ext/Goko_Live_Log_Viewer.user.js' |
| 10 | +PARSER = 'src/dev/set_parser.js' |
44 | 11 |
|
45 |
| -@name = 'Dominion-Online-User-Extension' |
46 |
| -@version = File.read('VERSION').strip |
47 |
| -@versioned_name = "#{@name}-#{@version}" |
48 |
| - |
49 |
| -def insert_set_parser_into_main_script out_file_name |
50 |
| - out = File.new(out_file_name, 'w') |
51 |
| - File.open(@script) do |script| |
52 |
| - current_line = 1 |
53 |
| - skip_this_line = false |
54 |
| - script.each_line do |line| |
55 |
| - out.write(File.read(@parser)) if current_line == @start_of_foo |
56 |
| - skip_this_line = true if line == @import_start |
57 |
| - skip_this_line = false if line == @after_import_end |
58 |
| - out.write(line) unless skip_this_line |
59 |
| - current_line += 1 |
60 |
| - end |
61 |
| - end |
62 |
| - out.close |
63 |
| -end |
64 |
| - |
65 |
| -def insert_automatch_into_main_script |
66 |
| - out = File.new('tmp', 'w') |
67 |
| - File.open(@script) do |script| |
68 |
| - current_line = 1 |
69 |
| - script.each_line do |line| |
70 |
| - if current_line == @end_of_foo |
71 |
| - File.open(@automatch) do |automatch| |
72 |
| - automatch.each_line do |a_line| |
73 |
| - if a_line == @host_line |
74 |
| - out.write(@localhost_line) |
75 |
| - else |
76 |
| - out.write(a_line) unless a_line == "var foo = function () { |
77 |
| -" || a_line == "}; document.addEventListener ('DOMContentLoaded', foo); |
78 |
| -" |
79 |
| - end |
80 |
| - end |
81 |
| - end |
82 |
| - end |
83 |
| - out.write(line) |
84 |
| - current_line += 1 |
85 |
| - end |
86 |
| - end |
87 |
| - out.close |
88 |
| - FileUtils.mv 'tmp', @script |
89 |
| -end |
| 12 | +CREATE_AND_SIGN = 'src/dev/createAndSign.sh' |
| 13 | +WRAPPER = 'src/dev/runInPageContext.js' |
90 | 14 |
|
| 15 | +VERSION = 'VERSION' |
91 | 16 |
|
| 17 | +CHROME_MANIFEST = 'chrome/manifest.json' |
| 18 | +CHROME_IMAGES = 'chrome/images/' |
92 | 19 |
|
| 20 | +FIREFOX_PACKAGE = 'firefox/package.json' |
93 | 21 |
|
94 |
| -# TODO: improve this version stuff: maybe use ruby's FileList to generate the file tasks, with a hash to map files to their version string functions |
95 |
| -def increment_version |
96 |
| - version_parts = @version.split('.') |
97 |
| - version_parts[2] = version_parts[2].to_i + 1 |
98 |
| - version_parts.join('.') |
99 |
| -end |
| 22 | +SAFARI_INFO = 'safari/Info.plist' |
| 23 | +SAFARI_SETTINGS = 'safari/Settings.plist' |
100 | 24 |
|
101 |
| -task :update_version, :new_version do |t, args| |
102 |
| - @version = args[:new_version] || increment_version |
103 |
| - File.open("VERSION", "w") {|f| f.puts @version} |
| 25 | +def get_version |
| 26 | + File.read(VERSION).strip |
104 | 27 | end
|
105 | 28 |
|
106 |
| -def update_version_in_file old, new, target |
107 |
| - text = File.read(target) |
108 |
| - replace = text.gsub(/#{old}/, "#{new}") |
109 |
| - File.open(target, "w") {|f| f.puts replace} |
| 29 | +def replace_pattern_in_file(old_pattern, new_string, target) |
| 30 | + text = File.read(target).gsub(/#{old_pattern}/, "#{new_string}") |
| 31 | + File.open(target, 'w') { |f| f.puts text } |
110 | 32 | end
|
111 | 33 |
|
112 |
| -file "chrome/src/manifest.json" => "VERSION" do |t| |
113 |
| - def manifest_version v |
114 |
| - "\"version\": \"#{v}\"," |
115 |
| - end |
116 |
| - old_v_pattern = ".*" |
117 |
| - update_version_in_file (manifest_version old_v_pattern), (manifest_version @version), t.name |
| 34 | +def insert_set_parser_into_main_script(out_file_name) |
| 35 | + out = File.new(out_file_name, 'w') |
| 36 | + out.write(File.read(PARSER)) |
| 37 | + out.write(File.read(SCRIPT)) |
| 38 | + out.close |
118 | 39 | end
|
119 | 40 |
|
120 |
| -file "safari/src/Info.plist" => "VERSION" do |t| |
121 |
| - def info_version v |
122 |
| - " <key>CFBundleShortVersionString</key> |
123 |
| - <string>#{v}<\/string> |
124 |
| -" |
125 |
| - end |
126 |
| - def info_version_2 v |
127 |
| - " <key>CFBundleVersion</key> |
128 |
| - <string>#{v}<\/string> |
129 |
| -" |
| 41 | +def run_in_page_context(file) |
| 42 | + f = File.read(file) |
| 43 | + t = File.new(file, 'w') |
| 44 | + File.open(WRAPPER) do |w| |
| 45 | + w.each_line do |l| |
| 46 | + t.write(l.strip == '// insert file here' ? f : l) |
| 47 | + end |
130 | 48 | end
|
131 |
| - old_v_pattern = ".*" |
132 |
| - update_version_in_file (info_version old_v_pattern), (info_version @version), t.name |
133 |
| - update_version_in_file (info_version_2 old_v_pattern), (info_version_2 @version), t.name |
134 |
| -end |
135 |
| - |
136 |
| -desc 'Increment the version number by 0.0.1, or set a new version' |
137 |
| -task :version, [:new_version] => [:update_version, "chrome/src/manifest.json", "safari/src/Info.plist"] |
138 |
| - |
139 |
| - |
140 |
| - |
141 |
| -desc 'insert the automatch script into the main extension script' |
142 |
| -task :automatch do |
143 |
| - insert_automatch_into_main_script |
144 |
| - puts 'automatch script inserted into main script' |
145 |
| -end |
146 |
| - |
147 |
| -desc 'Use this directory as an "unpacked extension" for developing on Chrome' |
148 |
| -task :chrome_dev do |
149 |
| - FileUtils.cp_r ['chrome/src/images', 'chrome/src/manifest.json'], '.' |
150 |
| - puts 'ready to use this directory as unpacked extension' |
151 |
| -end |
152 |
| - |
153 |
| -desc 'Create a .zip file for publishing in the Chrome store' |
154 |
| -task :chrome_publish do |
155 |
| - insert_set_parser_into_main_script "chrome/src/#{@script}" |
156 |
| - FileUtils.rm_rf "chrome/#{@versioned_name}.zip" |
157 |
| - sh "cd chrome/src && zip -r ../../build/#{@versioned_name}.zip . && cd -" |
158 |
| - puts "build/#{@versioned_name}.zip created and ready to publish" |
159 |
| -end |
160 |
| - |
161 |
| -desc 'Create a Safari extension file for development' |
162 |
| -task :safari_dev do |
163 |
| - tmp_ext_dir = "#{@name}.safariextension" |
164 |
| - FileUtils.mkdir_p tmp_ext_dir |
165 |
| - insert_set_parser_into_main_script "#{tmp_ext_dir}/#{@script}" |
166 |
| - FileUtils.cp ['safari/src/Info.plist', 'safari/src/Settings.plist'], tmp_ext_dir |
167 |
| - sh 'safari/createAndSign.sh' |
168 |
| - FileUtils.rm_rf tmp_ext_dir |
169 |
| - FileUtils.mv "#{@name}.safariextz", "build/#{@name}-dev.safariextz" |
170 |
| - puts "build/#{@name}-dev.safariextz created" |
171 |
| -end |
172 |
| - |
173 |
| -desc 'Create a versioned Safari extension file for publishing' |
174 |
| -task :safari_publish => [:safari_dev] do |
175 |
| - FileUtils.mv "build/#{@name}-dev.safariextz", "build/#{@versioned_name}.safariextz" |
176 |
| - puts "build/#{@name}-dev.safariextz renamed to build/#{@versioned_name}.safariextz" |
| 49 | + t.close |
177 | 50 | end
|
178 | 51 |
|
179 |
| -desc 'Use this directory as an "unpacked extension" for developing on Opera' |
180 |
| -task :opera_dev => [:chrome_dev] |
| 52 | +Dir.glob('tasks/*.rake').each { |r| import r } |
181 | 53 |
|
182 |
| -desc 'Create a .zip file for publishing in the Opera store' |
183 |
| -task :opera_publish => [:chrome_publish] |
| 54 | +desc 'Build packages for all supported browsers' |
| 55 | +task :default => ['build:chrome', 'build:firefox', 'build:safari'] |
0 commit comments