forked from ticean/ptchfrknzb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
96 lines (85 loc) · 2.58 KB
/
Rakefile
File metadata and controls
96 lines (85 loc) · 2.58 KB
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
require 'rubygems'
require 'json/pure'
require 'rake'
require 'rake/clean'
require 'pathname'
begin
require 'crxmake'
rescue LoadError
warn "require jsonschema"
warn "gem sources -a http://gems.github.com"
warn "gem install Constellation-crxmake"
exit 1
end
require 'crxmake'
require 'open-uri'
project_name = 'Ptchfrknzb'
github_account = 'ticean@gmail.com' # `git config github.user`.chomp
github_project = 'ptchfrknzb'
extension_url = "http://cloud.github.com/downloads/#{github_account}/#{github_project}/#{project_name}.crx"
root_path = Pathname.new(__FILE__).parent
src_path = root_path.join('src')
manifest_path = src_path.join('manifest.json')
update_path = src_path.join('update.xml')
output_path = root_path.join('bin')
pem_file = ENV['PEM'] || root_path.join(project_name + '.pem')
task :release => [:clean, :update_xml, :package]
task :default => ['manifest:validate']
CLEAN.include ['**/.*.sw?', '.*.sw?']
namespace :manifest do
desc "json schema check"
task :validate do
begin
require 'jsonschema'
rescue LoadError
warn "require jsonschema"
warn "gem sources -a http://gems.github.com"
warn "gem install Constellation-jsonschema"
exit 1
end
data = JSON.parse manifest_path.read
schema = JSON.parse open('http://gist.github.com/179669.txt').read # manifest.json schema by os0x
puts "JSON schema check."
begin
JSON::Schema.validate(data, schema)
puts "JSON schema valid."
rescue JSON::Schema::ValueError => e
puts "JSON schema invalid!"
puts e.to_s
end
end
end
task :update_xml do
puts "update xml: #{update_path}"
manifest = JSON.parse manifest_path.read
raise 'require id & version' unless manifest['id'] && manifest['version']
template = <<-EOF
<gupdate xmlns="http://www.google.com/update2/response" protocol="2.0">
<app appid="#{manifest['id']}">
<updatecheck codebase="#{extension_url}" version="#{manifest['version']}" />
</app>
</gupdate>
EOF
update_path.open('w') do |f|
f.puts template
end
end
task :package do
output_path.mkpath unless output_path.directory?
crx = output_path.join("#{project_name}.crx").to_s
options = {
:ex_dir => src_path.to_s,
:crx_output => crx,
# :verbose => true,
:ignorefile => /\.sw[op]/,
:ignoredir => /\.(?:svn|git|cvs)/
}
if pem_file && Pathname.new(pem_file.to_s).exist?
options[:pkey] = pem_file.to_s
else
options[:pkey_output] = pem_file.to_s
end
CrxMake.make(options)
puts "generated package: #{crx}"
puts "generated pkem(.pem): #{options[:pkey_output]}" if options[:pkey_output]
end